Call an ACK API operation with Java SDK
This topic explains how to use the SDK to call an OpenAPI operation and create an ACK managed cluster.ACK managed cluster.
Step 1: Review the API documentation
Before calling, review Create an ACK managed cluster by using an OpenAPI operation for required parameters and permissions. See API overview for parameter details.
Step 2: Create a RAM user and grant permissions
Call this operation with an Alibaba Cloud account, RAM user, or RAM role. See identity for the differences.
An Alibaba Cloud account has access to all APIs. For security, create and use a RAM user for API calls and daily operations.
-
-
Log on to the RAM console with your Alibaba Cloud account.
-
In the left-side navigation pane, choose .
-
On the User page, click Create User.
-
On the Create User page, set Logon Name and Display Name, and select Console Password Logon for Access Method.
-
Click OK.
After creation, record the logon name and password for logging on to the OpenAPI Developer Portal.
-
-
Grant AliyunCSFullAccess to the RAM user. See Manage permissions for a RAM user.
NoteAliyunCSFullAccess: Full access to Container Service for Kubernetes.
AliyunCSReadOnlyAccess: Read-only access to Container Service for Kubernetes.
To create a custom policy, see Authorization information.
-
On the RAM user's details page, go to the Authentication tab and click Create AccessKey. See Create an AccessKey.
Step 3: Call the API
This example calls CreateCluster as a RAM user with Java SDK to create an ACK Pro cluster. For other languages, see Container Service for Kubernetes (ACK) SDK. For alternative calling methods, see Methods for calling an operation.
Configure environment variables
Configure environment variables for credentials before calling. See Configure environment variables on Linux, macOS, and Windows.
Download the SDK sample code
-
Go to CreateCluster.
-
In the Parameters section, specify the required parameters and click Initiate Call.
-
Example value for name: test
-
Example value for region_id: cn-beijing
-
Example value for cluster_type: ManagedKubernetes
-
Example value for cluster_spec: ack.pro.small
-
Example value for cluster_version: 1.30.1-aliyun.1
-
Example value for vpcid: vpc-2zedl8cyb7tnkaux1****
-
Example value for container_cidr: 10.0.0.0/8
-
Example value for service_cidr: 172.21.0.0/20
-
Example value for vswitch_ids: vsw-2ze7hfp0ah8rk1nz9****
-
-
On the SDK Sample tab, select SDK version 2.0 and your language, then click Download Project. Decompress the downloaded package locally.
NoteUse SDK V2.0. See Differences between SDK V1.0 and SDK V2.0 for version comparison.
After specifying parameters such as
name,region_id,cluster_type,cluster_spec, andcluster_versionon the Parameters tab, the code pane automatically generates sample code for the selected language.
Run the SDK sample code
-
Open IntelliJ IDEA. Go to File > Open, select the project folder, and wait for Maven to install dependencies.
-
Run the sample code.
Double-click the Sample file, verify no errors appear, and run it.
-
View the result.
In the bottom console, find
statusCode."statusCode": 202indicates the call succeeded and cluster creation has begun. View the new cluster on the Clusters page of the ACK console.
{ "headers": { "content-type": "application/json;charset=utf-8", "access-control-expose-headers": "*", "x-acs-trace-id": "30c74bc83a7fae0a081e5f5846be703e" }, "statusCode": 202, "body": { "clusterId": "c6104ee21d6304ef8..." } }