本文主要介绍使用 Terraform 在自定义节点池中添加或移除已有节点(云服务器 ECS 实例)的操作。
添加已有 ECS 实例到自定义节点池时:
容量
≥ (目标节点池配置的镜像大小
+ 10 GiB
)。使用 Terraform 将已有 ECS 实例添加到自定义节点池时,请按照如下步骤操作。
main.tf
的配置文件。terraform { required_providers { volcengine = { source = "volcengine/volcengine" version = "0.0.140" # version 信息请从 Terraform 官网(https://registry.terraform.io/providers/volcengine/volcengine/latest)获取。 } } } provider "volcengine" { access_key = "**********" # 火山引擎账号的 Access Key ID。 secret_key = "**********" # 火山引擎账号的 Secret Access Key。 region = "cn-beijing" # 容器服务业务所在的地域。 } data "volcengine_vke_clusters" "default" { name_regex = "tf-created-vke" # 通过 Terraform 创建的节点池所属集群名称。 } resource "volcengine_vke_node_pool" "node-pool-test" { cluster_id = data.volcengine_vke_clusters.default.clusters[0].id name = "demo" # 自定义节点池名称。 instance_ids = ["i-ydazicr0n4yg********"] # 已有节点(ECS 实例)的 ID。 keep_instance_name = true # 是否保留原云服务器实例名称。取值:false(不保留)、true(保留)。 node_config { instance_type_ids = ["ecs.c1ie.large"] # 节点对应 ECS 实例的规格。 subnet_ids = ["subnet-rrmacgc4b37kv******"] # 节点网络所属的子网 ID。 security { login { password = "*******" # 节点的访问方式,Root 用户登录密码。使用 Base64 编码格式。 } } # 系统盘,type 需要所选节点型号支持挂载。 system_volume { type = "ESSD_PL0" # 云盘类型。取值:ESSD_PL0(PL0 级别极速型 SSD 云盘)、ESSD_FlexPL(PL1 级别极速型 SSD 云盘)。 size = 40 # 云盘容量,单位为 GiB。极速型 SSD(ESSD_PL0,ESSD_FlexPL)容量取值范围 40~2048。 } # 设置后,第一块数据盘会 mount 到 /mnt/vdb,并挂载 /var/lib/containerd 和 /var/lib/kubelet 目录。 # 如设置了自定义挂载点,会 mount 到自定义挂载点,并挂载 /var/lib/containerd 和 /var/lib/kubelet 目录。 additional_container_storage_enabled = true # 数据盘,type 需要所选节点型号能挂载,支持配置自定义挂载点。 data_volumes { type = "ESSD_PL0" # 磁盘类型。取值:ESSD_PL0(PL0 级别极速型 SSD 云盘)、ESSD_FlexPL(PL1 级别极速型 SSD 云盘)。 size = 50 # 磁盘容量,单位为 GiB。极速型 SSD(ESSD_PL0,ESSD_FlexPL)容量取值范围 40~2048。 } data_volumes { type = "ESSD_PL0" size = 50 } ecs_tags { # 节点对应 ECS 实例绑定的标签信息,用于搜索、管理 ECS 实例。 key = "ecs_k1" value = "ecs_v1" } } kubernetes_config { # 配置节点标签(label)。 labels { key = "aaa" value ="bbb" } cordon = false # 是否封锁节点。取值:true(封锁),false(不封锁)。 } tags { # 节点池自定义标签。 key = "k1" value = "v1" } }
预期执行结果如下所示。terraform init
Initializing the backend... Initializing provider plugins... - Finding volcengine/volcengine versions matching "0.0.140"... - Installing volcengine/volcengine v0.0.140... ... Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
预期执行结果如下所示。terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place Terraform will perform the following actions: ... Plan: 0 to add, 1 to change, 0 to destroy.
预期执行结果如下所示。terraform apply
您也可以登录 容器服务控制台,找到目标自定义节点池(即 ID 为Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place Terraform will perform the following actions: ... Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes volcengine_vke_node.node-pool-test: Updating... ... Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
pcq3p3f******
的节点池),查看该节点池中已添加的节点。使用 Terraform 从自定义点池中移除之前添加的已有节点时,请按照如下步骤操作。
注意
main.tf
文件 volcengine_vke_node_pool 字段下的instance_ids
参数中,去掉目标 ECS 实例 ID。... resource "volcengine_vke_node_pool" "node-pool-test" { cluster_id = data.volcengine_vke_clusters.default.clusters[0].id name = "demo" instance_ids = ["i-ydazicr0n4yg********"] # 从该参数的值中,去掉需要移除的 ECS 实例 ID(双引号一并去掉)。 ... }
预期执行结果如下所示。terraform apply
您也可以登录 容器服务控制台,在目自定义点池中查看节点是否被移除。Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place Terraform will perform the following actions: ... Plan: 0 to add, 1 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes ... Apply complete! Resources: 0 added, 1 changed, 0 destroyed.