SNOWTOO
Just for Sharing

升级k8s集群版本

2020年04月18日 分类:学习笔记k8s

kubernetes的发行版已经到v1.18,目前集群用的版本还在v1.16,kubernetes-dashboard也推出了适配v1.17的v2.0.0-rc7,所以升级集群的版本到v1.17,下面记录主要的步骤。

1. 卸载旧版Kubernetes Dashboard

kubectl delete ns kubernetes-dashboard

2. 升级控制节点

# 列出可以升级的最新小版本,目前1.17最新的是1.17.5
yum list --showduplicates kubeadm --disableexcludes=kubernetes
# 验证版本号
kubeadm version
# 升级kubeadm
yum install -y kubeadm-1.17.5-0 --disableexcludes=kubernetes
# 检查您的集群是否可以升级,并可以获取到升级的版本
kubeadm upgrade plan
# 升级到指定版本
kubeadm upgrade apply v1.17.5


# 升级CNI(如果需要的话)
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml


# 升级kubelet和kubectl
yum install -y kubelet-1.17.5-0 kubectl-1.17.5-0 --disableexcludes=kubernetes
# 重新加载配置和重启
systemctl daemon-reload
systemctl restart kubelet

3. 升级工作节点

# 升级kubeadm
yum install -y kubeadm-1.17.5-0 --disableexcludes=kubernetes
# 升级 kubelet 配置
kubeadm upgrade node config --kubelet-version v1.17.5
# 升级kubelet和kubectl
yum install -y kubelet-1.17.5-0 kubectl-1.17.5-0 --disableexcludes=kubernetes
# 重新加载配置和重启
systemctl daemon-reload
systemctl restart kubelet

4. 安装新版Kubernetes Dashboard

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc6/aio/deploy/recommended.yaml

创建登录用户

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard

获取登录token

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

5. 参考文档

作者:wuyuan 本文来自Wuyuan's Blog 转载请注明,谢谢! 文章地址: https://www.snowtoo.com/blog/detail/134