1.1 升级步骤
注意kubectl命令主节点执行,yum命令需要升级的服务器执行;
查看当前系统支持的所有k8s版本和当前版本
yum list --showduplicates kubeadm --disableexcludes=kubernetes
2.1.1 升级控制节点
1、查看当前版本和升级计划(即可以从目前版本升级到哪个版本)
kubectl version
#匹配最佳升级版本
kubeadm upgrade plan
#首先我们保留 kubeadm config 文件:
kubeadm config view > kubeadm-config.yaml
vim kubeadm-config.yaml
apiServer:
extraArgs:
authorization-mode: Node,RBAC
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: 12.10.100.226:8443
controllerManager: {}
dns:
type: CoreDNS
etcd:
external:
caFile: /etc/etcd/pki/ca.pem
certFile: /etc/etcd/pki/client.pem
endpoints:
- https://12.10.100.220:2379
- https://12.10.100.221:2379
- https://12.10.100.222:2379
keyFile: /etc/etcd/pki/client-key.pem
imageRepository: registry.aliyuncs.com/k8sxio # 修改成阿里云镜像源
kind: ClusterConfiguration
kubernetesVersion: v1.18.20 #修改成想要升级版本
networking:
dnsDomain: cluster.local
podSubnet: 10.244.0.0/16
serviceSubnet: 10.96.0.0/12
scheduler: {}
#下载包
yum makecache fast && yum install -y kubeadm-1.18.20-0 kubectl-1.18.20-0
#下载镜像
kubeadm config images pull --config kubeadm-config.yaml
#测试
kubeadm upgrade apply v1.18.20 --config kubeadm-config.yaml --dry-run
#然后就可以执行真正的升级命令
kubeadm upgrade apply v1.18.20 --config kubeadm-config.yaml
3、升级kubelet和kubectl
yum install -y kubelet-1.18.20-0 kubectl-1.18.20-0 --disableexcludes=kubernetes
systemctl daemon-reload
systemctl restart kubelet
#查看当前版本
kubectl version
kubectl get nodes
4.1 升级工作节点
#子节点执行
yum install -y kubeadm-1.18.20-0 --disableexcludes=kubernetes
#主节点执行-将节点标记为不可调度并驱逐所有负载,准备节点的维护
kubectl drain k8s-node01 --ignore-daemonsets
#更新子节点
kubeadm upgrade node
#主节点执行-通过将节点标记为可调度,让节点重新上线:
kubectl uncordon k8s-node01
#子节点执行
yum install -y kubelet-1.18.20-0 kubectl-1.18.20-0 --disableexcludes=kubernetes
systemctl daemon-reload
systemctl restart kubelet
#主节点执行
kubectl version
kubectl get nodes
成功截图