kubectl を使用したスーパーバイザー名前空間とインフラストラクチャ リソースの作成

DevOps ユーザーは、CCI kubectl コマンドを使用して、スーパーバイザー名前空間を作成し、名前空間内にインフラストラクチャ リソースを作成できます。このセクションの例では、スーパーバイザー名前空間を作成し、その名前空間に仮想マシンを追加する方法を示します。

前提条件

スーパーバイザー名前空間の作成

この例では、
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: True
    および
    Type: Ready
    と表示されたら、スーパーバイザー名前空間が使用可能になり、ユーザー インターフェイスに表示されます。
    • 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
    結果から仮想マシン クラスを 1 つ選択します。
    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: GuestCustomization
    Type: VirtualMachinePrereqReady
    、および
    Type: VirtualMachineTools
    の 3 つに
    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