Skip to content

Commit 9ac4bc5

Browse files
committed
create-ack-proprietary-cluster
1 parent 24da8b3 commit 9ac4bc5

File tree

3 files changed

+212
-0
lines changed

3 files changed

+212
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
## Providers
3+
4+
| Name | Version |
5+
|------|---------|
6+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
7+
8+
## Modules
9+
10+
No modules.
11+
12+
## Resources
13+
14+
| Name | Type |
15+
|------|------|
16+
| [alicloud_cs_kubernetes.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_kubernetes) | resource |
17+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
18+
| [alicloud_vswitch.terway_vswitches](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
19+
| [alicloud_vswitch.vswitches](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
20+
| [alicloud_enhanced_nat_available_zones.enhanced](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/enhanced_nat_available_zones) | data source |
21+
| [alicloud_instance_types.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/instance_types) | data source |
22+
| [alicloud_resource_manager_resource_groups.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/resource_manager_resource_groups) | data source |
23+
24+
## Inputs
25+
26+
| Name | Description | Type | Default | Required |
27+
|------|-------------|------|---------|:--------:|
28+
| <a name="input_cluster_addons"></a> [cluster\_addons](#input\_cluster\_addons) | 指定ACK集群安装的组件。声明每个组件的名称和对应配置。 | <pre>list(object({<br/> name = string<br/> config = string<br/> }))</pre> | <pre>[<br/> {<br/> "config": "",<br/> "name": "terway-eniip"<br/> },<br/> {<br/> "config": "",<br/> "name": "csi-plugin"<br/> },<br/> {<br/> "config": "",<br/> "name": "csi-provisioner"<br/> },<br/> {<br/> "config": "{\"IngressDashboardEnabled\":\"true\"}",<br/> "name": "logtail-ds"<br/> },<br/> {<br/> "config": "{\"IngressSlbNetworkType\":\"internet\"}",<br/> "name": "nginx-ingress-controller"<br/> },<br/> {<br/> "config": "",<br/> "name": "arms-prometheus"<br/> },<br/> {<br/> "config": "{\"sls_project_name\":\"\"}",<br/> "name": "ack-node-problem-detector"<br/> }<br/>]</pre> | no |
29+
| <a name="input_name"></a> [name](#input\_name) | 定义资源的名称或标签。 | `string` | `"tf-example"` | no |
30+
| <a name="input_region_id"></a> [region\_id](#input\_region\_id) | n/a | `string` | `"cn-hangzhou"` | no |
31+
| <a name="input_terway_vswitch_cidrs"></a> [terway\_vswitch\_cidrs](#input\_terway\_vswitch\_cidrs) | List of cidr blocks used to create several new vswitches when 'terway\_vswitch\_cidrs' is not specified. | `list(string)` | <pre>[<br/> "10.4.0.0/16",<br/> "10.5.0.0/16",<br/> "10.6.0.0/16"<br/>]</pre> | no |
32+
| <a name="input_terway_vswitch_ids"></a> [terway\_vswitch\_ids](#input\_terway\_vswitch\_ids) | List of existing vswitch ids for terway. | `list(string)` | `[]` | no |
33+
| <a name="input_vpc_cidr"></a> [vpc\_cidr](#input\_vpc\_cidr) | The cidr block used to launch a new vpc when 'vpc\_id' is not specified. | `string` | `"10.0.0.0/8"` | no |
34+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | Existing vpc id used to create several vswitches and other resources. | `string` | `""` | no |
35+
| <a name="input_vswitch_cidrs"></a> [vswitch\_cidrs](#input\_vswitch\_cidrs) | List of cidr blocks used to create several new vswitches when 'vswitch\_ids' is not specified. | `list(string)` | <pre>[<br/> "10.1.0.0/16",<br/> "10.2.0.0/16",<br/> "10.3.0.0/16"<br/>]</pre> | no |
36+
| <a name="input_vswitch_ids"></a> [vswitch\_ids](#input\_vswitch\_ids) | List of existing vswitch id. | `list(string)` | `[]` | no |
37+
<!-- END_TF_DOCS -->
38+
39+
## Documentation
40+
<!-- docs-link -->
41+
42+
The template is based on Aliyun document: [Create ACK proprietary cluster](http://help.aliyun.com/document_detail/2674339.htm)
43+
44+
<!-- docs-link -->
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
provider "alicloud" {
2+
region = var.region_id
3+
}
4+
5+
variable "region_id" {
6+
type = string
7+
default = "cn-hangzhou"
8+
}
9+
10+
# 定义资源的名称或标签。
11+
variable "name" {
12+
default = "tf-example"
13+
}
14+
15+
# 指定现有的vpc_id。如果为空,则表示创建一个新的VPC。
16+
variable "vpc_id" {
17+
description = "Existing vpc id used to create several vswitches and other resources."
18+
default = ""
19+
}
20+
21+
# 当没有指定vpc_id时,定义了新VPC的CIDR地址,即IP地址范围。
22+
variable "vpc_cidr" {
23+
description = "The cidr block used to launch a new vpc when 'vpc_id' is not specified."
24+
default = "10.0.0.0/8"
25+
}
26+
27+
# 指定现有的vSwitch(虚拟交换机)ID。
28+
variable "vswitch_ids" {
29+
description = "List of existing vswitch id."
30+
type = list(string)
31+
default = []
32+
}
33+
34+
35+
variable "vswitch_cidrs" { # 创建新的vSwitch,需要填写三个且不重叠的CIDR地址块。
36+
description = "List of cidr blocks used to create several new vswitches when 'vswitch_ids' is not specified."
37+
type = list(string)
38+
default = ["10.1.0.0/16", "10.2.0.0/16", "10.3.0.0/16"]
39+
}
40+
41+
# 指定网络组件Terway配置。
42+
variable "terway_vswitch_ids" {
43+
description = "List of existing vswitch ids for terway."
44+
type = list(string)
45+
default = []
46+
}
47+
48+
# 当没有指定terway_vswitch_ids时,用于创建Terway使用的vSwitch的CIDR地址块。
49+
variable "terway_vswitch_cidrs" {
50+
description = "List of cidr blocks used to create several new vswitches when 'terway_vswitch_cidrs' is not specified."
51+
type = list(string)
52+
default = ["10.4.0.0/16", "10.5.0.0/16", "10.6.0.0/16"]
53+
}
54+
55+
# 指定ACK集群安装的组件。声明每个组件的名称和对应配置。
56+
variable "cluster_addons" {
57+
type = list(object({
58+
name = string
59+
config = string
60+
}))
61+
62+
default = [
63+
{
64+
"name" = "terway-eniip",
65+
"config" = "",
66+
},
67+
{
68+
"name" = "csi-plugin",
69+
"config" = "",
70+
},
71+
{
72+
"name" = "csi-provisioner",
73+
"config" = "",
74+
},
75+
{
76+
"name" = "logtail-ds",
77+
"config" = "{\"IngressDashboardEnabled\":\"true\"}",
78+
},
79+
{
80+
"name" = "nginx-ingress-controller",
81+
"config" = "{\"IngressSlbNetworkType\":\"internet\"}",
82+
},
83+
{
84+
"name" = "arms-prometheus",
85+
"config" = "",
86+
},
87+
{
88+
"name" = "ack-node-problem-detector",
89+
"config" = "{\"sls_project_name\":\"\"}",
90+
}
91+
]
92+
}
93+
94+
# 查询用于获取支持增强型网关NAT的区域。
95+
data "alicloud_enhanced_nat_available_zones" "enhanced" {
96+
}
97+
98+
# 当没有提供vpc_id变量时,这个资源将创建一个新的专有网络,其CIDR块由vpc_cidr变量指定。
99+
resource "alicloud_vpc" "vpc" {
100+
count = var.vpc_id == "" ? 1 : 0
101+
cidr_block = var.vpc_cidr
102+
}
103+
104+
# 当没有提供vswitch_ids变量时,默认会根据填写的vswitch_cidrs创建新的vSwitch。
105+
resource "alicloud_vswitch" "vswitches" {
106+
count = length(var.vswitch_ids) > 0 ? 0 : length(var.vswitch_cidrs)
107+
vpc_id = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id
108+
cidr_block = element(var.vswitch_cidrs, count.index)
109+
zone_id = data.alicloud_enhanced_nat_available_zones.enhanced.zones[count.index].zone_id
110+
}
111+
112+
# 当没有提供terway_vswitch_ids变量时,默认会根据填写的vswitch_cidrs创建Terway使用的vSwitch。
113+
resource "alicloud_vswitch" "terway_vswitches" {
114+
count = length(var.terway_vswitch_ids) > 0 ? 0 : length(var.terway_vswitch_cidrs)
115+
vpc_id = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id
116+
cidr_block = element(var.terway_vswitch_cidrs, count.index)
117+
zone_id = data.alicloud_enhanced_nat_available_zones.enhanced.zones[count.index].zone_id
118+
}
119+
120+
# 查询当前阿里云用户的资源组。
121+
data "alicloud_resource_manager_resource_groups" "default" {
122+
status = "OK"
123+
}
124+
125+
# 查询阿里云的ECS实例类型。
126+
data "alicloud_instance_types" "default" {
127+
count = 3
128+
availability_zone = data.alicloud_enhanced_nat_available_zones.enhanced.zones[0].zone_id
129+
cpu_core_count = 4
130+
memory_size = 8
131+
kubernetes_node_role = "Master"
132+
system_disk_category = "cloud_essd"
133+
}
134+
135+
# 创建ACK专有集群,配置包括控制面虚拟交换机、Pod虚拟交换机、实例类型、磁盘、密码、Service网络地址段等。
136+
resource "alicloud_cs_kubernetes" "default" {
137+
master_vswitch_ids = length(var.vswitch_ids) > 0 ? split(",", join(",", var.vswitch_ids)) : length(var.vswitch_cidrs) < 1 ? [] : split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 查询支持增强型NAT的可用区列表。
138+
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)) # 使用Terway时pod网络的vswitch地址段。
139+
master_instance_types = [data.alicloud_instance_types.default.0.instance_types.0.id, data.alicloud_instance_types.default.1.instance_types.0.id, data.alicloud_instance_types.default.2.instance_types.0.id] # 控制面节点的实例类型。
140+
master_disk_category = "cloud_ssd" # 控制面节点系统盘类型。
141+
password = "Yourpassword1234" # SSH登录密码。
142+
service_cidr = "172.18.0.0/16" # Service网络地址段。
143+
load_balancer_spec = "slb.s1.small" # 负载均衡规格。
144+
install_cloud_monitor = "true" # 安装云监控服务。
145+
resource_group_id = data.alicloud_resource_manager_resource_groups.default.groups.0.id # 集群所属资源组ID,实现不同资源的隔离。
146+
deletion_protection = "false" # 集群删除保护,防止通过控制台或API误删除集群。
147+
timezone = "Asia/Shanghai" # 集群使用的时区。
148+
os_type = "Linux" # 操作系统平台类型。
149+
platform = "AliyunLinux3" # 操作系统发行版。
150+
cluster_domain = "cluster.local" # 集群本地域名。
151+
proxy_mode = "ipvs" # kube-proxy代理模式。
152+
custom_san = "www.terraform.io" # 自定义证书SAN。
153+
new_nat_gateway = "true" # 创建一个新的NAT网关。
154+
dynamic "addons" {
155+
for_each = var.cluster_addons
156+
content {
157+
name = lookup(addons.value, "name", var.cluster_addons)
158+
config = lookup(addons.value, "config", var.cluster_addons)
159+
}
160+
}
161+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_providers {
3+
alicloud = {
4+
source = "aliyun/alicloud"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)