Call ACK One API with Alibaba Cloud CLI

更新时间:
复制 MD 格式

Use Distributed Cloud Container Platform for Kubernetes to call the DescribeHubClusters operation of the Distributed Cloud Container Platform for Kubernetes (ACK One) API and query master instances in your Alibaba Cloud account.

Before you begin

Alibaba Cloud CLI is an OpenAPI-based command-line tool for managing Distributed Cloud Container Platform for Kubernetes resources. See What is Alibaba Cloud CLI?

Step 1: Install Alibaba Cloud CLI

Alibaba Cloud CLI supports Windows, Linux, and macOS. Select the installation package for your operating system.

Cloud Shell has Alibaba Cloud CLI pre-installed and auto-configured with your credentials. Run CLI commands directly in Cloud Shell. See What is Cloud Shell?

Step 2: Configure Alibaba Cloud CLI

Important

An Alibaba Cloud account has full API access to all services, which poses security risks. Create a Resource Access Management (RAM) user and grant only the required permissions based on the least privilege principle. Use the RAM user to call API operations. For system policies for Distributed Cloud Container Platform for Kubernetes, see AliyunAdcpFullAccess and AliyunAdcpReadOnlyAccess.

Configure your identity credentials before using Alibaba Cloud CLI. The CLI supports multiple credential types. See Configure and manage credentials. The following steps use the AccessKey pair of a RAM user:

  1. Create a RAM user and an AccessKey pair for identity credentials. See Create a RAM user and Create an AccessKey pair.

  2. Grant the required permissions to the RAM user. This example attaches the AliyunAdcpReadOnlyAccess policy for read-only access to Distributed Cloud Container Platform for Kubernetes. See Grant permissions to a RAM user.

  3. Obtain the region ID where your clusters reside. Alibaba Cloud CLI calls APIs in the specified region. For the regions in which Distributed Cloud Container Platform for Kubernetes is available, see Endpoints.

    Note

    The --region option overrides the region in default credentials and environment variables. See Command line options for API calls.

  4. Configure identity credentials with the RAM user's AccessKey pair in a profile named AkProfile. See Configuration examples.

Step 3: Generate a sample command

  1. In OpenAPI Explorer, go to the DescribeHubClusters debugging page.

  2. On the Parameters tab, enter request parameters. Click the CLI Example tab to view the CLI example.

  3. Copy the command or run it in Cloud Shell.

    • Click the Run Commandimage to open Cloud Shell and debug the command.

    • Click the Copyimage to copy the CLI example to your clipboard. Paste it into a local shell or use it in an automation script.

    Note
    • When pasting the CLI command into your local shell, note the parameter format requirements. See Parameter formats.

    • OpenAPI Explorer adds the --region option to sample commands by default. This option overrides the region in default credentials and environment variables. Delete or retain it based on your requirements.

Step 4: Call the Distributed Cloud Container Platform for Kubernetes API

Example 1: Query operations of the Distributed Cloud Container Platform for Kubernetes supported by Alibaba Cloud CLI

Use the --help option to query Distributed Cloud Container Platform for Kubernetes API operations supported by Alibaba Cloud CLI. See List of operations by function.

  1. List available API operations:

    aliyun adcp --help
  2. Expected output:

    Product: adcp (Distributed Cloud Container Platform for Kubernetes)
    Version: 2022-01-01
    Available Api List:
        AttachClusterToHub            Adds an ACK cluster to an ACK One master instance.
        ChangeResourceGroup
        CreateHubCluster              Creates an ACK One master instance.
        DeleteHubCluster              Deletes an ACK One master instance.
        DeletePolicyInstance          Deletes a policy rule instance in an associated cluster.
        DeleteUserPermission          Deletes the RBAC authorization of a RAM user.
        DeployPolicyInstance          Deploys a policy rule instance in a cluster that is associated with a master instance.
        DescribeHubClusterDetails     Obtains the details of an ACK One master instance.

Example 2: Query master instances in your account

Call the DescribeHubClusters operation of the Distributed Cloud Container Platform for Kubernetes API to query master instances by type and resource ID. See DescribeHubClusters - Queries master instances.

  1. Query master instances:

    aliyun adcp DescribeHubClusters --ResourceGroupId 'rg-aek3dinj3xkf***' --Profile Default
  2. Expected output:

    {
      "RequestId": "2D676EFC-8C04-5CCE-A08E-BB97D24B47E8",
      "Clusters": [
        {
          "Endpoints": {
            "IntranetApiServerEndpoint": "https://172.16.6.**:6443\n",
            "PublicApiServerEndpoint": "https://123.57.21.***:6443\n"
          },
          "ClusterInfo": {
            "Profile": "Default",
            "CreationTime": "2021-11-05T10:25:48Z",
            "UpdateTime": "2021-09-02T13:39:50Z",
            "ErrorMessage": "Success",
            "Version": "1.22.3-aliyun.1\n",
            "State": "running",
            "ClusterId": "c2d3e0121ea214b438010502a8019****",
            "Name": "ackone-heyuan",
            "RegionId": "cn-beijing",
            "ClusterSpec": "ack.pro.small",
            "ResourceGroupID": "rg-dt6rk4xm1r6***",
            "Tags": [
              {
                "Key": "headername",
                "Value": "release"
              }
            ]
          },
          "Network": {
            "VpcId": "vpc-2zeusrwi7c2mlww4a****",
            "VSwitches": [
              "[\"vsw-2ze1h7tt2fgr1gxlx****\"]"
            ],
            "SecurityGroupIDs": [
              "[\"sg-2ze1h7tt2fgr****\"]\n"
            ],
            "ClusterDomain": "cluster.local"
          },
          "ApiServer": {
            "EnabledPublic": true,
            "LoadBalancerId": "lb-bp1qyp4l6bscqxw69****",
            "ApiServerEipId": "eip-xxx"
          },
          "MeshConfig": {
            "EnableMesh": false,
            "MeshId": "c2d3e0121ea214b438010502a8019****"
          },
          "LogConfig": {
            "EnableLog": true,
            "LogProject": "audit-log-abc",
            "LogStoreTTL": "7"
          },
          "Conditions": [
            {
              "Type": "DeletionProtection",
              "Status": "True",
              "Reason": "Successful",
              "Message": "Successful!"
            }
          ]
        }
      ]
    }
    Note
    • If an error is returned when calling the Distributed Cloud Container Platform for Kubernetes API, verify the request parameters and values against the error code.

    • Use the RequestID or SDK error message with OpenAPI problem diagnosis to troubleshoot the call.