可以新增 Cloud Consumption Interface (CCI) 元素,以在 VMware Aria Automation 範本中使用 CCI 服務,這樣您的使用者可以在主管命名空間中使用虛擬機器服務和 Tanzu Kubernetes Grid Service 請求以 Kubernetes 為基礎的工作負載。

若要查看 CCI 元素,請展開雲端範本中資源庫內的 Cloud Consumption Interface 區段,或在搜尋資源類型欄位中輸入 cci

在雲端範本中找到 CCI 元素

下表顯示了範本中可供使用者拖放和設定的三種 CCI 資源類型。
主管命名空間資源

CCI.Supervisor.Namespace

建立新的主管命名空間,該主管命名空間可為以 Kubernetes 為基礎的工作區提供資源限制、使用者存取和可用的主管服務,以便使用者可以根據應用程式需求佈建虛擬機器和 TKG 資源。
主管資源

CCI.Supervisor.Resource

根據傳遞給正在設定的主管資源的 Kubernetes 資訊清單,在主管命名空間中建立任何受支援的主管 Kubernetes 資源,例如 virtualmachinesvirtualmachineservicestanzukubernetesclusterspersistentvolumeclaimssecrets 等。
TKG 資源

CCI.TKG.Resource

在 TKG 叢集中建立任何受支援的 Kubernetes 資源。
備註: 將 CCI 元素新增到雲端範本之前, VMware Aria Automation 管理員必須先設定 CCI。請參閱 Cloud Consumption Interface 設定和組態
以下範例顯示了 CCI 資源如何在雲端範本的 YAML 代碼中呈現。每個範例已經過剪除,僅顯示重要行。

主管命名空間資源範例

CCI.Supervisor.Namespace 表示以主管 Kubernetes 為基礎的工作區,可在其中為應用程式建立使用者管理的 vSphere 主管 IaaS 資源。

此範例定義了一個名為 cciNamespace 的 CCI 主管命名空間資源,以佈建一個名為 demo 的主管命名空間。

為確保在目標主管上佈建命名空間,必須使用專案定義的 classNameregionName 設定主管命名空間。
formatVersion: 1
inputs: {}
resources:
  cciNamespace:
    type: CCI.Supervisor.Namespace
    properties:
      name: demo
      className: default
      regionName: dev-us-west

主管資源範例

您使用 CCI.Supervisor.Resource 傳遞支援在主管命名空間內容中執行的 Kubernetes 物件的 Kubernetes 資訊清單。

  • 若要在特定的主管命名空間中佈建主管資源,可以透過使用範本繫結運算式將主管資源內容屬性對應至主管命名空間識別碼來設定該內容,例如,context: ${resource.cciNamespace.id}
  • 若要指定需要佈建的物件,可以透過將 Kubernetes 資訊清單傳遞給要建立的 Kubernetes 物件來設定主管資源的資訊清單內容。
此範例透過提供 Kubernetes 資訊清單建立了一個 TKG 叢集,該資訊清單指定了網路、拓撲、控制平面大小和 Worker 節點計數等設定。
formatVersion: 1
inputs: {}
resources:
  cciTKGCluster:
    type: CCI.Supervisor.Resource
    properties:
      context: ${resource.cciNamespace.id}
      manifest:
        apiVersion: cluster.x-k8s.io/v1beta1
        kind: Cluster
        metadata:
          name: ${input.tkg_Name}
          labels:
            tkg-cluster-selector: ${input.tkg_Name}
        spec:
          clusterNetwork:
            cni:
              name: antrea
            pods:
              cidrBlocks:
                - 192.168.156.0/20
            services:
              cidrBlocks:
                - 10.96.0.0/12
            serviceDomain: cluster.local
          topology:
            class: tanzukubernetescluster
            version: v1.24.9---vmware.1-tkg.4
            variables:
              - name: storageClasses
                value:
                  - tmm-kubernetes-storage-policy
              - name: defaultStorageClass
                value: tmm-kubernetes-storage-policy
              - name: vmClass
                value: ${input.controlPlaneVmClassName}
              - name: storageClass
                value: tmm-kubernetes-storage-policy
            controlPlane:
              replicas: ${input.controlPlaneCount}
              metadata:
                annotations:
                  run.tanzu.vmware.com/resolve-os-image: os-name=photon
            workers:
              machineDeployments:
                - class: node-pool
                  name: ${input.tkg_Name}-nodepool
                  replicas: ${input.workerCount}
                  metadata:
                    annotations:
                      run.tanzu.vmware.com/resolve-os-image: os-name=photon
                  variables:
                    overrides:
                      - name: vmClass
                        value: ${input.workerVmClassName}
此範例透過提供 Kubernetes 資訊清單定義了一個虛擬機器,該資訊清單定義了虛擬機器組態並包含基於等待的條件。
formatVersion: 1
inputs: {}
resources:
  vm:
    type: CCI.Supervisor.Resource
    properties:
      context: ${resource.cciNamespace.id}
      manifest:
        apiVersion: vmoperator.vmware.com/v1alpha1
        kind: VirtualMachine
        metadata:
          finalizers:
            - virtualmachine.vmoperator.vmware.com
          generation: 1
          labels:
            vm-selector: vm-2rfx
          name: vm-2rfx
        spec:
          className: best-effort-xsmall
          imageName: vmi-c3d184be88e1af1cd
          networkInterfaces:
            - networkType: nsx-t
          powerOffMode: hard
          powerState: poweredOn
          restartMode: hard
          storageClass: vsan-default-storage-policy
          suspendMode: hard
      wait:
        conditions:
          - type: VirtualMachinePrereqReady
            status: "False"
            reason: VirtualMachineImageNotReady
            indicatesFailure: true

TKG 資源範例

您使用 CCI.TKG. Resource 在 TKG 叢集內或 TKG 叢集上執行的命名空間內建立支援的 Kubernetes 資源。
  • 若要將 TKG 資源繫結至 TKG 叢集,可以將主管 TKG 叢集資源的識別碼與內容屬性進行對應,例如,context: ${resource.cciTKGCluster.id}
  • 例如,如果要在名為 cciTKGNamespace 的 TKG 資源中建立命名空間,可以透過在內容屬性中插入 TKG 資源的名稱 (即 context: ${resource.cciTKGNamespace.id}),將 TKG 資源繫結至命名空間。
  • 在資源內容中傳遞的 Kubernetes 資訊清單指定了要佈建的 Kubernetes 物件類型。
此範例顯示了將密碼作為 TKG 資源繫結至名為 cciTKGCluster 的 TKG 叢集。
...
  tkgSecret:
    type: CCI.TKG.Resource
    properties:
      context: ${resource.cciTKGCluster.id}
      manifest:
        apiVersion: v1
        kind: Secret
        metadata:
          name: nvaie-apikey
        type: Opaque
        data:
          username: KM9hdCCodG9rZW4=
          password: ${base64_encode(input.password)}
...

新增等待內容

主管資源和 TKG 資源都支援等待內容,透過該內容,將等待資源內滿足特定條件或欄位值後才視為資源建立完成。等待內容類型包括:
  • 欄位等待:欄位清單,其中每個欄位都可以設定內容路徑和值。必須與該值相符後,才會視為資源已完成。
  • 條件等待:指示資源建立成功或失敗的條件清單。
此範例顯示了在主管資源中新增了等待條件。必須滿足該條件,主管資源才會標記為已完成。
...
    wait:
      fields:
        - path: status.loadBalancer.ingress[0].ip
          value: "*"
...