You need to enable JavaScript to run this app.
文档中心
容器服务

容器服务

复制全文
下载 pdf
Terraform
管理通过 Terraform 创建的节点池
复制全文
下载 pdf
管理通过 Terraform 创建的节点池
通过 Terraform 创建集群后,可以继续使用 Terraform 在该集群内创建自定义节点池,为自定义节点池扩容,删除自定义节点池等。​
前提条件​
已通过 Terraform 创建集群。详细操作,请参见 管理使用 Terraform 创建的集群。​
创建自定义节点池​
使用 Terraform 在集群内创建自定义节点池时,请按照如下步骤操作。​
  1. 创建一个文件夹,并在该文件夹中创建名为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" # 自定义节点池名称​
    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"​
    }​
    }​
    auto_scaling {​
    enabled = false # 是否开通节点池弹性。true:开启,false:不开启。​
    max_replicas = 5 # 节点池的最大节点数。​
    min_replicas = 0 # 节点池的最小节点数。​
    desired_replicas = 0 # 节点池的期望节点数。​
    priority = 15 # 优先级,仅对 priority 算法生效。​
    }​
    kubernetes_config {​
    #配置节点标签(label)​
    labels {​
    key = "aaa"​
    value ="bbb"​
    }​
    cordon = false # 是否封锁节点。true:封锁,false:不封锁。​
    }​
    tags { #节点池自定义标签​
    key = "k1"​
    value = "v1"​
    }​
    }​
    ​
  1. 初始化 Terraform 运行环境。​
  • ​
    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.​
    ​
  1. 进行资源规划。​
  • ​
    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.​
    ​
  1. 创建自定义节点池。​
  • ​
    terraform apply​
    ​
  • 预期执行结果如下所示。​
  • ​
    ...​
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.​
    ​
节点池扩容或缩容节点​
使用 Terraform 为通过 Terraform 创建的自定义节点池扩容节点或缩容节点时,请按照如下步骤操作。​
  1. 更新main.tf文件中的 auto_scaling.desired_replicas 字段,取值在 max_replicas 和 min_replicas 之间。​
  • ​
    auto_scaling {​
    enabled = false​
    max_replicas = 5​
    min_replicas = 0​
    desired_replicas = 2 # 手动扩容或缩容的节点数。​
    priority = 15​
    }​
    ​
  1. 执行扩容/缩容命令。​
  • ​
    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​
    volcengine_vke_node_pool.node-pool-test: Modifying...​
    ...​
    Apply complete! Resources: 0 added, 1 changed, 0 destroyed.​
    ​
删除自定义节点池​
使用 Terraform 删除通过 Terraform 创建的自定义节点池时,请按照如下步骤操作。​
注意​
使用 Terraform 删除自定义节点池时,不支持保留 Worker 节点,会自动释放所有非包年包月的 Worker 节点,请谨慎操作。包年包月类型的节点目前仅支持移除节点,如需销毁,请进入 云服务器控制台 手动操作。​
执行如下命令,删除自定义节点池。​
​
terraform destroy​
​
预期执行结果如下所示。​
​
...​
Destroy complete! Resources: 1 destroyed.​
​
​
最近更新时间:2025.12.15 16:58:24
这个页面对您有帮助吗?
有用
有用
无用
无用