You can call the CreateCluster operation to create a Kubernetes cluster and add nodes to the cluster.

Request information

Request line

POST /clusters HTTP/1.1

Custom request headers

None. For more information, see Public request headers.

Request body

Note You must set parameters correctly. Otherwise, errors may occur in the cluster creation process. When you create a cluster in the console, you can click Generate API Request Parameters on the Create Kubernetes Cluster page to view all parameters. For more information, see Generate API parameters.
{ "disable_rollback": "whether to roll back when the operation fails", "name": "cluster name", "timeout_mins": "cluster creation timeout", "cluster_type": "cluster type. Kubernetes", "region_id": "region", "vpcid": "VPC ID", "master_vswitch_ids": "VSwitch IDs of master nodes. Specify three VSwitches in different zones to ensure high availability.", "master_instance_type": "instance types of master nodes. Specify three instance types.", "master_count": "number of master nodes. Valid values: 3 and 5", "container_cidr": "pod CIDR block", "service_cidr": "service CIDR block", "ssh_flags": "whether to allow Internet access through SSH", "cloud_monitor_flags": "whether to install the CloudMonitor agent", "login_password": "SSH logon password. Select between SSH authentication and key pair authentication", "key_pair":"key pair name. Select between SSH authentication and key pair authentication", "master_instance_charge_type":"billing method of master nodes. PostPaid or PrePaid", "master_period_unit": "unit of the subscription duration of master nodes. Month or Year. This parameter takes effect only when parameter master_instance_charge_type is set to PrePaid", "master_period": "subscription duration of master nodes. This parameter takes effect only when parameter master_instance_charge_type is set to PrePaid", "master_auto_renew":"whether to automatically renew the subscription of master nodes", "master_auto_renew_period":"subscription duration when master nodes are renewed", "master_system_disk_category": "system disk type of master nodes", "master_system_disk_size":"system disk size of master nodes", "master_data_disk": "whether to mount data disks to master nodes.", "master_data_disks": "data disk configurations of master nodes", "master_system_disk_snapshot_policy_id": "snapshot policy ID on the system disk of master nodes", "worker_instance_charge_type":"billing method of worker nodes. PrePaid or PostPaid", "worker_period_unit": "unit of the subscription duration of worker nodes. Month or Year. This parameter takes effect only when parameter worker_instance_charge_type is set to PrePaid", "worker_period": "subscription duration of worker nodes. This parameter takes effect only when parameter worker_instance_charge_type is set to PrePaid", "worker_auto_renew":"whether to automatically renew the subscription of worker nodes. Valid values: true and false", "worker_auto_renew_period": "subscription duration when worker nodes are renewed", "worker_instance_types": "instance types of worker nodes", "worker_vswitch_ids": "VSwitch IDs of worker nodes. Specify one to five VSwitches", "worker_system_disk_category": "system disk type of worker nodes", "worker_system_disk_size": "system disk size of worker nodes", "worker_data_disk": "whether to mount data disks to worker nodes.", "worker_data_disks":"data disk configurations of worker nodes", "worker_system_disk_snapshot_policy_id": "snapshot policy ID on the system disk of worker nodes", "num_of_nodes": "number of worker nodes", "snat_entry": "whether to configure SNAT entries", "endpoint_public_access": "whether to enable Internet access to the cluster endpoint", "cpu_policy": "CPU policy. Valid values: static and none", "node_port_range": "port range of nodes. Valid values: 30000 to 65535", "proxy_mode": "network mode. Valid values: iptables and ipvs", "addons": "optional add-ons in an array", "tags": "tags in an array", "security_group_id": "security group ID",    "auto_snapshot_policy_id": "automatic snapshot policy ID",
"taint": "taints in an array" "deletion_protection": "whether to enable cluster deletion protection. If this option is enabled, the cluster cannot be deleted through the console or API operations." "os_type": "operating system of the nodes that run pods. For example, Linux and Windows", "platform": "architecture of the nodes that run pods", "runtime": "container runtime. Default is Docker", }
Table 1. Request body parameters
Parameter Type Required Description
cluster_type string Yes The type of the cluster.
key_pair string Yes The name of the key pair. Select between login_password and key_pair.
login_password string Yes The SSH logon password. The password must be 8 to 30 characters in length and contain three of the following four types of characters: uppercase letters, lowercase letters, digits, and special characters. Select between login_password and key_pair.
master_instance_charge_type string No The billing method of master nodes. Valid values:
  • PrePaid: subscription
  • PostPaid: pay-as-you-go
Default value: PostPaid.
master_instance_types list Yes The instance types of master nodes. For more information, see Instance families.
master_system_disk_category string Yes The system disk type of master nodes. Valid values:
  • cloud_efficiency: ultra disk
  • cloud_ssd: standard SSD
