1.依赖安装 (集群部署前提条件)
环境:三台centos7系统 ip自己规划就行
貔貅云:ansible快速部署k8s集群,
依赖条件 :依赖安装
仅需要在部署节点安装即可,集群运行节点 无需执行 1.直接安装 2.脚本安装 两选一即可
安装步骤:
1.直接安装-有网络情况
curl https://raw.githubusercontent.com/gopixiu-io/kubez-ansible/master/tools/setup_env.sh | bash
2.脚本安装,
#自动获取,网络通时,通过curl命令直接获取脚本到本地
curl https://raw.githubusercontent.com/gopixiu-io/kubez-ansible/master/tools/setup_env.sh -o setup_env.sh
#手动获取,自动获取失败时,一般因为网络不通或者未安装curl
#拷贝项目的tools/setup_env.sh,并保存到 linux里面vi setup_env.sh
1 #!/usr/bin/env bash 2 # 3 # Bootstrap script to install kubernetes env. 4 # 5 # This script is intended to be used for install kubernetes env. 6 7 REPO=gopixiu-io 8 # 选择需要安装的分支,默认 master 分支 9 BRANCH=master 10 11 TARGET=kubez-ansible-${BRANCH//\//-} 12 13 function _ensure_lsb_release { 14 if type lsb_release >/dev/null 2>&1; then 15 return 16 fi 17 18 if type apt-get >/dev/null 2>&1; then 19 apt-get -y install lsb-release 20 elif type yum >/dev/null 2>&1; then 21 yum -y install redhat-lsb-core 22 fi 23 } 24 25 function _is_distro { 26 if [[ -z "$DISTRO" ]]; then 27 _ensure_lsb_release 28 DISTRO=$(lsb_release -si) 29 fi 30 31 [[ "$DISTRO" == "$1" ]] 32 } 33 34 function is_ubuntu { 35 _is_distro "Ubuntu" 36 } 37 38 function is_debian { 39 _is_distro "Debian" 40 } 41 42 function is_centos { 43 _is_distro "CentOS" 44 } 45 46 function prep_work { 47 if is_centos; then 48 if [[ "$(systemctl is-enabled firewalld)" == "active" ]]; then 49 systemctl disable firewalld 50 fi 51 if [[ "$(systemctl is-active firewalld)" == "enabled" ]]; then 52 systemctl stop firewalld 53 fi 54 55 configure_centos_sources 56 yum -y install epel-release 57 yum -y install git python-pip unzip 58 elif is_ubuntu || is_debian; then 59 if [[ "$(systemctl is-enabled ufw)" == "active" ]]; then 60 systemctl disable ufw 61 fi 62 if [[ "$(systemctl is-active ufw)" == "enabled" ]]; then 63 systemctl stop ufw 64 fi 65 66 if is_debian; then 67 configure_debian_sources 68 else 69 configure_ubuntu_sources 70 fi 71 apt-get update 72 apt install -y git python-pip unzip 73 else 74 echo "Unsupported Distro: $DISTRO" 1>&2 75 exit 1 76 fi 77 } 78 79 function cleanup { 80 if is_centos; then 81 yum clean all 82 elif is_ubuntu || is_debian; then 83 apt-get clean 84 else 85 echo "Unsupported Distro: $DISTRO" 1>&2 86 exit 1 87 fi 88 } 89 90 function configure_pip { 91 mkdir -p ~/.pip 92 cat > ~/.pip/pip.conf << EOF 93 [global] 94 trusted-host = mirrors.aliyun.com 95 index-url = http://mirrors.aliyun.com/pypi/simple/ 96 EOF 97 } 98 99 function configure_centos_sources { 100 if [ ! -f "/etc/yum.repos.d/CentOS-Base.repo.backup" ];then 101 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 102 fi 103 # CentOS 7 104 curl http://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/CentOS-Base.repo 105 } 106 107 function configure_debian_sources { 108 if [ ! -f "/etc/apt/sources.list.backup" ];then 109 mv /etc/apt/sources.list /etc/apt/sources.list.backup 110 fi 111 # debian 10.x (buster) 112 cat > /etc/apt/sources.list << EOF 113 deb https://mirrors.aliyun.com/debian/ buster main non-free contrib 114 deb-src https://mirrors.aliyun.com/debian/ buster main non-free contrib 115 deb https://mirrors.aliyun.com/debian-security buster/updates main 116 deb-src https://mirrors.aliyun.com/debian-security buster/updates main 117 deb https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib 118 deb-src https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib 119 deb https://mirrors.aliyun.com/debian/ buster-backports main non-free contrib 120 deb-src https://mirrors.aliyun.com/debian/ buster-backports main non-free contrib 121 EOF 122 } 123 124 function configure_ubuntu_sources() { 125 if [ ! -f "/etc/apt/sources.list.backup" ];then 126 mv /etc/apt/sources.list /etc/apt/sources.list.backup 127 fi 128 # ubuntu 18.04(bionic) 129 cat > /etc/apt/sources.list << EOF 130 deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse 131 deb-src https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse 132 deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse 133 deb-src https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse 134 deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse 135 deb-src https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse 136 deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 137 deb-src https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 138 EOF 139 } 140 141 function install_ansible { 142 if is_centos; then 143 yum -y install ansible 144 elif is_ubuntu||is_debian; then 145 apt-get -y install ansible 146 else 147 echo "Unsupported Distro: $DISTRO" 1>&2 148 exit 1 149 fi 150 } 151 152 function download_kubez_ansible { 153 curl https://codeload.github.com/${REPO}/kubez-ansible/zip/refs/heads/${BRANCH} -o ${TARGET}.zip 154 if [ $? -ne 0 ]; then 155 exit 1 156 fi 157 158 unzip -q ${TARGET}.zip && mv ${TARGET} /tmp/kubez-ansible && git init /tmp/kubez-ansible 159 } 160 161 function install_kubez_ansible { 162 if [[ ! -d /tmp/kubez-ansible ]]; then 163 download_kubez_ansible 164 fi 165 # prepare the configuration for deploy 166 cp -r /tmp/kubez-ansible/etc/kubez/ /etc/ 167 cp /tmp/kubez-ansible/ansible/inventory/multinode . 168 169 install_ansible 170 171 pip install -r /tmp/kubez-ansible/requirements.txt 172 pip install /tmp/kubez-ansible/ 173 } 174 175 # prepare and install kubernetes cluster 176 prep_work 177 configure_pip 178 # cleanup 179 install_kubez_ansible
#执行安装脚本
bash setup_env.sh
验证 #执行kubez-ansible 有正常回显 kubez-ansible -h # 工作目录(通常是/root目录)下自动生成multinode

浙公网安备 33010602011771号