Create an ACK Serverless cluster with Alibaba Cloud CLI

更新时间:
复制 MD 格式

Alibaba Cloud CLI is a management tool built on Alibaba Cloud OpenAPI. Use it from the command line to create and verify an ACK Serverless cluster, then deploy a sample NGINX workload to confirm the cluster is functional.

This guide uses default settings. For production, review 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 credential, region, and language settings (Overview).

  • kubectl installed.

Install Alibaba Cloud CLI and kubectl

If you use Cloud Shell, Alibaba Cloud CLI and your account credentials are preinstalled and configured. Skip this section.

Otherwise, install Alibaba Cloud CLI for your platform:

Platform Instructions
Linux Install on Linux
macOS Install on macOS, or if Homebrew is installed, run brew install aliyun-cli
Windows Install on Windows

Set up credentials with aliyun configure:

aliyun configure

Enter your Access Key ID, Access Key Secret, default region, and output format:

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

Confirm the CLI is installed and configured:

aliyun version

Create an ACK Serverless cluster

Step 1: Set configuration variables

Set environment variables for the cluster parameters. Replace the values with your 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 this content. Key fields:

{
    "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 The serverless profile
name test-serverless-k8s Your cluster name
region_id cn-hangzhou The cluster region
zoneid cn-hangzhou-h The zone
nat_gateway true Creates a NAT gateway for outbound internet access
private_zone false Disables PrivateZone-based service discovery

All configuration parameters: 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 as an environment variable:

export CLUSTER_ID="<your-cluster-id>"

Step 4: Verify the cluster is running

Cluster creation takes several minutes. 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 NGINX 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 all associated resources, including the Virtual Private Cloud (VPC):

aliyun cs DELETE /clusters/$CLUSTER_ID

Next steps