master_system_disk_size int Yes The system disk size of master nodes. Unit: GiB.
master_vswitch_ids list Yes The VSwitch IDs of master nodes. You must specify 1 to 3 VSwitch IDs. We recommend that you specify three VSwitches in different zones to ensure high availability.
num_of_nodes int Yes The number of worker nodes. Valid values: [0, 300]
name string Yes The name of the cluster. The name can contain uppercase letters, lowercase letters, Chinese characters, digits, and hyphens (-).
region_id string Yes The ID of the region where the cluster is deployed.
snat_entry bool Yes Whether to configure SNAT.
  • If the VPC network has Internet access, set this parameter to false.
  • If the VPC network has no Internet access:
    • Set this parameter to true to configure SNAT. This enables the cluster to access the Internet.
    • Set this parameter to false to not configure SNAT. The cluster will have no Internet access.
worker_instance_types list Yes The instance types of worker nodes. For more information, see Instance families.
worker_system_disk_category string Yes The system disk type of worker nodes.
worker_system_disk_size int Yes The system disk size of worker nodes. Unit: GiB.
worker_vswitch_ids list Yes The VSwitch IDs of worker nodes.
addons list No The add-ons to the Kubernetes cluster.
  • Add-ons parameters:
    • name: Required. The name of the add-on.
    • version: Optional. Default is the latest version.
    • config: Optional. If this parameter is not set, it indicates that this parameter is not required.
  • Network plug-in: Select between Flannel and Terway.
  • Log Service: Optional. If Log Service is not enabled, the cluster audit function is not available.
  • Ingress: The Ingress component is installed by default.
container_cidr string No The CIDR block of containers. This CIDR block must not overlap with that of the VPC network. If the VPC network is automatically created by the system, the container CIDR block is set to 172.16.0.0/16 by default.
cloud_monitor_flags bool No Whether to install the CloudMonitor agent.
  • A value of true indicates yes.
  • A value of false indicates no.
cpu_policy string No The CPU policy. For Kubernetes 1.12.6 and later versions, static and none are supported. Default value: none.
disable_rollback bool No Whether to roll back when the operation fails.
  • A value of true indicates no.
  • A value of false indicates yes.
Default value: true. If you choose to roll back when the operation fails, resources created during the operation are released. We recommend that you set this parameter to true.
master_auto_renew bool No Whether to automatically renew the subscription of master nodes. This parameter takes effect only when parameter master_instance_charge_type is set to PrePaid. Valid values:
  • A value of true indicates that auto renewal is enabled.
  • A value of false indicates that auto renewal is disabled.
master_auto_renew_period int No The duration of the subscription. This parameter is required when parameter master_instance_charge_type is set to PrePaid and parameter master_auto_renew is set to true.
  • When PeriodUnit is set to Month, valid values are as follows: 1, 2, 3, 6, and 12.
master_count int No The number of master nodes. Valid values: 3 and 5. Default value: 3.
master_data_disk bool No Whether to mount data disks to master nodes.
  • A value of true indicates yes.
  • A value of false indicates no. Default is false.
master_data_disks list No The data disk configurations of master nodes, such as the disk type and disk size. This parameter takes effect only when parameter master_data_disk is set to true.
  • category: The type of the data disk. Valid values:
    • cloud: basic disk
    • cloud_efficiency: ultra disk
    • cloud_ssd: standard SSD
  • size: The size of the data disk. Unit: GiB.
  • encrypted:
master_period int No The duration of the subscription. This parameter is required when parameter master_instance_charge_type is set to PrePaid.
  • When PeriodUnit is set to Month, valid values are as follows: 1, 2, 3, 6, and 12.
master_period_unit string No The unit of the subscription duration. This parameter is required when parameter master _instance_charge_type is set to PrePaid. Valid values:
  • A value of Month indicates that the subscription duration is measured in months.
node_port_range string No The port range of nodes. Valid values: 30000 to 65535.
proxy_mode string No The kube-proxy mode. Valid values: iptables and IPVS. Default value: iptables.
endpoint_public_access bool No Whether to allow Internet access to the API Server.
  • A value of true indicates that Internet access to the API Server is allowed. This is the default setting.
  • A value of false indicates that Internet access to the API Server is denied.
security_group_id string No The ID of the security group to which the ECS instances in the cluster belong.
service_cidr string No The service CIDR block. This CIDR block must not overlap with that of the VPC network or container. If the VPC network is automatically created by the system, the service CIDR block is set to 172.19.0.0/20 by default.
ssh_flags bool No Whether to enable SSH logon.
  • A value of true indicates that SSH logon is enabled.
  • A value of false indicates that SSH logon is disabled.
tags list No The tags of the cluster.
  • key: The name of the tag.
  • value: The value of the tag.
