K8s二进制生产环境扩容node节点
由于项目微服务也是部署在k8s集群中去维护的,所以扩容node节点也是必要的联系,扩容node节点一定要保证你整个集群的容器环境的网络都是互通的,这也是很重要的一步,这里我根据自己的经验去扩容,仅供参考
首先我这里是安装的二进制方式去部署的k8s集群,进行扩容node的时候,也是非常方便的
扩容node节点分为两步,第一步先将我们旧的node节点上的配置先去拷贝到我们新的节点上,第二点就是将我们的容器网络环境打通
这里我是直接扩容两个node节点。
第一步:
- 我们先去将我们的master节点上将我们的kubelet,kube-proxy的的bin下的目录文件拷贝到我们的新的节点上,以便于我们去扩容的时候去方便的将我们的服务使用systemd去启动管理起来。
创建文件目标所需node的节点的目录文件
[[email protected] ~]# mkdir -p /opt/kubernetes/{bin,ssl,cfg}
[[email protected] ~]# mkdir -p /opt/kubernetes/{bin,ssl,cfg}
[[email protected] ~]# scp /data/k8s/soft/kubernetes/server/bin/{kubelet,kube-proxy} [email protected]:/opt/kubernetes/bin/
[[email protected] ~]# scp /data/k8s/soft/kubernetes/server/bin/{kubelet,kube-proxy} [email protected]:/opt/kubernetes/bin/ - 将我们的最初node1节点上的/opt/kubernetes下的组件进行拷贝到新的节点上
[[email protected] ~]# scp -r /opt/kubernetes/ [email protected]:/opt
[[email protected] ~]# scp -r /opt/kubernetes/ [email protected]:/opt
[[email protected] ~]# scp /usr/lib/systemd/system/{kubelet,kube-proxy}.service [email protected]:/usr/lib/systemd/system
[[email protected] ~]# scp /usr/lib/systemd/system/{kubelet,kube-proxy}.service [email protected]:/usr/lib/systemd/system
去node3上操作
把拷贝过去的文件的证书删除,这是node1的证书,我们需要重新生成
[[email protected] ~]# cd /opt/kubernetes/ssl/
[[email protected] ssl]# ls
kubelet-client-2019-11-07-14-37-36.pem kubelet-client-current.pem kubelet.crt kubelet.key
[[email protected] ssl]# rm -rf
Node4上的也是一样删除
[[email protected] ~]# cd /opt/kubernetes/ssl/
[[email protected] ssl]# ls
kubelet-client-2019-11-07-14-37-36.pem kubelet-client-current.pem kubelet.crt kubelet.key
[[email protected] ssl]# rm -rf
修改ip ,找到配置文件把ip上改成第三个node,也就是本身的node
[[email protected] 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
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# docker -v
Docker version 19.03.4, build 9013bf583a
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# docker -v
Docker version 19.03.4, build 9013bf583a
另外就是需要etcd的启动文件。也拷贝过来,然后重启
[[email protected] ~]# scp -r /opt/etcd/ [email protected]:/opt
[[email protected] ~]# scp -r /opt/etcd/ [email protected]:/opt
把这些都修改为25主机的IP之后启动
[[email protected]]# systemctl restart kubelet
[[email protected] cfg]# systemctl restart kube-proxy.service
[[email protected] 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节点又有新的节点加入
[[email protected] ~]# 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
颁发证书
[[email protected] ~]# kubectl certificate approve node-csr-eH_jPNUBXJF6sIii9SvNz9fW71543MLjPvOYWeDteqo
certificatesigningrequest.certificates.k8s.io/node-csr-eH_jPNUBXJF6sIii9SvNz9fW71543MLjPvOYWeDteqo approved
[[email protected] ~]# 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节点状态
[[email protected] ~]# 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,将部署的文件拷贝过去
[[email protected] ~]# scp /usr/lib/systemd/system/{flanneld,docker}.service [email protected]:/usr/lib/systemd/system
[[email protected] ~]# scp /usr/lib/systemd/system/{flanneld,docker}.service [email protected]:/usr/lib/systemd/system
去node1上指定一个我们的node
[[email protected] ~]# ./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文件拷贝到新的节点上
[[email protected] ~]# cd /opt/kubernetes/cfg/
[[email protected] cfg]# ls
bootstrap.kubeconfig flanneld kubelet kubelet.config kubelet.kubeconfig kube-proxy kube-proxy.kubeconfig
[[email protected] cfg]# scp flanneld [email protected]:/opt/kubernetes/cfg/
[[email protected] cfg]# scp flanneld [email protected]:/opt/kubernetes/cfg/
重启新的节点
查看网络是否与docker同一网段
[[email protected] ~]# 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
[[email protected] ~]# systemctl start flanneld
[[email protected] ~]# systemctl restart docker
[[email protected] ~]# 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
并测试与其他节点的容器是否都能共享各个节点的网络环境
[[email protected] ~]# 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
测试成功都能连通
原文地址:https://blog.51cto.com/14143894/2448593