全部產品
Search
文件中心

Container Service for Kubernetes:使用Terraform建立ACK託管版叢集

更新時間:Nov 27, 2024

本文介紹如何使用Terraform建立ACK託管叢集

說明

本教程所含範例程式碼支援一鍵運行,您可以直接運行代碼。一鍵運行

前提條件

  • 已開通Container Service for KubernetesACK。若需要使用Terraform開通,請參見通過Terraform開通ACK並授權角色

  • 由於阿里雲帳號(主帳號)具有資源的所有許可權,一旦發生泄露將面臨重大風險。建議您使用RAM使用者,並為該RAM使用者建立AccessKey,具體操作方式請參見建立RAM使用者建立AccessKey

  • 為運行Terraform命令的RAM使用者綁定以下最小權限原則,以擷取管理本樣本所涉及資源的許可權。更多資訊,請參見為RAM使用者授權

    該權限原則允許RAM使用者進行VPC、交換器及ACK的建立、查看與刪除操作。

    {
      "Version": "1",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "vpc:CreateVpc",
            "vpc:CreateVSwitch",
            "cs:CreateCluster",
            "vpc:DescribeVpcAttribute",
            "vpc:DescribeVSwitchAttributes",
            "vpc:DescribeRouteTableList",
            "vpc:DescribeNatGateways",
            "cs:DescribeTaskInfo",
            "cs:DescribeClusterDetail",
            "cs:GetClusterCerts",
            "cs:CheckControlPlaneLogEnable",
            "cs:CreateClusterNodePool",
            "cs:DescribeClusterNodePoolDetail",
            "cs:ModifyClusterNodePool",
            "vpc:DeleteVpc",
            "vpc:DeleteVSwitch",
            "cs:DeleteCluster",
            "cs:DeleteClusterNodepool"
          ],
          "Resource": "*"
        }
      ]
    }
  • 準備Terraform運行環境,您可以選擇以下任一方式來使用Terraform。

    • Cloud Shell:阿里雲Cloud Shell中預裝了Terraform的組件,並已配置好身份憑證,您可直接在Cloud Shell中運行Terraform的命令。適用於低成本、快速、便捷地訪問和使用Terraform的情境。

    • 在本地安裝和配置Terraform:適用於網路連接較差或需要自訂開發環境的情境。

    重要

    請確保版本不低於v0.12.28。如需檢查現有版本,請運行terraform --version命令。

使用的資源

說明

本教程樣本包含的部分資源會產生一定費用,請在不需要時及時進行釋放或退訂。

使用Terraform建立ACK託管叢集(Terway)

