k8s集群扩容master节点和node节点
#集群扩容规划 #新增master节点和node节点如下 k8s-master3-etcd3-haproxy3 192.168.10.113 k8s-node3 192.168.10.116 #在k8s-harbor-deploy:192.168.10.110执行添加
1.新增master节点#查看现有集群服务器
root@t:/etc/kubeasz# kubectl get node -A NAME STATUS ROLES AGE VERSION 192.168.10.111 Ready,SchedulingDisabled master 3d11h v1.21.0 192.168.10.112 Ready,SchedulingDisabled master 3d11h v1.21.0 192.168.10.114 Ready node 3d11h v1.21.0 192.168.10.115 Ready node 3d11h v1.21.0 #添加master之前,检查node节点的kube-lb.conf文件,每个node节点上会启动一个负载均衡器,它是ningx实现的,用于实现对api server的负载均衡 root@k8s-node1:~# cat /etc/kube-lb/conf/kube-lb.conf user root; worker_processes 1; error_log /etc/kube-lb/logs/error.log warn; events { worker_connections 3000; } stream { upstream backend { server 192.168.10.111:6443 max_fails=2 fail_timeout=3s; server 192.168.10.112:6443 max_fails=2 fail_timeout=3s; } server { listen 127.0.0.1:6443; proxy_connect_timeout 1s; proxy_pass backend; } } #在master节点,add-master会自动执行01、03、04、06 root@k8s-harbor-deploy:/tools# cd /etc/kubeasz root@k8s-harbor-deploy:/etc/kubeasz# ./ezctl add-master k8s-01 192.168.10.113 部署无任何报错即可,其中ex-lb报错可以不用理会已经单独部署 #添加以后检查 root@k8s-master1-etcd1-haproxy1:/usr/local/src# kubectl get node -A -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME 192.168.10.111 Ready,SchedulingDisabled master 3d11h v1.21.0 192.168.10.111 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.112 Ready,SchedulingDisabled master 3d11h v1.21.0 192.168.10.112 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.113 Ready,SchedulingDisabled master 5m2s v1.21.0 192.168.10.113 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.114 Ready node 3d11h v1.21.0 192.168.10.114 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.115 Ready node 3d11h v1.21.0 192.168.10.115 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 每个node节点都有反向代理配置文件,本地的kubelet,kubectl,kebe-proxy会把本地的请求转发给本地的127.0.0.1的6443端口,然后在以轮询的方式转发向后端的master节点6443端口进 通过这种方式实现node节点对apiserver节点的高可用和高性能,负载均衡器会对apiserver进行探测,如果某个apiserver挂了会自动把挂了的apiserver从Nginx负载均衡删除掉 #添加之后的负载均衡文件,负载均衡的文件会自动更新把新的master节点添加上去 root@k8s-node1:~# cat /etc/kube-lb/conf/kube-lb.conf user root; worker_processes 1; error_log /etc/kube-lb/logs/error.log warn; events { worker_connections 3000; } stream { upstream backend { server 192.168.10.113:6443 max_fails=2 fail_timeout=3s; server 192.168.10.111:6443 max_fails=2 fail_timeout=3s; server 192.168.10.112:6443 max_fails=2 fail_timeout=3s; } server { listen 127.0.0.1:6443; proxy_connect_timeout 1s; proxy_pass backend; } }
2.新增node节点
#添加node节点 root@t:/etc/kubeasz# ./ezctl add-node k8s-01 192.168.10.116 2023-01-06 10:26:36 INFO add 192.168.10.116 into 'kube_node' group 2023-01-06 10:26:36 INFO start to add a work node:192.168.10.116 into cluster:k8s-01 PLAY [192.168.10.116] ************************************************************************************************************ TASK [Gathering Facts] *********************************************************************************************************** ok: [192.168.10.116] TASK [prepare : apt更新缓存刷新] ************************************************************************************************* ok: [192.168.10.116] TASK [prepare : 删除ubuntu默认安装] ********************************************************************************************** changed: [192.168.10.116] => (item=ufw) changed: [192.168.10.116] => (item=lxd) changed: [192.168.10.116] => (item=lxd-client) changed: [192.168.10.116] => (item=lxcfs) changed: [192.168.10.116] => (item=lxc-common) 执行过程无任何报错即可 #执行完毕检查 root@t:/etc/kubeasz# kubectl get node -A -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME 192.168.10.111 Ready,SchedulingDisabled master 3d12h v1.21.0 192.168.10.111 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.112 Ready,SchedulingDisabled master 3d12h v1.21.0 192.168.10.112 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.113 Ready,SchedulingDisabled master 33m v1.21.0 192.168.10.113 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.114 Ready node 3d12h v1.21.0 192.168.10.114 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.115 Ready node 3d12h v1.21.0 192.168.10.115 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15 192.168.10.116 Ready node 22m v1.21.0 192.168.10.116 <none> Ubuntu 20.04.3 LTS 5.4.0-135-generic docker://19.3.15