1、停止服务删除原来的配置
kubeadm reset -f
rm -rf ~/.kube/
rm -rf /etc/kubernetes/
rm -rf /etc/systemd/system/kubelet.service.d
rm -rf /etc/systemd/system/kubelet.service
rm -rf /usr/bin/kube*
yum clean all
yum remove kube*
2、安装新版本的kubeadm
yum -y install kubeadm-1.20.0 kubectl-1.20.0 kubelet-1.20.0
systemctl enable kubelet.service
3、修改kubeadm-config.yaml
先生成配置yaml
kubeadm config print init-defaults > kubeadm-config.yaml
#修改ip为自己的机器ip
advertiseAddress: 192.168.66.10
#这个是阿里云的镜像仓库,下载速度还可以
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
#使用ipvs模式
networking:
dnsDomain: cluster.local
podSubnet: "10.244.0.0/16"
serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
SupportIPVSProxyMode: true
mode: ipvs
kubeadm config migrate --old-config kubeadm-config.yaml --new-config new.yaml
4、下载镜像
kubeadm config images pull --config /root/new.yaml
复制到其他机器上,去下载镜像
scp new.yaml root@k8s-node02:/root/
scp new.yaml root@k8s-node01:/root/
5、初始化master
kubeadm init --config=kubeadm-config.yaml --upload-certs|tee kubeadm-init.log
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.66.10:6443 --token abcdef.0123456789abcdef
--discovery-token-ca-cert-hash sha256:b7a43fd7651c783f87dfcfda5a2ccc61317e7ee28624f9324f4caeca525d8685
说明我们升级成功了,剩下的就是把node加入到集群即可
6、加入集群后,node的状态不正常是网络原因,需要执行下原来的flannel的安装yaml即可
kubectl apply -f kube-flannel.yml
7、如果kubectl get nodes 报错“The connection to the server localhost:8080 was refused - did you specify the right host or port?”
我们可以加一个环境变量即可
echo "export KUBEConFIG=/etc/kubernetes/admin.conf" >> /etc/profile