Kubernetes【升级】 CKS 2021【11】---Cluster Hardening - Upgrade Kubernetes

简介: Kubernetes【升级】 CKS 2021【11】---Cluster Hardening - Upgrade Kubernetes

文章目录

1. 介绍

1035234-20181020215539574-213176954.png

1035234-20181020215539574-213176954.png

1035234-20181020215539574-213176954.png

2. Practice - Create outdated cluster

1035234-20181020215539574-213176954.png

参考链接:

https://github.com/killer-sh/cks-course-environment/tree/master/cluster-setup/previous

# master
bash <(curl -s https://raw.githubusercontent.com/killer-sh/cks-course-environment/master/cluster-setup/previous/install_master.sh)
# worker
bash <(curl -s https://raw.githubusercontent.com/killer-sh/cks-course-environment/master/cluster-setup/previous/install_worker.sh)

3. Upgrade master node

1035234-20181020215539574-213176954.png

root@master:~/cks/create_cluster# k drain   master --ignore-daemonsets
node/master cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/calico-node-ngbm8, kube-system/kube-proxy-lfkn9
node/master drained
root@master:~/cks/create_cluster# k get node
NAME     STATUS                     ROLES                  AGE   VERSION
master   Ready,SchedulingDisabled   control-plane,master   42h   v1.20.1
node1    Ready                      <none>                 42h   v1.20.1
node2    Ready                      <none>                 42h   v1.20.1
root@master:~/cks/create_cluster# apt-cache show kubeadm  |grep -e '1.20'
Version: 1.20.2-00
Filename: pool/kubeadm_1.20.2-00_amd64_38fa4593055ef1161d4cb322437eedda95186fb850819421b8cf75f3a943dc51.deb
Version: 1.20.1-00
Filename: pool/kubeadm_1.20.1-00_amd64_7cd8d4021bb251862b755ed9c240091a532b89e6c796d58c3fdea7c9a72b878f.deb
Version: 1.20.0-00
Filename: pool/kubeadm_1.20.0-00_amd64_18afc5e3855cf5aaef0dbdfd1b3304f9e8e571b3c4e43b5dc97c439d62a3321a.deb
root@master:~/cks/create_cluster# apt-get install kubeadm=1.20.2-00 kubectl=1.20.2-00 kubelet=1.20.2-00
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  rename
Use 'sudo apt autoremove' to remove it.
The following packages will be upgraded:
  kubeadm kubectl kubelet
3 upgraded, 0 newly installed, 0 to remove and 146 not upgraded.
Need to get 34.5 MB of archives.
After this operation, 32.8 kB of additional disk space will be used.
Get:1 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubelet amd64 1.20.2-00 [18.9 MB]
Get:2 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubectl amd64 1.20.2-00 [7,940 kB]
Get:3 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubeadm amd64 1.20.2-00 [7,706 kB]
Fetched 34.5 MB in 7s (4,914 kB/s)                                                                                                   
(Reading database ... 110090 files and directories currently installed.)
Preparing to unpack .../kubelet_1.20.2-00_amd64.deb ...
Unpacking kubelet (1.20.2-00) over (1.20.1-00) ...
Preparing to unpack .../kubectl_1.20.2-00_amd64.deb ...
Unpacking kubectl (1.20.2-00) over (1.20.0-00) ...
Preparing to unpack .../kubeadm_1.20.2-00_amd64.deb ...
Unpacking kubeadm (1.20.2-00) over (1.20.0-00) ...
Setting up kubelet (1.20.2-00) ...
Setting up kubectl (1.20.2-00) ...
Setting up kubeadm (1.20.2-00) ...
root@master:~/cks/create_cluster# kubeadm upgrade plan
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
[upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[preflight] Running pre-flight checks.
[upgrade] Running cluster health checks
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.20.0
[upgrade/versions] kubeadm version: v1.20.2
I0426 23:07:55.970280   68360 version.go:251] remote version is much newer: v1.21.0; falling back to: stable-1.20
[upgrade/versions] Latest stable version: v1.20.6
[upgrade/versions] Latest stable version: v1.20.6
[upgrade/versions] Latest version in the v1.20 series: v1.20.6
[upgrade/versions] Latest version in the v1.20 series: v1.20.6
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.6
            1 x v1.20.2   v1.20.6
Upgrade to the latest version in the v1.20 series:
COMPONENT                 CURRENT    AVAILABLE
kube-apiserver            v1.20.0    v1.20.6
kube-controller-manager   v1.20.0    v1.20.6
kube-scheduler            v1.20.0    v1.20.6
kube-proxy                v1.20.0    v1.20.6
CoreDNS                   1.7.0      1.7.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.6
Note: Before you can perform this upgrade, you have to update kubeadm to v1.20.6.
_____________________________________________________________________
The table below shows the current state of component configs as understood by this version of kubeadm.
Configs that have a "yes" mark in the "MANUAL UPGRADE REQUIRED" column require manual config upgrade or
resetting to kubeadm defaults before a successful upgrade can be performed. The version to manually
upgrade to is denoted in the "PREFERRED VERSION" column.
API GROUP                 CURRENT VERSION   PREFERRED VERSION   MANUAL UPGRADE REQUIRED
kubeproxy.config.k8s.io   v1alpha1          v1alpha1            no
kubelet.config.k8s.io     v1beta1           v1beta1             no
_____________________________________________________________________
root@master:~/cks/create_cluster# kubeadm upgrade apply v1.20.6
root@master:~/cks/create_cluster# k get nodes
NAME     STATUS                     ROLES                  AGE   VERSION
master   Ready,SchedulingDisabled   control-plane,master   42h   v1.20.2
node1    Ready                      <none>                 42h   v1.20.1
node2    Ready                      <none>                 42h   v1.20.1
root@master:~/cks/create_cluster# k uncordon master
node/master uncordoned
root@master:~/cks/create_cluster# k get node
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   42h   v1.20.2
node1    Ready    <none>                 42h   v1.20.1
node2    Ready    <none>                 42h   v1.20.1

4. Upgrade worker node

root@master:~/cks/create_cluster# k get node
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   42h   v1.20.2
node1    Ready    <none>                 42h   v1.20.1
node2    Ready    <none>                 42h   v1.20.1
root@master:~/cks/create_cluster# k drain node1 --ignore-daemonsets
node/node1 already cordoned
root@master:~/cks/create_cluster# k uncordon node1 
node/node1 uncordoned
root@node1:~# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38", GitTreeState:"clean", BuildDate:"2020-12-08T17:57:36Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
root@master:~/cks/create_cluster# apt-cache show kubeadm  |grep -e '1.20'
Version: 1.20.2-00
Filename: pool/kubeadm_1.20.2-00_amd64_38fa4593055ef1161d4cb322437eedda95186fb850819421b8cf75f3a943dc51.deb
Version: 1.20.1-00
Filename: pool/kubeadm_1.20.1-00_amd64_7cd8d4021bb251862b755ed9c240091a532b89e6c796d58c3fdea7c9a72b878f.deb
Version: 1.20.0-00
Filename: pool/kubeadm_1.20.0-00_amd64_18afc5e3855cf5aaef0dbdfd1b3304f9e8e571b3c4e43b5dc97c439d62a3321a.deb
root@master:~/cks/create_cluster# apt-get install kubeadm=1.20.2-00 kubectl=1.20.2-00 kubelet=1.20.2-00
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  rename
Use 'sudo apt autoremove' to remove it.
The following packages will be upgraded:
  kubeadm kubectl kubelet
3 upgraded, 0 newly installed, 0 to remove and 146 not upgraded.
Need to get 34.5 MB of archives.
After this operation, 32.8 kB of additional disk space will be used.
Get:1 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubelet amd64 1.20.2-00 [18.9 MB]
Get:2 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubectl amd64 1.20.2-00 [7,940 kB]
Get:3 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubeadm amd64 1.20.2-00 [7,706 kB]
Fetched 34.5 MB in 7s (4,914 kB/s)                                                                                                   
(Reading database ... 110090 files and directories currently installed.)
Preparing to unpack .../kubelet_1.20.2-00_amd64.deb ...
Unpacking kubelet (1.20.2-00) over (1.20.1-00) ...
Preparing to unpack .../kubectl_1.20.2-00_amd64.deb ...
Unpacking kubectl (1.20.2-00) over (1.20.0-00) ...
Preparing to unpack .../kubeadm_1.20.2-00_amd64.deb ...
Unpacking kubeadm (1.20.2-00) over (1.20.0-00) ...
Setting up kubelet (1.20.2-00) ...
Setting up kubectl (1.20.2-00) ...
Setting up kubeadm (1.20.2-00) ...
root@node1:~# kubeadm version
root@node1:~# kubectl version
root@node1:~# kubelet version
root@master:~/cks/create_cluster# k get node
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   42h   v1.20.2
node1    Ready    <none>                 42h   v1.20.2
node2    Ready    <none>                 42h   v1.20.1
root@master:~/cks/create_cluster# k uncordon node1 
node/node1 uncordoned


相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
相关文章
|
7月前
|
Kubernetes 网络协议 网络安全
提升你的云技能:深入了解CKA认证之k8s升级秘籍!
提升你的云技能:深入了解CKA认证之k8s升级秘籍!
118 0
|
7月前
|
Kubernetes 容器
k8s学习-CKS真题-日志审计 log audit
k8s学习-CKS真题-日志审计 log audit
175 0
|
4月前
|
Kubernetes 容器 Perl
【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决
【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决
|
4月前
|
Kubernetes 监控 API
在K8S中,RS资源如何实现升级和回滚?
在K8S中,RS资源如何实现升级和回滚?
|
4月前
|
Kubernetes API 开发工具
在K8S中,Deployment的升级过程是什么?
在K8S中,Deployment的升级过程是什么?
|
4月前
|
Kubernetes 容器 Perl
在k8S中,deployment升级策略是什么?
在k8S中,deployment升级策略是什么?
|
4月前
|
Kubernetes API Perl
在k8S中,deployment升级过程是什么?
在k8S中,deployment升级过程是什么?
|
4月前
|
Kubernetes 监控 Perl
在K8S中,deploy升级过程包括什么?
在K8S中,deploy升级过程包括什么?
|
4月前
|
Kubernetes jenkins 网络安全
Jenkins Pipeline 流水线 - 使用代理节点,Remote SSH 对 K8S 进行升级
Jenkins Pipeline 流水线 - 使用代理节点,Remote SSH 对 K8S 进行升级
58 0
|
4月前
|
Kubernetes Java Shell
Kubernetes(K8S) Deployment 升级和回滚
Kubernetes(K8S) Deployment 升级和回滚
160 0