Skip to content

Commit 939547f

Browse files
authored
Feat/adjust tke example(through tke endpoint) (#2051)
* fix e2e issue * add example for tke node pool with endpoint * adjust desc of cluster_internet and cluster_intranet * update addon doc
1 parent c0bd18f commit 939547f

10 files changed

+745
-12
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# examples for node pool based on a empty cluster
2+
locals {
3+
first_vpc_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.vpc_id
4+
first_subnet_id = data.tencentcloud_vpc_subnets.vpc_one.instance_list.0.subnet_id
5+
second_vpc_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.vpc_id
6+
second_subnet_id = data.tencentcloud_vpc_subnets.vpc_two.instance_list.0.subnet_id
7+
sg_id = tencentcloud_security_group.sg.id
8+
}
9+
10+
data "tencentcloud_vpc_subnets" "vpc_one" {
11+
is_default = true
12+
availability_zone = var.availability_zone_first
13+
}
14+
15+
data "tencentcloud_vpc_subnets" "vpc_two" {
16+
is_default = true
17+
availability_zone = var.availability_zone_second
18+
}
19+
20+
resource "tencentcloud_security_group" "sg" {
21+
name = "tf-example-np-sg"
22+
}
23+
24+
resource "tencentcloud_security_group_lite_rule" "sg_rule" {
25+
security_group_id = tencentcloud_security_group.sg.id
26+
27+
ingress = [
28+
"ACCEPT#10.0.0.0/16#ALL#ALL",
29+
"ACCEPT#172.16.0.0/22#ALL#ALL",
30+
"DROP#0.0.0.0/0#ALL#ALL",
31+
]
32+
33+
egress = [
34+
"ACCEPT#172.16.0.0/22#ALL#ALL",
35+
]
36+
}
37+
38+
resource "tencentcloud_kubernetes_cluster" "example" {
39+
vpc_id = local.first_vpc_id
40+
cluster_cidr = var.example_cluster_cidr
41+
cluster_max_pod_num = 32
42+
cluster_name = "tf_example_cluster_np"
43+
cluster_desc = "example for tke cluster"
44+
cluster_max_service_num = 32
45+
cluster_version = "1.22.5"
46+
cluster_deploy_type = "MANAGED_CLUSTER"
47+
# without any worker config
48+
}
49+
50+
resource "tencentcloud_kubernetes_node_pool" "example" {
51+
name = "tf_example_node_pool"
52+
cluster_id = tencentcloud_kubernetes_cluster.example.id
53+
max_size = 6 # set the node scaling range [1,6]
54+
min_size = 1
55+
vpc_id = local.first_vpc_id
56+
subnet_ids = [local.first_subnet_id]
57+
retry_policy = "INCREMENTAL_INTERVALS"
58+
desired_capacity = 4
59+
enable_auto_scale = true
60+
multi_zone_subnet_policy = "EQUALITY"
61+
62+
auto_scaling_config {
63+
instance_type = var.default_instance_type
64+
system_disk_type = "CLOUD_PREMIUM"
65+
system_disk_size = "50"
66+
security_group_ids = [local.sg_id]
67+
68+
data_disk {
69+
disk_type = "CLOUD_PREMIUM"
70+
disk_size = 50
71+
}
72+
73+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
74+
internet_max_bandwidth_out = 10
75+
public_ip_assigned = true
76+
password = "test123#"
77+
enhanced_security_service = false
78+
enhanced_monitor_service = false
79+
host_name = "12.123.0.0"
80+
host_name_style = "ORIGINAL"
81+
}
82+
83+
labels = {
84+
"test1" = "test1",
85+
"test2" = "test2",
86+
}
87+
88+
taints {
89+
key = "test_taint"
90+
value = "taint_value"
91+
effect = "PreferNoSchedule"
92+
}
93+
94+
taints {
95+
key = "test_taint2"
96+
value = "taint_value2"
97+
effect = "PreferNoSchedule"
98+
}
99+
100+
node_config {
101+
extra_args = [
102+
"root-dir=/var/lib/kubelet"
103+
]
104+
}
105+
}
106+
107+
# examples for node pool based on a empty cluster, and open the network through endpoint
108+
resource "tencentcloud_kubernetes_cluster" "example_np_ep" {
109+
vpc_id = local.first_vpc_id
110+
cluster_cidr = var.example_cluster_cidr
111+
cluster_max_pod_num = 32
112+
cluster_name = "tf_example_cluster"
113+
cluster_desc = "example for tke cluster"
114+
cluster_max_service_num = 32
115+
cluster_internet = false # (can be ignored) open it after the nodes added
116+
cluster_version = "1.22.5"
117+
cluster_deploy_type = "MANAGED_CLUSTER"
118+
# without any worker config
119+
}
120+
121+
resource "tencentcloud_kubernetes_node_pool" "example_np_ep" {
122+
name = "tf_example_node_pool_ep"
123+
cluster_id = tencentcloud_kubernetes_cluster.example_np_ep.id
124+
max_size = 6 # set the node scaling range [1,6]
125+
min_size = 1
126+
vpc_id = local.second_vpc_id
127+
subnet_ids = [local.second_subnet_id]
128+
retry_policy = "INCREMENTAL_INTERVALS"
129+
desired_capacity = 4
130+
enable_auto_scale = true
131+
multi_zone_subnet_policy = "EQUALITY"
132+
133+
auto_scaling_config {
134+
instance_type = var.default_instance_type
135+
system_disk_type = "CLOUD_PREMIUM"
136+
system_disk_size = "50"
137+
security_group_ids = [local.sg_id]
138+
139+
data_disk {
140+
disk_type = "CLOUD_PREMIUM"
141+
disk_size = 50
142+
}
143+
144+
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
145+
internet_max_bandwidth_out = 10
146+
public_ip_assigned = true
147+
password = "test123#"
148+
enhanced_security_service = false
149+
enhanced_monitor_service = false
150+
host_name = "12.123.0.0"
151+
host_name_style = "ORIGINAL"
152+
}
153+
154+
labels = {
155+
"test1" = "test1",
156+
"test2" = "test2",
157+
}
158+
159+
taints {
160+
key = "test_taint"
161+
value = "taint_value"
162+
effect = "PreferNoSchedule"
163+
}
164+
165+
taints {
166+
key = "test_taint2"
167+
value = "taint_value2"
168+
effect = "PreferNoSchedule"
169+
}
170+
171+
node_config {
172+
extra_args = [
173+
"root-dir=/var/lib/kubelet"
174+
]
175+
}
176+
}
177+
178+
resource "tencentcloud_kubernetes_cluster_endpoint" "example_np_ep" {
179+
cluster_id = tencentcloud_kubernetes_cluster.example_np_ep.id
180+
cluster_internet = true # open the internet here
181+
cluster_intranet = true
182+
cluster_internet_security_group = local.sg_id
183+
cluster_intranet_subnet_id = local.second_subnet_id
184+
depends_on = [ # wait for the node pool ready
185+
tencentcloud_kubernetes_node_pool.example_np_ep
186+
]
187+
}
188+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
variable "default_instance_type" {
2+
default = "SA2.2XLARGE16"
3+
}
4+
5+
variable "availability_zone_first" {
6+
default = "ap-guangzhou-3"
7+
}
8+
9+
variable "availability_zone_second" {
10+
default = "ap-guangzhou-4"
11+
}
12+
13+
variable "example_cluster_cidr" {
14+
default = "10.31.0.0/16"
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}

tencentcloud/resource_tc_kubernetes_addon_attachment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ resource "tencentcloud_kubernetes_addon_attachment" "addon_tcr" {
3232
"global.imagePullSecretsCrs[0].namespaces=${local.ns_name}", #input the specified namespaces of the cluster, or input `*` for all.
3333
"global.imagePullSecretsCrs[0].serviceAccounts=*", #input the specified service account of the cluster, or input `*` for all.
3434
"global.imagePullSecretsCrs[0].type=docker", #only support docker now
35-
"global.imagePullSecretsCrs[0].dockerUsername=${local.user_name}", #input the access username, or you can create it from data source `tencentcloud_tcr_tokens`
36-
"global.imagePullSecretsCrs[0].dockerPassword=${local.token}", #input the access token, or you can create it from data source `tencentcloud_tcr_tokens`
35+
"global.imagePullSecretsCrs[0].dockerUsername=${local.user_name}", #input the access username, or you can create it from `tencentcloud_tcr_token`
36+
"global.imagePullSecretsCrs[0].dockerPassword=${local.token}", #input the access token, or you can create it from `tencentcloud_tcr_token`
3737
"global.imagePullSecretsCrs[0].dockerServer=${local.tcr_name}-vpc.tencentcloudcr.com", #invalid format as: `${tcr_name}-vpc.tencentcloudcr.com`
3838
"global.imagePullSecretsCrs[1].name=${local.tcr_id}-public", #specify a unique name, invalid format as: `${tcr_id}-public`
3939
"global.imagePullSecretsCrs[1].namespaces=${local.ns_name}",

0 commit comments

Comments
 (0)