All Products
Search
Document Center

Container Service for Kubernetes:Java SDK call example

Last Updated:Mar 25, 2026

This topic describes how to use the Container Service for Kubernetes (ACK) SDK to call the ACK API to create an ACK managed cluster.

Prerequisites

Before you begin, ensure that you have:

  • An Alibaba Cloud account or RAM user — The calling identity must have API access. An Alibaba Cloud account has full access to all API operations; use a RAM user for routine O&M. For details, see Identity.

  • The AliyunCSFullAccess permission — Grant this policy to the RAM user that calls the API. For read-only access, grant AliyunCSReadOnlyAccess instead.

  • An AccessKey pair — Create one on the Authentication tab of the RAM user details page. For instructions, see Create an AccessKey pair.

  • Java and IntelliJ IDEA — Required to run the SDK demo project downloaded from OpenAPI Explorer.

  • Maven — The demo project uses Maven to manage dependencies.

Step 1: Read the API reference

Before calling the API, read Create an ACK managed cluster to understand the required and optional parameters. For a full list of ACK API operations, see List of operations by function.

Step 2: Set up a RAM user

Skip this step if you already have a RAM user with the AliyunCSFullAccess permission and an AccessKey pair.

  1. Create a RAM user. Log on to the RAM console with your Alibaba Cloud account.

  2. In the left-side navigation pane, choose Identities > Users.

  3. On the Users page, click Create User.

  4. On the Create User page, configure Logon Name and Display Name, and set Access Mode to Console Access.

  5. Click OK. Record the username and password — you will use these to log on to OpenAPI Explorer console.

  6. Grant the AliyunCSFullAccess permission to the RAM user. For instructions, see Grant permissions to a RAM user.

    Note

    AliyunCSFullAccess provides full permissions on Container Service for Kubernetes. AliyunCSReadOnlyAccess provides read-only access. For custom permission policies, see RAM authorization.

  7. On the user details page, click the Authentication tab, then click Create AccessKey to generate an AccessKey pair.

Step 3: Call the API

This example uses ACK SDK for Java to call the CreateCluster API operation and create an ACK Pro cluster. SDKs for other languages work the same way. For a full list of supported SDKs, see Container Service for Kubernetes SDK. For alternative call methods, see Call methods.

Configure environment variables

Store your AccessKey credentials as environment variables rather than hardcoding them in source code. For setup instructions, see Configure environment variables in Linux, macOS, and Windows.

Download the SDK demo

  1. Go to the CreateCluster API Explorer.CreateCluster

  2. On the Parameters tab, enter the following sample values and click Initiate Call:

    ParameterSample value
    nametest
    region_idcn-beijing
    cluster_typeManagedKubernetes
    cluster_specack.pro.small
    cluster_version1.30.1-aliyun.1
    vpcidvpc-2zedl8cyb7tnkaux1****
    container_cidr10.0.0.0/8
    service_cidr172.21.0.0/20
    vswitch_idsvsw-2ze7hfp0ah8rk1nz9****
  3. On the SDK Sample Code tab, select version 2.0, choose Java as the language, and click Download Project. Extract the downloaded package to your local machine.

    Note

    Use SDK version 2.0. For a comparison of version 1.0 and 2.0, see Alibaba Cloud SDK V1.0 and V2.0.

    image

Run the SDK demo

  1. Open IntelliJ IDEA, choose File > Open, and select the extracted project folder. Wait for Maven to finish installing dependencies.

  2. Double-click Sample to open the entry class. Confirm no errors are shown, then run the sample code.

  3. In the console output at the bottom of the IDE, search for statusCode. A response containing "statusCode":202 means the API call succeeded and ACK is creating the cluster.

    image

  4. To confirm the cluster is being created, log on to the ACK console and go to the Clusters page to view the newly created cluster.