Use the Enterprise Distributed Application Service (EDAS) SDK for Java to import Kubernetes clusters into EDAS and cancel cluster imports programmatically. After import, EDAS provides application-level management, release strategies, microservice governance, and CI/CD integration on top of your existing Kubernetes infrastructure.
Prerequisites
Before you begin, make sure you have:
EDAS SDK for Java installed. See Use EDAS SDK for Java to call EDAS API
The region ID where your Kubernetes cluster is deployed (for example,
cn-hangzhou)A Kubernetes cluster created in the Container Service for Kubernetes (ACK) console:
ACK managed or ACK dedicated clusters. See Create a managed Kubernetes cluster or Create an ACK dedicated cluster
ACK Serverless clusters. See Create an ACK Serverless cluster
A microservice namespace. See Create a microservice namespace
If a cluster or namespace already exists, retrieve its ID by calling the corresponding API operation:
Cluster ID: Call GetK8sCluster and use the
ClusterIdvalue from the response.Namespace ID: Call ListUserDefineRegion and use the
RegionIdvalue from the response.
Supported cluster types
EDAS supports importing the following ACK cluster types:
| ACK cluster type | EDAS cluster type after import |
|---|---|
| ACK dedicated cluster | ACK cluster |
| ACK managed cluster | ACK cluster |
| ACK Serverless cluster | ACK Serverless cluster |
| Hybrid cloud cluster (third-party or self-managed) | ACK cluster |
For a comparison of ACK cluster types, see What is ACK?
Register hybrid cloud clusters (Kubernetes clusters deployed on third-party clouds or self-managed clusters in data centers) in the ACK console before importing them to EDAS. See Create a cluster registration proxy and register a Kubernetes cluster.
What EDAS adds to Kubernetes
Importing a Kubernetes cluster into EDAS provides the following capabilities beyond standalone Kubernetes:
| Capability | Description |
|---|---|
| Application-level management | Manage Kubernetes workloads (deployments, pods) at the application level with cross-zone high-availability deployment |
| Release strategies | Perform phased and canary releases based on traffic ratio or request parameters, with full change tracking |
| CI/CD integration | Integrate with mainstream DevOps systems for continuous integration and delivery |
| Microservice governance | Run Spring Cloud and Dubbo applications commercially available in the past five years without code changes. Includes graceful shutdown, stress testing during release, service authentication, throttling, degradation, outlier ejection, and service query and testing |
| Production safety | Monitor releases end-to-end with release reports, configure canary release policies, and roll back with one click |
Import a Kubernetes cluster
Call the ImportK8sCluster operation to import a cluster into a specified microservice namespace.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ClusterId | String | Yes | The ID of the Kubernetes cluster to import |
NamespaceId | String | Yes | The target microservice namespace (for example, cn-hangzhou:doc) |
EnableAsm | Boolean | No | Whether to install a service mesh. true: install. false: skip |
Sample code
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.edas.model.v20170801.ImportK8sClusterRequest;
import com.aliyuncs.edas.model.v20170801.ImportK8sClusterResponse;
public class ImportK8sCluster {
public static void main(String[] args) {
// To avoid security risks, retrieve your AccessKey pair from environment variables
// instead of hardcoding them. Use a RAM user instead of your Alibaba Cloud account
// for least-privilege access.
String aliyun_user_ak = System.getenv("ACCESS_KEY_ID");
String aliyun_user_sk = System.getenv("ACCESS_KEY_SECRET");
// Replace with the region ID where your Kubernetes cluster is deployed
String region_id = "<region-id>";
DefaultProfile defaultProfile = DefaultProfile.getProfile(region_id, aliyun_user_ak, aliyun_user_sk);
DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
ImportK8sClusterRequest request = new ImportK8sClusterRequest();
request.setClusterId("<cluster-id>"); // Kubernetes cluster ID
request.setNamespaceId("<namespace-id>"); // Target microservice namespace
request.setEnableAsm(true); // Install a service mesh
try {
ImportK8sClusterResponse response = client.getAcsResponse(request);
System.out.println("Data=" + response.getData()
+ "\nMessage=" + response.getMessage()
+ "\nRequestId=" + response.getRequestId());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}Replace the following placeholders with your actual values:
| Placeholder | Description | Example |
|---|---|---|
<region-id> | Region ID where the cluster is deployed | cn-hangzhou |
<cluster-id> | Kubernetes cluster ID | da60f685-558a-4e00-b549-15e9143d**** |
<namespace-id> | Microservice namespace ID | cn-hangzhou:doc |
Sample response
Data=4d45f6db-2942-4747-a7ba-b0d43273****
Message=success
RequestId=847CF607-B352-4A71-828A-C0F8DECDEDF6Cancel a cluster import
Call the DeleteCluster operation to cancel a cluster import.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ClusterId | String | Yes | The ID of the Kubernetes cluster to remove from EDAS |
Sample code
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.edas.model.v20170801.DeleteClusterRequest;
import com.aliyuncs.edas.model.v20170801.DeleteClusterResponse;
public class DeleteCluster {
public static void main(String[] args) {
// To avoid security risks, retrieve your AccessKey pair from environment variables
// instead of hardcoding them. Use a RAM user instead of your Alibaba Cloud account
// for least-privilege access.
String aliyun_user_ak = System.getenv("ACCESS_KEY_ID");
String aliyun_user_sk = System.getenv("ACCESS_KEY_SECRET");
// Replace with the region ID where your Kubernetes cluster is deployed
String region_id = "<region-id>";
DefaultProfile defaultProfile = DefaultProfile.getProfile(region_id, aliyun_user_ak, aliyun_user_sk);
DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
DeleteClusterRequest request = new DeleteClusterRequest();
request.setClusterId("<cluster-id>"); // Kubernetes cluster ID to remove from EDAS
try {
DeleteClusterResponse response = client.getAcsResponse(request);
System.out.println("Data=" + response.getData()
+ "\nMessage=" + response.getMessage()
+ "\nRequestId=" + response.getRequestId());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}Sample response
Data=true
Message=success
RequestId=68CDDEC0-593E-4C1A-9CDC-96F9FEF0924EA Data value of true confirms the import was canceled.
Verify the result
After importing or canceling a cluster import, call the GetK8sCluster operation and check the ClusterImportStatus field in the response.
Sample response
{
"RequestId": "809FCC08-FFE1-417D-8ADF-F5D5BFD968D7",
"Message": "success",
"ClusterPage": {
"ClusterList": {
"Cluster": [
{
"ClusterImportStatus": 1,
"NodeNum": 6,
"ClusterId": "da60f685-558a-4e00-b549-15e9143d****",
......
},
{
"ClusterImportStatus": 0,
"NodeNum": 3,
"ClusterId": "6dca9bc0-b928-4f2c-ae76-396bd108****",
......
}
]
},
"PageSize": 12,
"CurrentPage": 0,
"TotalSize": 12
},
"Code": 200
}ClusterImportStatus values
| Value | Status |
|---|---|
| 0 | Not imported |
| 1 | Imported |
| 2 | Import failed |
| 3 | Importing |
| 4 | Deleted |
To confirm a successful import, verify that ClusterImportStatus is 1. To confirm a canceled import, verify that ClusterImportStatus is 0.