本文主要介绍在通过 Terraform 创建的集群中,创建默认节点池并在默认节点池中添加或移除已有节点的操作。
使用 Terraform 创建默认节点池,同时在默认节点池中添加已有节点时,请按照如下步骤操作。
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_default_node_pool" "vke_test" { cluster_id = data.volcengine_vke_clusters.default.clusters[0].id node_config { security { login { password = "*****" # 节点的访问方式,root 用户登录密码。使用 Base64 编码格式。 } } } instances { instance_id = "i-ybwgrtud6d********" # 已有节点(云服务器实例)的 ID。 keep_instance_name = true # 是否保留云服务器实例名称。true:保留,false:云服务器实例被添加到集群后重新命名。 additional_container_storage_enabled = true # 是否将数据盘格式化并挂载到容器、镜像存储目录。true:是,false:否。 container_storage_path = "/dev/vdb" # 指定数据盘挂载目录。 } instances { instance_id = "i-ybwgqqpjav********" keep_instance_name = true additional_container_storage_enabled = true container_storage_path = "/dev/vdb" } }
预期执行结果如下所示。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: + create Terraform will perform the following actions: ... Plan: 1 to add, 0 to change, 0 to destroy.
预期执行结果如下所示。terraform apply
您也可以登录 容器服务控制台,查看名为Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create 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_default_node_pool.vke_test: Creating... ... Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
vke-default-nodepool
的默认节点池中已添加的节点。使用 Terraform 从默认节点池中移除之前添加的已有节点时,请按照如下步骤操作。
注意
待移除的已有节点计费方式无论是包年包月还是按量计费,当前操作都不会释放该节点。如需释放节点,可通过云服务器控制台操作。操作指导,请参见 删除实例。
main.tf
文件中删除 instances 字段内容。... #instances { # instance_id = "i-ybwgqqpjav********" # keep_instance_name = true # additional_container_storage_enabled = true # container_storage_path = "/dev/vdb" #} ...
预期执行结果如下所示。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.