This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to import or delete a Kubernetes cluster by calling an API operation.

Prerequisites

Before you import or delete a Kubernetes cluster, make sure that the following prerequisites are met:
  • The region in which the Kubernetes cluster resides is obtained. For example, the Kubernetes cluster resides in the China (Hangzhou) region. The region ID is cn-hangzhou.
  • A Kubernetes cluster is created in the Container Service for Kubernetes (ACK) console.
    • To use a Container Service for Kubernetes (ACK) cluster in EDAS, create a managed Kubernetes cluster or a dedicated Kubernetes cluster in the Container Service for Kubernetes (ACK) console. For more information, see the following topics:
    • To use a serverless Kubernetes cluster in EDAS, create a serverless Kubernetes cluster in the Container Service for Kubernetes (ACK) console. For more information, see Create an ASK cluster.

    If you have created an ACK cluster or a serverless Kubernetes cluster, call the GetK8sCluster operation to query ACK clusters or serverless Kubernetes clusters. Obtain the ClusterId of the Kubernetes cluster, such as da60f685-558a-4e00-b549-15e9143d****.

  • A microservice namespace is created. For example, a microservice namespace with the ID of cn-hangzhou:doc is created. For more information, see Create a namespace.

    If a microservice namespace already exists, you can call the ListUserDefineRegion operation to query custom microservice namespace and obtain the value of the RegionId parameter for the microservice namespace that you want to use. For example, the value is cn-hangzhou:doc.

Features of Kubernetes clusters in EDAS

EDAS allows you to import the Dedicated Kubernetes clusters, Managed Kubernetes clusters, and Serverless Kubernetes clusters that you create in the Container Service for Kubernetes (ACK) console. For more information about the comparison among the three types of clusters, see What is Container Service for Kubernetes?.

Dedicated Kubernetes clusters and Managed Kubernetes clusters imported to EDAS correspond to Container Service Kubernetes clusters. Serverless Kubernetes clusters imported to EDAS correspond to Serverless Kubernetes clusters.

Hybrid cloud clusters including user-created clusters in other cloud domains or IDCs must be registered in the Container Service for Kubernetes (ACK) console and then imported to EDAS. Hybrid cloud clusters imported to EDAS correspond to Container Service Kubernetes clusters.

For more information about how to register a hybrid cloud cluster in Container Service for Kubernetes (ACK), see Create a cluster registration proxy and register an on-premises cluster.

Kubernetes clusters managed in EDAS have the following advantages over user-created Kubernetes clusters:
  • Based on cloud-native Kubernetes, EDAS provides the application hosting capability to implement open source microservice governance and light-weight O&M of Kubernetes applications from the application perspective.
    • From the application-centric perspective, EDAS manages Kubernetes-native workloads such as deployments and pods, and provides high-availability deployment of instances across zones.
    • EDAS provides phased release and canary release based on the traffic ratio and request parameters. EDAS monitors the entire change process and therefore makes your change records traceable.
    • EDAS integrates with mainstream DevOps systems to help enterprises implement continuous integration (CI) and continuous delivery (CD). This way, EDAS helps them reduce costs and improve efficiency.
  • EDAS supports three mainstream microservice frameworks, including Apache Dubbo (2.6.x and later), Spring Cloud (Edgware and later versions), and High-Speed Service Framework (HSF). User-created microservice-oriented applications based on these frameworks can be migrated to EDAS without code modification. The following microservice governance capabilities are supported for all the application frameworks:
    • Lossless shutdown and stress testing during application release
    • Service authentication, throttling and degradation, and outlier instance removal during the application runtime
    • Service query and testing in application O&M
  • Alibaba Cloud packages its idea of supporting observability, canary release, and rollback for application production security into services, and therefore allows you to immediately implement production security.
    • Observability: End-to-end monitoring in multiple dimensions is implemented based on application overview, release change records, and automatic generation of release reports.
    • Canary release: Canary release is supported for applications based on the traffic ratio or request content policy configuration.
    • Rollback: One-click rollback is supported during the release process, and running applications can be rolled back to an earlier version.

Import a Kubernetes cluster

The following code provides an example on how to import a Kubernetes cluster to the specified microservice namespace.

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)  {
        // The AccessKey ID of your Alibaba Cloud account or a RAM user within the Alibaba Cloud account. 
        String aliyun_user_ak = "<yourAccessKeyId>";
        // The AccessKey secret of your Alibaba Cloud account or a RAM user within the account. 
        String aliyun_user_sk = "<yourAccessKeySecret>";
        // The ID of the region in which the Kubernetes cluster resides. 
        String region_id = "cn-hangzhou";

        DefaultProfile defaultProfile = DefaultProfile.getProfile(region_id, aliyun_user_ak, aliyun_user_sk);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);

        // Create an API request and set the parameters. 
        ImportK8sClusterRequest request = new ImportK8sClusterRequest();
        // The ID of the Kubernetes cluster. 
        request.setClusterId("da60f685-558a-4e00-b549-15e9143d****");
        // The microservice namespace to which the Kubernetes cluster is imported. 
        request.setNamespaceId("cn-hangzhou:doc");
        // Specify whether to install a service mesh for the cluster. Valid values: true and false. A value of true indicates that a service mesh is installed. A value of false indicates that a service mesh is not installed. 
        request.setEnableAsm(true);


        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();
        }
    }
}
Run the code. The following result is returned:
Data=4d45f6db-2942-4747-a7ba-b0d43273****
Message=success
RequestId=847CF607-B352-4A71-828A-C0F8DECDEDF6

Delete a Kubernetes cluster

The following code provides an example on how to delete a Kubernetes cluster.

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)  {
        // The AccessKey ID of your Alibaba Cloud account or a RAM user within the Alibaba Cloud account. 
        String aliyun_user_ak = "<yourAccessKeyId>";
        // The AccessKey secret of your Alibaba Cloud account or a RAM user within the account. 
        String aliyun_user_sk = "<yourAccessKeySecret>";
        // The ID of the region in which the Kubernetes cluster resides. 
        String region_id = "cn-hangzhou";

        DefaultProfile defaultProfile = DefaultProfile.getProfile(region_id, aliyun_user_ak, aliyun_user_sk);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);

        // Create an API request and set the parameters. 
        DeleteClusterRequest request = new DeleteClusterRequest();
        // The ID of the Kubernetes cluster. 
        request.setClusterId("da60f685-558a-4e00-b549-15e9143d****");


        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();
        }
    }
}
Run the code. The following result is returned:
Data=true
Message=success
RequestId=68CDDEC0-593E-4C1A-9CDC-96F9FEF0924E

Verify the result

After you import or delete the Kubernetes cluster, call the GetK8sCluster operation to query ACK clusters or serverless Kubernetes clusters. You can determine whether the import or deletion is successful based on the value of the ClusterImportStatus parameter in the return result.

Sample response that is returned after you call the GetK8sCluster operation:
{
  "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
}
Check the value of the ClusterImportStatus parameter in the proceeding result. You can determine whether the import or deletion of the Kubernetes cluster is successful. Valid values:
  • 0: The cluster is not imported.
  • 1: The cluster is imported.
  • 2: The cluster fails to be imported.
  • 3: The cluster is being imported.
  • 4: The cluster is deleted.