ansible二进制部署kubernetes集群
kubernetes版本1.21.5
需要的资源文件请自行到我的阿里云盘下载 https://www.aliyundrive.com/s/zVegF78ATDV
修改主机信息
#根据自己的主机信息自行修改
vim sshkeygen.sh
#!/usr/bin/env bash
yum -y install ansible &>/dev/null
ansible_dir=$(pwd)/ansible
if [ $? -eq 0 ]; then
echo "ansible安装成功"
cp -r ${ansible_dir} /etc/
else
echo "ansible安装失败"
fi
cat <<EOF
##############################################
#
# 此脚本只适合高可用kubernetes集群(三节点)
# 请准备三个或三个以上节点
# 请保持可以访问外网
## 想要更多节点请自行添加
###############################################
EOF
#ansible主机配置
cat > hosts <<EOF
#证书创建节点
[k8spem]
192.168.77.131 ansible_ssh_user=root ansible_ssh_pass=123.com
#kubernetes 主节点高可用
[k8smaster]
192.168.77.131 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.77.132 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.77.133 ansible_ssh_user=root ansible_ssh_pass=123.com
[k8snode]
192.168.77.181 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.77.182 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.77.183 ansible_ssh_user=root ansible_ssh_pass=123.com
#包含主机
[k8s:children]
k8smaster
EOF
rpm -qa | grep ansible
if [ $? -eq 0 ]; then
cp hosts ansible/hosts
fi
#请自行修改主机信息
#前三个ip and hostname 是master节点
cat > kubernetes_IP.txt <<EOF
kubeapiserver: "192.168.77.120"
hight_master01_ip: "192.168.77.131"
hight_master02_ip: "192.168.77.132"
hight_master03_ip: "192.168.77.133"
hight_node01_ip: "192.168.77.181"
hight_node02_ip: "192.168.77.182"
hight_node03_ip: "192.168.77.183"
EOF
cat > kubernetes_hostname.txt <<EOF
hight_master01_hostname: "estarhaohao-centos7-master01"
hight_master01_hostname: "estarhaohao-centos7-master01"
hight_master01_hostname: "estarhaohao-centos7-master01"
hight_node01_hostname: "estarhaohao-centos7-node01"
hight_node02_hostname: "estarhaohao-centos7-node02"
hight_node03_hostname: "estarhaohao-centos7-node03"
EOF
#以上是node节点ip and hostname
# 想要更多节点请自行添加
cat kubernetes_IP.txt | while read line
do
for dir in $( ls -l | grep k8s | awk '{print $9}' )
do
echo $line >> $dir/vars/main.yml
done
done
cat kubernetes_hostname.txt | while read line
do
for dir in $( ls -l | grep k8s | awk '{print $9}' )
do
echo $line >> $dir/vars/main.yml
done
done
部署
#等待部署完成即可使用
ansible-playbook role.yml