来自 科技 2020-06-30 16:58 的文章
k8s二进制升级从1.14.2至1.16.2
升级前准备
master节点组件: kubectl,kube-apiserver,kube-controller-manager,kube-scheduler
node节点组件:kube-proxy,kubelet
##暂不升级的组件,需要升级后面再单独升级
数据库组件:etcd
网络组件:flannel
二进制包下载:https://github.com/kubernetes/kubernetes/releases
开始升级升级kubectl备份kubectl,在所有的master节点操作
[root@bjxg-sy-test bin]# cd /opt/k8s/bin
[root@bjxg-sy-test bin]# mv kubectl kubectl.bak.v1.12
[root@bjxg-sy-test opt]# mkdir /opt/k8s.1.16.2-client
[root@bjxg-sy-test k8s.1.16.2-client]# cd /opt/k8s.1.16.2-client
[root@bjxg-sy-test k8s.1.16.2-client]# tar -zxvf kubernetes-client-linux-amd64.tar.gz
分发kubectl到所有节点
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
scp kubernetes/client/bin/kubectl root@${node_ip}:/opt/k8s/bin/
ssh root@${node_ip} "chmod +x /opt/k8s/bin/*"
done
查看kubectl版本
[root@bjxg-sy-test k8s.1.16.2-client]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:18:23Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:14:56Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
client版本是kubectl执行文件的版本.
server版本是kube-apiserver执行文件的版本.
升级master节点组件在master节点操作,另需要注意一台master节点一台操作,如果是用的keepalived做的vip高可用,需要先让vip漂移;如果是nginx的4层代理,需要先将要升级的master节点摘掉。
systemctl stop kube-apiserver
systemctl stop kube-scheduler
systemctl stop kube-controller-manager
mv /opt/k8s/bin/kube-apiserver{,.bak.v1.12}
mv /opt/k8s/bin/kube-controller-manager{,.bak.v1.12}
mv /opt/k8s/bin/kube-scheduler{,.bak.v1.12}
mv /opt/k8s/bin/kubeadm{,.bak.v1.12}
mkdir /opt/k8s.1.16.2-server
cd /opt/k8s.1.16.2-server
tar -zxvf kubernetes-server-linux-amd64.tar.gz
复制新版本客户端
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
scp kubernetes/server/bin/kube-apiserver root@${node_ip}:/opt/k8s/bin/
scp kubernetes/server/bin/{kube-controller-manager,kube-scheduler,kubeadm} root@${node_ip}:/opt/k8s/bin/
ssh root@${node_ip} "chmod +x /opt/k8s/bin/*"
done
启动服务 kube-apiserver
[root@bjxg-sy-test k8s.1.16.2-server]# systemctl status kube-apiserver
● kube-apiserver.service - Kubernetes API Server
Loaded: loaded (/etc/systemd/system/kube-apiserver.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-04-15 14:52:14 CST; 39s ago
Docs: https://github.com/GoogleCloudPlatform/kubernetes
Main PID: 11427 (kube-apiserver)
Tasks: 13
Memory: 340.5M
CGroup: /system.slice/kube-apiserver.service
└─11427 /opt/k8s/bin/kube-apiserver --advertise-address=10.16.16.11 --default-not-ready-tolerati...
看下kubectl version
[root@bjxg-sy-test k8s.1.16.2-server]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:18:23Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:09:08Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
[root@bjxg-sy-test k8s.1.16.2-server]#
启动kube-controller-manager和kube-scheduler
systemctl start kube-controller-manager && systemctl start kube-scheduler
升级node节点组件在所有node节点执行
systemctl stop kubelet
systemctl stop kube-proxy
mv /opt/k8s/bin/kubelet{,.bak.v1.12}
mv /opt/k8s/bin/kube-proxy{,.bak.v1.12}
拷贝二进制文件
source /opt/k8s/bin/environment.sh
for node_ip in ${NODE_IPS[@]}
do
echo ">>> ${node_ip}"
scp kubernetes/server/bin/{kubelet,kube-proxy} root@${node_ip}:/opt/k8s/bin/
ssh root@${node_ip} "chmod +x /opt/k8s/bin/*"
done
在kubernetes 1.15版起kubelet需要删除allow-privileged这个参数,因为新版本中这个参数已经过时。我们只需要在kubelet启动脚步中删除即可
sed -i '/allow-privileged/d' /etc/systemd/system/kubelet.service
systemctl daemon-reload && systemctl start kubelet
systemctl start kube-proxy
查看并验证查看node节点
[root@bjxg-sy-test k8s.1.16.2-server]# kubectl get node
NAME STATUS ROLES AGE VERSION
bjxg-sy-test Ready <none> 27h v1.16.2
启动一个pod
[root@bjxg-sy-test k8s.1.16.2-server]# kubectl create deploy nginx --image=nginx
deployment.apps/nginx created
[root@bjxg-sy-test k8s.1.16.2-server]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-86c57db685-hzsxk 0/1 ContainerCreating 0 5s
至此,k8s集群升级完毕