kubeadm从1.15.0升级k8s到1.20.0

原文

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*

systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/*
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/*
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker

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

k8s1.20之后不支持SupportIPVSProxyMode模式
featureGates:
SupportIPVSProxyMode: true
mode: ipvs

完整配置如下:

apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 172.16.0.15
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: ops--172-16-0-15
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.20.0
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
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加入到集群即可

加入集群,执行上面输出的:

kubeadm join 192.168.66.10:6443 --token abcdef.0123456789abcdef \
  --discovery-token-ca-cert-hash sha256:b7a43fd7651c783f87dfcfda5a2ccc61317e7ee28624f9324f4caeca525d8685 

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值