alicloud_cs_managed_kubernetes
This resource will help you to manage a ManagedKubernetes Cluster in Alibaba Cloud Kubernetes Service.
-> NOTE: Available since v1.26.0.
-> NOTE: It is recommended to create a cluster with zero worker nodes, and then use a node pool to manage the cluster nodes.
-> NOTE: Kubernetes cluster only supports VPC network and it can access internet while creating kubernetes cluster.
A Nat Gateway and configuring a SNAT for it can ensure one VPC network access internet. If there is no nat gateway in the
VPC, you can set new_nat_gateway to "true" to create one automatically.
-> NOTE: Creating kubernetes cluster need to install several packages and it will cost about 15 minutes. Please be patient.
-> NOTE: From version 1.9.4, the provider supports to download kube config, client certificate, client key and cluster ca certificate after creating cluster successfully, and you can put them into the specified location, like '~/.kube/config'.
-> NOTE: From version 1.20.0, the provider supports disabling internet load balancer for API Server by setting false to slb_internet_enabled.
-> NOTE: If you want to manage Kubernetes, you can use Kubernetes Provider.
-> NOTE: You need to activate several other products and confirm Authorization Policy used by Container Service before using this resource.
Please refer to the Authorization management and Cluster management sections in the Document Center.
-> NOTE: From version 1.72.0, Some parameters have been removed from resource,You can check them below and re-import the cluster if necessary.
-> NOTE: From version 1.120.0, Support for cluster migration from Standard cluster to professional.
-> NOTE: From version 1.177.0, runtime,enable_ssh,rds_instances,exclude_autoscaler_nodes,worker_number,worker_instance_types,password,key_name,kms_encrypted_password,kms_encryption_context,worker_instance_charge_type,worker_period,worker_period_unit,worker_auto_renew,worker_auto_renew_period,worker_disk_category,worker_disk_size,worker_data_disks,node_name_mode,node_port_range,os_type,platform,image_id,cpu_policy,user_data,taints,worker_disk_performance_level,worker_disk_snapshot_policy_id,install_cloud_monitor are deprecated.
We Suggest you using resource alicloud_cs_kubernetes_node_pool to manage your cluster worker nodes.
-> NOTE: From version 1.212.0, runtime,enable_ssh,rds_instances,exclude_autoscaler_nodes,worker_number,worker_instance_types,password,key_name,kms_encrypted_password,kms_encryption_context,worker_instance_charge_type,worker_period,worker_period_unit,worker_auto_renew,worker_auto_renew_period,worker_disk_category,worker_disk_size,worker_data_disks,node_name_mode,node_port_range,os_type,platform,image_id,cpu_policy,user_data,taints,worker_disk_performance_level,worker_disk_snapshot_policy_id,install_cloud_monitor,kube_config,availability_zone are removed.
Please use resource alicloud_cs_kubernetes_node_pool to manage your cluster worker nodes.
Example Usage
ACK cluster
variable "name" {
default = "tf-example-"
}
# leave it to empty would create a new one
variable "vpc_id" {
description = "Existing vpc id used to create several vswitches and other resources."
default = ""
}
variable "vpc_cidr" {
description = "The cidr block used to launch a new vpc when 'vpc_id' is not specified."
default = "10.0.0.0/8"
}
# leave it to empty then terraform will create several vswitches
variable "vswitch_ids" {
description = "List of existing vswitch id."
type = list(string)
default = []
}
variable "vswitch_cidrs" {
description = "List of cidr blocks used to create several new vswitches when 'vswitch_ids' is not specified."
type = list(string)
default = ["10.1.0.0/16", "10.2.0.0/16"]
}
# options: ipvs|iptables
variable "proxy_mode" {
description = "Proxy mode is option of kube-proxy."
default = "ipvs"
}
variable "service_cidr" {
description = "The kubernetes service cidr block. It cannot be equals to vpc's or vswitch's or pod's and cannot be in them."
default = "192.168.0.0/16"
}
variable "terway_vswitch_ids" {
description = "List of existing vswitch ids for terway."
type = list(string)
default = []
}
variable "terway_vswitch_cidrs" {
description = "List of cidr blocks used to create several new vswitches when 'terway_vswitch_cidrs' is not specified."
type = list(string)
default = ["10.4.0.0/16", "10.5.0.0/16"]
}
data "alicloud_enhanced_nat_available_zones" "enhanced" {}
data "alicloud_kms_keys" "default" {
filters = "[{\"Key\":\"KeyState\",\"Values\":[\"Enabled\"]},{\"Key\":\"KeySpec\",\"Values\":[\"Aliyun_AES_256\"]},{\"Key\":\"KeyUsage\",\"Values\":[\"ENCRYPT/DECRYPT\"]},{\"Key\":\"CreatorType\",\"Values\":[\"User\"]}]"
}
# If there is not specifying vpc_id, the module will launch a new vpc
resource "alicloud_vpc" "vpc" {
count = var.vpc_id == "" ? 1 : 0
cidr_block = var.vpc_cidr
}
# According to the vswitch cidr blocks to launch several vswitches
resource "alicloud_vswitch" "vswitches" {
count = length(var.vswitch_ids) > 0 ? 0 : length(var.vswitch_cidrs)
vpc_id = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id
cidr_block = element(var.vswitch_cidrs, count.index)
zone_id = data.alicloud_enhanced_nat_available_zones.enhanced.zones[count.index].zone_id
}
# According to the vswitch cidr blocks to launch several vswitches
resource "alicloud_vswitch" "terway_vswitches" {
count = length(var.terway_vswitch_ids) > 0 ? 0 : length(var.terway_vswitch_cidrs)
vpc_id = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id
cidr_block = element(var.terway_vswitch_cidrs, count.index)
zone_id = data.alicloud_enhanced_nat_available_zones.enhanced.zones[count.index].zone_id
}
resource "alicloud_cs_managed_kubernetes" "k8s" {
name_prefix = var.name
cluster_spec = "ack.pro.small"
# version can not be defined in variables.tf.
# version = "1.26.3-aliyun.1"
vswitch_ids = length(var.vswitch_ids) > 0 ? split(",", join(",", var.vswitch_ids)) : length(var.vswitch_cidrs) < 1 ? [] : split(",", join(",", alicloud_vswitch.vswitches.*.id))
pod_vswitch_ids = length(var.terway_vswitch_ids) > 0 ? split(",", join(",", var.terway_vswitch_ids)) : length(var.terway_vswitch_cidrs) < 1 ? [] : split(",", join(",", alicloud_vswitch.terway_vswitches.*.id))
new_nat_gateway = true
proxy_mode = var.proxy_mode
service_cidr = var.service_cidr
skip_set_certificate_authority = true
encryption_provider_key = data.alicloud_kms_keys.default.keys[0].key_id
addons {
name = "terway-eniip"
}
addons {
name = "csi-plugin"
}
addons {
name = "csi-provisioner"
}
addons {
name = "logtail-ds"
config = jsonencode({
IngressDashboardEnabled = "true"
})
}
addons {
name = "nginx-ingress-controller"
config = jsonencode({
IngressSlbNetworkType = "internet"
})
# to disable install nginx-ingress-controller automatically
# disabled = true
}
addons {
name = "arms-prometheus"
}
addons {
name = "ack-node-problem-detector"
config = jsonencode({
# sls_project_name = "your-sls-project"
})
}
}
ACK Cluster with Auto Mode
variable "name" {
default = "auto-mode"
}
variable "proxy_mode" {
description = "Proxy mode is option of kube-proxy."
default = "ipvs"
}
variable "service_cidr" {
description = "The kubernetes service cidr block."
default = "192.168.0.0/16"
}
data "alicloud_enhanced_nat_available_zones" "enhanced" {}
resource "alicloud_cs_managed_kubernetes" "auto-mode" {
name = var.name
cluster_spec = "ack.pro.small"
zone_ids = [data.alicloud_enhanced_nat_available_zones.enhanced.zones.0.zone_id]
new_nat_gateway = true
is_enterprise_security_group = true
slb_internet_enabled = false
skip_set_certificate_authority = true
proxy_mode = var.proxy_mode
service_cidr = var.service_cidr
ip_stack = "ipv4"
deletion_protection = true
auto_mode {
enabled = true
}
maintenance_window {
duration = "3h"
weekly_period = "Monday"
enable = true
maintenance_time = "2025-07-07T00:00:00.000+08:00"
}
operation_policy {
cluster_auto_upgrade {
channel = "stable"
enabled = true
}
}
control_plane_log_components = [
"apiserver",
"kcm",
"scheduler",
"ccm",
"controlplane-events",
"alb",
"ack-goatscaler",
"coredns",
"gatekeeper"
]
control_plane_log_ttl = "30"
audit_log_config {
enabled = true
}
addons {
name = "metrics-server"
}
addons {
name = "managed-coredns"
}
addons {
name = "managed-security-inspector"
}
addons {
name = "ack-cost-exporter"
}
addons {
name = "terway-controlplane"
config = jsonencode({
ENITrunking = "true"
})
}
addons {
name = "terway-eniip"
config = jsonencode({
NetworkPolicy = "false"
ENITrunking = "true"
IPVlan = "false"
})
}
addons {
name = "csi-plugin"
}
addons {
name = "managed-csiprovisioner"
}
addons {
name = "storage-operator"
config = jsonencode({
CnfsOssEnable = "false"
CnfsNasEnable = "false"
})
}
addons {
name = "loongcollector"
config = jsonencode({
IngressDashboardEnabled = "true"
})
}
addons {
name = "ack-node-problem-detector"
config = jsonencode({
sls_project_name = ""
})
}
addons {
name = "nginx-ingress-controller"
disabled = true
}
addons {
name = "alb-ingress-controller"
config = jsonencode({
albIngress = {
CreateDefaultALBConfig = false
}
})
}
addons {
name = "arms-prometheus"
config = jsonencode({
prometheusMode = "default"
})
}
addons {
name = "alicloud-monitor-controller"
}
addons {
name = "managed-aliyun-acr-credential-helper"
}
}
ACK Cluster with an automatically created private NLB
When load_balancer_id is omitted, ACK automatically creates and manages a private NLB for the cluster API server endpoint, so there is no need to create an alicloud_nlb_load_balancer resource. The cluster must span at least two zones so that the auto-created NLB gets a valid zone list.
variable "name" {
default = "tf-example-auto-nlb"
}
variable "service_cidr" {
description = "The kubernetes service cidr block."
default = "172.23.0.0/16"
}
data "alicloud_nlb_zones" "default" {}
resource "alicloud_vpc" "default" {
vpc_name = var.name
cidr_block = "10.1.0.0/21"
}
resource "alicloud_vswitch" "default_1" {
vswitch_name = "${var.name}-1"
vpc_id = alicloud_vpc.default.id
cidr_block = "10.1.1.0/24"
zone_id = data.alicloud_nlb_zones.default.zones.0.id
}
resource "alicloud_vswitch" "default_2" {
vswitch_name = "${var.name}-2"
vpc_id = alicloud_vpc.default.id
cidr_block = "10.1.2.0/24"
zone_id = data.alicloud_nlb_zones.default.zones.1.id
}
resource "alicloud_cs_managed_kubernetes" "default" {
name = var.name
cluster_spec = "ack.pro.small"
vswitch_ids = [alicloud_vswitch.default_1.id, alicloud_vswitch.default_2.id]
pod_vswitch_ids = [alicloud_vswitch.default_1.id, alicloud_vswitch.default_2.id]
new_nat_gateway = false
service_cidr = var.service_cidr
is_enterprise_security_group = true
addons {
name = "terway-eniip"
}
control_plane_endpoints_config {
# load_balancer_id is left empty so ACK creates a private NLB automatically.
load_balancers_config {
endpoint_type = "private"
}
}
}
Need more examples? VIEW MORE EXAMPLES
Argument Reference
The following arguments are supported:
Global params
-
name- (Optional) The kubernetes cluster's name. It is unique in one Alicloud account. -
zone_ids- (Optional, Available since v1.243.0) The IDs of the zone in which the cluster control plane is deployed. ACK automatically creates a VPC in the region and vSwitches in the specified zones. Only works for Create Operation. Do not specify this withvswitch_idstogether. -
worker_vswitch_ids- (Optional, Deprecated since v1.241.0) The vSwitches used by control plane. Modification after creation will not take effect. Please usevswitch_idsto managed control plane vSwitches, which supports modifying control plane vSwitches. -
vswitch_ids- (Optional, Available since v1.241.0) The vSwitches of the control plane.-> NOTE: Please take of note before updating the
vswitch_ids:- This parameter overwrites the existing configuration. You must specify all vSwitches of the control plane.
- The control plane restarts during the change process. Exercise caution when you perform this operation.
- Ensure that all security groups of the cluster, including the security groups of the control plane, all node pools, and container network, are allowed to access the CIDR blocks of the new vSwitches. This ensures that the nodes and containers can connect to the API server.
- If the new vSwitches of the control plane are configured with an ACL, ensure that the ACL allows communication between the new vSwitches and CIDR blocks such as those of the cluster nodes and the container network.
-
name_prefix- (Optional) The kubernetes cluster name's prefix. It is conflict withname. If it is specified, terraform will use it to build the only cluster name. Default to "Terraform-Creation". -
timezone- (Optional, Available since v1.103.2) Cluster timezone, works for control plane and Worker nodes.-> NOTE: Please take of note before updating the
timezone:- After modifying the timezone, cluster inspection configurations will adopt the new timezone.
- During timezone updates, the cluster control plane and managed components (e.g., terway-controlplane) will restart briefly. Perform this operation during off-peak hours.
- After updating the timezone: Newly scaled-out nodes will automatically apply the new timezone. Existing nodes remain unaffected. Reset the node to apply changes to existing nodes.
-
resource_group_id- (Optional, Available since v1.101.0) The ID of the resource group,by default these cloud resources are automatically assigned to the default resource group. -
version- (Optional, Available since 1.70.1) Desired Kubernetes version. If you do not specify a value, the latest available version at resource creation is used and no upgrades will occur except you set a higher version number. The value must be configured and increased to upgrade the version when desired. Downgrades are not supported by ACK. Do not specify if cluster auto upgrade is enabled, see cluster_auto_upgrade for more information. -
security_group_id- (Optional, Available since v1.91.0) The ID of the security group to which the ECS instances in the cluster belong. If it is not specified, a new Security group will be built.-> NOTE: Please take of note before updating the
security_group_id:- If block rules are configured in the security group, ensure the security group rules allow traffic for protocols and ports required by the cluster. For recommended security group rules, see Configure and manage security groups for an ACK cluster.
- During security group updates, the cluster control plane and managed components (e.g., terway-controlplane) will restart briefly. Perform this operation during off-peak hours.
- After updating the control plane security group, the Elastic Network Interfaces (ENIs) used by the control plane and managed components will automatically join the new security group.
-
is_enterprise_security_group- (Optional, ForceNew, Available since v1.91.0) Enable to create advanced security group. default: false. Only works for Create Operation. See Advanced security group. -
proxy_mode- (Optional, ForceNew) kube-proxy proxy mode. Default:ipvs. Options:iptables,ipvs,nftables.iptables: A mature and stable kube-proxy mode. Kubernetes Service discovery and load balancing use iptables rules. Performance is moderate and scales poorly with large numbers of Services. Suitable for clusters with few Services.ipvs: A high-performance kube-proxy mode. Kubernetes Service discovery and load balancing use the Linux IPVS module. Suitable for clusters with many Services requiring high-performance load balancing.nftables: A next-generation kube-proxy mode based on Linux nftables for Service discovery and load balancing. It is a modern replacement for iptables, offering better network performance, rule update efficiency, and scalability for large Service counts. Supported only for clusters running Kubernetes 1.35 or later. The Kubernetes community deprecated IPVS starting in version 1.35. We recommend using nftables for new clusters to ensure long-term community support.
-
cluster_domain- (Optional, ForceNew, Available since v1.103.2) Cluster local domain name, Default tocluster.local. A domain name consists of one or more sections separated by a decimal point (.), each of which is up to 63 characters long, and can be lowercase, numerals, and underscores (-), and must be lowercase or numerals at the beginning and end. -
custom_san- (Optional, Available since v1.103.2) Customize the certificate SAN, multiple IP or domain names are separated by English commas (,).-> NOTE: Make sure you have specified all certificate SANs before updating. Updating this field will lead APIServer to restart.
-
user_ca- (Optional) The path of customized CA cert, you can use this CA to sign client certs to connect your cluster. -
deletion_protection- (Optional, Available since v1.103.2) Whether to enable cluster deletion protection. -
enable_rrsa- (Optional, Available since v1.171.0) Whether to enable cluster to support RRSA for kubernetes version 1.22.3+. Default tofalse. Once the RRSA function is turned on, it is not allowed to turn off. If your cluster has enabled this function, please manually modify your tf file and add the rrsa configuration to the file, learn more RAM Roles for Service Accounts. -
service_account_issuer- (Optional, ForceNew, Available since v1.92.0) The issuer of the Service Account token for Service Account Token Volume Projection, corresponds to theissfield in the token payload. Set this to"https://kubernetes.default.svc"to enable the Token Volume Projection feature (requires specifyingapi_audiencesas well). From cluster version 1.22, Service Account Token Volume Projection will be enabled by default. -
api_audiences- (Optional, ForceNew, Available since v1.92.0) A list of API audiences for Service Account Token Volume Projection. Set this to["https://kubernetes.default.svc"]if you want to enable the Token Volume Projection feature (requires specifyingservice_account_issueras well. From cluster version 1.22, Service Account Token Volume Projection will be enabled by default. -
tags- (Optional, Available since v1.97.0) Default nil, A map of tags assigned to the kubernetes cluster and work nodes. Seetagsbelow. -
cluster_spec- (Optional, Available since v1.101.0) The cluster specifications of kubernetes cluster, which can be empty. Valid values:- ack.standard : Basic managed clusters.
- ack.pro.small : Professional managed clusters.
- ack.pro.xlarge : ACK Pro Provisioned Control Plane (Pro XL).
- ack.pro.2xlarge : ACK Pro Provisioned Control Plane (Pro 2XL).
- ack.pro.4xlarge : ACK Pro Provisioned Control Plane (Pro 4XL). Requires whitelist access from customer service.
ACK Pro Provisioned Control Plane (Pro XL/2XL/4XL) tiers pre-allocate and dedicate control plane resources to ensure consistently high API concurrency and pod scheduling performance, making them suitable for AI training/inference, ultra-large-scale clusters, and mission-critical workloads. For details, see Cluster management fees and ACK Pro Provisioned Control Plane.
-
profile- (Optional, ForceNew, Available since v1.250.0) The profile of cluster. Valid values:Default: ACK managed cluster. ACK managed clusters include ACK Basic clusters and ACK Pro clusters.Edge: ACK Edge cluster. ACK Edge clusters include ACK Edge Basic clusters and ACK Edge Pro clusters.Serverless: ACK Serverless cluster. ACK Serverless clusters include ACK Serverless Basic clusters and ACK Serverless Pro clusters.Acs: ACS cluster.
-
encryption_provider_key- (Optional, Available since v1.103.2) The ID of the Key Management Service (KMS) key that is used to encrypt Kubernetes Secrets.-> Note: To enable encryption, you must specify both
encryption_provider_keyanddisable_encryption = false. Whendisable_encryptionis set totrue, changes toencryption_provider_keywill be ignored. -
disable_encryption- (Optional, Computed, Available since v1.275.0) Whether to disable encryption for Kubernetes Secrets. Default value isfalse. Set totrueto disable encryption.-> Note: When enabling encryption, you must explicitly set
disable_encryption = falsealong withencryption_provider_key. When disabling encryption, you only need to setdisable_encryption = true, and theencryption_provider_keywill be ignored. -
maintenance_window- (Optional, Available since v1.109.1) The cluster maintenance window. Managed node pool will use it. Seemaintenance_windowbelow. -
operation_policy- (Optional, Available since v1.232.0) The cluster automatic operation policy, only works whenmaintenance_windowis enabled. Seeoperation_policybelow. -
load_balancer_spec- (Optional, Deprecated since v1.232.0) The cluster api server load balancer instance specification. For more information on how to select a LB instance specification, see SLB instance overview. Only works for Create Operation. The spec will not take effect because the charge of the load balancer has been changed to PayByCLCU. -
control_plane_log_ttl- (Optional, Available since v1.141.0) Control plane log retention duration (unit: day). Default30. If control plane logs are to be collected,control_plane_log_ttlandcontrol_plane_log_componentsmust be specified. -
control_plane_log_components- (Optional, Available since v1.141.0) List of target components for which logs need to be collected. Supportsapiserver,kcm,scheduler,ccmandcontrolplane-events. -
control_plane_log_project- (Optional, Available since v1.141.0) Control plane log project. If this field is not set, a log service project named k8s-log-{ClusterID} will be automatically created. -
audit_log_config- (Optional, Available since v1.250.0) Audit log configuration. Seeaudit_log_configbelow. -
auto_mode- (Optional, ForceNew, Available since v1.254.0) Auto mode cluster configuration. Seeauto_modebelow. -
control_plane_endpoints_config- (Optional, Available since v1.286.0) The cluster access configuration. Seecontrol_plane_endpoints_configbelow. -
retain_resources- (Optional, Available since v1.141.0) Resources that are automatically created during cluster creation, including NAT gateways, SNAT rules, SLB instances, and RAM Role, will be deleted. Resources that are manually created after you create the cluster, such as SLB instances for Services, will also be deleted. If you need to retain resources, please configure withretain_resources. There are several aspects to pay attention to when usingretain_resourcesto retain resources. After configuringretain_resourcesinto the terraform configuration manifest file, you first need to runterraform apply.Then executeterraform destroy. -
delete_options- (Optional, Available since v1.223.2) Delete options, only work for deleting resource. Make sure you have runterraform applyto make the configuration applied. Seedelete_optionsbelow. -
addons- (Optional, Available since v1.88.0) The addon you want to install in cluster. Seeaddonsbelow. Only works for Create Operation, use resource cs_kubernetes_addon to manage addons if cluster is created. -
skip_set_certificate_authority- (Optional) Configure whether to save certificate authority data for your cluster to attributecertificate_authority. For cluster security, recommended configuration astrue. Will be removed with attribute certificate_authority removed. -
upgrade_policy- (Optional, Set, Available since v1.269.0) Configuration block for cluster upgrade operations. Seeupgrade_policybelow.-> NOTE: This parameter only applies during resource update.
Network params
-
pod_cidr- (Optional, ForceNew) - [Flannel Specific] The CIDR block for the pod network when using Flannel. -
pod_vswitch_ids- (Optional) - [Terway Specific] The vswitches for the pod network when using Terway. It is recommended thatpod_vswitch_idsis not belong tovswitch_idsbut must be in same availability zones. Only works for Create Operation. -
new_nat_gateway- (Optional) Whether to create a new nat gateway while creating kubernetes cluster. Default to true. Then openapi in Alibaba Cloud are not all on intranet, So turn this option on is a good choice. Only works for Create Operation. -
service_cidr- (Optional, ForceNew) The CIDR block for the service network. It cannot be duplicated with the VPC CIDR and CIDR used by Kubernetes cluster in VPC, cannot be modified after creation. -
node_cidr_mask- (Optional, ForceNew) The node cidr block to specific how many pods can run on single node. 24-28 is allowed. 24 means 2^(32-24)-1=255 and the node can run at most 255 pods. default: 24 -
slb_internet_enabled- (Optional) Whether to create internet load balancer for API Server. Default to true. Only works for Create Operation. -
ip_stack- (Optional, ForceNew, Available since v1.243.0) The IP address family that the cluster network uses. Valid values:ipv4: IPv4 stack.dual: IPv4/IPv6 dual stack. IPv4 addresses are used for communication between worker nodes and the control plane. The VPC used by the cluster must support IPv4 and IPv6 dual-stack. This feature is only supported for Kubernetes version 1.22 and later, and you must selectTerwayas CNI network plugin. If you use the shared ENI mode ofTerway, the ECS instance type must support IPv6 addresses and the number of IPv4 addresses supported by the ECS instance type must be the same as the number of IPv6 addresses, for more information about ECS instance types, see Overview of instance families. Dual stack is not supported if you want to use Elastic Remote Direct Memory Access (eRDMA) in the cluster.
-> NOTE: If you want to use
Terwayas CNI network plugin, You need to specify thepod_vswitch_idsfield and addons withterway-eniip. If you want to useFlannelas CNI network plugin, You need to specify thepod_cidrfield and addons withflannel.
Computed params
client_cert- (Optional, Deprecated from v1.248.0) From version 1.248.0, new DataSourcealicloud_cs_cluster_credentialis recommended to manage cluster's kubeconfig, you can also save the certificate_authority.client_cert attribute content of new DataSourcealicloud_cs_cluster_credentialto an appropriate path(like ~/.kube/client-cert.pem) for replace it.client_key- (Optional, Deprecated from v1.248.0) From version 1.248.0, new DataSourcealicloud_cs_cluster_credentialis recommended to manage cluster's kubeconfig, you can also save the certificate_authority.client_key attribute content of new DataSourcealicloud_cs_cluster_credentialto an appropriate path(like ~/.kube/client-key.pem) for replace it.cluster_ca_cert- (Optional, Deprecated from v1.248.0) From version 1.248.0, new DataSourcealicloud_cs_cluster_credentialis recommended to manage cluster's kubeconfig, you can also save the certificate_authority.cluster_cert attribute content of new DataSourcealicloud_cs_cluster_credentialto an appropriate path(like ~/.kube/cluster-ca-cert.pem) for replace it.
maintenance_window
The following arguments are supported in the maintenance_window configuration block:
enable- (Optional) Whether to open the maintenance window. The following parameters take effect onlyenable = true.maintenance_time- (Optional) Initial maintenance time, RFC3339 format. For example: "2024-10-15T12:31:00.000+08:00".duration- (Optional) The maintenance time, values range from 1 to 24,unit is hour. For example: "3h".weekly_period- (Optional) Maintenance cycle, you can set the values from Monday to Sunday, separated by commas when the values are multiple. The default is Thursday.
for example:
maintenance_window {
enable = true
maintenance_time = "2024-10-15T12:31:00.000+08:00"
duration = "3h"
weekly_period = "Monday,Friday"
}
operation_policy
cluster_auto_upgrade- (Optional) Automatic cluster upgrade policy. Seecluster_auto_upgradebelow.
operation_policy-cluster_auto_upgrade
Automatic cluster upgrade policy. If enabled is set to true, ACK will automatically upgrade cluster depends on the channel value. The version field may show diffs if set in config, please remove the field or ignore it.
enabled- (Optional) Whether to enable automatic cluster upgrade.channel- (Optional) The automatic cluster upgrade channel. Valid values:patch,stable,rapid.
for example:
operation_policy {
cluster_auto_upgrade {
enabled = true
channel = "stable"
}
}
audit_log_config
Audit log config. If enabled is set to true, a Logstore is created in the specified Simple Log Service project(SLS) to store cluster audit logs.
enabled- (Optional) Whether to enable audit logging. Valid values:true,false.sls_project_name- (Optional) The SLS project to which the Logstore storing the cluster audit logs belongs.
auto_mode
Auto mode cluster config.
enabled- (Optional, ForceNew) Whether to enable auto mode. Valid values:true,false. Only ACK managed Pro clusters support Auto Mode.
control_plane_endpoints_config
The cluster access configuration.
load_balancers_config- (Optional, Computed) The load balancing configuration for cluster access. Seeload_balancers_configbelow.internal_dns_config- (Optional, Computed) The cluster internal domain name configuration, applicable to ACK managed clusters. Seeinternal_dns_configbelow.
control_plane_endpoints_config-load_balancers_config
-> NOTE: CLB configuration may be generated automatically after updating for an old cluster, so keep it in load_balancers_config unless you really intend to remove the CLB. Removing a load balancer configuration may affect access to the cluster, please proceed with caution. When a configuration is removed, its associated load balancer (SLB/NLB) instance is only disassociated from the cluster and is not released, you need to release it manually.
load_balancer_id- (Optional, Computed) The ID of the SLB (NLB) instance associated with the endpoint.endpoint_type- (Optional, Computed) The endpoint type. Valid values:private,public.endpoint- (Computed) The access address.
control_plane_endpoints_config-internal_dns_config
bind_vpcs- (Optional, Computed) The list of VPCs where the API Server access domain name takes effect. By default, the VPC of the cluster is included.enabled- (Optional, Computed) Whether to enable the cluster internal domain name access. When enabled, node-side components (kubelet, kube-proxy) access the API Server through the cluster internal domain name. This field can only be set on update, not on create.
upgrade_policy
Configuration block for cluster upgrade operations. This is a transient parameter that controls upgrade behavior when updating the version field.
control_plane_only- (Optional) Whether to upgrade only the control plane without upgrading worker nodes. Valid values:true,false. When set totrue, only the cluster control plane components will be upgraded, and worker nodes will remain at their current version. Default isfalse.
for example:
# Upgrade cluster version with control plane only
version = "1.32.1-aliyun.1"
upgrade_policy {
control_plane_only = true
}
-> NOTE: After the upgrade completes, you may remove the upgrade_policy block from your configuration to prevent unintended re-upgrades on subsequent applies.
addons
The following arguments are supported in the addons configuration block:
name- (Optional) This parameter specifies the name of the component.config- (Optional) If this parameter is left empty, no configurations are required. For more config information, see cs_kubernetes_addon_metadata.version- (Optional) It specifies the version of the component.disabled- (Optional) It specifies whether to disable automatic installation.
It is a new field since 1.75.0. You can specific network plugin, log component,ingress component and so on.
You can get more information about addons on ACK web console. When you create a ACK cluster. You can get openapi-spec before creating the cluster on submission page.
logtail-ds - You can specify IngressDashboardEnabled and sls_project_name in config. If you switch on IngressDashboardEnabled and sls_project_name,then logtail-ds would use sls_project_name as default log store.
nginx-ingress-controller - You can specific IngressSlbNetworkType in config. Options: internet|intranet.
The main.tf:
resource "alicloud_cs_managed_kubernetes" "k8s" {
# ... other configuration ...
dynamic "addons" {
for_each = var.cluster_addons
content {
name = lookup(addons.value, "name", var.cluster_addons)
config = lookup(addons.value, "config", var.cluster_addons)
version = lookup(addons.value, "version", var.cluster_addons)
disabled = lookup(addons.value, "disabled", var.cluster_addons)
}
}
}
The varibales.tf:
# Network-flannel is required, Conflicts With Network-terway
variable "cluster_addons" {
description = "Addon components in kubernetes cluster"
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "flannel",
"config" = "",
}
]
}
# Network-terway is required, Conflicts With Network-flannel
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "terway-eniip",
"config" = "",
}
]
}
# Storage-csi is required, Conflicts With Storage-flexvolume
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "csi-plugin",
"config" = "",
},
{
"name" = "csi-provisioner",
"config" = "",
}
]
}
# Storage-flexvolume is required, Conflicts With Storage-csi
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "flexvolume",
"config" = "",
}
]
}
# Log, Optional
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "logtail-ds",
"config" = "{\"IngressDashboardEnabled\":\"true\",\"sls_project_name\":\"your-sls-project-name\"}",
}
]
}
# Ingress,Optional
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "nginx-ingress-controller",
"config" = "{\"IngressSlbNetworkType\":\"internet\"}",
}
]
}
# Ingress-Disable, Optional
variable "cluster_addons" {
type = list(object({
name = string
config = string
disabled = bool
}))
default = [
{
"name" = "nginx-ingress-controller",
"config" = "",
"disabled": true,
}
]
# Prometheus, Optional.
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "arms-prometheus",
"config" = "",
}
]
}
# Event Center, Optional.
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "ack-node-problem-detector",
"config" = "{\"sls_project_name\":\"\"}",
}
]
}
# ACK default alert, Optional.
variable "cluster_addons" {
type = list(object({
name = string
config = string
}))
default = [
{
"name" = "alicloud-monitor-controller",
"config" = "{\"group_contact_ids\":\"[159]\"}",
}
]
}
tags
The following example is the definition of tags block. The type of this field is map:
# for example, define three tags
tags = {
"key1" = "value1"
"key2" = "value2"
"name" = "tf"
}
delete_options
The following arguments are supported in the delete_options configuration block:
delete_mode- (Optional) The deletion mode of the cluster. Different resources may have different default behavior, seeresource_typefor details. Valid values:delete: delete resources created by the cluster.retain: retain resources created by the cluster.
resource_type- (Optional) The type of resources that are created by cluster. Valid values:SLB: SLB resources created by the Nginx Ingress Service, default behavior is to delete, option to retain is available.ALB: ALB resources created by the ALB Ingress Controller, default behavior is to retain, option to delete is available.SLS_Data: SLS Project used by the cluster logging feature, default behavior is to retain, option to delete is available.SLS_ControlPlane: SLS Project used for the managed cluster control plane logs, default behavior is to retain, option to delete is available.
...
// Specify delete_options as below when deleting cluster
// delete SLB resources created by the Nginx Ingress Service
delete_options {
delete_mode = "delete"
resource_type = "SLB"
}
// delete ALB resources created by the ALB Ingress Controller
delete_options {
delete_mode = "delete"
resource_type = "ALB"
}
// delete SLS Project used by the cluster logging feature
delete_options {
delete_mode = "delete"
resource_type = "SLS_Data"
}
// delete SLS Project used for the managed cluster control plane logs
delete_options {
delete_mode = "delete"
resource_type = "SLS_ControlPlane"
}
Attributes Reference
The following attributes are exported:
id- The ID of the container cluster.vpc_id- The ID of VPC where the current cluster is located.slb_intranet- The ID of private load balancer where the current cluster master node is located.slb_internet- The public ip of load balancer.slb_id- The ID of APIServer load balancer.nat_gateway_id- The ID of nat gateway used to launch kubernetes cluster.connections- A list of kubernetes cluster connection information.api_server_internet- API Server Internet endpoint.api_server_intranet- API Server Intranet endpoint.master_public_ip- Master node SSH IP address.service_domain- Service Access Domain.
worker_ram_role_name- The RamRole Name attached to worker node.certificate_authority- (List, Deprecated from v1.248.0) Nested attribute containing certificate authority data for your cluster. Please use the attribute certificate_authority of new DataSourcealicloud_cs_cluster_credentialto replace it.cluster_cert- The base64 encoded cluster certificate data required to communicate with your cluster. Add this to the certificate-authority-data section of the kubeconfig file for your cluster.client_cert- The base64 encoded client certificate data required to communicate with your cluster. Add this to the client-certificate-data section of the kubeconfig file for your cluster.client_key- The base64 encoded client key data required to communicate with your cluster. Add this to the client-key-data section of the kubeconfig file for your cluster.
rrsa_metadata- (Optional, Available since v1.185.0) Nested attribute containing RRSA related data for your cluster.enabled- Whether the RRSA feature has been enabled.rrsa_oidc_issuer_url- The issuer URL of RRSA OIDC Token.ram_oidc_provider_name- The name of OIDC Provider that was registered in RAM.ram_oidc_provider_arn- The arn of OIDC provider that was registered in RAM.
Timeouts
-> NOTE: Available since v1.58.0.
The timeouts block allows you to specify timeouts for certain actions:
create- (Defaults to 90 mins) Used when creating the kubernetes cluster (until it reaches the initialrunningstatus).update- (Defaults to 60 mins) Used when activating the kubernetes cluster when necessary during update.delete- (Defaults to 60 mins) Used when terminating the kubernetes cluster.
Import
Kubernetes managed cluster can be imported using the id, e.g. Then complete the main.tf accords to the result of terraform plan.
$ terraform import alicloud_cs_managed_kubernetes.main cluster_id