將叢集網路介面附加至執行個體

建立執行個體後,即可將其附加至現有的叢集網路執行個體子網。 或者,您也可以先建立叢集網路實例,再建立要附加的子網實例,以此規劃您的網路架構。

開始之前

您可以使用 CLI、API 或 Terraform 將叢集網路介面附加到實例。

透過命令列介面將叢集網路介面附加至執行個體

要從命令列介面將介面附加至實例,請遵循以下步驟:

  1. 設定您的 CLI 環境

  2. 請透過 CLI 登入您的帳戶。 輸入密碼後,系統會提示輸入帳戶和地區:

    ibmcloud login --sso
    
  3. 若要將介面附加到實例,請輸入以下命令:

    ibmcloud is instance-cluster-network-attachments INSTANCE --cnac CLUSTER_NETWORK_ATTACHMENT
    

    其中:

    INSTANCE
    實例的 ID 或名稱。
    --output
    指定輸出格式,只支援 JSON。 下列其中一項:JSON
    -q, quiet
    抑制詳細輸出。

命令範例

  • 若要建立具有群集網路附件的實例 my-ins-1

    ibmcloud is instance-create my-ins-1 cli-vpc us-south-2 fx3d-160c1792x9h100 cli-subnet --image ibm-ubuntu-20-04-6-minimal-amd64-5 --cluster-network-attachments '[{"name":"instance-cnac-1","cluster_network_interface":{"id":"7208-18204195-be40-4f12-aaaa-2649e19acb91"}},{"name":"instance-cnac-2","cluster_network_interface":{"id":"7208-cf6023a3-86c7-459f-84b8-536b4f812541"}},{"name":"instance-cnac-3","cluster_network_interface":{"id":"7208-2d55d27c-835c-4566-acbc-da36bcf49da7"}},{"name":"instance-cnac-4","cluster_network_interface":{"id":"7208-161e2919-c505-4e6d-bd49-88e7e0c0f1f3"}},{"name":"instance-cnac-5","cluster_network_interface":{"id":"7208-d700a40e-af61-45ee-b71a-a09203db76bd"}},{"name":"instance-cnac-6","cluster_network_interface":{"id":"7208-c7dbc8b9-6b47-4b83-8649-512e4e8f0a81"}},{"name":"instance-cnac-7","cluster_network_interface":{"id":"7208-f4773e40-49b5-4d44-8c68-7a75513bbf16"}},{"name":"instance-cnac-8","cluster_network_interface":{"id":"7208-46e097b5-c1ea-4669-aafd-7a4cc82d0e02"}}]'
    
  • 若要使用叢集網路附件 JSON 檔案建立實例 my-ins-2

    ibmcloud is instance-create my-ins-2 deceiving-strode-dimly-undesirable us-south-2 hx3d-160x1002x8h100 test-subnet --image ibm-ubuntu-20-04-6-minimal-amd64-5 --cluster-network-attachments @~/cnac.json
    

透過 API 將叢集網路介面附加至執行個體

若要透過 API 將叢集網路介面附加至執行個體,請遵循以下步驟:

  1. 使用正確的變數 設定您的 API 環境。
  2. 將任何用於 API 指令的額外變數儲存起來。 例如:

version (字串):API 版本,格式為 YYYY-MM-DD

  1. 啟動所有變數後,輸入以下命令將叢集網路介面附加到實例:

    curl -X POST "$vpc_api_endpoint/v1/instances/$instance_id/cluster_network_attachments?version=$today&generation=2" -H "Authorization: Bearer $iam_token" -d '{
      "name": "my-cluster-network-attachment",
      "cluster_network_interface": {
        "id": "$cluster_network_interface_id"
      }
    }'
    

若要查看完整的叢集網路 API 集,請參閱 VPC API 參考

使用 Terraform 將叢集網路介面附加至執行個體

以下範例使用 Terraform 配置實例叢集網路連線:

resource "ibm_is_instance_cluster_network_attachment" "is_instance_cluster_network_attachment_instance" {
  instance = var.is_instance_cluster_network_attachment_instance_id
  before {
    # href = "https://us-south.iaas.cloud.ibm.com/v1/instances/5dd61d72-acaa-47c2-a336-3d849660d010/cluster_network_attachments/0767-fb880975-db45-4459-8548-64e3995ac213" // conflicts with id
    id = "0767-fb880975-db45-4459-8548-64e3995ac213"
  }
  cluster_network_interface {
    # id              = var.is_cluster_network_interface_id // conflicts with other properties
    auto_delete     = var.is_cluster_auto_delete
    name            = var.is_cluster_name
    subnet          = var.is_cluster_subnet_id
    primary_ip {
      address = "192.168.3.4"
      name    = "my-cluster-subnet-reserved-ip-1"
    }
  }
  name = var.is_instance_cluster_network_attachment_name
}