Skip to content

Commit 3c9f5ed

Browse files
lsylsy1968
authored andcommitted
create-ram-user-with-policy
ack doc link fix doc link fix
1 parent cb41495 commit 3c9f5ed

File tree

9 files changed

+535
-0
lines changed

9 files changed

+535
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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_node_pool.autoscale_node_pool](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_kubernetes_node_pool) | resource |
17+
| [alicloud_cs_kubernetes_node_pool.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_kubernetes_node_pool) | resource |
18+
| [alicloud_cs_kubernetes_node_pool.managed_node_pool](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_kubernetes_node_pool) | resource |
19+
| [alicloud_cs_managed_kubernetes.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_managed_kubernetes) | resource |
20+
| [alicloud_vpc.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
21+
| [alicloud_vswitch.terway_vswitches](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
22+
| [alicloud_vswitch.vswitches](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
23+
| [alicloud_instance_types.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/instance_types) | data source |
24+
25+
## Inputs
26+
27+
| Name | Description | Type | Default | Required |
28+
|------|-------------|------|---------|:--------:|
29+
| <a name="input_availability_zone"></a> [availability\_zone](#input\_availability\_zone) | The availability zones of vswitches. | `list` | <pre>[<br/> "cn-shenzhen-c",<br/> "cn-shenzhen-e",<br/> "cn-shenzhen-f"<br/>]</pre> | no |
30+
| <a name="input_cluster_addons"></a> [cluster\_addons](#input\_cluster\_addons) | n/a | <pre>list(object({<br/> name = string<br/> config = string<br/> }))</pre> | <pre>[<br/> {<br/> "config": "",<br/> "name": "terway-eniip"<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/> {<br/> "config": "",<br/> "name": "csi-plugin"<br/> },<br/> {<br/> "config": "",<br/> "name": "csi-provisioner"<br/> }<br/>]</pre> | no |
31+
| <a name="input_k8s_name_prefix"></a> [k8s\_name\_prefix](#input\_k8s\_name\_prefix) | The name prefix used to create managed kubernetes cluster. | `string` | `"tf-ack-shenzhen"` | no |
32+
| <a name="input_node_vswitch_cidrs"></a> [node\_vswitch\_cidrs](#input\_node\_vswitch\_cidrs) | List of cidr blocks used to create several new vswitches when 'node\_vswitch\_ids' is not specified. | `list(string)` | <pre>[<br/> "172.16.0.0/23",<br/> "172.16.2.0/23",<br/> "172.16.4.0/23"<br/>]</pre> | no |
33+
| <a name="input_node_vswitch_ids"></a> [node\_vswitch\_ids](#input\_node\_vswitch\_ids) | List of existing node vswitch ids for terway. | `list(string)` | `[]` | no |
34+
| <a name="input_password"></a> [password](#input\_password) | The password of ECS instance. | `string` | `"Test123456"` | no |
35+
| <a name="input_region_id"></a> [region\_id](#input\_region\_id) | n/a | `string` | `"cn-shenzhen"` | no |
36+
| <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\_ids' is not specified. | `list(string)` | <pre>[<br/> "172.16.208.0/20",<br/> "172.16.224.0/20",<br/> "172.16.240.0/20"<br/>]</pre> | no |
37+
| <a name="input_terway_vswitch_ids"></a> [terway\_vswitch\_ids](#input\_terway\_vswitch\_ids) | List of existing pod vswitch ids for terway. | `list(string)` | `[]` | no |
38+
| <a name="input_worker_instance_types"></a> [worker\_instance\_types](#input\_worker\_instance\_types) | The ecs instance types used to launch worker nodes. | `list` | <pre>[<br/> "ecs.g6.2xlarge",<br/> "ecs.g6.xlarge"<br/>]</pre> | no |
39+
<!-- END_TF_DOCS -->
40+
## Documentation
41+
<!-- docs-link -->
42+
43+
The template is based on Aliyun document: [Create ACK managed cluster](http://help.aliyun.com/document_detail/197780.htm)
44+
45+
<!-- docs-link -->
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
provider "alicloud" {
2+
region = var.region_id
3+
}
4+
5+
variable "region_id" {
6+
type = string
7+
default = "cn-shenzhen"
8+
}
9+
10+
# 指定虚拟交换机(vSwitches)的可用区。
11+
variable "availability_zone" {
12+
description = "The availability zones of vswitches."
13+
default = ["cn-shenzhen-c", "cn-shenzhen-e", "cn-shenzhen-f"]
14+
}
15+
16+
# 指定交换机ID(vSwitch IDs)的列表。
17+
variable "node_vswitch_ids" {
18+
description = "List of existing node vswitch ids for terway."
19+
type = list(string)
20+
default = []
21+
}
22+
23+
# 当没有提供node_vswitch_ids时,这个变量定义了用于创建新vSwitches的CIDR地址块列表。
24+
variable "node_vswitch_cidrs" {
25+
description = "List of cidr blocks used to create several new vswitches when 'node_vswitch_ids' is not specified."
26+
type = list(string)
27+
default = ["172.16.0.0/23", "172.16.2.0/23", "172.16.4.0/23"]
28+
}
29+
30+
# 指定网络组件Terway配置。如果为空,默认会根据terway_vswitch_cidrs的创建新的terway vSwitch。
31+
variable "terway_vswitch_ids" {
32+
description = "List of existing pod vswitch ids for terway."
33+
type = list(string)
34+
default = []
35+
}
36+
37+
# 当没有指定terway_vswitch_ids时,用于创建Terway使用的vSwitch的CIDR地址块。
38+
variable "terway_vswitch_cidrs" {
39+
description = "List of cidr blocks used to create several new vswitches when 'terway_vswitch_ids' is not specified."
40+
type = list(string)
41+
default = ["172.16.208.0/20", "172.16.224.0/20", "172.16.240.0/20"]
42+
}
43+
44+
# 定义了用于启动工作节点的ECS实例类型。
45+
variable "worker_instance_types" {
46+
description = "The ecs instance types used to launch worker nodes."
47+
default = ["ecs.g6.2xlarge", "ecs.g6.xlarge"]
48+
}
49+
50+
# 设置工作阶段的密码
51+
variable "password" {
52+
description = "The password of ECS instance."
53+
default = "Test123456"
54+
}
55+
56+
# 指定ACK集群安装的组件。包括Terway(网络组件)、csi-plugin(存储组件)、csi-provisioner(存储组件)、logtail-ds(日志组件)、Nginx Ingress Controller、ack-arms-prometheus(监控组件)以及ack-node-problem-detector(节点诊断组件)。
57+
variable "cluster_addons" {
58+
type = list(object({
59+
name = string
60+
config = string
61+
}))
62+
63+
default = [
64+
{
65+
"name" = "terway-eniip",
66+
"config" = "",
67+
},
68+
{
69+
"name" = "logtail-ds",
70+
"config" = "{\"IngressDashboardEnabled\":\"true\"}",
71+
},
72+
{
73+
"name" = "nginx-ingress-controller",
74+
"config" = "{\"IngressSlbNetworkType\":\"internet\"}",
75+
},
76+
{
77+
"name" = "arms-prometheus",
78+
"config" = "",
79+
},
80+
{
81+
"name" = "ack-node-problem-detector",
82+
"config" = "{\"sls_project_name\":\"\"}",
83+
},
84+
{
85+
"name" = "csi-plugin",
86+
"config" = "",
87+
},
88+
{
89+
"name" = "csi-provisioner",
90+
"config" = "",
91+
}
92+
]
93+
}
94+
95+
# 指定创建ACK托管集群名称的前缀。
96+
variable "k8s_name_prefix" {
97+
description = "The name prefix used to create managed kubernetes cluster."
98+
default = "tf-ack-shenzhen"
99+
}
100+
101+
# 默认资源名称。
102+
locals {
103+
k8s_name_terway = substr(join("-", [var.k8s_name_prefix, "terway"]), 0, 63)
104+
k8s_name_flannel = substr(join("-", [var.k8s_name_prefix, "flannel"]), 0, 63)
105+
k8s_name_ask = substr(join("-", [var.k8s_name_prefix, "ask"]), 0, 63)
106+
new_vpc_name = "tf-vpc-172-16"
107+
new_vsw_name_azD = "tf-vswitch-azD-172-16-0"
108+
new_vsw_name_azE = "tf-vswitch-azE-172-16-2"
109+
new_vsw_name_azF = "tf-vswitch-azF-172-16-4"
110+
nodepool_name = "default-nodepool"
111+
managed_nodepool_name = "managed-node-pool"
112+
autoscale_nodepool_name = "autoscale-node-pool"
113+
log_project_name = "log-for-${local.k8s_name_terway}"
114+
}
115+
116+
# 节点ECS实例配置。将查询满足CPU、Memory要求的ECS实例类型。
117+
data "alicloud_instance_types" "default" {
118+
cpu_core_count = 8
119+
memory_size = 32
120+
availability_zone = var.availability_zone[0]
121+
kubernetes_node_role = "Worker"
122+
}
123+
124+
# 专有网络。
125+
resource "alicloud_vpc" "default" {
126+
vpc_name = local.new_vpc_name
127+
cidr_block = "172.16.0.0/12"
128+
}
129+
130+
# Node交换机。
131+
resource "alicloud_vswitch" "vswitches" {
132+
count = length(var.node_vswitch_ids) > 0 ? 0 : length(var.node_vswitch_cidrs)
133+
vpc_id = alicloud_vpc.default.id
134+
cidr_block = element(var.node_vswitch_cidrs, count.index)
135+
zone_id = element(var.availability_zone, count.index)
136+
}
137+
138+
# Pod交换机。
139+
resource "alicloud_vswitch" "terway_vswitches" {
140+
count = length(var.terway_vswitch_ids) > 0 ? 0 : length(var.terway_vswitch_cidrs)
141+
vpc_id = alicloud_vpc.default.id
142+
cidr_block = element(var.terway_vswitch_cidrs, count.index)
143+
zone_id = element(var.availability_zone, count.index)
144+
}
145+
146+
# Kubernetes托管版。
147+
resource "alicloud_cs_managed_kubernetes" "default" {
148+
name = local.k8s_name_terway # Kubernetes集群名称。
149+
cluster_spec = "ack.pro.small" # 创建Pro版集群。
150+
version = "1.28.9-aliyun.1"
151+
worker_vswitch_ids = split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 节点池所在的vSwitch。指定一个或多个vSwitch的ID,必须在availability_zone指定的区域中。
152+
pod_vswitch_ids = split(",", join(",", alicloud_vswitch.terway_vswitches.*.id)) # Pod虚拟交换机。
153+
new_nat_gateway = true # 是否在创建Kubernetes集群时创建新的NAT网关。默认为true。
154+
service_cidr = "10.11.0.0/16" # Pod网络的CIDR块。当cluster_network_type设置为flannel,你必须设定该参数。它不能与VPC CIDR相同,并且不能与VPC中的Kubernetes集群使用的CIDR相同,也不能在创建后进行修改。集群中允许的最大主机数量:256。
155+
slb_internet_enabled = true # 是否为API Server创建Internet负载均衡。默认为false。
156+
enable_rrsa = true
157+
control_plane_log_components = ["apiserver", "kcm", "scheduler", "ccm"] # 控制平面日志。
158+
159+
dynamic "addons" { # 组件管理。
160+
for_each = var.cluster_addons
161+
content {
162+
name = lookup(addons.value, "name", var.cluster_addons)
163+
config = lookup(addons.value, "config", var.cluster_addons)
164+
}
165+
}
166+
}
167+
168+
# 普通节点池。
169+
resource "alicloud_cs_kubernetes_node_pool" "default" {
170+
cluster_id = alicloud_cs_managed_kubernetes.default.id # Kubernetes集群名称。
171+
node_pool_name = local.nodepool_name # 节点池名称。
172+
vswitch_ids = split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 节点池所在的vSwitch。指定一个或多个vSwitch的ID,必须在availability_zone指定的区域中。
173+
instance_types = var.worker_instance_types
174+
instance_charge_type = "PostPaid"
175+
runtime_name = "containerd"
176+
runtime_version = "1.6.20"
177+
desired_size = 2 # 节点池的期望节点数。
178+
password = var.password # SSH登录集群节点的密码。
179+
install_cloud_monitor = true # 是否为Kubernetes的节点安装云监控。
180+
system_disk_category = "cloud_efficiency"
181+
system_disk_size = 100
182+
image_type = "AliyunLinux"
183+
184+
data_disks { # 节点数据盘配置。
185+
category = "cloud_essd" # 节点数据盘种类。
186+
size = 120 # 节点数据盘大小。
187+
}
188+
}
189+
190+
# 创建托管节点池。
191+
resource "alicloud_cs_kubernetes_node_pool" "managed_node_pool" {
192+
cluster_id = alicloud_cs_managed_kubernetes.default.id # Kubernetes集群名称。
193+
node_pool_name = local.managed_nodepool_name # 节点池名称。
194+
vswitch_ids = split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 节点池所在的vSwitch。指定一个或多个vSwitch的ID,必须在availability_zone指定的区域中。
195+
desired_size = 0 # 节点池的期望节点数。
196+
197+
management {
198+
auto_repair = true
199+
auto_upgrade = true
200+
max_unavailable = 1
201+
}
202+
203+
instance_types = var.worker_instance_types
204+
instance_charge_type = "PostPaid"
205+
runtime_name = "containerd"
206+
runtime_version = "1.6.20"
207+
password = var.password
208+
install_cloud_monitor = true
209+
system_disk_category = "cloud_efficiency"
210+
system_disk_size = 100
211+
image_type = "AliyunLinux"
212+
213+
data_disks {
214+
category = "cloud_essd"
215+
size = 120
216+
}
217+
}
218+
219+
# 创建自动伸缩节点池,节点池最多可以扩展到 10 个节点,最少保持 1 个节点。
220+
resource "alicloud_cs_kubernetes_node_pool" "autoscale_node_pool" {
221+
cluster_id = alicloud_cs_managed_kubernetes.default.id
222+
node_pool_name = local.autoscale_nodepool_name
223+
vswitch_ids = split(",", join(",", alicloud_vswitch.vswitches.*.id))
224+
225+
scaling_config {
226+
min_size = 1
227+
max_size = 10
228+
}
229+
230+
instance_types = var.worker_instance_types
231+
runtime_name = "containerd"
232+
runtime_version = "1.6.20"
233+
password = var.password # SSH登录集群节点的密码。
234+
install_cloud_monitor = true # 是否为kubernetes的节点安装云监控。
235+
system_disk_category = "cloud_efficiency"
236+
system_disk_size = 100
237+
image_type = "AliyunLinux3"
238+
239+
data_disks { # 节点数据盘配置。
240+
category = "cloud_essd" # 节点数据盘种类。
241+
size = 120 # 节点数据盘大小。
242+
}
243+
}
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)