taints list No Taints are applied to nodes to make sure that pods are not scheduled to unsuitable nodes. Tolerations are applied to pods. If a pod has a toleration that matches the taint on a node, this pod can be scheduled to the node.
kubernetes_version string No The Kubernetes version. Default is the latest version.
timeout_mins int No The maximum time in minutes during which a resource creation operation must complete. Default: 60.
vpcid string No Optional. The ID of the VPC network where the cluster is deployed. If this parameter is not set, the system automatically creates a VPC network with CIDR block 192.168.0.0/16.
Note The vpcid and vswitchid parameters must be used together.
worker_auto_renew bool No Whether to automatically renew the subscription of worker nodes. Valid values:
  • A value of true indicates that auto renewal is enabled.
  • A value of false indicates that auto renewal is disabled.
worker_auto_renew_period int No The duration of the subscription. This parameter is required when parameter worker_instance_charge_type is set to PrePaid and parameter worker_auto_renew is set to true.
  • When PeriodUnit is set to Month, valid values are as follows: 1, 2, 3, 6, and 12.
worker_data_disk string No Whether to mount data disks to worker nodes. Valid values:
  • A value of true indicates yes.
  • A value of false indicates no.
worker_data_disks list No The data disk configurations of worker nodes, such as the disk type and disk size. This parameter takes effect only when parameter worker_data_disk is set to true.
  • category: The type of the data disk. Valid values:
    • cloud: basic disk
    • cloud_efficiency: ultra disk
    • cloud_ssd: standard SSD
  • size: The size of the data disk. Unit: GiB.
  • encrypted: whether to encrypt the data disk. Valid values: true and false.
worker_instance_charge_type string No The billing method of worker nodes. Valid values:
  • PrePaid: subscription
  • PostPaid: pay-as-you-go
Default value: PostPaid.
worker_period int No The duration of the subscription. This parameter is required when parameter worker_instance_charge_type is set to PrePaid.
  • When PeriodUnit is set to Month, valid values are as follows: 1, 2, 3, 6, and 12.
worker_period_unit string No The unit of the subscription duration. This parameter is required when parameter worker_instance_charge_type is set to PrePaid. Valid values:
  • A value of Month indicates that the subscription duration is measured in months.
deletion_protection bool No Whether to enable cluster deletion protection. If this option is enabled, the cluster cannot be deleted through the console or API operations.
os_type string No The operating system of the nodes that run pods. For example, Linux and Windows.
platform string No The architecture of the nodes that run pods.
runtime json No The container runtime. Default is Docker. You need to specify the name and version.
node_cidr_mask string No The prefix length of the node CIDR block.

Response information

Response line

HTTP/1.1 202 Accepted

Custom response headers

None. For more information, see Public response headers.

Table 2. Response body
Parameter Type Description
cluster_id string The ID of the cluster.
request_id string The ID of the request.
task_id string The ID of the task. It is system-assigned and can be used to query the task status.

Examples

Sample requests

POST /clusters HTTP/1.1
<Common request headers> { "cluster_type":"Kubernetes",
"name":"my-test-Kubernetes-cluster",
"region_id":"cn-beijing",
"disable_rollback":true,
"timeout_mins":60, "kubernetes_version":"1.12.6-aliyun.1",
"snat_entry":true,
"endpoint_public_access":false,
"cloud_monitor_flags":false,
"node_cidr_mask":"25",
"proxy_mode":"iptables",
"tags":[],
"addons": [{"name": "flannel"},{"name": "aliyun-log-controller","config": "{\"sls_project_name\":\"k8s-log-c64f6eab6a1764d3dbee3dc2b9e41****\"}"},{"name": "nginx-ingress-controller", "config": "{\"IngressSlbNetworkType\":\"internet\"}"}],
"node_port_range":"30000-32767",
"login_password":"test****",
"cpu_policy":"none",
"master_count":3,
"master_vswitch_ids":["vsw-2ze48rkq464rsdts****","vsw-2ze48rkq464rsdts1****","vsw-2ze48rkq464rsdts1****"],
"master_instance_types":["ecs.sn1.medium","ecs.sn1.medium","ecs.sn1.medium"],
"master_system_disk_category":"cloud_efficiency",
"master_system_disk_size":40,
"worker_instance_types":["ecs.sn2.3xlarge"],
"num_of_nodes":3,
"worker_system_disk_category":"cloud_efficiency",
"worker_system_disk_size":120,
"vpcid":"vpc-2zegvl5etah5requ0****",
"worker_vswitch_ids":["vsw-2ze48rkq464rsdts****"],
"container_cidr":"172.20.XX.XX/16",
"service_cidr":"172.21.XX.XX/20",
"worker_data_disks": [{"category": "cloud_ssd", "size": 500}],
"master_data_disks": [{"category": "cloud_ssd", "size": 500}],
"taints":[{"key": "special", "value": "true", "effect": "NoSchedule"}]
}

Sample responses

HTTP/1.1 202 Accepted
<Common response headers> {    "cluster_id": "cb95aa626a47740afbf6aa099b650****",
    "request_id": "687C5BAA-D103-4993-884B-C35E4314A1E1",
    "task_id": "T-5a54309c80282e39ea00002f"
}