2

我想用 Terraform 创建 Kubernetes 集群,

关于此处的文档页面:https ://www.terraform.io/docs/providers/alicloud/r/cs_managed_kubernetes.html

variable "name" {
default = "my-first-k8s"
}
data "alicloud_zones" main {
  available_resource_creation = "VSwitch"
}

data "alicloud_instance_types" "default" {
    availability_zone = "${data.alicloud_zones.main.zones.0.id}"
    cpu_core_count = 1
    memory_size = 2
} 

我在哪里插入 vswitch id?以及如何设置区域ID?

4

2 回答 2

2

resource您可以在定义中插入 vswitch id :

resource "alicloud_cs_managed_kubernetes" "k8s" {
  name = "${var.name}"
  availability_zone = "${data.alicloud_zones.main.zones.0.id}"
  new_nat_gateway = true
  worker_instance_types = ["${data.alicloud_instance_types.default.instance_types.0.id}"]
  worker_numbers = [2]
  password = "Test12345"
  pod_cidr = "172.20.0.0/16"
  service_cidr = "172.21.0.0/20"
  install_cloud_monitor = true
  worker_disk_category  = "cloud_efficiency"
  vswitch_ids = ["your-alibaba-vswitch-id"]
}

对于基于thisdocs的区域(如果您想覆盖默认值) ,您需要执行以下操作:

data "alicloud_zones" main {
  available_resource_creation = "VSwitch"

  zones = [
     {
       id = "..."
       local_name = "..."
       ...
     },
     {
       id = "..."
       local_name = "..."
       ...
     },
     ...
  ]
}
于 2018-12-27T18:39:25.387 回答
2

设置区域:

在 Terraform 本身中配置 Alicloud 提供程序时,您可以设置区域:

provider "alicloud" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region     = "${var.region}"
}

例如,让我将北京视为该地区:

provider "alicloud" {
      access_key = "accesskey"
      secret_key = "secretkey"
      region     = "cn-beijing"
    }

要设置 vswitch ID:

在定义resource部分时,我们可以插入所需的 vswitch

resource "alicloud_instance"{
  # ...
  instance_name = "in-the-vpc"
  vswitch_id = "${data.alicloud_vswitches.vswitches_ds.vswitches.0.id}"
  # ...
}

例如,让我将vsw-25naue4gz视为 vswitch id:

resource "alicloud_instance"{
      # ...
      vswitch_id = "vsw-25naue4gz"
      # ...
    }
于 2018-12-29T14:10:53.753 回答