本樣本將建立一個包含普通節點池、託管節點池及自動調整節點池的ACK託管叢集,並為該叢集預設安裝一系列組件,包括Terway(網路組件)、csi-plugin(儲存群組件)、csi-provisioner(儲存群組件)、logtail-ds(日誌組件)、Nginx Ingress Controller、ack-arms-prometheus(監控組件)以及ack-node-problem-detector(節點診斷組件)。

  1. 建立一個工作目錄,並在該工作目錄中建立名為main.tf的設定檔,然後將以下代碼複製到main.tf中。

    provider "alicloud" {
      region = var.region_id
    }
    
    variable "region_id" {
      type    = string
      default = "cn-shenzhen"
    }
    
    variable "cluster_spec" {
      type        = string
      description = "The cluster specifications of kubernetes cluster,which can be empty. Valid values:ack.standard : Standard managed clusters; ack.pro.small : Professional managed clusters."
      default     = "ack.pro.small"
    }
    
    variable "ack_version" {
      type        = string
      description = "Desired Kubernetes version. "
      default     = "1.28.9-aliyun.1"
    }
    
    # 指定虛擬交換器(vSwitches)的可用性區域。
    variable "availability_zone" {
      description = "The availability zones of vswitches."
      default     = ["cn-shenzhen-c", "cn-shenzhen-e", "cn-shenzhen-f"]
    }
    
    # 指定交換器ID(vSwitch IDs)的列表。
    variable "node_vswitch_ids" {
      description = "List of existing node vswitch ids for terway."
      type        = list(string)
      default     = []
    }
    
    # 當沒有提供node_vswitch_ids時,這個變數定義了用於建立新vSwitches的CIDR地址塊列表。
    variable "node_vswitch_cidrs" {
      description = "List of cidr blocks used to create several new vswitches when 'node_vswitch_ids' is not specified."
      type        = list(string)
      default     = ["172.16.0.0/23", "172.16.2.0/23", "172.16.4.0/23"]
    }
    
    # 指定網路組件Terway配置。如果為空白,預設會根據terway_vswitch_cidrs的建立新的terway vSwitch。
    variable "terway_vswitch_ids" {
      description = "List of existing pod vswitch ids for terway."
      type        = list(string)
      default     = []
    }
    
    # 當沒有指定terway_vswitch_ids時,用於建立Terway使用的vSwitch的CIDR地址塊。
    variable "terway_vswitch_cidrs" {
      description = "List of cidr blocks used to create several new vswitches when 'terway_vswitch_ids' is not specified."
      type        = list(string)
      default     = ["172.16.208.0/20", "172.16.224.0/20", "172.16.240.0/20"]
    }
    
    # 定義了用於啟動工作節點的ECS執行個體類型。
    variable "worker_instance_types" {
      description = "The ecs instance types used to launch worker nodes."
      default     = ["ecs.g6.2xlarge", "ecs.g6.xlarge"]
    }
    
    # 設定工作節點的密碼。
    variable "password" {
      description = "The password of ECS instance."
      default     = "Test123456"
    }
    
    # 指定ACK叢集安裝的組件。包括Terway(網路組件)、csi-plugin(儲存群組件)、csi-provisioner(儲存群組件)、logtail-ds(日誌組件)、Nginx Ingress Controller、ack-arms-prometheus(監控組件)以及ack-node-problem-detector(節點診斷組件)。
    variable "cluster_addons" {
      type = list(object({
        name   = string
        config = string
      }))
    
      default = [
        {
          "name"   = "terway-eniip",
          "config" = "",
        },
        {
          "name"   = "logtail-ds",
          "config" = "{\"IngressDashboardEnabled\":\"true\"}",
        },
        {
          "name"   = "nginx-ingress-controller",
          "config" = "{\"IngressSlbNetworkType\":\"internet\"}",
        },
        {
          "name"   = "arms-prometheus",
          "config" = "",
        },
        {
          "name"   = "ack-node-problem-detector",
          "config" = "{\"sls_project_name\":\"\"}",
        },
        {
          "name"   = "csi-plugin",
          "config" = "",
        },
        {
          "name"   = "csi-provisioner",
          "config" = "",
        }
      ]
    }
    
    # 指定建立ACK託管叢集名稱的首碼。
    variable "k8s_name_prefix" {
      description = "The name prefix used to create managed kubernetes cluster."
      default     = "tf-ack-shenzhen"
    }
    
    # 預設資源名稱。
    locals {
      k8s_name_terway         = substr(join("-", [var.k8s_name_prefix, "terway"]), 0, 63)
      k8s_name_flannel        = substr(join("-", [var.k8s_name_prefix, "flannel"]), 0, 63)
      k8s_name_ask            = substr(join("-", [var.k8s_name_prefix, "ask"]), 0, 63)
      new_vpc_name            = "tf-vpc-172-16"
      new_vsw_name_azD        = "tf-vswitch-azD-172-16-0"
      new_vsw_name_azE        = "tf-vswitch-azE-172-16-2"
      new_vsw_name_azF        = "tf-vswitch-azF-172-16-4"
      nodepool_name           = "default-nodepool"
      managed_nodepool_name   = "managed-node-pool"
      autoscale_nodepool_name = "autoscale-node-pool"
      log_project_name        = "log-for-${local.k8s_name_terway}"
    }
    
    # 節點ECS執行個體配置。將查詢滿足CPU、Memory要求的ECS執行個體類型。
    data "alicloud_instance_types" "default" {
      cpu_core_count       = 8
      memory_size          = 32
      availability_zone    = var.availability_zone[0]
      kubernetes_node_role = "Worker"
    }
    
    # 專用網路。
    resource "alicloud_vpc" "default" {
      vpc_name   = local.new_vpc_name
      cidr_block = "172.16.0.0/12"
    }
    
    # Node交換器。
    resource "alicloud_vswitch" "vswitches" {
      count      = length(var.node_vswitch_ids) > 0 ? 0 : length(var.node_vswitch_cidrs)
      vpc_id     = alicloud_vpc.default.id
      cidr_block = element(var.node_vswitch_cidrs, count.index)
      zone_id    = element(var.availability_zone, count.index)
    }
    
    # Pod交換器。
    resource "alicloud_vswitch" "terway_vswitches" {
      count      = length(var.terway_vswitch_ids) > 0 ? 0 : length(var.terway_vswitch_cidrs)
      vpc_id     = alicloud_vpc.default.id
      cidr_block = element(var.terway_vswitch_cidrs, count.index)
      zone_id    = element(var.availability_zone, count.index)
    }
    
    # Kubernetes託管版。
    resource "alicloud_cs_managed_kubernetes" "default" {
      name                         = local.k8s_name_terway # Kubernetes叢集名稱。
      cluster_spec                 = var.cluster_spec      # 建立Pro版叢集。
      version                      = var.ack_version
      worker_vswitch_ids           = split(",", join(",", alicloud_vswitch.vswitches.*.id))        # 節點池所在的vSwitch。指定一個或多個vSwitch的ID,必須在availability_zone指定的地區中。
      pod_vswitch_ids              = split(",", join(",", alicloud_vswitch.terway_vswitches.*.id)) # Pod虛擬交換器。
      new_nat_gateway              = true                                                          # 是否在建立Kubernetes叢集時建立新的NAT Gateway。預設為true。
      service_cidr                 = "10.11.0.0/16"                                                # Pod網路的CIDR塊。當cluster_network_type設定為flannel,你必須設定該參數。它不能與VPC CIDR相同,並且不能與VPC中的Kubernetes叢集使用的CIDR相同,也不能在建立後進行修改。叢集中允許的最大主機數量:256。
      slb_internet_enabled         = true                                                          # 是否為API Server建立Internet負載平衡。預設為false。
      enable_rrsa                  = true
      control_plane_log_components = ["apiserver", "kcm", "scheduler", "ccm"] # 控制平面日誌。
    
      dynamic "addons" { # 組件管理。
        for_each = var.cluster_addons
        content {
          name   = lookup(addons.value, "name", var.cluster_addons)
          config = lookup(addons.value, "config", var.cluster_addons)
        }
      }
    }
    
    # 普通節點池。
    resource "alicloud_cs_kubernetes_node_pool" "default" {
      cluster_id            = alicloud_cs_managed_kubernetes.default.id              # Kubernetes叢集名稱。
      node_pool_name        = local.nodepool_name                                    # 節點池名稱。
      vswitch_ids           = split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 節點池所在的vSwitch。指定一個或多個vSwitch的ID,必須在availability_zone指定的地區中。
      instance_types        = var.worker_instance_types
      instance_charge_type  = "PostPaid"
      runtime_name          = "containerd"
      runtime_version       = "1.6.20"
      desired_size          = 2            # 節點池的期望節點數。
      password              = var.password # SSH登入叢集節點的密碼。
      install_cloud_monitor = true         # 是否為Kubernetes的節點安裝CloudMonitor。
      system_disk_category  = "cloud_efficiency"
      system_disk_size      = 100
      image_type            = "AliyunLinux"
    
      data_disks {              # 節點資料盤配置。
        category = "cloud_essd" # 節點資料盤種類。
        size     = 120          # 節點資料盤大小。
      }
    }
    
    # 建立託管節點池。
    resource "alicloud_cs_kubernetes_node_pool" "managed_node_pool" {
      cluster_id     = alicloud_cs_managed_kubernetes.default.id              # Kubernetes叢集名稱。
      node_pool_name = local.managed_nodepool_name                            # 節點池名稱。
      vswitch_ids    = split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 節點池所在的vSwitch。指定一個或多個vSwitch的ID,必須在availability_zone指定的地區中。
      desired_size   = 0                                                      # 節點池的期望節點數。
    
      management {
        auto_repair     = true
        auto_upgrade    = true
        max_unavailable = 1
      }
    
      instance_types        = var.worker_instance_types
      instance_charge_type  = "PostPaid"
      runtime_name          = "containerd"
      runtime_version       = "1.6.20"
      password              = var.password
      install_cloud_monitor = true
      system_disk_category  = "cloud_efficiency"
      system_disk_size      = 100
      image_type            = "AliyunLinux"
    
      data_disks {
        category = "cloud_essd"
        size     = 120
      }
    }
    
    # 建立自動調整節點池,節點池最多可以擴充到 10 個節點,最少保持 1 個節點。
    resource "alicloud_cs_kubernetes_node_pool" "autoscale_node_pool" {
      cluster_id     = alicloud_cs_managed_kubernetes.default.id
      node_pool_name = local.autoscale_nodepool_name
      vswitch_ids    = split(",", join(",", alicloud_vswitch.vswitches.*.id))
    
      scaling_config {
        min_size = 1
        max_size = 10
      }
    
      instance_types        = var.worker_instance_types
      runtime_name          = "containerd"
      runtime_version       = "1.6.20"
      password              = var.password # SSH登入叢集節點的密碼。
      install_cloud_monitor = true         # 是否為kubernetes的節點安裝CloudMonitor。
      system_disk_category  = "cloud_efficiency"
      system_disk_size      = 100
      image_type            = "AliyunLinux3"
    
      data_disks {              # 節點資料盤配置。
        category = "cloud_essd" # 節點資料盤種類。
        size     = 120          # 節點資料盤大小。
      }
    }
  2. 執行以下命令,初始化Terraform運行環境。

    terraform init

    返回如下資訊,表示Terraform初始化成功。

    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.
  3. 建立執行計畫,並預覽變更。

    terraform plan
  4. 執行以下命令,建立叢集。

    terraform apply

    在執行過程中,根據提示輸入yes並按下Enter鍵,等待命令執行完成,若出現以下資訊,則表示ACK叢集建立成功。

    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
    
    ...
    alicloud_cs_managed_kubernetes.default: Creation complete after 5m48s [id=ccb53e72ec6c447c990762800********]
    ...
    
    Apply complete! Resources: 11 added, 0 changed, 0 destroyed.
  5. 驗證結果

    執行terraform show命令

    您可以使用以下命令查詢Terraform已建立的資來源詳細資料。

    terraform show

    登入ACK控制台

    登入Container Service管理主控台,查看已建立的叢集。

