請參閱以下指示,以使用 Tanzu CLI 安裝並設定 Cluster Autoscaler 套件。

需求

請遵循下列需求。
  • 最低 vSphere 版本為 vSphere 8 U3,包括 vCenter 和 ESXi 主機
  • vSphere 8 的最低 TKr 版本為 TKr 1.27.x
  • TKr 的次要版本和 Cluster Autoscaler 套件的次要版本必須相符
備註: Autoscaler 套件次要版本與 TKr 次要版本之間存在一對一關係。例如,如果使用的是 TKr 1.27.11,則應安裝 Autoscaler v1.27.2。如果版本不符,套件重新調整將失敗。

設定 vSphere 命名空間

完成佈建 TKG 叢集的下列必要條件工作。

  1. 安裝或將您的環境更新到 vSphere 8 U3 和適用於 vSphere 8 的 TKr 1.27.x
  2. 使用最新的 Tanzu Kubernetes 版本 建立或更新內容程式庫。請參閱管理用於 TKG 服務 叢集的 Kubernetes 版本
  3. 建立並設定 vSphere 命名空間 以便主控 TKG 叢集。請參閱設定 vSphere 命名空間 以便託管 TKG 服務 叢集
  4. 安裝 vSphere 適用的 Kubernetes CLI 工具

    下列範例可用於從命令列安裝工具。如需其他指導,請參閱安裝 vSphere 適用的 Kubernetes CLI 工具

    wget https://SUPERVISOR-IP-or-FQDN/wcp/plugin/linux-amd64/vsphere-plugin.zip
    unzip vsphere-plugin.zip
    chmod +x bin/kubectl*
    mv bin/kubectl* /usr/bin/kubectl vsphere --help
    rm ~/.kube/config
    kubectl vsphere login --insecure-skip-tls-verify --server SUPERVISOR-IP-or-FQDN --tanzu-kubernetes-cluster-namespace VSPHERE-NAMESPACE --vsphere-username VSPHERE-USER
    kubectl config use-context VSPHERE-NAMESPACE
  5. 執行 kubectlkubectl vsphere 以確認安裝。

使用 Autoscaler 註解建立 TKG 叢集

按照指示建立 TKG 叢集。如需其他指導,請參閱使用 Kubectl 佈建 TKG 叢集的工作流程

若要使用 Autoscaler,您必須根據此處提供的叢集規格範例設定帶有 autoscaler 標籤註解的叢集。與一般叢集佈建不同,您不會對 worker 節點複本的數目進行硬式編碼。Kubernetes 根據 autoscaler 的最小和最大大小註解內建了複本的預設邏輯。由於這是新的叢集,因此使用最小大小建立叢集。如需詳細資訊,請參閱 https://cluster-api.sigs.k8s.io/tasks/automated-machine-management/autoscaling
  1. 使用 kubectl 對 主管 進行驗證。
    kubectl vsphere login --server=SUPERVISOR-CONTROL-PLANE-IP-ADDRESS-or-FQDN --vsphere-username USERNAME
  2. 將內容切換到將主控叢集的目標 vSphere 命名空間
    kubectl config use-context tkgs-cluster-namespace
  3. 列出 vSphere 命名空間 中可用的虛擬機器類別。

    您只能使用已繫結到目標 vSphere 命名空間 的虛擬機器類別。請參閱對 TKG 服務 叢集使用虛擬機器類別

  4. 列出可用的持續性磁碟區儲存區類別。
    kubectl describe namespace VSPHERE-NAMESPACE-NAME

    命令將傳回有關 vSphere 命名空間 的詳細資料,包括儲存區類別。命令 kubectl describe storageclasses 還會傳回可用的儲存區類別,但需要 vSphere 管理員權限。

  5. 列出可用的 Tanzu Kubernetes 版本
    kubectl get tkr

    此命令將傳回此 vSphere 命名空間 中可用的 TKr 及其相容性。請參閱管理用於 TKG 服務 叢集的 Kubernetes 版本

  6. 使用您收集的資訊來編寫 TKG 叢集規格 YAML 檔案,其中包含所需的 Cluster Autoscaler 組態。
    • 對 worker 節點集區使用 *-min-size 個和 *-max-size 個註解,在此範例中,3 表示可以調整的最小 worker 節點數,5 表示可以調整的最大 worker 節點數。依預設,將建立具有 3 個 worker 節點的叢集。
    • 為 TKr 和 Autoscaler 套件使用符合的次要版本。
    • 使用的叢集 metadata.namemetadata.namespace 值與 Autoscaler 套件預設值一致。如果在叢集規格中變更這些值,則需要在 autoscaler-data-values 中變更這些值 (請參閱以下內容)。
    #cc-autoscaler.yaml
    apiVersion: cluster.x-k8s.io/v1beta1
    kind: Cluster
    metadata:
     name: tkc
     namespace: cluster
    spec:
     clusterNetwork:
       pods:
         cidrBlocks:
         - 192.0.2.0/16
       serviceDomain: cluster.local
       services:
         cidrBlocks:
         - 198.51.100.0/12
     topology:
       class: tanzukubernetescluster
       controlPlane:
         metadata: {}
         replicas: 3
       variables:
       - name: storageClasses
         value:
         - wcpglobal-storage-profile
       - name: vmClass
         value: guaranteed-medium
       - name: storageClass
         value: wcpglobal-storage-profile
       #minor versions must match
       version: v1.27.11---vmware.1-fips.1-tkg.2
       workers:
         machineDeployments:
         - class: node-pool
           metadata:
             annotations:
               cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "3"
               cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "5"
           name: np-1
  7. 套用叢集規格。
    kubectl apply -f cc-autoscaler.yaml
  8. 確認叢集建立。
    kubectl get cluster,vm
  9. 確認叢集節點版本。
    kubectl get node

