You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
Terraform
Managing node pools created via Terraform
Copy page
Download PDF
Managing node pools created via Terraform
After you create a cluster by using Terraform, you can continue to use Terraform to manage the cluster. For example, you can create custom node pools within the cluster, scale out custom node pools, and delete custom node pools.​
Prerequisites​
A cluster has been created by using Terraform. For details, see Managing clusters created with Terraform.​
Creating custom node pools​
To create a custom node pool within a cluster by using Terraform, follow these steps.​
  1. Create a folder and a configuration file named main.tf within it.​
  • ​
    terraform {​
    required_providers {​
    volcengine = {​
    source = "volcengine/volcengine"​
    version = "0.0.140" # Query available versions from the official Terraform website (https://registry.terraform.io/providers/volcengine/volcengine/latest).​
    }​
    }​
    }​
    ​
    provider "volcengine" {​
    access_key = "**********" # The access key ID of the Volcano Engine root user.​
    secret_key = "**********" # The secret access key of the Volcano Engine root user.​
    region = "cn-beijing" # The region where the VKE cluster is located.​
    }​
    ​
    data "volcengine_vke_clusters" "default" {​
    name_regex = "tf-created-vke" # The name of the cluster to which the node pool created by Terraform belongs.​
    }​
    ​
    resource "volcengine_vke_node_pool" "node-pool-test" {​
    cluster_id = data.volcengine_vke_clusters.default.clusters[0].id​
    name = "demo" # The name of the custom node pool.​
    node_config {​
    instance_type_ids = ["ecs.c1ie.large"] # The specification of the ECS instance.​
    subnet_ids = ["subnet-rrmacgc4b37kv******"] # The ID of the subnet ID to which the node network belongs.​
    security {​
    login {​
    password = "*******" # The access credential of the node. It is the password of the root user. The value must be Base64-encoded.​
    }​
    }​
    # The system volume. The type must be supported for mounting.​
    system_volume {​
    type = "ESSD_PL0" # The cloud disk type. Valid values include ESSD_PL0 (PL0 ESSD) and ESSD_FlexPL (PL1 ESSD).​
    size = 40 # Cloud disk capacity in GiB. The value range for ESSD (ESSD_PL0 and ESSD_FlexPL) is 40 to 2048.​
    }​
    ​
    # If this setting is enabled and configured, the first data volume will be mounted to /mnt/vdb, and to the /var/lib/containerd and /var/lib/kubelet directories.​
    # If a custom mount point is set, the data volume will be mounted to the custom mount point, and to the /var/lib/containerd and /var/lib/kubelet directories.​
    additional_container_storage_enabled = true​
    # Data volumes. The type must be mountable by the selected node and must support a custom mount point.​
    data_volumes {​
    type = "ESSD_PL0" # Disk type. Valid values include ESSD_PL0 (PL0 ESSD) and ESSD_FlexPL (PL1 ESSD).​
    size = 50 # Disk capacity in GiB. The value range for ESSD (ESSD_PL0 and ESSD_FlexPL) is 40 to 2048.​
    }​
    data_volumes {​
    type = "ESSD_PL0"​
    size = 50​
    }​
    ecs_tags { # Labels associated with the ECS instance as the node. The labels are used for filtering and managing ECS instances.​
    key = "ecs_k1"​
    value = "ecs_v1"​
    }​
    }​
    auto_scaling {​
    enabled = false # Whether to enable node pool elasticity. The value true enables the feature. The value false disables the feature.​
    max_replicas = 5 # Maximum number of nodes in the node pool.​
    min_replicas = 0 # Minimum number of nodes in the node pool.​
    desired_replicas = 0 # Desired number of nodes in the node pool.​
    priority = 15 # Priority. This setting is only effective for a priority scaling algorithm.​
    }​
    kubernetes_config {​
    # Configure node labels.​
    labels {​
    key = "aaa"​
    value ="bbb"​
    }​
    cordon = false # Whether to cordon the node. The value true indicates cordoning and false indicates no cordoning.​
    }​
    tags { # Custom labels for the node pool.​
    key = "k1"​
    value = "v1"​
    }​
    }​
    ​
  1. Initialize the Terraform environment.​
  • ​
    terraform init​
    ​
  • The expected result is as follows.​
  • ​
    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. Perform resource planning.​
  • ​
    terraform plan​
    ​
  • The expected result is as follows.​
  • ​
    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. Create the custom node pool.​
  • ​
    terraform apply​
    ​
  • The expected result is as follows.​
  • ​
    ...​
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.​
    ​
  • You can view the created custom node pool in the VKE console.​
Increasing or decreasing the number of nodes​
To scale out or scale in a custom node pool that was created via Terraform, follow these steps.​
  1. Update the auto_scaling.desired_replicas field in the main.tf file to a value between max_replicas and min_replicas.​
  • ​
    auto_scaling {​
    enabled = false​
    max_replicas = 5​
    min_replicas = 0​
    desired_replicas = 2 # The desired number of nodes.​
    priority = 15​
    }​
    ​
  1. Run the command to scale out or in the node pool.​
​
terraform apply​
​
  • The expected result is as follows.​
  • ​
    ...​
    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.​
    ​
  • You can view the nodes in the target cluster after a scale-out or scale-in in the VKE console.​
Deleting custom node pools​
To delete a custom node pool created via Terraform, follow these steps.​
Warning​
When deleting a custom node pool using Terraform, you cannot retain worker nodes in the node pool. All non-subscription worker nodes will be automatically released. Exercise caution when you perform this operation.​
Run the following command to delete the custom node pool.​
​
terraform destroy​
​
The expected result is as follows.​
​
...​
Destroy complete! Resources: 1 destroyed.​
​
​
Last updated: 2026.07.23 14:31:47