全部產品
Search
文件中心

Container Service for Kubernetes:更新ACK專有叢集即將到期的認證

更新時間:Aug 12, 2026

本文介紹如何更新ACK專有叢集即將到期的認證。您可以通過控制台或kubectl更新所有節點的認證,也可以手動更新Master和Worker節點認證。

說明

ACK會自動更新ACK託管叢集中Master節點的認證,無需您手動處理。

通過控制台更新所有節點認證

  1. 登入Container Service管理主控台,在左側導覽列選擇叢集列表

  2. 單擊認證即將到期叢集右側的更新認證,進入更新認證頁面。

    說明

    如果叢集認證即將在兩個月左右到期,會出現更新認證

    在叢集列表中找到目的地組群,單擊其右側操作列中的更新認證

  3. 更新認證頁面,單擊更新認證,按照頁面指引完成認證的更新。

    成功更新叢集認證後,您可以看到以下內容:

    • 更新認證頁面,顯示更新成功

    • 叢集列表頁面,目的地組群沒有更新認證提示。

通過kubectl自動更新所有節點認證

更新認證

在叢集任意Master節點,執行以下命令完成叢集所有節點的認證更新。

curl http://aliacs-k8s-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/public/cert-update/renew.sh | bash

結果驗證

需已通過kubectl串連叢集,請參見通過kubectl串連Kubernetes叢集
  1. 執行以下命令,查看叢集Master和Worker節點狀態。

    kubectl get nodes
    [root@xxx ~]# kubectl get nodes
    NAME                      STATUS    ROLES     AGE       VERSION
    cn-hangzhou.xxx           Ready     <none>    23d       v1.11.2
    cn-hangzhou.xxx           Ready     <none>    23d       v1.11.2
    cn-hangzhou.xxx           Ready     master    47d       v1.11.2
    cn-hangzhou.xxx           Ready     master    47d       v1.11.2
    cn-hangzhou.xxx           Ready     master    47d       v1.11.2
    cn-hangzhou.xxx           Ready     <none>    47d       v1.11.2
    cn-hangzhou.xxx           Ready     <none>    47d       v1.11.2
    [root@xxx ~]#
  2. 執行以下命令,當Master節點對應的COMPLETIONS均為1,Worker節點對應的COMPLETIONS為叢集Worker節點數時,所有認證完成更新。

    kubectl -n kube-system get job
    [root@                              ~]# kubectl get job -nkube-system
    NAME                                  COMPLETIONS   DURATION   AGE
    aliyun-cert-renew-master-1            1/1           46s        4m49s
    aliyun-cert-renew-master-2            1/1           28s        4m19s
    aliyun-cert-renew-master-3            1/1           26s        3m48s
    aliyun-cert-renew-worker              6/6           46s        3m18s
    ingress-nginx-admission-create        1/1           29s        3d
    ingress-nginx-admission-patch         1/1           43s        3d
    kube-eventer-init-1.5-5e0e7cl-aliyun  1/1           31s        3d

手動更新Master節點認證

  1. 任意路徑下,複製以下內容,建立job-master.yml檔案。

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: ${jobname}
      namespace: kube-system
    spec:
      backoffLimit: 0
      completions: 1
      parallelism: 1
      template:
        spec:
          activeDeadlineSeconds: 3600
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                - matchExpressions:
                  - key: kubernetes.io/hostname
                    operator: In
                    values:
                    - ${hostname}
          containers:
          - command:
            - /renew/upgrade-k8s.sh
            - --role
            - master
            image: registry.cn-hangzhou.aliyuncs.com/acs/cert-rotate:v1.0.0
            imagePullPolicy: Always
            name: ${jobname}
            securityContext:
              privileged: true
            volumeMounts:
            - mountPath: /alicoud-k8s-host
              name: ${jobname}       
          hostNetwork: true
          hostPID: true
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          tolerations:
          - effect: NoSchedule
            key: node-role.kubernetes.io/master
          volumes:
          - hostPath:
              path: /
              type: Directory
            name: ${jobname}
  2. 擷取叢集Master節點個數和節點名稱等資訊。

    • 方法一:通過命令列

      執行以下命令:

      kubectl get nodes
      [root@xxx            ~]# kubectl get nodes
      NAME               STATUS    ROLES     AGE    VERSION
      cn-hangzhou.ixxx   Ready     <none>    22d    v1.11.2
      cn-hangzhou.ixxx   Ready     <none>    22d    v1.11.2
      cn-hangzhou.ixxx   Ready     master    46d    v1.11.2
      cn-hangzhou.ixxx   Ready     master    46d    v1.11.2
      cn-hangzhou.ixxx   Ready     master    46d    v1.11.2
      cn-hangzhou.ixxx   Ready     <none>    46d    v1.11.2
      cn-hangzhou.ixxx   Ready     <none>    46d    v1.11.2
      [root@xxx            ~]#
    • 方法二:通過控制台

      1. 登入Container Service管理主控台,在左側導覽列選擇叢集列表

      2. 叢集列表頁面中,單擊目的地組群名稱或者目的地組群右側操作列下的詳情

      3. 在叢集管理頁的左側導覽列中,選擇節點管理 > 節點擷取Master個數和對應的名稱、IP地址、執行個體ID。

  3. 執行以下命令替換job-master.yml檔案中指定的變數${jobname}${hostname}

    sed 's/${jobname}/cert-job-2/g; s/${hostname}/hostname/g' job-master.yml > job-master2.yml

    其中:

    • ${jobname}為Job的名稱,此處設定為cert-job-2

    • ${hostname}為叢集Master節點的名稱,此處請將hostname替換為步驟2中查看到的Master名稱。

  4. 執行以下命令建立Job。

    kubectl create -f job-master2.yml
  5. 執行以下命令查看Job狀態,當COMPLETIONS均為1時,認證完成更新。

    kubectl get job -nkube-system
  6. 重複執行步驟3~5,完成所有Master節點的認證更新。

    [root@xxx ~]# kubectl get job -nkube-system
    NAME          COMPLETIONS   DURATION   AGE
    cert-job-2    1/1           46s        22m
    cert-job-3    1/1           28s        2m
    cert-job-4    1/1           26s        1m
    [root@xxx ~]#

