zoukankan      html  css  js  c++  java
  • 升级Node和Calico

    一、升级Node

    1.1、升级kubelet(先升级master02)

    # 1、下线k8s-master02
    [root@k8s-master01 ~]# kubectl drain k8s-master02 --delete-local-data --force --ignore-daemonsets
    
    # 2、查看状态master02节点已经变成SchedulingDisabled状态
    [root@k8s-master01 ~]# kubectl get node
    NAME           STATUS                     ROLES    AGE    VERSION
    k8s-master01   Ready                      matser   5d5h   v1.19.5
    k8s-master02   Ready,SchedulingDisabled   <none>   5d5h   v1.19.5
    k8s-master03   Ready                      <none>   5d5h   v1.19.5
    k8s-node01     Ready                      <none>   5d5h   v1.19.5
    k8s-node02     Ready                      <none>   5d5h   v1.19.5
    
    # 3、停止kubelet(master02节点上、升级那个节点就去那个节点停止,然后拷贝)
    [root@k8s-master02 ~]# systemctl stop kubelet  
    
    # 4、备份原文件且copy kubelet文件
    [root@k8s-master02 ~]# cd /usr/local/bin/
    [root@k8s-master02 bin]# mkdir kube-back
    [root@k8s-master02 bin]# mv kubelet kube-back/
    [root@k8s-master02 bin]# scp k8s-master01:/root/kubernetes/server/bin/kubelet .
    [root@k8s-master02 bin]# ./kubelet --version    # 验证版本是否正确
    Kubernetes v1.20.0
    
    
    # 5、启动kubelet文件
    !!!先不启动,先升级了Calico!!!
    !!!请先往下走,升级了Calico,再启动kubelet!!!
    

    二、升级Calico

    2.1、calico安装文档

    # 安装方式有几种、参考官方文档选择吧
    https://docs.projectcalico.org/getting-started/kubernetes/self-managed-onprem/onpremises
    

    2.2、官网升级文档

    https://docs.projectcalico.org/maintenance/kubernetes-upgrade#upgrading-an-installation-that-uses-the-kubernetes-api-datastore
    

    2.3、下载

    # 1、网络和网络策略管理都是用Calico
    [root@k8s-master01 ~]# curl https://docs.projectcalico.org/manifests/calico.yaml -O    # 我用的是这个
    
    # 2、网络策略管理用Calico和网络用flannel
    curl https://docs.projectcalico.org/manifests/canal.yaml -O
    

    2.4、备份原来的cm、deploy

    [root@k8s-master01 ~]# kubectl get cm -n kube-system  calico-config -oyaml > calico-config.yaml
    [root@k8s-master01 ~]# kubectl get deploy -n kube-system  calico-kube-controllers -oyaml > calico-kube-controllers.yaml
    

    2.5、升级k8s-master02

    # 1、查看版本。现在的版本(最新的)
    [root@k8s-master01 ~]# cat calico.yaml | grep image    
              image: docker.io/calico/cni:v3.17.1
              image: docker.io/calico/cni:v3.17.1
              image: docker.io/calico/pod2daemon-flexvol:v3.17.1
              image: docker.io/calico/node:v3.17.1
              image: docker.io/calico/kube-controllers:v3.17.1
              
    # 2、更改一下更新策略(防止更新失败)
    [root@k8s-master01 ~]# vim calico.yaml 
    # 原来的策略:
      updateStrategy:
        type: RollingUpdate
        rollingUpdate:
          maxUnavailable: 1
    # 更改为:
      updateStrategy:
        type: OnDelete
    # 然后apply它
    [root@k8s-master01 ~]# kubectl apply -f calico.yaml 
    
    # 3、查看是否加载成功
    [root@k8s-master01 ~]# kubectl edit ds -n kube-system
    # 查找calico的镜像,看到3.17.1说明更新成功
    image: docker.io/calico/cni:v3.17.1
    # 更新策略也变了
      updateStrategy:
        rollingUpdate:
          maxUnavailable: 1
        type: OnDelete
        
    # 4、启动kubelet(在刚刚停止的节点启动,这次是升级的matser02,所以在02节点启动)
    [root@k8s-master02 ~]# systemctl start kubelet
    
    # 5、上线节点k8s-master02
    [root@k8s-master01 ~]# kubectl uncordon k8s-master02
    node/k8s-master02 uncordoned
    
    # 6、查看版本是否正确
    [root@k8s-master01 ~]# kubectl get node
    NAME           STATUS     ROLES    AGE    VERSION
    k8s-master01   Ready      matser   5d6h   v1.19.5
    k8s-master02   Ready      <none>   5d6h   v1.20.0   # 已经成功变成了v1.20.0
    k8s-master03   Ready      <none>   5d6h   v1.19.5
    k8s-node01     Ready      <none>   5d6h   v1.19.5
    k8s-node02     NotReady   <none>   5d6h   v1.19.5
    
    # 7、更新Calico  #这次更新的Calico是k8s-master02上的,所以只滚动更新k8s-master02 节点上的
    [root@k8s-master01 ~]#  kubectl get pod -n kube-system -owide | grep k8s-master02 
    calico-node-wz2l9       1/1     Running   9          5d6h   192.168.1.202   k8s-master02 
    [root@k8s-master01 ~]#  kubectl delete pod -n kube-system  calico-node-wz2l9 
    pod "calico-node-wz2l9" deleted
    
    # 8、查看更新状态
    [root@k8s-master01 ~]#  kubectl get pod -n kube-system -owide | grep k8s-master02 
    calico-node-dr6pk       0/1     Init:0/3   0          19s    192.168.1.202   k8s-master02 
    
    # 9、等状态变成Running,查看版本是否更新成功
    [root@k8s-master01 ~]# kubectl edit po calico-node-dr6pk   -n kube-system
    
    # 到此为止,一个节点完整的步骤已经走完了!那么我们更新一下其他的节点的吧
    

    三、更新k8s-master01节点

    # 1、常规操作
    [root@k8s-master01 ~]# systemctl stop kubelet
    [root@k8s-master01 ~]# cd kubernetes/server/bin/
    [root@k8s-master01 bin]# cp -rp  kubelet  /usr/local/bin/
    [root@k8s-master01 bin]# systemctl start kubelet && systemctl status kubelet
    
    # 2、更新k8s-master01节点上的calico
    [root@k8s-master01 bin]# kubectl get pod -n kube-system -owide | grep k8s-master01 
    calico-node-t8c5l        0/1     Running   10         5d7h   192.168.1.201   k8s-master01
    [root@k8s-master01 bin]# kubectl delete pod -n kube-system  calico-node-t8c5l 
    pod "calico-node-t8c5l" deleted
    
    # 3、查看node是否更新成功
    [root@k8s-master01 bin]# kubectl get node
    NAME           STATUS     ROLES    AGE    VERSION
    k8s-master01   Ready      matser   5d7h   v1.20.0
    k8s-master02   Ready      <none>   5d7h   v1.20.0
    k8s-master03   Ready      <none>   5d7h   v1.19.5
    k8s-node01     Ready      <none>   5d7h   v1.19.5
    k8s-node02     NotReady   <none>   5d7h   v1.19.5
    

    四、更新k8s-node01节点(其他节点的都一样)

    # 1、更新kubelet
    [root@k8s-node01 ~]# systemctl stop kubelet
    [root@k8s-node02 ~]# cd  /usr/local/bin/ ;  mkdir kube_back; mv kubelet  kube_back/
    [root@k8s-node01 bin]# scp k8s-master01:/root/kubernetes/server/bin/kubelet .
    
    # 2、更新calico
    [root@k8s-master01 ~]# kubectl get pod -n kube-system -owide
    [root@k8s-master01 ~]# kubectl delete pod -n kube-system calico-node-hjqvm
    pod "calico-node-hjqvm" deleted
    
    # 3、启动kubelet
    [root@k8s-node01 bin]# systemctl restart kubelet && systemctl status kubelet
    
    # 4、确定calicoRunning后,查看kubelet版本是否更新成功
    [root@k8s-master01 ~]# kubectl get node
    NAME           STATUS   ROLES    AGE    VERSION
    k8s-master01   Ready    matser   5d7h   v1.20.0
    k8s-master02   Ready    <none>   5d7h   v1.20.0
    k8s-master03   Ready    <none>   5d7h   v1.19.5
    k8s-node01     Ready    <none>   5d7h   v1.20.0
    k8s-node02     Ready    <none>   5d7h   v1.20.0
    
  • 相关阅读:
    练习题
    作业2.6-2.15 两次作业
    11.13(2)
    11.13
    11.6
    10.30
    10.15
    10.9
    9.25号作业
    9.18号
  • 原文地址:https://www.cnblogs.com/hsyw/p/14396062.html
Copyright © 2011-2022 走看看