Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions examples/tencentcloud-tke-nodepool/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# examples for node pool based on a empty cluster
locals {
first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id
first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id
second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id
second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id
sg_id = tencentcloud_security_group.sg.id
}

data "tencentcloud_vpc_subnets" "vpc_one" {
is_default = true
availability_zone = var.availability_zone_first
}

data "tencentcloud_vpc_subnets" "vpc_two" {
is_default = true
availability_zone = var.availability_zone_second
}

resource "tencentcloud_security_group" "sg" {
name = "tf-example-np-sg"
}

resource "tencentcloud_security_group_lite_rule" "sg_rule" {
security_group_id = tencentcloud_security_group.sg.id

ingress = [
"ACCEPT#10.0.0.0/16#ALL#ALL",
"ACCEPT#172.16.0.0/22#ALL#ALL",
"DROP#0.0.0.0/0#ALL#ALL",
]

egress = [
"ACCEPT#172.16.0.0/22#ALL#ALL",
]
}

resource "tencentcloud_kubernetes_cluster" "example" {
vpc_id = local.first_vpc_id
cluster_cidr = var.example_cluster_cidr
cluster_max_pod_num = 32
cluster_name = "tf_example_cluster_np"
cluster_desc = "example for tke cluster"
cluster_max_service_num = 32
cluster_version = "1.22.5"
cluster_deploy_type = "MANAGED_CLUSTER"
# without any worker config
}

resource "tencentcloud_kubernetes_node_pool" "example" {
name = "tf_example_node_pool"
cluster_id = tencentcloud_kubernetes_cluster.example.id
max_size = 6 # set the node scaling range [1,6]
min_size = 1
vpc_id = local.first_vpc_id
subnet_ids = [local.first_subnet_id]
retry_policy = "INCREMENTAL_INTERVALS"
desired_capacity = 4
enable_auto_scale = true
multi_zone_subnet_policy = "EQUALITY"

auto_scaling_config {
instance_type = var.default_instance_type
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = "50"
security_group_ids = [local.sg_id]

data_disk {
disk_type = "CLOUD_PREMIUM"
disk_size = 50
}

internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
internet_max_bandwidth_out = 10
public_ip_assigned = true
password = "test123#"
enhanced_security_service = false
enhanced_monitor_service = false
host_name = "12.123.0.0"
host_name_style = "ORIGINAL"
}

labels = {
"test1" = "test1",
"test2" = "test2",
}

taints {
key = "test_taint"
value = "taint_value"
effect = "PreferNoSchedule"
}

taints {
key = "test_taint2"
value = "taint_value2"
effect = "PreferNoSchedule"
}

node_config {
extra_args = [
"root-dir=/var/lib/kubelet"
]
}
}

# examples for node pool based on a empty cluster, and open the network through endpoint
resource "tencentcloud_kubernetes_cluster" "example_np_ep" {
vpc_id = local.first_vpc_id
cluster_cidr = var.example_cluster_cidr
cluster_max_pod_num = 32
cluster_name = "tf_example_cluster"
cluster_desc = "example for tke cluster"
cluster_max_service_num = 32
cluster_internet = false # (can be ignored) open it after the nodes added
cluster_version = "1.22.5"
cluster_deploy_type = "MANAGED_CLUSTER"
# without any worker config
}

resource "tencentcloud_kubernetes_node_pool" "example_np_ep" {
name = "tf_example_node_pool_ep"
cluster_id = tencentcloud_kubernetes_cluster.example_np_ep.id
max_size = 6 # set the node scaling range [1,6]
min_size = 1
vpc_id = local.second_vpc_id
subnet_ids = [local.second_subnet_id]
retry_policy = "INCREMENTAL_INTERVALS"
desired_capacity = 4
enable_auto_scale = true
multi_zone_subnet_policy = "EQUALITY"

auto_scaling_config {
instance_type = var.default_instance_type
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = "50"
security_group_ids = [local.sg_id]

data_disk {
disk_type = "CLOUD_PREMIUM"
disk_size = 50
}

internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
internet_max_bandwidth_out = 10
public_ip_assigned = true
password = "test123#"
enhanced_security_service = false
enhanced_monitor_service = false
host_name = "12.123.0.0"
host_name_style = "ORIGINAL"
}

labels = {
"test1" = "test1",
"test2" = "test2",
}

taints {
key = "test_taint"
value = "taint_value"
effect = "PreferNoSchedule"
}

taints {
key = "test_taint2"
value = "taint_value2"
effect = "PreferNoSchedule"
}

node_config {
extra_args = [
"root-dir=/var/lib/kubelet"
]
}
}

resource "tencentcloud_kubernetes_cluster_endpoint" "example_np_ep" {
cluster_id = tencentcloud_kubernetes_cluster.example_np_ep.id
cluster_internet = true # open the internet here
cluster_intranet = true
cluster_internet_security_group = local.sg_id
cluster_intranet_subnet_id = local.second_subnet_id
depends_on = [ # wait for the node pool ready
tencentcloud_kubernetes_node_pool.example_np_ep
]
}

15 changes: 15 additions & 0 deletions examples/tencentcloud-tke-nodepool/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "default_instance_type" {
default = "SA2.2XLARGE16"
}

variable "availability_zone_first" {
default = "ap-guangzhou-3"
}

variable "availability_zone_second" {
default = "ap-guangzhou-4"
}

variable "example_cluster_cidr" {
default = "10.31.0.0/16"
}
3 changes: 3 additions & 0 deletions examples/tencentcloud-tke-nodepool/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12"
}
4 changes: 2 additions & 2 deletions tencentcloud/resource_tc_kubernetes_addon_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_tcr" {
"global.imagePullSecretsCrs[0].namespaces=${local.ns_name}", #input the specified namespaces of the cluster, or input `*` for all.
"global.imagePullSecretsCrs[0].serviceAccounts=*", #input the specified service account of the cluster, or input `*` for all.
"global.imagePullSecretsCrs[0].type=docker", #only support docker now
"global.imagePullSecretsCrs[0].dockerUsername=${local.user_name}", #input the access username, or you can create it from data source `tencentcloud_tcr_tokens`
"global.imagePullSecretsCrs[0].dockerPassword=${local.token}", #input the access token, or you can create it from data source `tencentcloud_tcr_tokens`
"global.imagePullSecretsCrs[0].dockerUsername=${local.user_name}", #input the access username, or you can create it from `tencentcloud_tcr_token`
"global.imagePullSecretsCrs[0].dockerPassword=${local.token}", #input the access token, or you can create it from `tencentcloud_tcr_token`
"global.imagePullSecretsCrs[0].dockerServer=${local.tcr_name}-vpc.tencentcloudcr.com", #invalid format as: `${tcr_name}-vpc.tencentcloudcr.com`
"global.imagePullSecretsCrs[1].name=${local.tcr_id}-public", #specify a unique name, invalid format as: `${tcr_id}-public`
"global.imagePullSecretsCrs[1].namespaces=${local.ns_name}",
Expand Down
Loading