Alibaba Cloud CLI is a management tool built on Alibaba Cloud APIs. This guide walks you through creating an ACK Serverless cluster, verifying it, and deploying a test application — all from the command line.
This guide uses default settings for a quick start. For production clusters, review all configuration options in Create an ACK Serverless cluster before deploying.
Prerequisites
Before you begin, ensure that you have:
-
Alibaba Cloud CLI installed and configured with your credentials. See Overview for the required credential, region, and language settings.
-
kubectl installed. See Install and set up kubectl.
Install Alibaba Cloud CLI
If you use Cloud Shell, Alibaba Cloud CLI is preinstalled and pre-configured — skip this section.
Otherwise, install Alibaba Cloud CLI for your platform:
| Platform | Instructions |
|---|---|
| Linux | Install on Linux |
| macOS | Install on macOS, or run brew install aliyun-cli |
| Windows | Install on Windows |
After installing, run aliyun configure to set up your credentials:
aliyun configure
Enter your Access Key ID, Access Key Secret, default region, and preferred output format when prompted:
Configuring profile 'default' in 'AK' authenticate mode...
Access Key Id []: ************
Access Key Secret []: ************
Default Region Id []: cn-beijing
Default Output Format [json]: json (Only support json)
Default Language [zh|en] en:
Saving profile[default] ...Done.
Verify the installation
Run the following command to confirm the CLI is installed and configured correctly:
aliyun version
Create an ACK Serverless cluster
Step 1: Set configuration variables
Set environment variables for the cluster parameters you'll reference throughout this guide. Replace the values with your own region and zone:
export CLUSTER_NAME="test-serverless-k8s"
export REGION_ID="cn-hangzhou"
export ZONE_ID="cn-hangzhou-h"
export KUBECONFIG="$HOME/.kube/ask-config"
Step 2: Create the cluster configuration file
Create a file named create.json with the following content. The key fields are explained in the table below:
{
"cluster_type": "ManagedKubernetes",
"profile": "Serverless",
"name": "test-serverless-k8s",
"region_id": "cn-hangzhou",
"zoneid": "cn-hangzhou-h",
"nat_gateway": true,
"private_zone": false,
"tags": [
{"key": "env", "value": "test"}
]
}
| Field | Value | Description |
|---|---|---|
cluster_type |
ManagedKubernetes |
Required for ACK Serverless clusters |
profile |
Serverless |
Specifies the serverless profile |
name |
test-serverless-k8s |
Your cluster name |
region_id |
cn-hangzhou |
The region where the cluster is created |
zoneid |
cn-hangzhou-h |
The zone within the region |
nat_gateway |
true |
Creates a NAT gateway for outbound internet access |
private_zone |
false |
Disables PrivateZone-based service discovery |
For a full list of configuration parameters, see Create an ACK Serverless cluster.
Step 3: Submit the cluster creation request
aliyun cs POST /clusters --header "Content-Type=application/json" --body "$(cat create.json)"
The response includes your cluster ID:
{
"cluster_id": "************************",
"instanceId": "************************",
"request_id": "**********-****-****-****-************",
"task_id": "*-************"
}
Save the cluster_id value. You'll need it in the next steps. Set it as an environment variable:
export CLUSTER_ID="<your-cluster-id>"
Step 4: Verify the cluster is running
Cluster creation takes several minutes. Run the following command to check the status:
aliyun cs GET /clusters/$CLUSTER_ID
The cluster is ready when "state": "running" appears in the response:
{
"cluster_id": "************************",
"cluster_spec": "ack.standard",
"cluster_type": "ManagedKubernetes",
"created": "2024-05-06T14:48:40+08:00",
"current_version": "1.28.3-aliyun.1",
"deletion_protection": false,
"external_loadbalancer_id": "lb-*********",
"init_version": "1.28.3-aliyun.1",
"name": "test-serverless-k8s",
"network_mode": "vpc",
"profile": "Serverless",
"region_id": "cn-hangzhou",
"resource_group_id": "rg-*********",
"security_group_id": "sg-*********",
"service_domain_name": "",
"size": 0,
"state": "running",
"tags": [
{"key": "env", "value": "test"},
{"key": "ack.aliyun.com", "value": "cc98dd6edd4ff4c*****************"}
],
"updated": "2024-05-06T14:52:44+08:00",
"vpc_id": "vpc-*********",
"vswitch_id": "vsw-*********",
"zone_id": "cn-hangzhou-*"
}
Step 5: Configure kubectl access
Download the kubeconfig and confirm kubectl can reach the cluster:
aliyun cs GET /k8s/$CLUSTER_ID/user_config | jq -r '.config' > $KUBECONFIG
kubectl get ns
The cluster is accessible when you see the four system namespaces:
NAME STATUS AGE
default Active 7m43s
kube-node-lease Active 7m45s
kube-public Active 7m45s
kube-system Active 7m45s
Test the cluster
Step 6: Deploy a test application
Deploy an NGINX application to verify the cluster accepts workloads:
kubectl run nginx --image=registry-vpc.cn-shenzhen.aliyuncs.com/acs-sample/nginx:latest
Expected output:
deployment.apps/nginx created
Step 7: Verify the deployment is ready
kubectl get deploy nginx
The deployment is ready when READY shows 1/1:
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 58s
Clean up resources
Delete the NGINX deployment:
kubectl delete deploy nginx
Expected output:
deployment.extensions "nginx" deleted
To delete the cluster and release all associated resources, including the virtual private cloud (VPC):
aliyun cs DELETE /clusters/$CLUSTER_ID