1.升级说明
Kubernetes集群小版本升级
基本上是只需要更新二进制文件即可。如果大版本升级
需要注意kubelet参数的变化,以及其他组件升级之后的变化。 由于Kubernete版本更新过快许多依赖并没有解决完善,并不建议生产环境使用较新版本。建议使用,比如1.29.10
,要10这个位置的数字大于5
升级集群版本建议逐步升级,k8s版本以 x.y.z 表示,其中 x 是主要版本, y 是次要版本,z 是补丁版本,尽量不能跳过次要版本升级,比如1.28.0->1.30.0可能遭遇失败,补丁版本可以跳跃更新,比如1.28.2->1.28.10
尽量将kubelet和kubeadm版本保持一致,可以偏差一个版本
升级后,因为容器spec的哈希值已更改,所有容器都会被重新启动
建议:多master环境的话,先其中一个master升级好所有服务。然后创建一个测试应用跑在该master节点,观察应用是否正常。没有问题再逐台升级
https://v1-29.docs.kubernetes.io/zh-cn/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
1.1 升级顺序
升级控制节点(master)
升级其他控制平面节点(高可用集群)
升级工作节点(worker)
2.kubeadm升级
2.1 备份数据
bash
# 备份目录
cp -a /etc/kubernetes/ /etc/kubernetes.bak
cp -a /var/lib/etcd /var/lib/etcd.bak
# 备份etcd数据
ETCDCTL_API=3 etcdctl snapshot save /data/etcd/etcd_bak.db \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key
# 如果没有etcdctl工具需要安装一下
yum install -y etcd
# 备份目录
cp -a /etc/kubernetes/ /etc/kubernetes.bak
cp -a /var/lib/etcd /var/lib/etcd.bak
# 备份etcd数据
ETCDCTL_API=3 etcdctl snapshot save /data/etcd/etcd_bak.db \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key
# 如果没有etcdctl工具需要安装一下
yum install -y etcd
2.2 配置源
bash
cat <<EOF | tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.29/rpm/repodata/repomd.xml.key
EOF
cat <<EOF | tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.29/rpm/repodata/repomd.xml.key
EOF
2.3 master节点
- 查看版本
bash
yum list --showduplicates kubeadm --disableexcludes=kubernetes
yum list --showduplicates kubeadm --disableexcludes=kubernetes
- 设置master节点为不可调度
bash
#禁止调度
kubectl cordon <node>
#驱逐
kubectl drain <node-to-drain> --ignore-daemonsets
#禁止调度
kubectl cordon <node>
#驱逐
kubectl drain <node-to-drain> --ignore-daemonsets
1.升级kubeadm
bash
yum install -y kubeadm-'1.29.10-*' --disableexcludes=kubernetes
yum install -y kubeadm-'1.29.10-*' --disableexcludes=kubernetes
- 查看版本升级后版本
bash
kubeadm version
kubeadm version
- 验证
bash
kubeadm upgrade plan
kubeadm upgrade plan
- 升级
bash
# 将 x 替换为你为此次升级所选择的补丁版本号
kubeadm upgrade apply v1.29.x
# 将 x 替换为你为此次升级所选择的补丁版本号
kubeadm upgrade apply v1.29.x
2.升级 kubelet 和 kubectl
bash
yum install -y kubelet-'1.29.10-*' kubectl-'1.29.10-*' --disableexcludes=kubernetes
yum install -y kubelet-'1.29.10-*' kubectl-'1.29.10-*' --disableexcludes=kubernetes
- 重启服务
sudo systemctl daemon-reload
sudo systemctl restart kubelet
sudo systemctl daemon-reload
sudo systemctl restart kubelet
- 解除调度
bash
# 将 <node-to-uncordon> 替换为你的节点名称
kubectl uncordon <node-to-uncordon>
# 将 <node-to-uncordon> 替换为你的节点名称
kubectl uncordon <node-to-uncordon>
2.4 work节点
1.升级 kubeadm
bash
# 将 1.29.x-* 中的 x 替换为最新的补丁版本
sudo yum install -y kubeadm-'1.29.x-*' --disableexcludes=kubernetes
yum install -y kubeadm-'1.29.10-*' --disableexcludes=kubernetes
# 将 1.29.x-* 中的 x 替换为最新的补丁版本
sudo yum install -y kubeadm-'1.29.x-*' --disableexcludes=kubernetes
yum install -y kubeadm-'1.29.10-*' --disableexcludes=kubernetes
- 升级
bash
kubeadm upgrade node
kubeadm upgrade node
2.升级 kubelet 和 kubectl
- 禁止调度
kubectl cordon <node-to-uncordon>
#驱逐
kubectl drain <node-to-drain> --ignore-daemonsets
kubectl cordon <node-to-uncordon>
#驱逐
kubectl drain <node-to-drain> --ignore-daemonsets
- 升级
bash
yum install -y kubelet-'1.29.10-*' kubectl-'1.29.10-*' --disableexcludes=kubernetes
yum install -y kubelet-'1.29.10-*' kubectl-'1.29.10-*' --disableexcludes=kubernetes
- 重启服务
sudo systemctl daemon-reload
sudo systemctl restart kubelet
sudo systemctl daemon-reload
sudo systemctl restart kubelet
- 解除调度
bash
kubectl uncordon <node-to-uncordon>
kubectl uncordon <node-to-uncordon>
2.5 验证
访问服务,和创建pod能否成功
3.二进制升级
bash
# 检查弃用的API使用情况
kubectl get pods --all-namespaces \
-o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,PHASE:.status.phase,API:.apiVersion
# 检查容器运行时
kubectl get nodes -o wide
# 检查弃用的API使用情况
kubectl get pods --all-namespaces \
-o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,PHASE:.status.phase,API:.apiVersion
# 检查容器运行时
kubectl get nodes -o wide
4.集群升级版本检查
通过kubepug来检查
2.1介绍
Kubepug
即是这样一个工具,一个升级前检查器,可帮助在迁移到新的主要版本之前在 Kubernetes 资源中找到已弃用和已删除的 API
2.2原理
下载生成的 data.json文件,其中包含指定Kubernetes 版本的APl弃用信息
扫描正在运行的Kubernetes集群,以确定是否有任何对象会受到剥夺的影响
向用户显示受影响的对象
2.3部署
1.在线部署
kubectl krew install deprecations
kubectl krew install deprecations
2.离线部署
- 安装
wget https://github.com/kubepug/kubepug/releases/download/v1.7.1/kubepug_linux_amd64.tar.gz
#解压
tar -zxvf kubepug_linux_amd64.tar.gz
mv ./kubepug /usr/local/bin/
wget https://github.com/kubepug/kubepug/releases/download/v1.7.1/kubepug_linux_amd64.tar.gz
#解压
tar -zxvf kubepug_linux_amd64.tar.gz
mv ./kubepug /usr/local/bin/
- 查看版本
bash
[root@kube-master-01 init_pack]# kubepug version
__ ___ __ __ .______ _______ .______ __ __ _______
| |/ / | | | | | _ \ | ____|| _ \ | | | | / _____|
| ' / | | | | | |_) | | |__ | |_) | | | | | | | __
| < | | | | | _ < | __| | ___/ | | | | | | |_ |
| . \ | `--' | | |_) | | |____ | | | `--' | | |__| |
|__|\__\ \______/ |______/ |_______|| _| \______/ \______|
kubepug: Shows all the deprecated objects in a Kubernetes cluster allowing the operator to verify them before upgrading the cluster.
It uses the Kubernetes API source code markers to define deprecated and deleted versions.
GitVersion: v1.7.1
GitCommit: unknown
GitTreeState: unknown
BuildDate: unknown
GoVersion: go1.21.3
Compiler: gc
Platform: linux/amd64
[root@kube-master-01 init_pack]# kubepug version
__ ___ __ __ .______ _______ .______ __ __ _______
| |/ / | | | | | _ \ | ____|| _ \ | | | | / _____|
| ' / | | | | | |_) | | |__ | |_) | | | | | | | __
| < | | | | | _ < | __| | ___/ | | | | | | |_ |
| . \ | `--' | | |_) | | |____ | | | `--' | | |__| |
|__|\__\ \______/ |______/ |_______|| _| \______/ \______|
kubepug: Shows all the deprecated objects in a Kubernetes cluster allowing the operator to verify them before upgrading the cluster.
It uses the Kubernetes API source code markers to define deprecated and deleted versions.
GitVersion: v1.7.1
GitCommit: unknown
GitTreeState: unknown
BuildDate: unknown
GoVersion: go1.21.3
Compiler: gc
Platform: linux/amd64
- 验证
bash
[root@kube-master-01 init_pack]# kubepug
No deprecated or deleted APIs found
Kubepug validates the APIs using Kubernetes markers. To know what are the deprecated and deleted APIS it checks, please go to https://kubepug.xyz/status/
??有问题
[root@kube-master-01 init_pack]# kubepug
No deprecated or deleted APIs found
Kubepug validates the APIs using Kubernetes markers. To know what are the deprecated and deleted APIS it checks, please go to https://kubepug.xyz/status/
??有问题