A terraform example to launching a kubernetes cluster in alibaba cloud.
These types of the module resource are supported:
This example can specify the following arguments to create user-defined kuberntes cluster
- alicloud_access_key: The Alicloud Access Key ID
- alicloud_secret_key: The Alicloud Access Secret Key
- region: The ID of region in which launching resources
- k8s_name_prefix: The name prefix of kubernetes cluster
- k8s_number: The number of kubernetes cluster
- k8s_worker_number: The number of worker nodes in each kubernetes cluster
- k8s_pod_cidr: The kubernetes pod cidr block. It cannot be equals to vpc's or vswitch's and cannot be in them. If vpc's cidr block is
172.16.XX.XX/XX
, it had better to192.168.XX.XX/XX
or10.XX.XX.XX/XX
- k8s_service_cidr: The kubernetes service cidr block. Its setting rule is same as
k8s_pod_cidr
- Other kubernetes cluster arguments
Note: In order to avoid some needless error, you had better to set new_nat_gateway
to true
.
Otherwise, you must you must ensure you specified vswitches can access internet before running the example.
Planning phase
terraform plan
Apply phase
terraform apply
Destroy
terraform destroy
This example can support the following creating kubernetes cluster scenario by setting different arguments.
You can specify the following user-defined arguments:
- vpc_name: A new vpc name
- vpc_cidr: A new vpc cidr block
- vswitch_name_prefix: The name prefix of several vswitches
- vswitch_cidrs: List of cidr blocks for several new vswitches
variable "profile" {
default = "default"
}
variable "region" {
default = "cn-hangzhou"
}
data "alicloud_vpcs" "default" {
is_default = true
}
module "k8s" {
source = "../"
new_nat_gateway = true
vpc_name = "tf-k8s-vpc"
vpc_cidr = "10.0.0.0/8"
vswitch_name_prefix = "tf-k8s-vsw"
vswitch_cidrs = ["10.1.0.0/16", "10.2.0.0/16", "10.3.0.0/16"]
master_instance_types = ["ecs.n1.medium", "ecs.c5.large", "ecs.n1.medium"]
worker_instance_types = ["ecs.n1.medium"]
k8s_pod_cidr = "192.168.5.0/24"
k8s_service_cidr = "192.168.2.0/24"
k8s_worker_number = 2
}
You can specify the following user-defined arguments:
- vpc_id: A existing vpc ID
- vswitch_ids: List of IDs for several existing vswitches
variable "profile" {
default = "default"
}
variable "region" {
default = "cn-hangzhou"
}
data "alicloud_vpcs" "default" {
is_default = true
}
module "k8s" {
source = "../"
vpc_id = data.alicloud_vpcs.default.vpcs.0.id
vswitch_ids = ["vsw-bp1pog8voc3f42arr****", "vsw-bp1jxetj1386gqssg****", "vsw-bp1s1835sq5tjss9s****"]
master_instance_types = ["ecs.n1.medium", "ecs.c5.large", "ecs.n1.medium"]
worker_instance_types = ["ecs.n1.medium"]
k8s_pod_cidr = "192.168.5.0/24"
k8s_service_cidr = "192.168.2.0/24"
k8s_worker_number = 2
}
You can specify the following user-defined arguments:
- vpc_id: A existing vpc ID
- vswitch_ids: List of IDs for several existing vswitches
- new_nat_gateway: Set it to false. But you must ensure you specified vswitches can access internet. In other words, you must set snat entry for each vswitch before running the example.
variable "profile" {
default = "default"
}
variable "region" {
default = "cn-hangzhou"
}
data "alicloud_vpcs" "default" {
is_default = true
}
module "k8s" {
source = "../"
new_nat_gateway = false
vpc_id = data.alicloud_vpcs.default.vpcs.0.id
vswitch_ids = ["vsw-bp1pog8voc3f42arr****", "vsw-bp1jxetj1386gqssg****", "vsw-bp1s1835sq5tjss9s****"]
master_instance_types = ["ecs.n1.medium", "ecs.c5.large", "ecs.n1.medium"]
worker_instance_types = ["ecs.n1.medium"]
k8s_pod_cidr = "192.168.5.0/24"
k8s_service_cidr = "192.168.2.0/24"
k8s_worker_number = 2
}
From the version v1.4.0, the module has removed the following provider
setting:
provider "alicloud" {
profile = var.profile != "" ? var.profile : null
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
region = var.region
skip_region_validation = var.skip_region_validation
configuration_source = "terraform-alicloud-modules/kubernetes"
}
If you still want to use the provider
setting to apply this module, you can specify a supported version, like 1.3.0:
module "k8s" {
source = "terraform-alicloud-modules/kubernetes/alicloud"
version = "1.3.0"
region = "cn-hangzhou"
profile = "Your-Profile-Name"
new_nat_gateway = true
vpc_name = "tf-k8s-vpc"
// ...
}
If you want to upgrade the module to 1.4.0 or higher in-place, you can define a provider which same region with previous region:
provider "alicloud" {
region = "cn-hangzhou"
profile = "Your-Profile-Name"
}
module "k8s" {
source = "terraform-alicloud-modules/kubernetes/alicloud"
new_nat_gateway = true
vpc_name = "tf-k8s-vpc"
// ...
}
or specify an alias provider with a defined region to the module using providers
:
provider "alicloud" {
region = "cn-hangzhou"
profile = "Your-Profile-Name"
alias = "hz"
}
module "k8s" {
source = "terraform-alicloud-modules/kubernetes/alicloud"
providers = {
alicloud = alicloud.hz
}
new_nat_gateway = true
vpc_name = "tf-k8s-vpc"
// ...
}
and then run terraform init
and terraform apply
to make the defined provider effect to the existing module state.
More details see How to use provider in the module
Name | Version |
---|---|
terraform | >= 0.13 |
Name | Version |
---|---|
alicloud | n/a |
No modules.
Name | Type |
---|---|
alicloud_cs_kubernetes.k8s | resource |
alicloud_cs_kubernetes_node_pool.default | resource |
alicloud_eip.default | resource |
alicloud_eip_association.default | resource |
alicloud_nat_gateway.default | resource |
alicloud_snat_entry.default | resource |
alicloud_vpc.vpc | resource |
alicloud_vswitch.vswitches | resource |
alicloud_instance_types.default | data source |
alicloud_zones.default | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
cluster_addons | Addon components in kubernetes cluster | list(object({ |
[] |
no |
cpu_core_count | CPU core count is used to fetch instance types. | number |
1 |
no |
cpu_policy | kubelet cpu policy. Valid values: 'none','static'. Default to 'none'. | string |
"none" |
no |
create_vpc | Boolean. If you have a vpc already, use that one, else make this true and one will be created. | bool |
false |
no |
data_disks | Additional data disks to attach to the scaled ECS instance. | list(map(string)) |
[] |
no |
enable_ssh | Enable login to the node through SSH. | bool |
false |
no |
example_name | The name as prefix used to create resources. | string |
"tf-example-kubernetes" |
no |
install_cloud_monitor | Install cloud monitor agent on ECS. | bool |
true |
no |
instance_charge_type | The charge type of instance. Choices are 'PostPaid' and 'PrePaid'. | string |
"PostPaid" |
no |
k8s_name_prefix | The name prefix used to create several kubernetes clusters. Default to variable example_name |
string |
"" |
no |
k8s_number | The number of kubernetes cluster. | number |
1 |
no |
k8s_pod_cidr | The kubernetes pod cidr block. It cannot be equals to vpc's or vswitch's and cannot be in them. | string |
"172.20.0.0/16" |
no |
k8s_service_cidr | The kubernetes service cidr block. It cannot be equals to vpc's or vswitch's or pod's and cannot be in them. | string |
"172.21.0.0/20" |
no |
k8s_version | The version of the kubernetes version. | string |
"" |
no |
k8s_worker_number | The number of worker nodes in kubernetes cluster. | number |
2 |
no |
master_instance_types | The ecs instance types used to launch master nodes. | list(string) |
[] |
no |
master_password | The password of master ECS instance. | string |
"Just4Test" |
no |
memory_size | Memory size used to fetch instance types. | number |
2 |
no |
new_nat_gateway | Whether to create a new nat gateway. In this template, a new nat gateway will create a nat gateway, eip and server snat entries. | bool |
true |
no |
node_cidr_mask | The node cidr block to specific how many pods can run on single node. Valid values: [24-28]. | number |
24 |
no |
number_format | The number format used to output. | string |
"%02d" |
no |
proxy_mode | Proxy mode is option of kube-proxy. Valid values: 'ipvs','iptables'. Default to 'iptables'. | string |
"iptables" |
no |
subscription | A mapping of fields for Prepaid ECS instances created. | map(string) |
{ |
no |
system_disk_category | The system disk category used to launch one or more worker ecs instances. | string |
"cloud_efficiency" |
no |
system_disk_size | The system disk size used to launch one or more worker ecs instances. | number |
40 |
no |
vpc_cidr | The cidr block used to launch a new vpc when 'vpc_id' is not specified. | string |
"10.0.0.0/8" |
no |
vpc_id | Existing vpc id used to create several vswitches and other resources. | string |
"" |
no |
vpc_name | The vpc name used to create a new vpc when 'vpc_id' is not specified. Default to variable example_name |
string |
"" |
no |
vswitch_cidrs | List of cidr blocks used to create several new vswitches when 'vswitch_ids' is not specified. | list(string) |
[ |
no |
vswitch_ids | List of existing vswitch id. | list(string) |
[] |
no |
vswitch_name_prefix | The vswitch name prefix used to create several new vswitches. Default to variable 'example_name'. | string |
"" |
no |
worker_instance_types | The ecs instance types used to launch worker nodes. | list(string) |
[] |
no |
worker_password | The password of worker ECS instance. | list(string) |
[ |
no |
Name | Description |
---|---|
cluster_id | ID of the kunernetes cluster. |
cluster_nodes | List nodes of cluster. |
nat_gateway_id | The ID of the NAT Gateway. |
security_group_id | ID of the Security Group used to deploy kubernetes cluster. |
this_k8s_node_ids | List ids of of cluster node. |
vpc_id | The ID of the VPC. |
vswitch_ids | List ID of the VSwitches. |
If you have any problems when using this module, please opening a provider issue and let us know.
Note: There does not recommend to open an issue on this repo.
Created and maintained by Alibaba Cloud Terraform Team([email protected])
Mozilla Public License 2.0. See LICENSE for full details.