在 TKG 叢集上建立套件存放庫

佈建 TKG 叢集後,請安裝 Tanzu CLI 並設定套件存放庫。
  1. 安裝 Tanzu CLI。

    請參閱安裝 Tanzu CLI 以用於 TKG 服務 叢集

  2. 登入叢集。
    rm ~/.kube/config
    kubectl vsphere login --insecure-skip-tls-verify --server 192.168.0.2 --tanzu-kubernetes-cluster-namespace autoscaler --vsphere-username [email protected] --tanzu-kubernetes-cluster-name cckubectl 
    config use-context cc
  3. 建立套件存放庫。
    #Standard package repository URL might change depending on the required cluster autoscaler version
    tanzu package repository add standard-repo --url projects.registry.vmware.com/tkg/packages/standard/repo:v2024.4.12 -n tkg-system
    tanzu package available list -n tkg-system
    tanzu package available get cluster-autoscaler.tanzu.vmware.com -n tkg-system

安裝 Autoscaler 套件

安裝 Cluster Autoscaler 套件。將在 kube-system 命名空間中安裝 Cluster Autoscaler。
  1. 使用 Tanzu CLI 命令產生預設 values.yaml
    tanzu package available get cluster-autoscaler.tanzu.vmware.com/1.27.2+vmware.1-tkg.3  -n tkg-system --default-values-file-output values.yaml
  2. 更新套件安裝的 values.yaml
    arguments:  
      ignoreDaemonsetsUtilization: true  
      maxNodeProvisionTime: 15m  
      maxNodesTotal: 0  
      metricsPort: 8085  
      scaleDownDelayAfterAdd: 10m  
      scaleDownDelayAfterDelete: 10s  
      scaleDownDelayAfterFailure: 3m  
      scaleDownUnneededTime: 10m
    clusterConfig:  
      clusterName: "tkc"  
      clusterNamespace: "cluster"
    paused: false
  3. 使用 Tanzu CLI 安裝 Cluster Autoscaler 套件。
    tanzu package install cluster-autoscaler-pkgi -n tkg-system --package cluster-autoscaler.tanzu.vmware.com --version 1.27.2+vmware.1-tkg.3 --values-file values.yaml

測試叢集自動調整

若要測試叢集自動調整功能,請部署應用程式,增加複本數,並確認已擴充額外的 worker 節點以處理額外的負載。

請參閱測試叢集 Autoscaler

升級自動調整的叢集

若要升級自動調整的叢集,必須先暫停 Autoscaler 套件。

請參閱使用 Tanzu CLI 升級自動縮放的叢集