Skip to content

Commit a728d3f

Browse files
susu9527xiaozhu36
authored andcommitted
Improves the module example
1 parent 24f3458 commit a728d3f

File tree

10 files changed

+135
-176
lines changed

10 files changed

+135
-176
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
## 1.6.0 (Unreleased)
1+
## 1.7.0 (Unreleased)
2+
## 1.6.0 (July 25, 2023)
3+
4+
IMPROVEMENTS:
5+
6+
- Improves the module example [GH-18](https://github.com/terraform-alicloud-modules/terraform-alicloud-managed-kubernetes/pull/18)
7+
28
## 1.5.0 (November 15, 2021)
39

410
IMPROVEMENTS:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module "managed-k8s" {
2828
source = "terraform-alicloud-modules/managed-kubernetes/alicloud"
2929
3030
k8s_name_prefix = "my-managed-k8s-with-new-vpc"
31+
cluster_spec = "ack.pro.small"
3132
new_vpc = true
3233
vpc_cidr = "192.168.0.0/16"
3334
vswitch_cidrs = [
@@ -47,6 +48,7 @@ module "managed-k8s" {
4748
source = "terraform-alicloud-modules/managed-kubernetes/alicloud"
4849
4950
k8s_name_prefix = "my-managed-k8s-with-new-vpc"
51+
cluster_spec = "ack.pro.small"
5052
new_vpc = false
5153
vswitch_ids = [
5254
"vsw-12345678",

examples/basic/main.tf

Lines changed: 0 additions & 65 deletions
This file was deleted.
File renamed without changes.

examples/complete/main.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
data "alicloud_zones" "default" {
2+
available_resource_creation = "VSwitch"
3+
}
4+
5+
resource "alicloud_vpc" "default" {
6+
vpc_name = "tf-example"
7+
cidr_block = "10.4.0.0/16"
8+
}
9+
10+
resource "alicloud_vswitch" "default" {
11+
vswitch_name = "tf-example"
12+
cidr_block = "10.4.0.0/24"
13+
vpc_id = alicloud_vpc.default.id
14+
zone_id = data.alicloud_zones.default.zones.0.id
15+
}
16+
17+
module "managed-k8s" {
18+
source = "../../"
19+
k8s_name_prefix = "tf-example"
20+
cluster_spec = "ack.pro.small"
21+
vswitch_ids = [alicloud_vswitch.default.id]
22+
k8s_pod_cidr = cidrsubnet("10.0.0.0/8", 8, 36)
23+
k8s_service_cidr = cidrsubnet("172.16.0.0/16", 4, 7)
24+
kubernetes_version = "1.24.6-aliyun.1"
25+
cluster_addons = [
26+
{
27+
name = "flannel",
28+
config = "",
29+
},
30+
{
31+
name = "flexvolume",
32+
config = "",
33+
},
34+
{
35+
name = "alicloud-disk-controller",
36+
config = "",
37+
},
38+
{
39+
name = "logtail-ds",
40+
config = "{\"IngressDashboardEnabled\":\"true\"}",
41+
},
42+
{
43+
name = "nginx-ingress-controller",
44+
config = "{\"IngressSlbNetworkType\":\"internet\"}",
45+
},
46+
]
47+
}

examples/basic/outputs.tf renamed to examples/complete/outputs.tf

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@ output "this_k8s_id" {
77
description = "ID of the kunernetes cluster."
88
value = module.managed-k8s.this_k8s_id
99
}
10-
output "this_k8s_nodes" {
11-
description = "List nodes of cluster."
12-
value = module.managed-k8s.this_k8s_nodes
13-
}
14-
output "this_k8s_node_ids" {
15-
description = "List ids of of cluster node."
16-
value = module.managed-k8s.this_k8s_node_ids
17-
}
18-
// Output VPC
19-
output "this_vpc_id" {
20-
description = "The ID of the VPC."
21-
value = module.managed-k8s.this_vpc_id
10+
11+
output "this_k8s_node_pool_id" {
12+
description = "ID of the kunernetes node pool."
13+
value = module.managed-k8s.this_k8s_node_pool_id
2214
}
2315

2416
output "this_vswitch_ids" {
@@ -29,3 +21,4 @@ output "this_security_group_id" {
2921
description = "ID of the Security Group used to deploy kubernetes cluster."
3022
value = module.managed-k8s.this_security_group_id
3123
}
24+

main.tf

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
resource "alicloud_cs_managed_kubernetes" "this" {
2-
count = length(local.vswitch_ids) > 0 ? 1 : 0
3-
name = local.k8s_name
4-
worker_vswitch_ids = local.vswitch_ids
5-
new_nat_gateway = var.new_vpc == true ? false : var.new_nat_gateway
6-
worker_disk_category = var.worker_disk_category
7-
password = var.ecs_password
8-
pod_cidr = var.k8s_pod_cidr
9-
service_cidr = var.k8s_service_cidr
10-
slb_internet_enabled = true
11-
install_cloud_monitor = true
12-
version = var.kubernetes_version
13-
worker_instance_types = var.worker_instance_types
14-
worker_number = var.worker_number
2+
count = length(local.vswitch_ids) > 0 ? 1 : 0
3+
name = local.k8s_name
4+
cluster_spec = var.cluster_spec
5+
worker_vswitch_ids = local.vswitch_ids
6+
new_nat_gateway = var.new_vpc == true ? false : var.new_nat_gateway
7+
pod_cidr = var.k8s_pod_cidr
8+
service_cidr = var.k8s_service_cidr
9+
slb_internet_enabled = true
10+
version = var.kubernetes_version
1511
dynamic "addons" {
1612
for_each = var.cluster_addons
1713
content {
1814
name = lookup(addons.value, "name", var.cluster_addons)
1915
config = lookup(addons.value, "config", var.cluster_addons)
2016
}
2117
}
22-
kube_config = var.kube_config_path
2318
client_cert = var.client_cert_path
2419
client_key = var.client_key_path
2520
cluster_ca_cert = var.cluster_ca_cert_path
21+
}
2622

27-
depends_on = [alicloud_snat_entry.new]
23+
resource "alicloud_cs_kubernetes_node_pool" "this" {
24+
count = length(local.vswitch_ids) > 0 ? 1 : 0
25+
name = local.k8s_name
26+
cluster_id = alicloud_cs_managed_kubernetes.this.0.id
27+
vswitch_ids = local.vswitch_ids
28+
instance_types = var.worker_instance_types
29+
system_disk_category = var.worker_disk_category
30+
system_disk_size = var.worker_disk_size
31+
desired_size = var.worker_number
2832
}

outputs.tf

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,12 @@ output "this_k8s_id" {
77
description = "ID of the kunernetes cluster."
88
value = concat(alicloud_cs_managed_kubernetes.this.*.id, [""])[0]
99
}
10-
output "this_k8s_nodes" {
11-
description = "List nodes of cluster."
12-
value = concat(alicloud_cs_managed_kubernetes.this.*.worker_nodes, [""])[0]
13-
}
14-
output "this_k8s_node_ids" {
15-
description = "List ids of of cluster node."
16-
value = [for _, obj in concat(alicloud_cs_managed_kubernetes.this.*.worker_nodes, [{}])[0] : lookup(obj,"id")]
10+
11+
output "this_k8s_node_pool_id" {
12+
description = "ID of the kunernetes node pool."
13+
value = concat(alicloud_cs_kubernetes_node_pool.this.*.id, [""])[0]
1714
}
1815
// Output VPC
19-
output "this_vpc_id" {
20-
description = "The ID of the VPC."
21-
value = concat(alicloud_cs_managed_kubernetes.this.*.vpc_id, [""])[0]
22-
}
23-
2416
output "this_vswitch_ids" {
2517
description = "List ID of the VSwitches."
2618
value = local.vswitch_ids

variables.tf

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ variable "new_nat_gateway" {
6464
type = bool
6565
default = false
6666
}
67-
# Cluster nodes variables
67+
# Cluster variables
68+
variable "cluster_spec" {
69+
description = "The cluster specifications of kubernetes cluster. Valid values: ack.standard | ack.pro.small "
70+
type = string
71+
default = ""
72+
}
73+
6874
variable "cpu_core_count" {
6975
description = "CPU core count is used to fetch instance types."
7076
type = number
@@ -83,12 +89,6 @@ variable "kubernetes_version" {
8389
default = ""
8490
}
8591

86-
variable "worker_instance_types" {
87-
description = "The ecs instance type used to launch worker nodes. If not set, data source `alicloud_instance_types` will return one based on `cpu_core_count` and `memory_size`."
88-
type = list(string)
89-
default = ["ecs.n4.xlarge"]
90-
}
91-
9292
variable "cluster_addons" {
9393
description = "Addon components in kubernetes cluster"
9494
type = list(object({
@@ -98,30 +98,6 @@ variable "cluster_addons" {
9898
default = []
9999
}
100100

101-
variable "worker_disk_category" {
102-
description = "The system disk category used to launch one or more worker nodes."
103-
type = string
104-
default = "cloud_efficiency"
105-
}
106-
107-
variable "worker_disk_size" {
108-
description = "The system disk size used to launch one or more worker nodes."
109-
type = number
110-
default = 40
111-
}
112-
113-
variable "ecs_password" {
114-
description = "The password of worker nodes."
115-
type = string
116-
default = "Abc12345"
117-
}
118-
119-
variable "worker_number" {
120-
description = "The number of kubernetes cluster work nodes."
121-
type = number
122-
default = 2
123-
}
124-
125101
variable "k8s_name_prefix" {
126102
description = "The name prefix used to create managed kubernetes cluster."
127103
type = string
@@ -140,28 +116,6 @@ variable "k8s_service_cidr" {
140116
default = "172.21.0.0/20"
141117
}
142118

143-
variable "cluster_network_type" {
144-
description = "(Deprecated from v1.3.0, use 'cluster_addons' instead)Network type, valid options are `flannel` and `terway`."
145-
type = string
146-
default = "flannel"
147-
}
148-
149-
variable "new_sls_project" {
150-
description = "(Deprecated from v1.3.0, use 'cluster_addons' instead)Create a new sls project for this module."
151-
type = bool
152-
default = false
153-
}
154-
variable "sls_project_name" {
155-
description = "(Deprecated from v1.3.0, use 'cluster_addons' instead)Specify a existing sls project for this module."
156-
type = string
157-
default = ""
158-
}
159-
160-
variable "kube_config_path" {
161-
description = "The path of kube config, like ~/.kube/config"
162-
type = string
163-
default = ""
164-
}
165119
variable "client_cert_path" {
166120
description = "The path of client certificate, like ~/.kube/client-cert.pem"
167121
type = string
@@ -176,4 +130,29 @@ variable "cluster_ca_cert_path" {
176130
description = "The path of cluster ca certificate, like ~/.kube/cluster-ca-cert.pem"
177131
type = string
178132
default = ""
133+
}
134+
135+
# Cluster nodes variables
136+
variable "worker_instance_types" {
137+
description = "The ecs instance type used to launch worker nodes. If not set, data source `alicloud_instance_types` will return one based on `cpu_core_count` and `memory_size`."
138+
type = list(string)
139+
default = ["ecs.c7.xlarge"]
140+
}
141+
142+
variable "worker_disk_category" {
143+
description = "The system disk category used to launch one or more worker nodes."
144+
type = string
145+
default = "cloud_efficiency"
146+
}
147+
148+
variable "worker_disk_size" {
149+
description = "The system disk size used to launch one or more worker nodes."
150+
type = number
151+
default = 40
152+
}
153+
154+
variable "worker_number" {
155+
description = "The number of kubernetes cluster work nodes."
156+
type = number
157+
default = 2
179158
}

0 commit comments

Comments
 (0)