身為 DevOps 使用者,您可以使用 CCI kubectl 命令建立主管命名空間並在命名空間內建立基礎結構資源。以下範例顯示了如何建立主管命名空間以及在命名空間中新增虛擬機器。

必要條件

  • 確認 Automation 管理員已設定 Cloud Consumption Interface 基礎結構。請參閱使用 kubectl 設定 Cloud Consumption Interface 基礎結構
  • 確認您是 Automation Service Broker 中至少一個專案的成員。
  • 確認您至少是 Automation 中的組織成員,具有 Automation Service Broker 使用者服務角色。
  • 確認您具備以下條件:
    • 已下載 CCI kubectl 外掛程式。
    • 取得使用者服務角色的 API Token 並將其作為變數指派。
      TOKEN='<your_API_token>'
    • 已使用 Token 登入 CCI 伺服器。
    請參閱準備使用命令行介面執行CCI工作

建立主管命名空間

以下範例顯示了如何建立名為 ns-for-devops-example 的主管命名空間。

使用 kubectl 命令收集下列資源的資訊:
  • 專案
  • 區域繫結
  • 主管命名空間類別繫結
然後,將中繼資料和規格新增至 YAML 檔案,以建立主管命名空間。
  1. 將預設內容設定為 CCI 。
    kubectl config use-context cci
  2. 列出可用專案。
    kubectl get projects
    結果將列出您所在的專案。
    NAME          SHARED RESOURCES
    cci-document   true
  3. 列出 cci-document 中的區域。
    kubectl get regionbinding -n cci-document
    結果將顯示專案中的所有區域。
    NAME        AGE
    us-docs-1   2d13h
  4. 列出 cci-document 中的主管命名空間類別。
    kubectl get supervisornamespaceclassbinding -n cci-document
    結果將顯示專案中的所有主管命名空間類別。
    NAME         AGE
    docs-class   2d13h
  5. 為要建立的主管命名空間建立 YAML 檔案。下列範例使用以下設定建立命名空間:
    • 專案 cci-document
    • 區域 us-docs-1
    • 命名空間類別 docs-class
    apiVersion: infrastructure.cci.vmware.com/v1alpha1
    kind: SupervisorNamespace
    metadata:
      name: ns-for-devops-example
      namespace: cci-document
    spec:
      description: Create_Namespace_example
      regionName: us-docs-1
      className: docs-class
  6. 將 YAML 檔案作為輸入,建立主管命名空間。在此範例中,YAML 檔案與 kubectl 應用程式位於同一目錄中。
    kubectl create -f Create_Supervisor_Namespace.YAML
  7. 檢查 cci-document 中主管命名空間的狀態。
    kubectl describe supervisornamespace ns-for-devops-example -n cci-document
    結果顯示 Status: TrueType: Ready 時,表示主管命名空間即可使用並顯示在 UI 中。
    • 對於 Automation Service Broker,請移至耗用 > 主管命名空間
    • 對於 Automation Assembler,請移至基礎結構 > 資源 > 主管
    Name:         ns-for-devops-example
    Namespace:    cci-document
    Labels:       <none>
    Annotations:  infrastructure.cci.vmware.com/wcp-address: 192.168.0.2
    API Version:  infrastructure.cci.vmware.com/v1alpha1
    Kind:         SupervisorNamespace
    Metadata:
      Creation Timestamp:  2023-07-31T17:30:49Z
      UID:                 b2f65844-d545-4a5f-976d-381e079275b1
    Spec:
      Class Name:  docs-class
      Class Parameters:
      Description:  Create_Namespace_example
      Region Name:  us-docs-1
    Status:
      Conditions:
        Last Transition Time:  2023-07-31T17:30:50Z
        Status:                True
        Type:                  Ready
      Phase:                   Created
    Events:                    <none>
  8. 如果要刪除主管命名空間,請提供命名空間的名稱和專案的名稱,並包含 --force 旗標。
    kubectl delete supervisornamespace ns-for-devops-example -n cci-document --force

將虛擬機器新增至主管命名空間

以下範例顯示了如何建立名為 VM-for-devops-example 的虛擬機器。

使用 kubectl 命令收集下列資源的資訊:
  • 虛擬機器類別
  • 虛擬機器映像
  • 儲存區類別
