All Products
Search
Document Center

Enterprise Distributed Application Service:Create a Java application from an image by calling an API operation

Last Updated:Mar 11, 2026

When you need to automate container deployments or integrate application creation into CI/CD pipelines, the Enterprise Distributed Application Service (EDAS) console is insufficient. The InsertK8sApplication API operation, called through the EDAS SDK for Java, lets you programmatically deploy a Java application from a container image to a Kubernetes cluster managed by EDAS.

Quick start

The following Java snippet creates an application from a container image on a Kubernetes cluster in EDAS. Replace the placeholder values with your actual configuration.

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) {
        // Retrieve credentials from environment variables.
        String aliyun_user_ak = System.getenv("ACCESS_KEY_ID");
        String aliyun_user_sk = System.getenv("ACCESS_KEY_SECRET");
        String region_id = "cn-hangzhou";

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

        InsertK8sApplicationRequest request = new InsertK8sApplicationRequest();
        request.setAppName("edas-SDK0311image");
        request.setClusterId("da60f685-558a-4e00-b549-15e9143d****");
        request.setReplicas(2);
        request.setLimitCpu(0);
        request.setLimitMem(0);
        request.setRequestsCpu(0);
        request.setRequestsMem(0);
        request.setLogicalRegionId("cn-hangzhou:doc");
        request.setRepoId("image-demo-project");
        request.setImageUrl("registry-vpc.cn-hangzhou.aliyuncs.com/image-demo-project/provider:1.0");

        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();
        }
    }
}

Expected output:

AppId=d8130adc-2298-49ea-9c64-f19165fa****
AppName=edas-SDK0311image

For parameter details, see the step-by-step walkthrough below. For the full parameter list, see InsertK8sApplication.

Prerequisites

Before you begin, ensure that you have:

Note

To look up an existing namespace or cluster, call ListUserDefineRegion for the namespace RegionId or ListCluster for the ClusterId.

Step 1: Configure the SDK client

Initialize a DefaultAcsClient with your AccessKey credentials and target region. Store credentials in environment variables to keep them out of source 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.InsertK8sApplicationRequest;
import com.aliyuncs.edas.model.v20170801.InsertK8sApplicationResponse;

public class InsertK8sApplication {

    public static void main(String[] args) {
        // Retrieve credentials from environment variables.
        // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations.
        // For production workloads, use a Resource Access Management (RAM) user with
        // least-privilege permissions instead.
        String aliyun_user_ak = System.getenv("ACCESS_KEY_ID");
        String aliyun_user_sk = System.getenv("ACCESS_KEY_SECRET");

        // Replace with your target region ID
        String region_id = "cn-hangzhou";

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

Step 2: Build the deployment request

Create an InsertK8sApplicationRequest and set the required parameters: application name, cluster ID, replica count, resource quotas, namespace, and image URL.

        // Build the request
        InsertK8sApplicationRequest request = new InsertK8sApplicationRequest();

        // Application name
        request.setAppName("edas-SDK0311image");

        // Cluster ID of the target Kubernetes cluster
        request.setClusterId("da60f685-558a-4e00-b549-15e9143d****");

        // Number of application instances
        request.setReplicas(2);

        // CPU and memory quotas. Value 0 means no quota is enforced.
        request.setLimitCpu(0);
        request.setLimitMem(0);
        request.setRequestsCpu(0);
        request.setRequestsMem(0);

        // Microservice namespace ID. Omit this parameter to use the default namespace.
        request.setLogicalRegionId("cn-hangzhou:doc");

        // Image repository name and full image address
        request.setRepoId("image-demo-project");
        request.setImageUrl("registry-vpc.cn-hangzhou.aliyuncs.com/image-demo-project/provider:1.0");

Replace the values in the code with your actual configuration:

ParameterDescriptionExample
AppNameApplication nameedas-SDK0311image
ClusterIdTarget Kubernetes cluster IDda60f685-558a-4e00-b549-15e9143d****
ReplicasNumber of application instances2
LimitCpuMaximum CPU cores per instance. 0 disables the limit.0
LimitMemMaximum memory (MiB) per instance. 0 disables the limit.0
RequestsCpuReserved CPU cores per instance. 0 means no reservation.0
RequestsMemReserved memory (MiB) per instance. 0 means no reservation.0
LogicalRegionIdMicroservice namespace ID. Omit to use the default namespace.cn-hangzhou:doc
ImageUrlFull image address including registry, namespace, repository, and tagregistry-vpc.cn-hangzhou.aliyuncs.com/image-demo-project/provider:1.0
RepoIdImage repository nameimage-demo-project
Important

Setting LimitCpu and LimitMem to 0 disables resource quotas. This is acceptable for testing but not for production. For production deployments, set appropriate CPU and memory limits to prevent resource contention.

This example omits advanced parameters such as scheduling rules, startup commands, and environment variables. For the full parameter list, see InsertK8sApplication.

Step 3: Submit the request and check the response

Send the request to EDAS. On success, EDAS creates a change order that schedules application instances on the target cluster, pulls the specified image, and starts the containers. The response returns the AppId and AppName of the newly created application.

        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();
        }
    }
}

Expected output:

AppId=d8130adc-2298-49ea-9c64-f19165fa****
AppName=edas-SDK0311image

Step 4: Verify the deployment

After submitting the deployment request, call GetChangeOrderInfo to track the change order progress. For parameter details, see GetChangeOrderInfo.

The changeOrderInfo.Status field indicates the deployment state:

Status valueMeaning
0Ready
1In progress
2Successful
3Failed
6Terminated
8Waiting for manual trigger (manual phased release)
9Waiting for automatic trigger (automatic phased release)
10Failed due to system exception

Sample response (abbreviated):

{
    "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"
                }
            ]
        }
    }
}
Note

If changeOrderInfo.Status returns 3 (failed), check the TaskMessage field for error details and troubleshoot the issue before retrying the deployment.

Related information