手動更新Worker節點認證

  1. 任意路徑下,複製以下內容,建立job-node.yml檔案。

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: ${jobname}
      namespace: kube-system
    spec:
      backoffLimit: 0
      completions: ${nodesize}
      parallelism: ${nodesize}
      template:
        spec:
          activeDeadlineSeconds: 3600
          affinity:
            podAntiAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
              - labelSelector:
                  matchExpressions:
                  - key: job-name
                    operator: In
                    values:
                    - ${jobname}
                topologyKey: kubernetes.io/hostname
          containers:
          - command:
            - /renew/upgrade-k8s.sh
            - --role
            - node
            - --rootkey
            - ${key}
            image: registry.cn-hangzhou.aliyuncs.com/acs/cert-rotate:v1.0.0
            imagePullPolicy: Always
            name: ${jobname}
            securityContext:
              privileged: true
            volumeMounts:
            - mountPath: /alicoud-k8s-host
              name: ${jobname}
          hostNetwork: true
          hostPID: true
          restartPolicy: Never
          schedulerName: default-scheduler
          securityContext: {}
          volumes:
          - hostPath:
              path: /
              type: Directory
            name: ${jobname}
    說明

    如果Worker節點帶有Taint,需要在job-node.yml檔案中增加對該Taint的tolerations,即在securityContext: {}volumes:之間增加以下內容(若有n個帶有Taint的Worker節點,請複製n次):

          tolerations:
          - effect: NoSchedule
            key: ${key}
            operator: Equal
            value: ${value}

    擷取${name}${value}的方法如下:

    1. 任意路徑下,複製以下內容,建立taint.tml檔案。

      {{printf "%-50s %-12s\n" "Node" "Taint"}}
                          {{- range .items}}
                          {{- if $taint := (index .spec "taints") }}
                          {{- .metadata.name }}{{ "\t" }}
                          {{- range $taint }}
                          {{- .key }}={{ .value }}:{{ .effect }}{{ "\t" }}
                          {{- end }}
                          {{- "\n" }}
                          {{- end}}
                          {{- end}}
    2. 執行以下命令,查詢帶有Taint的Worker節點的${name}${value}

      kubectl get nodes -o go-template-file="taint.tml"
      [root@xxx                       ~]# kubectl get nodes -o go-template-file="taint.tml"
      Node                              Taint
      cn-hangzhou.i-xxx                 key1=value1:NoSchedule
      cn-hangzhou.i-xxx                 node-role.kubernetes.io/master=<no value>:NoSchedule
      cn-hangzhou.i-xxx                 node-role.kubernetes.io/master=<no value>:NoSchedule
      cn-hangzhou.i-xxx                 node-role.kubernetes.io/master=<no value>:NoSchedule
  2. 執行以下命令,擷取叢集的CAKey。

    sed '1d' /etc/kubernetes/pki/ca.key | base64 -w 0
  3. 執行以下命令替換job-node.yml檔案中指定的變數${jobname}${nodesize}${key}

    sed 's/${jobname}/cert-node-2/g; s/${nodesize}/nodesize/g; s/${key}/key/g' job-node.yml > job-node2.yml

    其中:

    • ${jobname}為Job的名稱,此處設定為cert-node-2

    • ${nodesize}為Worker節點個數,擷取方法可參見手動更新Worker節點認證的步驟1。此處請將nodesize替換為叢集的Worker個數。

    • ${key}為叢集的CAKey,此處請將key替換為手動更新Worker節點認證步驟2擷取到的CAKey。

  4. 執行以下命令建立Job。

    kubectl create -f job-node2.yml
  5. 執行以下命令查看Job狀態,當COMPLETIONS為叢集Worker節點數時,認證完成更新。

    kubectl get job -nkube-system
    [root@xxx ~]# kubectl get job -nkube-system
    NAME          COMPLETIONS   DURATION   AGE
    cert-job-2    1/1           46s        1h
    cert-job-3    1/1           28s        47m
    cert-job-4    1/1           26s        46m
    cert-node-2   4/4           46s        1m
    [root@xxx ~]#