然後,將資源規格新增至 YAML 檔案以建立虛擬機器。
  1. 再次登入 CCI 伺服器,並確認在回應中看到新建立的主管命名空間。
    kubectl cci login --server api.mgmt.cloud.vmware.com --token $TOKEN
    Logging into api.mgmt.cloud.vmware.com
    Getting supervisor namespaces
    Successfully logged into api.mgmt.cloud.vmware.com
    Created kubeconfig contexts:
             cci
             cci:cci-document:ns-7lan
             cci:cci-document:ns-for-devops-example
             cci:supervisor:gp-namespace
  2. 設定預設內容,以便無需在每個命令中使用內容指定命名空間。
    kubectl config use-context cci:cci-document:ns-for-devops-example
    結果確認內容已切換,並且每個後續命令都將位於 cci:cci-document:ns-for-devops-example 內容中。
    Switched to context "cci:cci-document:ns-for-devops-example".
  3. 列出可用的虛擬機器類別。
    kubectl get virtualmachineclassess
    從結果中選取其中一個虛擬機器類別。
    NAME                  CPU   MEMORY   AGE
    best-effort-2xlarge   8     64Gi     2d15h
    best-effort-4xlarge   16    128Gi    2d15h
    best-effort-8xlarge   32    128Gi    2d15h
    best-effort-large     4     16Gi     2d15h
    best-effort-medium    2     8Gi      2d15h
    best-effort-small     2     4Gi      2d15h
    best-effort-xlarge    4     32Gi     2d15h
    best-effort-xsmall    2     2Gi      2d15h
    guaranteed-2xlarge    8     64Gi     2d15h
    guaranteed-4xlarge    16    128Gi    2d15h
    guaranteed-8xlarge    32    128Gi    2d15h
    guaranteed-large      4     16Gi     2d15h
    guaranteed-medium     2     8Gi      2d15h
    guaranteed-small      2     4Gi      2d15h
    guaranteed-xlarge     4     32Gi     2d15h
    guaranteed-xsmall     2     2Gi      2d15h
  4. 列出可用的虛擬機器映像。
    kubectl get virtualmachineimages
    選取要使用的映像。
    NAME                    PROVIDER-NAME              CONTENT-LIBRARY-NAME   IMAGE-NAME                                              VERSION         OS-TYPE                 FORMAT   AGE
    vmi-02549e2ab956621e9   clitem-02549e2ab956621e9   cl-c7a511c539dddc1f1   groovy-20210415.1-with-ovt-11.3                                         ubuntu64Guest           OVF      143m
    vmi-041ff2740d6aee34a   clitem-041ff2740d6aee34a   cl-c7a511c539dddc1f1   ubuntu-20-1633387172196-v1.1                                            ubuntu64Guest           OVF      143m
    vmi-1cc3c618d0ead1129   clitem-1cc3c618d0ead1129   cl-c7a511c539dddc1f1   jammy-server-cloudimg-amd64                                             ubuntu64Guest           OVF      143m
    
  5. 若要列出可用的儲存區原則,請使用 命令取得資源配額。
    kubectl get resourcequota
    請求的第一個區段是儲存區原則。
    NAME                                 AGE     REQUEST                                                                                         LIMIT
    ns-for-devops-example-storagequota   6m22s   wcpglobal-storage-profile.storageclass.storage.k8s.io/requests.storage: 0/9223372036854775807
    
  6. 為要新增至主管命名空間的虛擬機器建立 YAML 檔案。下列範例使用以下設定建立虛擬機器:
    • 命名空間 ns-for-devops-example
    • 虛擬機器映像 vmi-02549e2ab956621e9
    • 虛擬機器類別 guaranteed-small
    • 儲存區原則 wcpglobal-storage-profile
    apiVersion: vmoperator.vmware.com/v1alpha1
    kind: VirtualMachine
    metadata:
      name: VM-for-devops-example
      namespace: ns-for-devops-example
    spec:
      imageName: vmi-02549e2ab956621e9
      className: guaranteed-small  
      storageClass: wcpglobal-storage-profile  
      powerState: poweredOn
  7. 將 YAML 檔案作為輸入,在主管命名空間中建立虛擬機器。在此範例中,YAML 檔案與 kubectl 應用程式位於同一目錄中。
    kubectl create -f Create_VM.YAML
  8. 檢查在 ns-for-devops-example 中建立虛擬機器的狀態。
    kubectl describe virtualmachine vm-for-devops-example -n ns-for-devops-example
    結果顯示 Type: GuestCustomizationType: VirtualMachinePrereqReadyType: VirtualMachineTools 這三個的狀態都為 Status: True 時,表示已在主管命名空間中成功建立虛擬機器。
    Name:         vm-for-devops-example
    Namespace:    ns-for-devops-example
    Labels:       topology.kubernetes.io/zone=domain-c50
    Annotations:  virtualmachine.vmoperator.vmware.com/first-boot-done: true
    API Version:  vmoperator.vmware.com/v1alpha1
    Kind:         VirtualMachine
    Metadata:
      Creation Timestamp:  2023-08-15T00:30:55Z
      Finalizers:
        virtualmachine.vmoperator.vmware.com
      Generation:        1
      Resource Version:  19196052
      UID:               f2460f3c-225b-460b-8d11-95a1bdaebe72
    Spec:
      Class Name:  guaranteed-small
      Image Name:  vmi-02549e2ab956621e9
      Network Interfaces:
        Network Type:  vsphere-distributed
      Power Off Mode:  hard
      Power State:     poweredOn
      Restart Mode:    hard
      Storage Class:   wcpglobal-storage-profile
      Suspend Mode:    hard
    Status:
      Bios UUID:              421eb2b5-04ef-f3e1-8d17-f8e73a2576b2
      Change Block Tracking:  false
      Conditions:
        Last Transition Time:  2023-08-15T00:32:30Z
        Status:                True
        Type:                  GuestCustomization
        Last Transition Time:  2023-08-15T00:31:55Z
        Status:                True
        Type:                  VirtualMachinePrereqReady
        Last Transition Time:  2023-08-15T00:32:20Z
        Status:                True
        Type:                  VirtualMachineTools
      Host:                    10.186.234.28
      Instance UUID:           501ea6c0-c0cb-b03c-08e6-324642f923d1
      Network Interfaces:
        Connected:  true
        Ip Addresses:
          192.168.128.11/16
          fe80::250:56ff:fe9e:ff48/64
        Mac Address:  00:50:56:9e:ff:48
      Phase:          Created
      Power State:    poweredOn
      Unique ID:      vm-104
      Vm Ip:          192.168.128.11
      Zone:           domain-c50
    Events:           <none>
  9. 如果要刪除虛擬機器,請提供虛擬機器的名稱和命名空間的名稱,並包含 --force 旗標。
    kubectl delete virtualmachine vm-for-devops-example -n ns-for-devops-example --force