清理資源

當您不再需要上述通過Terraform建立或管理的資源時,請運行terraform destroy命令以釋放資源。關於terraform destroy的更多資訊,請參見常用命令

terraform destroy

完整樣本

說明

當前範例程式碼支援一鍵運行,您可以直接運行代碼。一鍵運行

provider "alicloud" {
  region = var.region_id
}

variable "region_id" {
  type    = string
  default = "cn-shenzhen"
}

variable "cluster_spec" {
  type        = string
  description = "The cluster specifications of kubernetes cluster,which can be empty. Valid values:ack.standard : Standard managed clusters; ack.pro.small : Professional managed clusters."
  default     = "ack.pro.small"
}

variable "ack_version" {
  type        = string
  description = "Desired Kubernetes version. "
  default     = "1.28.9-aliyun.1"
}

# 指定虛擬交換器(vSwitches)的可用性區域。
variable "availability_zone" {
  description = "The availability zones of vswitches."
  default     = ["cn-shenzhen-c", "cn-shenzhen-e", "cn-shenzhen-f"]
}

# 指定交換器ID(vSwitch IDs)的列表。
variable "node_vswitch_ids" {
  description = "List of existing node vswitch ids for terway."
  type        = list(string)
  default     = []
}

# 用於建立新vSwitches的CIDR地址塊列表。
variable "node_vswitch_cidrs" {
  description = "List of cidr blocks used to create several new vswitches when 'node_vswitch_ids' is not specified."
  type        = list(string)
  default     = ["172.16.0.0/23", "172.16.2.0/23", "172.16.4.0/23"]
}

