This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to create a multilingual application in a Kubernetes cluster by calling an API operation.
Prerequisites
- 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.
- The cluster in which you want to create an application is imported to the microservice namespace. For example, the ID of the cluster is da60f685-558a-4e00-b549-15e9143d****. For more information, see Import a Kubernetes cluster.
If a cluster has been imported to the microservice namespace, you can call the ListCluster operation to query clusters and obtain the ID of the cluster in which you want to create an application.
- A multilingual application image is stored in the image repository that you want to use. For example, the ID of the image repository is image-demo-project, and the address of the image is registry-vpc.cn-hangzhou.aliyuncs.com/image-demo-project/productpage-python:v1.
Create a multilingual application
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.InsertK8sApplicationRequest;
import com.aliyuncs.edas.model.v20170801.InsertK8sApplicationResponse;
public class InsertK8sApplication {
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 Alibaba Cloud account.
String aliyun_user_sk = "<yourAccessKeySecret>";
// The ID of the region in which you want to create an application.
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.
InsertK8sApplicationRequest request = new InsertK8sApplicationRequest();
// The name of the application. The name must start with a letter and can contain digits, letters, and hyphens (-). The name must be 1 to 36 characters in length.
// In this example, the application name is set to Productpage. The application name must be unique within the microservice namespace.
request.setAppName("Productpage");
// The ID of the cluster.
request.setClusterId("da60f685-558a-4e00-b549-15e9143d****");
// The number of instances for the application.
request.setReplicas(2);
// The CPU quota and memory quota for application instances. A value of 0 indicates that no quotas are set.
request.setLimitCpu(0);
request.setLimitMem(0);
request.setRequestsCpu(0);
request.setRequestsMem(0);
// The ID of the EDAS microservice namespace. Set this parameter if you do not want to use the default microservice namespace.
request.setLogicalRegionId("cn-hangzhou:doc");
// The ID of the image repository and the address of the image.
request.setImageUrl("registry-vpc.cn-hangzhou.aliyuncs.com/image-demo-project/productpage-python:v1");
request.setRepoId("image-demo-project");
try {
InsertK8sApplicationResponse response = client.getAcsResponse(request);
System.out.println("AppId=" + response.getApplicationInfo().getAppId() + "\nAppName=" + response.getApplicationInfo().getAppName());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}
AppId=3a2a3a70-fcb2-491c-a8cf-fd68097a****
AppName=Productpage
Verify the result
After you create the application, you can call the GetChangeOrderInfo operation to view the change details and obtain the change status of the application. For more information about the API operation, see GetChangeOrderInfo.
{
"Message": "success",
"RequestId": "C26DBA1C-9A38-442D-A4D5-587515C5E522",
"Code": 200,
"changeOrderInfo": {
"Status": 3,
"Desc": "Version: 20210423:1442 | Package Name: sc-provider-D-0.0.1-SNAPSHOT.jar",
"PipelineInfoList": {
"PipelineInfo": [
{
......
"TaskMessage": "Apply success. <br>application is ready at desired state, version: 1"
......
// The sample response is incomplete and is only for reference.
- 0: ready
- 1: in progress
- 2: successful
- 3: failed
- 6: terminated
- 8: wait for manual confirmation to trigger the next phase during a manual phased release
- 9: wait to trigger the next phase during an automatic phased release
- 10: failed due to a system exception