kubernetes 升级
只能一个大版本大版本升级,也就是1.26.1-1.27.1再进行1.27.1-1.28.1
不能跳版本
升级流程
驱逐master 上的pod,且不可调度
kubectl drain master --ignore-daemonsets# 安装新版本的kubeadm
yum install -y kubeadm-1.27.1-0 --disableexcludes=kubernetes
需要一层一层升级# 更新检查
kubeadm upgrade plan --ignore-preflight-errors=CoreDNSUnsupportedPlugins,CoreDNSMigration
# --ignore-preflight-errors=CoreDNSUnsupportedPlugins,CoreDNSMigration 跳过 coreDNS报错# 集群更新
kubeadm upgrade apply v1.27.1 --ignore-preflight-errors=CoreDNSUnsupportedPlugins,CoreDNSMigration --etcd-upgrade=false --certificate-renewal=false
# --certificate-renewal=false 不更新证书,防止 kube-apiserver on Node master did not change after 5m0s: timed out waiting for the condition# 组件更新
yum install -y kubelet-1.27.1-0 kubectl-1.27.1-0 --disableexcludes=kubernetes
systemctl daemon-reload
systemctl restart kubelet# 回复调度
kubectl uncordon master
报错问题
更新后 kubeadm upgrade plan 还是显示之前的版本
更新的images (/etc/kubernetes/manifests/kube-apiserver.yaml)
systemctl restart kubelet
查看
kubectl get pods -n kube-system -l component=kube-apiserver -o=jsonpath='{$.items[0].spec.containers[0].image}'
kubectl get pods -n kube-system -l component=kube-controller-manager -o=jsonpath='{$.items[0].spec.containers[0].image}'
kubectl get pods -n kube-system -l component=kube-scheduler -o=jsonpath='{$.items[0].spec.containers[0].image}'
集群升级题目 - cka题库
root@master01:~# kubectl cordon master01
node/master01 cordonedroot@master01:~# kubectl drain --ignore-daemonsets master01
node/master01 already cordoned
Warning: ignoring DaemonSet-managed Pods: calico-system/calico-node-87nzw, kube-system/kube-proxy-25gqq
node/master01 drained# ssh 到 master 节点,并切换到 root 下
ssh master01
sudo -i
apt-get update
apt-cache show kubeadm|grep 1.25.2
apt-get install kubeadm=1.25.2-00root@master01:~# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.2", GitCommit:"5835544ca568b757a8ecae5c153f317e5736700e", GitTreeState:"clean", BuildDate:"2022-09-21T14:32:18Z", GoVersion:"go1.19.1", Compiler:"gc", Platform:"linux/amd64"}# 可以一步一步-h
root@master01:~# kubeadm upgrade apply v1.25.2 --etcd-upgrade=false
[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/version] You have chosen to change the cluster version to "v1.25.2"
[upgrade/versions] Cluster version: v1.25.1
[upgrade/versions] kubeadm version: v1.25.2
[upgrade] Are you sure you want to proceed? [y/N]: y
检查
root@master01:~# 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.25.2
[upgrade/versions] kubeadm version: v1.25.2
# 升级 kubelet kubectl
apt-get install kubelet=1.25.2-00
kubelet --version
apt-get install kubectl=1.25.2-00
kubectl versionkubectl get node
candidate@node01:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master01 Ready control-plane 118d v1.25.2
node01 Ready <none> 118d v1.25.1
node02 Ready <none> 118d v1.25.1# 恢复调用
kubectl uncordon master01