kubernetes二进制 v1.15.2 平滑升级到 v1.15.4
背景:如果需要使用到新的功能或当前版本出现了严重的漏洞,需要做版本升级;如果升级到相对应的版本后,发现不稳定的也可以进行降级,不管是升级还是降级,都需要一台升级/降级好后再对下一台进行操作,不建议一起进行
接下来演示Kubernetes 二进制从 v1.15.2 升级到 v1.15.4。
操作前检查
[root@node7-21 src]# kubectl get node
NAME STATUS ROLES AGE VERSION
node7-21.host.com Ready master,node 24h v1.15.2
node7-22.host.com Ready master,node 24h v1.15.2
[root@node7-21 src]# kubectl get pod -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-6b6c4f9648-dmgvm 1/1 Running 1 23h 172.7.21.3 node7-21.host.com <none> <none>
heapster-b5b9f794-4fm9k 1/1 Running 1 23h 172.7.21.5 node7-21.host.com <none> <none>
kubernetes-dashboard-76dcdb4677-k4kc9 1/1 Running 0 21m 172.7.22.4 node7-22.host.com <none> <none>
traefik-ingress-n7gfv 1/1 Running 1 23h 172.7.22.2 node7-22.host.com <none> <none>
traefik-ingress-x8j8p 1/1 Running 1 23h 172.7.21.2 node7-21.host.com <none> <none>
升级版本
注释掉server 10.4.7.21:644
~]# vi /etc/nginx/nginx.conf
stream {
upstream kube-apiserver {
# server 10.4.7.21:6443 max_fails=3 fail_timeout=30s;
server 10.4.7.22:6443 max_fails=3 fail_timeout=30s;
}
server {
listen 7443;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass kube-apiserver;
}
}
[root@node7-11 ~]# vi /etc/nginx/conf.d/od.com.conf
upstream default_backend_traefik {
#server 10.4.7.21:81 max_fails=3 fail_timeout=10s;
server 10.4.7.22:81 max_fails=3 fail_timeout=10s;
}
[root@node7-11 ~]# nginx -s reload
[root@node7-21 src]# kubectl delete node node7-21.host.com
node "node7-21.host.com" deleted
[root@node7-21 src]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node7-22.host.com Ready master,node 24h v1.15.2
[root@node7-21 src]# kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-6b6c4f9648-5sghd 0/1 ContainerCreating 0 35s <none> node7-22.host.com <none> <none>
heapster-b5b9f794-lcmht 0/1 ContainerCreating 0 35s <none> node7-22.host.com <none> <none>
kubernetes-dashboard-76dcdb4677-k4kc9 1/1 Running 0 30m 172.7.22.4 node7-22.host.com <none> <none>
traefik-ingress-n7gfv 1/1 Running 1 23h 172.7.22.2 node7-22.host.com <none> <none>
[root@node7-21 src]# kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-6b6c4f9648-5sghd 1/1 Running 0 43s 172.7.22.7 node7-22.host.com <none> <none>
heapster-b5b9f794-lcmht 1/1 Running 0 43s 172.7.22.5 node7-22.host.com <none> <none>
kubernetes-dashboard-76dcdb4677-k4kc9 1/1 Running 0 30m 172.7.22.4 node7-22.host.com <none> <none>
traefik-ingress-n7gfv 1/1 Running 1 23h 172.7.22.2 node7-22.host.com <none> <none>
测试DNS
[root@node7-22 ~]# dig -t A kubernetes.default.svc.cluster.local @192.168.0.2 +short
192.168.0.1
可以看到资源迁移到其它node,且正常运行。
[root@node7-21 src]# tar xfv kubernetes-1.15.4-server-linux-amd64.tar.gz
[root@node7-21 src]# mv kubernetes ../kubernetes-v1.15.4
[root@node7-21 src]# cd ../kubernetes-v1.15.4
[root@node7-21 kubernetes-v1.15.4]# rm -f kubernetes-src.tar.gz
[root@node7-21 kubernetes-v1.15.4]# cd server/bin
[root@node7-21 bin]# rm -f *.tar
[root@node7-21 bin]# rm -f *_tag
[root@node7-21 bin]# mkdir conf
[root@node7-21 bin]# mkdir certs
[root@node7-21 bin]# cd certs/
[root@node7-21 certs]# cp /opt/kubernetes/server/bin/certs/* .
[root@node7-21 certs]# cd ../conf/
[root@node7-21 conf]# cp /opt/kubernetes/server/bin/conf/* .
[root@node7-21 conf]# cd ..
[root@node7-21 bin]# cp /opt/kubernetes/server/bin/*.sh .
[root@node7-21 bin]# cd /opt/
[root@node7-21 opt]# supervisorctl stop all
kube-kubelet-7-21: stopped
kube-apiserver-7-21: stopped
kube-controller-manager-7-21: stopped
kube-proxy-7-21: stopped
flanneld-7-21: stopped
kube-scheduler-7-21: stopped
etcd-server-7-21: stopped
注意:这里会出现实际有进程未stopped,逐一 ps aux|grep [名字],然后kill -9 [id]
[root@node7-21 opt]# rm -rf kubernetes
[root@node7-21 opt]# ln -s /opt/kubernetes-v1.15.4/ /opt/kubernetes
[root@node7-21 opt]# supervisorctl start all
验证版本
[root@node7-21 opt]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node7-21.host.com Ready <none> 32s v1.15.4
node7-22.host.com Ready master,node 24h v1.15.2
完成node7-21版本升级。
参考以上可以完成node7-22节点的升级
升级完成
[root@node7-22 opt]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
node7-21.host.com Ready <none> 8h v1.15.4
node7-22.host.com Ready <none> 8h v1.15.4