ansible二進位制部署kubernetes叢集
阿新 • • 發佈:2022-03-10
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