Skip to content

Commit ed6d1a4

Browse files
committed
Create ASK cluster
1 parent 64d696f commit ed6d1a4

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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_serverless_kubernetes.serverless](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_serverless_kubernetes) | resource |
17+
| [alicloud_security_group.group](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group) | resource |
18+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
19+
| [alicloud_vswitch.vsw](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
20+
| [alicloud_eci_zones.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/eci_zones) | data source |
21+
22+
## Inputs
23+
24+
| Name | Description | Type | Default | Required |
25+
|------|-------------|------|---------|:--------:|
26+
| <a name="input_ack_version"></a> [ack\_version](#input\_ack\_version) | Desired Kubernetes version. | `string` | `"1.31.1-aliyun.1"` | no |
27+
| <a name="input_cluster_spec"></a> [cluster\_spec](#input\_cluster\_spec) | The cluster specifications of kubernetes cluster,which can be empty. Valid values:ack.standard : Standard managed clusters; ack.pro.small : Professional managed clusters. | `string` | `"ack.pro.small"` | no |
28+
| <a name="input_k8s_name_prefix"></a> [k8s\_name\_prefix](#input\_k8s\_name\_prefix) | The name prefix used to create ASK cluster. | `string` | `"ask-example"` | no |
29+
| <a name="input_region_id"></a> [region\_id](#input\_region\_id) | n/a | `string` | `"cn-shenzhen"` | no |
30+
<!-- END_TF_DOCS -->
31+
## Documentation
32+
<!-- docs-link -->
33+
34+
The template is based on Aliyun document: [Create ASK cluster](http://help.aliyun.com/document_detail/2391966.htm)
35+
36+
<!-- docs-link -->
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
provider "alicloud" {
2+
region = var.region_id
3+
}
4+
5+
variable "region_id" {
6+
type = string
7+
default = "cn-shenzhen"
8+
}
9+
10+
variable "cluster_spec" {
11+
type = string
12+
description = "The cluster specifications of kubernetes cluster,which can be empty. Valid values:ack.standard : Standard managed clusters; ack.pro.small : Professional managed clusters."
13+
default = "ack.pro.small"
14+
}
15+
16+
variable "k8s_name_prefix" {
17+
description = "The name prefix used to create ASK cluster."
18+
default = "ask-example"
19+
}
20+
21+
variable "ack_version" {
22+
type = string
23+
description = "Desired Kubernetes version. "
24+
default = "1.31.1-aliyun.1"
25+
}
26+
27+
# 默认资源名称。
28+
locals {
29+
k8s_name_ask = substr(join("-", [var.k8s_name_prefix, "ask"]), 0, 63)
30+
new_vpc_name = "tf-vpc-172-16"
31+
new_vsw_name = "tf-vswitch-172-16-0"
32+
new_sg_name = "tf-sg-172-16"
33+
}
34+
35+
data "alicloud_eci_zones" "default" {}
36+
37+
resource "alicloud_vpc" "vpc" {
38+
vpc_name = local.new_vpc_name
39+
cidr_block = "172.16.0.0/12"
40+
}
41+
42+
resource "alicloud_vswitch" "vsw" {
43+
vswitch_name = local.new_vsw_name
44+
vpc_id = alicloud_vpc.vpc.id
45+
cidr_block = cidrsubnet(alicloud_vpc.vpc.cidr_block, 8, 8)
46+
zone_id = data.alicloud_eci_zones.default.zones.0.zone_ids.1
47+
}
48+
49+
resource "alicloud_security_group" "group" {
50+
name = local.new_sg_name
51+
vpc_id = alicloud_vpc.vpc.id
52+
}
53+
54+
resource "alicloud_cs_serverless_kubernetes" "serverless" {
55+
name = local.k8s_name_ask
56+
version = var.ack_version # 替换为您所需创建的集群版本。
57+
cluster_spec = var.cluster_spec
58+
vpc_id = alicloud_vpc.vpc.id
59+
vswitch_ids = split(",", join(",", alicloud_vswitch.vsw.*.id))
60+
new_nat_gateway = true
61+
endpoint_public_access_enabled = true
62+
deletion_protection = false
63+
security_group_id = alicloud_security_group.group.id
64+
# 通过RRSA配置ServiceAccount。
65+
enable_rrsa = true
66+
time_zone = "Asia/Shanghai"
67+
service_cidr = "10.13.0.0/16"
68+
service_discovery_types = ["CoreDNS"]
69+
70+
# tags
71+
tags = {
72+
"cluster" = "ack-serverless"
73+
}
74+
# addons
75+
addons {
76+
name = "nginx-ingress-controller"
77+
# 使用Internet。
78+
config = "{\"IngressSlbNetworkType\":\"internet\",\"IngressSlbSpec\":\"slb.s2.small\"}"
79+
# 如果使用Intranet, 配置如下。
80+
# config = "{\"IngressSlbNetworkType\":\"intranet\",\"IngressSlbSpec\":\"slb.s2.small\"}"
81+
}
82+
addons {
83+
name = "metrics-server"
84+
}
85+
addons {
86+
name = "knative"
87+
}
88+
addons {
89+
name = "managed-arms-prometheus"
90+
}
91+
addons {
92+
name = "logtail-ds"
93+
# 指定具体的sls_project_name
94+
# config = "{\"sls_project_name\":\"<YOUR-SLS-PROJECT-NAME>}\"}"
95+
}
96+
}
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)