kubeasz部署高可用kubernetes集群
环境信息
角色 | IP地址 | 系统版本 | 配置 |
---|---|---|---|
kubeasz管理节点 | 192.168.121.20 | centos7.8 | 2核4G |
master1(etcd1) | 192.168.121.11 | centos7.8 | 2核4G |
master2(etcd2) | 192.168.121.12 | centos7.8 | 2核4G |
master3(etcd3) | 192.168.121.13 | centos7.8 | 2核4G |
node1 | 192.168.121.14 | centos7.8 | 2核4G |
node2 | 192.168.121.15 | centos7.8 | 2核4G |
一、下载kubeasz(kubeasz管理节点执行)
1、下载easzup
curl -C- -fLO --retry 3 https://github.com/easzlab/kubeasz/releases/download/2.2.1/easzup
chmod a+x easzup
mv easzup /usr.local/bin/
easzup -D
2、配置集群信息
cp /etc/ansible/example/hosts.multi-node /etc/ansible/hosts
根据规划修改/etc/ansible/hosts中配置信息
3、配置互信、验证节点是否免密
bash /etc/ansible/tools/yc-ssh-key-copy.sh /etc/ansible/hosts username password
ansible all -m ping
4、部署k8s
#ansible all -m shell -a "wget https://bootstrap.pypa.io/get-pip.py -P /tmp/"
#ansible all -m shell -a "python /tmp/get-pip.py"
#ansible all -m shell -a "pip install netaddr -i https://pypi.tuna.tsinghua.edu.cn/simple"
#ansible all -m shell -a "rm -rf /tmp/get-pip.py"
easzup -S
docker exec -it kubeasz bash
cd /etc/ansible/
ansible-playbook 90.setup.yml
5、查看集群信息
kubectl version
kubectl get cs
kubectl get node -o wide
kubectl cluster-info
二、easzctl管理kubernetes集群
1、删除master节点、添加master节点
easzctl del-master 192.168.121.13
kubectl delete node 192.168.121.13
easzctl add-master 192.168.121.13
2、删除etcd节点、添加etcd节点
easzctl del-etcd 192.168.121.13
easzctl add-etcd 192.168.121.13
输入新的etcd节点名称(etcd-2)
3、删除node节点、添加node节点
easzctl del-node 192.168.121.15
kubectl delete node 192.168.121.15
easzctl add-node 192.168.121.15
4、删除集群
easzctl destroy
ansible all -m shell -a "reboot"
5、管理节点清理
easzup -C
docker system prune -a
systemctl stop docker
rm -rf /etc/ansible /etc/docker /opt/kube
umount /var/run/docker/netns/default
umount /var/lib/docker/overlay
rm -rf /var/lib/docker /var/run/docker
reboot