# 指定網路組件Terway配置。如果為空白,預設會根據terway_vswitch_cidrs的建立新的terway vSwitch。
variable "terway_vswitch_ids" {
  description = "List of existing pod vswitch ids for terway."
  type        = list(string)
  default     = []
}

# 當沒有指定terway_vswitch_ids時,用於建立Terway使用的vSwitch的CIDR地址塊。
variable "terway_vswitch_cidrs" {
  description = "List of cidr blocks used to create several new vswitches when 'terway_vswitch_ids' is not specified."
  type        = list(string)
  default     = ["172.16.208.0/20", "172.16.224.0/20", "172.16.240.0/20"]
}

# 定義了用於啟動工作節點的ECS執行個體類型。
variable "worker_instance_types" {
  description = "The ecs instance types used to launch worker nodes."
  default     = ["ecs.g6.2xlarge", "ecs.g6.xlarge"]
}

# 設定工作階段的密碼
variable "password" {
  description = "The password of ECS instance."
  default     = "Test123456"
}

# 指定ACK叢集安裝的組件。包括Terway(網路組件)、csi-plugin(儲存群組件)、csi-provisioner(儲存群組件)、logtail-ds(日誌組件)、Nginx Ingress Controller、ack-arms-prometheus(監控組件)以及ack-node-problem-detector(節點診斷組件)。
variable "cluster_addons" {
  type = list(object({
    name   = string
    config = string
  }))

  default = [
    {
      "name"   = "terway-eniip",
      "config" = "",
    },
    {
      "name"   = "logtail-ds",
      "config" = "{\"IngressDashboardEnabled\":\"true\"}",
    },
    {
      "name"   = "nginx-ingress-controller",
      "config" = "{\"IngressSlbNetworkType\":\"internet\"}",
    },
    {
      "name"   = "arms-prometheus",
      "config" = "",
    },
    {
      "name"   = "ack-node-problem-detector",
      "config" = "{\"sls_project_name\":\"\"}",
    },
    {
      "name"   = "csi-plugin",
      "config" = "",
    },
    {
      "name"   = "csi-provisioner",
      "config" = "",
    }
  ]
}

