Book source: "CKA/CKAD Test Guide: From Docker to Kubernetes Complete Raiders"
Organize the reading notes while studying, and share them with everyone. If the copyright is violated, it will be deleted. Thank you for your support!
Attach a summary post: Kubernetes Certification Exam Self-study Series | Summary_COCOgsta's Blog-CSDN Blog
Step 1: Check the current version.
[root@vms15 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
vms15.rhce.cc Ready master 23m v1.20.1
vms16.rhce.cc Ready <none> 20m v1.20.1
[root@vms15 ~]#
复制代码
Or view it with the following command.
[root@vms15 ~]# kubectl version --short
Client Version: v1.20.1
Server Version: v1.20.1
[root@vms15 ~]#
复制代码
It shows that version v1.20.1 is currently installed, and now it needs to be upgraded to version v1.21.1.
Step 2: Determine the available version of kubeadm in the current yum source.
[root@vms15 ~]# yum list --showduplicates kubeadm --disableexcludes=kubernetes
已加载插件: fastestmirror
Loading mirror speeds from cached hostfile
已安装的软件包
kubeadm.x86_64 1.20.1-0 @kubernetes
可安装的软件包
kubeadm.x86_64 1.6.0-0 kubernetes
... 输出 ...
kubeadm.x86_64 1.20.1-0 kubernetes
kubeadm.x86_64 1.21.1-0 kubernetes
[root@vms15 ~]#
复制代码
This shows that the latest version available for kubeadm in the yum source is 1.21.1.
4.2.1 Upgrade kubeadm
Step 1: Upgrade kubeadm to 1.21.1.
[root@vms15 ~]# yum install -y kubeadm-1.21.1-0 --disableexcludes=kubernetes
已加载插件: fastestmirror
... 输出 ...
更新完毕:
kubeadm.x86_64 0:1.21.1-0
完毕!
[root@vms15 ~]#
复制代码
Step 2: Verify the version of kubeadm.
[root@vms15 ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1",...
[root@vms15 ~]#
复制代码
Step 3: Use kubeadm upgrade plan to check whether the cluster needs to be upgraded and the version that can be upgraded.
[root@vms15 ~]# kubeadm upgrade plan
... 输出 ...
Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT CURRENT AVAILABLE
kubelet 2 x v1.20.1 v1.20.8
Upgrade to the latest version in the v1.20 series:
COMPONENT CURRENT AVAILABLE
kube-apiserver v1.20.1 v1.20.8
kube-controller-manager v1.20.1 v1.20.8
kube-scheduler v1.20.1 v1.20.8
kube-proxy v1.20.1 v1.20.8
CoreDNS 1.7.0 v1.8.0
etcd 3.4.13-0 3.4.13-0
You can now apply the upgrade by executing the following command:
kubeadm upgrade apply v1.20.8
--------------------------------------------------------------------
Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT CURRENT AVAILABLE
kubelet 2 x v1.20.1 v1.21.1
Upgrade to the latest stable version:
COMPONENT CURRENT AVAILABLE
kube-apiserver v1.20.1 v1.21.1
kube-controller-manager v1.20.1 v1.21.1
kube-scheduler v1.20.1 v1.21.1
kube-proxy v1.20.1 v1.21.1
CoreDNS 1.7.0 v1.8.0
etcd 3.4.13-0 3.4.13-0
You can now apply the upgrade by executing the following command:
kubeadm upgrade apply v1.21.1
... 输出 ...
[root@vms15 ~]#
复制代码
This command checks whether the cluster can be upgraded, and the upgraded version can be obtained.
Step 4: Set the master to maintenance mode and clear the pods running on it.
[root@vms15 ~]#
[root@vms15 ~]# kubectl drain vms15.rhce.cc --ignore-daemonsets
node/vms15.rhce.cc cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/calico-node-zlkm4, kube-system/kube-proxy-kgcpx
node/vms15.rhce.cc drained
[root@vms15 ~]#
[root@vms15 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
vms15.rhce.cc Ready, SchedulingDisabled master 2h v1.20.1
vms16.rhce.cc Ready <none> 2h v1.20.1
[root@vms15 ~]#
复制代码
Note: kubectl drain can be executed before or after the command kubeadm upgrade apply to upgrade the cluster is run. Here it is executed before it.
4.2.2 Upgrade each component on the master in the kubernetes cluster
After the kubeadm upgrade, start using the kubeadm command to upgrade each component on the master.
Note that coredns-1.21.tar should be imported in advance.
Step 1: Start upgrading the kubernetes cluster.
[root@vms15 ~J# kubeadm upgrade apply v1.21.1
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
... 输出 ...
[upgrade/version] You have chosen to change the cluster version to "v1.21.1"
[upgrade/versions] Cluster version: v1.20.1
[upgrade/versions] kubeadm version: v1.21.1
[upgrade/confirm] Are you sure you want to proceed with the upgrade?[y/N]: y
... 输出 ...
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
[upgrade/successful] SUCCESS!Your cluster was upgraded to "v1.21.1". Enjoy!
[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.
[root@vms15 ~]#
复制代码
Step 2: After the upgrade is complete, cancel the maintenance mode of the master.
[root@vms15 ~]# kubectl uncordon vms15.rhce.cc
node/vms15.rhce.cc uncordoned
[root@vms15 ~]#
[root@vms15 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
vms15.rhce.cc Ready master 2h v1.20.1
vms16.th ce.cc Ready <none> 2h v1.20.1
[root@vms15 ~]#
复制代码
It shows that the version of vms15 is still v1.20.1, and the kubelet and kubectl need to be upgraded next.
4.2.3 Upgrade kubelet and kubectl on the master
Let's start upgrading kubelet and kubectl.
Step 1: Install the v1.21.1 version of kubelet and kubectl.
[root@vms15 ~]# yum install -y kubelet-1.21.1-0 kubectl-1.21.1-0 --disableexcludes=kubernetes
已加载插件: fastestmirror
base | 3.6 kB 00:00:00
... 输出 ...
更新完毕:
kubelet.x86_64 0:1.21.1-0 kubectl.x86_64 0:1.21.1-0
完毕!
[root@vms15 ~] #
复制代码
Restart the service.
[root@vms15 ~]# systemctl daemon-reload ; systemctl restart kubelet
[root@vms15 ~]#
复制代码
Step 2: Verify the version of kubectl.
[root@vms15 ~]# kubectl version --short
Client Version: v1.21.1
Server Version: v1.21.1
[root@vms15 ~]#
复制代码
Or verify with the following command.
[root@vms15 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
vms15.rhce.cc Ready master 2h v1.21.1
vms16.rhce.cc Ready <none> 2h v1.20.1
[root@vms15 ~]#
复制代码
Here you can see that the master has been upgraded to v1.21.1, but the worker has not been upgraded yet.
If there are other masters in the environment, the steps to upgrade the second master are the same as the previous steps, just replace the command kubeadm upgrade apply v1.21.1 with kubeadm upgrade node.