您好,登录后才能下订单哦!
K8s二进制生产环境扩容node节点
由于项目微服务也是部署在k8s集群中去维护的,所以扩容node节点也是必要的联系,扩容node节点一定要保证你整个集群的容器环境的网络都是互通的,这也是很重要的一步,这里我根据自己的经验去扩容,仅供参考
首先我这里是安装的二进制方式去部署的k8s集群,进行扩容node的时候,也是非常方便的
扩容node节点分为两步,第一步先将我们旧的node节点上的配置先去拷贝到我们新的节点上,第二点就是将我们的容器网络环境打通
这里我是直接扩容两个node节点。
第一步:
[root@k8s-node3 ~]# mkdir -p /opt/kubernetes/{bin,ssl,cfg}
[root@k8s-node4 ~]# mkdir -p /opt/kubernetes/{bin,ssl,cfg}
[root@k8s-master1 ~]# scp /data/k8s/soft/kubernetes/server/bin/{kubelet,kube-proxy} root@192.168.30.25:/opt/kubernetes/bin/
[root@k8s-master1 ~]# scp /data/k8s/soft/kubernetes/server/bin/{kubelet,kube-proxy} root@192.168.30.26:/opt/kubernetes/bin/
[root@k8s-node1 ~]# scp -r /opt/kubernetes/ root@192.168.30.25:/opt
[root@k8s-node1 ~]# scp -r /opt/kubernetes/ root@192.168.30.26:/opt
[root@k8s-node1 ~]# scp /usr/lib/systemd/system/{kubelet,kube-proxy}.service root@192.168.30.25:/usr/lib/systemd/system
[root@k8s-node1 ~]# scp /usr/lib/systemd/system/{kubelet,kube-proxy}.service root@192.168.30.26:/usr/lib/systemd/system
去node3上操作
把拷贝过去的文件的证书删除,这是node1的证书,我们需要重新生成
[root@k8s-node3 ~]# cd /opt/kubernetes/ssl/
[root@k8s-node3 ssl]# ls
kubelet-client-2019-11-07-14-37-36.pem kubelet-client-current.pem kubelet.crt kubelet.key
[root@k8s-node3 ssl]# rm -rf *
Node4上的也是一样删除
[root@k8s-node4 ~]# cd /opt/kubernetes/ssl/
[root@k8s-node4 ssl]# ls
kubelet-client-2019-11-07-14-37-36.pem kubelet-client-current.pem kubelet.crt kubelet.key
[root@k8s-node4 ssl]# rm -rf *
修改ip ,找到配置文件把ip上改成第三个node,也就是本身的node
[root@k8s-node3 cfg]# grep 23 *
kubelet:--hostname-override=192.168.30.23 \
kubelet.config:address: 192.168.30.23
kube-proxy:--hostname-override=192.168.30.23 \
这个和扩容第4个node节点都是一样的
扩容的时候记得这里是需要docker环境的,需要安装一下docker-ce
[root@k8s-node3 ~]# systemctl restart docker
[root@k8s-node3 ~]# docker -v
Docker version 19.03.4, build 9013bf583a
[root@k8s-node4 ~]# systemctl restart docker
[root@k8s-node4 ~]# docker -v
Docker version 19.03.4, build 9013bf583a
另外就是需要etcd的启动文件。也拷贝过来,然后重启
[root@k8s-node1 ~]# scp -r /opt/etcd/ root@192.168.30.25:/opt
[root@k8s-node1 ~]# scp -r /opt/etcd/ root@192.168.30.25:/opt
把这些都修改为25主机的IP之后启动
[root@k8s-node3cfg]# systemctl restart kubelet
[root@k8s-node3 cfg]# systemctl restart kube-proxy.service
[root@k8s-node3 cfg]# ps -ef |grep kube
root 62846 1 0 16:49 ? 00:00:07 root 86738 1 6 21:27 ? 00:00:00 /opt/kubernetes/bin/kubelet --logtostderr=false --log-dir=/opt/kubernetes/log --v=4 --hostname-override=192.168.30.25 --kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig --bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig --config=/opt/kubernetes/cfg/kubelet.config --cert-dir=/opt/kubernetes/ssl --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0
root 86780 1 35 21:28 ? 00:00:02 /opt/kubernetes/bin/kube-proxy --logtostderr=true --v=4 --hostname-override=192.168.30.25 --cluster-cidr=10.0.0.0/24 --proxy-mode=ipvs --kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig
root 86923 66523 0 21:28 pts/1 00:00:00 grep --color=auto kube
查看到master节点又有新的节点加入
[root@k8s-master1 ~]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-eH_jPNUBXJF6sIii9SvNz9fW71543MLjPvOYWeDteqo 90s kubelet-bootstrap Pending
node-csr-xLNLbvb3cibW-fyr_5Qyd3YuUYAX9DJgDwViu3AyXMk 31m kubelet-bootstrap Approved,Issued
颁发证书
[root@k8s-master1 ~]# kubectl certificate approve node-csr-eH_jPNUBXJF6sIii9SvNz9fW71543MLjPvOYWeDteqo
certificatesigningrequest.certificates.k8s.io/node-csr-eH_jPNUBXJF6sIii9SvNz9fW71543MLjPvOYWeDteqo approved
[root@k8s-master1 ~]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-eH_jPNUBXJF6sIii9SvNz9fW71543MLjPvOYWeDteqo 3m18s kubelet-bootstrap Approved,Issued
node-csr-xLNLbvb3cibW-fyr_5Qyd3YuUYAX9DJgDwViu3AyXMk 33m kubelet-bootstrap Approved,Issued
查看node节点状态
[root@k8s-master1 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
192.168.30.23 Ready <none> 25m v1.15.1
192.168.30.24 Ready <none> 51s v1.15.1
192.168.30.25 Ready <none> 25m v1.15.1
192.168.30.26 Ready <none> 51s v1.15.1
第二步:
打通容器之间的网络通信环境,这里我使用的是flannel进行管理
准备docker环境,这里我们之前是准备好的,但是我们还是需要给他们去分配一个子网,flanneld和docker分配要一个子网里面
给新加入的节点部署flannel,将部署的文件拷贝过去
[root@k8s-node1 ~]# scp /usr/lib/systemd/system/{flanneld,docker}.service root@192.168.30.25:/usr/lib/systemd/system
[root@k8s-node1 ~]# scp /usr/lib/systemd/system/{flanneld,docker}.service root@192.168.30.26:/usr/lib/systemd/system
去node1上指定一个我们的node[root@k8s-node1 ~]# ./flannel.sh https://192.168.30.21:2379,https://192.168.30.22:2379,https://192.168.30.23:2379,https://192.168.30.24:2379,https://192.168.30.25:2379,https://192.168.30.26:2379
然后将我们的指定好的flanneld文件拷贝到新的节点上
[root@k8s-node1 ~]# cd /opt/kubernetes/cfg/
[root@k8s-node1 cfg]# ls
bootstrap.kubeconfig flanneld kubelet kubelet.config kubelet.kubeconfig kube-proxy kube-proxy.kubeconfig
[root@k8s-node1 cfg]# scp flanneld root@192.168.30.25:/opt/kubernetes/cfg/
[root@k8s-node1 cfg]# scp flanneld root@192.168.30.26:/opt/kubernetes/cfg/
重启新的节点
查看网络是否与docker同一网段
[root@k8s-node3 ~]# ip a
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:97:f5:6c:cd brd ff:ff:ff:ff:ff:ff
inet 172.17.25.1/24 brd 172.17.25.255 scope global docker0
valid_lft forever preferred_lft forever
6: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
link/ether b2:1a:97:5c:61:1f brd ff:ff:ff:ff:ff:ff
inet 172.17.25.0/32 scope global flannel.1
valid_lft forever preferred_lft forever
[root@k8s-node4 ~]# systemctl start flanneld
[root@k8s-node4 ~]# systemctl restart docker
[root@k8s-node4 ~]# ip a
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:3f:3c:a8:62 brd ff:ff:ff:ff:ff:ff
inet 172.17.77.1/24 brd 172.17.77.255 scope global docker0
valid_lft forever preferred_lft forever
6: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
link/ether 96:1c:bc:ec:05:d6 brd ff:ff:ff:ff:ff:ff
inet 172.17.77.0/32 scope global flannel.1
并测试与其他节点的容器是否都能共享各个节点的网络环境
[root@k8s-master1 ~]# kubectl exec -it nginx-deployment-7b8677db56-wkbzb /bin/sh
ping 172.17.79.2
PING 172.17.79.2 (172.17.79.2): 56 data bytes
64 bytes from 172.17.79.2: icmp_seq=0 ttl=62 time=0.703 ms
64 bytes from 172.17.79.2: icmp_seq=1 ttl=62 time=0.459 ms
^C--- 172.17.79.2 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.459/0.581/0.703/0.122 ms
ping 172.17.40.3
PING 172.17.40.3 (172.17.40.3): 56 data bytes
64 bytes from 172.17.40.3: icmp_seq=0 ttl=62 time=0.543 ms
64 bytes from 172.17.40.3: icmp_seq=1 ttl=62 time=0.404 ms
^C--- 172.17.40.3 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.404/0.474/0.543/0.070 ms
ping 172.17.6.3
PING 172.17.6.3 (172.17.6.3): 56 data bytes
64 bytes from 172.17.6.3: icmp_seq=0 ttl=62 time=0.385 ms
64 bytes from 172.17.6.3: icmp_seq=1 ttl=62 time=0.323 ms
^C--- 172.17.6.3 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.323/0.354/0.385/0.031 ms
测试成功都能连通
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。