# 指定建立ACK託管叢集名稱的首碼。
variable "k8s_name_prefix" {
  description = "The name prefix used to create managed kubernetes cluster."
  default     = "tf-ack-shenzhen"
}

# 預設資源名稱。
locals {
  k8s_name_terway         = substr(join("-", [var.k8s_name_prefix, "terway"]), 0, 63)
  k8s_name_flannel        = substr(join("-", [var.k8s_name_prefix, "flannel"]), 0, 63)
  k8s_name_ask            = substr(join("-", [var.k8s_name_prefix, "ask"]), 0, 63)
  new_vpc_name            = "tf-vpc-172-16"
  new_vsw_name_azD        = "tf-vswitch-azD-172-16-0"
  new_vsw_name_azE        = "tf-vswitch-azE-172-16-2"
  new_vsw_name_azF        = "tf-vswitch-azF-172-16-4"
  nodepool_name           = "default-nodepool"
  managed_nodepool_name   = "managed-node-pool"
  autoscale_nodepool_name = "autoscale-node-pool"
  log_project_name        = "log-for-${local.k8s_name_terway}"
}

# 節點ECS執行個體配置。將查詢滿足CPU、Memory要求的ECS執行個體類型。
data "alicloud_instance_types" "default" {
  cpu_core_count       = 8
  memory_size          = 32
  availability_zone    = var.availability_zone[0]
  kubernetes_node_role = "Worker"
}

# 專用網路。
resource "alicloud_vpc" "default" {
  vpc_name   = local.new_vpc_name
  cidr_block = "172.16.0.0/12"
}

# Node交換器。
resource "alicloud_vswitch" "vswitches" {
  count      = length(var.node_vswitch_ids) > 0 ? 0 : length(var.node_vswitch_cidrs)
  vpc_id     = alicloud_vpc.default.id
  cidr_block = element(var.node_vswitch_cidrs, count.index)
  zone_id    = element(var.availability_zone, count.index)
}

# Pod交換器。
resource "alicloud_vswitch" "terway_vswitches" {
  count      = length(var.terway_vswitch_ids) > 0 ? 0 : length(var.terway_vswitch_cidrs)
  vpc_id     = alicloud_vpc.default.id
  cidr_block = element(var.terway_vswitch_cidrs, count.index)
  zone_id    = element(var.availability_zone, count.index)
}

