将集群网络接口附加到实例

创建实例后,您可以将其附加到现有集群网络实例的子网中。 或者,您也可以先创建集群网络实例来规划网络,然后再创建子网实例进行连接。

准备工作

您可以使用 CLI、API 或 Terraform 将群集网络接口附加到实例。

通过命令行界面将集群网络接口附加到实例

要通过命令行界面将接口附加到实例,请按以下步骤操作:

  1. 设置 CLI 环境

  2. 通过命令行界面(CLI)登录您的账户。 输入密码后,系统会提示输入账户和地区:

    ibmcloud login --sso
    
  3. 要将接口附加到实例,请输入以下命令:

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

    其中:

    INSTANCE
    实例的标识或名称。
    --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
}