All Products
Search
Document Center

Container Service for Kubernetes:Create an ACK Serverless cluster by using Alibaba Cloud CLI

Last Updated:Jun 06, 2024

Alibaba Cloud CLI is a management tool developed based on Alibaba Cloud APIs. You can use Alibaba Cloud CLI to call the APIs of Alibaba Cloud services.

Prerequisites

Before you use Alibaba Cloud CLI, you must configure the information that is required for calling Alibaba Cloud resources. This information includes the credential, region, and language. For more information, see Overview.

Install and set up Alibaba Cloud CLI and kubectl

By default, Cloud Shell is preinstalled with Alibaba Cloud CLI and configured with the account information. You do not need to make any configuration changes. If you do not use Cloud Shell, you must install and set up Alibaba Cloud CLI and kubectl.

  • Install Alibaba Cloud CLI.

    • Install Alibaba Cloud CLI in Linux. For more information, see Linux.

    • Install Alibaba Cloud CLI in macOS.

      • Install Alibaba Cloud CLI in macOS.

      • You can also use a package manager to install Alibaba Cloud CLI in macOS. For more information, see Homebrew. After the package manager is installed, run the following command to install Alibaba Cloud CLI:

        brew install aliyun-cli
    • For more information about how to install Alibaba Cloud CLI in Windows, see Windows.

  • Configure Alibaba Cloud CLI. Run the following command to create environment variables that are used to store identity information:

    aliyun configure

    Expected output:

    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.
    
    Configure Done!!!
    ..............888888888888888888888 ........=8888888888888888888D=..............
    ...........88888888888888888888888 ..........D8888888888888888888888I...........
    .........,8888888888888ZI: ...........................=Z88D8888888888D..........
    .........+88888888 ..........................................88888888D..........
    .........+88888888 .......Welcome to use Alibaba Cloud.......O8888888D..........
    .........+88888888 ............. ************* ..............O8888888D..........
    .........+88888888 .... Command Line Interface(Reloaded) ....O8888888D..........
    .........+88888888...........................................88888888D..........
    ..........D888888888888DO+. ..........................?ND888888888888D..........
    ...........O8888888888888888888888...........D8888888888888888888888=...........
    ............ .:D8888888888888888888.........78888888888888888888O ..............                    

Install and set up a kubectl client. For more information, see Install and Set Up kubectl.

Create an ACK Serverless cluster

  1. Create a working directory and a file named create.json in the directory.

    The following template is an example of the create.json file:

    {
        "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"}
        ]
    }             

    The preceding sample template describes the configurations that are used to create an ACK Serverless cluster. For more information, see Create an ACK Serverless cluster.

  2. Run the following command to create an ACK Serverless cluster:

    aliyun cs  POST /clusters --header "Content-Type=application/json" --body "$(cat create.json)"                       
    {
        "cluster_id": "************************",
        "instanceId": "************************",
        "request_id": "**********-****-****-****-************",
        "task_id": "*-************"
    }
  3. After the ACK Serverless cluster is created, run the following command to query information about the cluster:

    aliyun cs GET /clusters/<YOUR-CLUSTER-ID>                    

    Expected output:

       {
        "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-*"
    }
  4. Run the following command to query the cluster configurations:

    KUBECONFIG=<YOUR-LOCAL-KUBECONFIG-PATH>
    aliyun cs GET /k8s/$cluster_id/user_config | jq -r '.config' > $KUBECONFIG
    kubectl get ns

    Expected output:

    NAME              STATUS   AGE
    default           Active   7m43s
    kube-node-lease   Active   7m45s
    kube-public       Active   7m45s
    kube-system       Active   7m45s

Test the ACK Serverless cluster

  1. Run the following command to deploy an NGINX application in the ACK Serverless cluster:

    kubectl run nginx --image=registry-vpc.cn-shenzhen.aliyuncs.com/acs-sample/nginx:latest

    Expected output:

    deployment.apps/nginx created
  2. Run the following command to query the state of the NGINX application:

    kubectl get deploy nginx

    Expected output:

     NAME    READY   UP-TO-DATE   AVAILABLE   AGE
     nginx   1/1     1            1           58s

Delete and release resources

  • Run the following command to delete the NGINX application:

    kubectl delete deploy nginx

    Expected output:

    deployment.extensions "nginx" deleted
  • You can also run the following command to delete the ACK Serverless cluster and release the relevant resources, such as the virtual private cloud (VPC) where the cluster is deployed:

    aliyun cs DELETE /clusters/************