# Kubernetes託管版。
resource "alicloud_cs_managed_kubernetes" "default" {
  name                         = local.k8s_name_terway # Kubernetes叢集名稱。
  cluster_spec                 = var.cluster_spec      # 建立Pro版叢集。
  version                      = var.ack_version
  worker_vswitch_ids           = split(",", join(",", alicloud_vswitch.vswitches.*.id))        # 節點池所在的vSwitch。指定一個或多個vSwitch的ID,必須在availability_zone指定的地區中。
  pod_vswitch_ids              = split(",", join(",", alicloud_vswitch.terway_vswitches.*.id)) # Pod虛擬交換器。
  new_nat_gateway              = true                                                          # 是否在建立Kubernetes叢集時建立新的NAT Gateway。預設為true。
  service_cidr                 = "10.11.0.0/16"                                                # Pod網路的CIDR塊。當cluster_network_type設定為flannel,你必須設定該參數。它不能與VPC CIDR相同,並且不能與VPC中的Kubernetes叢集使用的CIDR相同,也不能在建立後進行修改。叢集中允許的最大主機數量:256。
  slb_internet_enabled         = true                                                          # 是否為API Server建立Internet負載平衡。預設為false。
  enable_rrsa                  = true
  control_plane_log_components = ["apiserver", "kcm", "scheduler", "ccm"] # 控制平面日誌。

  dynamic "addons" { # 組件管理。
    for_each = var.cluster_addons
    content {
      name   = lookup(addons.value, "name", var.cluster_addons)
      config = lookup(addons.value, "config", var.cluster_addons)
    }
  }
}

# 普通節點池。
resource "alicloud_cs_kubernetes_node_pool" "default" {
  cluster_id            = alicloud_cs_managed_kubernetes.default.id              # Kubernetes叢集名稱。
  node_pool_name        = local.nodepool_name                                    # 節點池名稱。
  vswitch_ids           = split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 節點池所在的vSwitch。指定一個或多個vSwitch的ID,必須在availability_zone指定的地區中。
  instance_types        = var.worker_instance_types
  instance_charge_type  = "PostPaid"
  runtime_name          = "containerd"
  runtime_version       = "1.6.20"
  desired_size          = 2            # 節點池的期望節點數。
  password              = var.password # SSH登入叢集節點的密碼。
  install_cloud_monitor = true         # 是否為Kubernetes的節點安裝CloudMonitor。
  system_disk_category  = "cloud_efficiency"
  system_disk_size      = 100
  image_type            = "AliyunLinux"

  data_disks {              # 節點資料盤配置。
    category = "cloud_essd" # 節點資料盤種類。
    size     = 120          # 節點資料盤大小。
  }
}

# 建立託管節點池。
resource "alicloud_cs_kubernetes_node_pool" "managed_node_pool" {
  cluster_id     = alicloud_cs_managed_kubernetes.default.id              # Kubernetes叢集名稱。
  node_pool_name = local.managed_nodepool_name                            # 節點池名稱。
  vswitch_ids    = split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 節點池所在的vSwitch。指定一個或多個vSwitch的ID,必須在availability_zone指定的地區中。
  desired_size   = 0                                                      # 節點池的期望節點數。

  management {
    auto_repair     = true
    auto_upgrade    = true
    max_unavailable = 1
  }

  instance_types        = var.worker_instance_types
  instance_charge_type  = "PostPaid"
  runtime_name          = "containerd"
  runtime_version       = "1.6.20"
  password              = var.password
  install_cloud_monitor = true
  system_disk_category  = "cloud_efficiency"
  system_disk_size      = 100
  image_type            = "AliyunLinux"

  data_disks {
    category = "cloud_essd"
    size     = 120
  }
}

# 建立自動調整節點池,節點池最多可以擴充到 10 個節點,最少保持 1 個節點。
resource "alicloud_cs_kubernetes_node_pool" "autoscale_node_pool" {
  cluster_id     = alicloud_cs_managed_kubernetes.default.id
  node_pool_name = local.autoscale_nodepool_name
  vswitch_ids    = split(",", join(",", alicloud_vswitch.vswitches.*.id))

  scaling_config {
    min_size = 1
    max_size = 10
  }

  instance_types        = var.worker_instance_types
  runtime_name          = "containerd"
  runtime_version       = "1.6.20"
  password              = var.password # SSH登入叢集節點的密碼。
  install_cloud_monitor = true         # 是否為kubernetes的節點安裝CloudMonitor。
  system_disk_category  = "cloud_efficiency"
  system_disk_size      = 100
  image_type            = "AliyunLinux3"

  data_disks {              # 節點資料盤配置。
    category = "cloud_essd" # 節點資料盤種類。
    size     = 120          # 節點資料盤大小。
  }
}