All Products
Search
Document Center

Enterprise Distributed Application Service:Add labels to application pods

Last Updated:Mar 06, 2024

In a microservices model, a Kubernetes cluster may contain many applications. Each application may have multiple versions. In this case, a large number of pods may exist in the cluster. You can configure labels in the name-value format in the Enterprise Distributed Application Service (EDAS) console for applications to identify application pods. Then, you can search for application pods by label, which simplifies application management. This topic describes how to configure labels for application pods when you create or deploy applications.

Procedure

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, click Application Management > Applications. In the top navigation bar, select a region. In the upper part of the page, select a namespace. Select Container Service or Serverless Kubernetes Cluster from the Cluster Type drop-down list. Then, find the application that you want to deploy and click the application name.

  3. In the upper-right corner of the Application Overview page, choose Deploy > Deploy.

  4. On the Select Deployment Mode page, select a deployment mode and click Start Deployment in the upper-right corner of the deployment mode section.

    Note

    In this example, the Release to All at Once mode is used.

  5. On the Release to All at Once page, modify the deployment parameter settings, click Label Configuration, and then configure name-value pairs. Click OK.

    Note

    You must specify the name of the application as the value in the name-value pairs.

    After the application is deployed, run the following kubectl command to search for pods by specified labels.

    kubectl get pod -l demo-app-name=sc-server-demo

    A command output similar to the following one appears:

    NAME                                        READY   STATUS    RESTARTS   AGE
    sc-server-demo-group-1-1-5795d5487c-****   2/2     Running   0          2m58s

Configure pod affinity by using labels

When you deploy applications in Kubernetes clusters, you must take the dependencies between different components into account. For example, you can schedule specific pods to the same topology domain, but you cannot schedule other pods to the same topology domain. In this case, you can configure custom pod affinity or pod anti-affinity by using labels. The following section describes how to use labels to implement pod affinity.

Prerequisites

An application to which you add the demo-app-name=sc-server-demo label is deployed.

Procedure

The following steps describe how to configure pod affinity for another application and then schedule the pods of the two applications to the same node.

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, click Application Management > Applications. In the top navigation bar, select a region. In the upper part of the page, select a namespace. Select Container Service or Serverless Kubernetes Cluster from the Cluster Type drop-down list. Then, find the application that you want to deploy and click the application name.

  3. In the upper-right corner of the Application Overview page, choose Deploy > Deploy.

  4. On the Select Deployment Mode page, select a deployment mode and click Start Deployment in the upper-right corner of the deployment mode section.

    Note

    In this example, the Release to All at Once mode is used.

  5. On the Release to All at Once page, modify the application environment and deployment package, and click Scheduling Rules.

    In the Select a mode field, select Custom Configuration. On the Pod Affinity tab, create scheduling rules and perform the following configurations:

    • Select kubernetes.io/hostname in the Topology Key field.

    • Enter demo-app-name in the Application Tag Key field.

    • Select In in the Operator field.

    • Enter sc-server-demo in the Application Tag Value field.

  6. Click Label Configuration and configure the demo-app-name=sc-client-demo name-value pair. Then, click OK.

    After the application is deployed, run the following kubectl commands to query the node on which the two application pods reside:

    kubectl get pod -l demo-app-name=sc-client-demo -o wide
    kubectl get pod -l demo-app-name=sc-server-demo -o wide

    A command output similar to the following one appears:

    NAME                                        READY   STATUS    RESTARTS   AGE   IP            NODE                          NOMINATED NODE   READINESS GATES
    sc-client-demo-group-1-1-5c5cbb9889-****   2/2     Running   0          24s   10.85.***.*4   cn-hangzhou.192.168.AAA.BBB   <none>           <none>
    NAME                                        READY   STATUS    RESTARTS   AGE   IP            NODE                          NOMINATED NODE   READINESS GATES
    sc-server-demo-group-1-1-5795d5487c-****   2/2     Running   0          35m   10.85.***.*3   cn-hangzhou.192.168.AAA.BBB   <none>           <none>

    The command output indicates that the two application pods reside on the same node.

What to do next

When you deploy applications, you can create scheduling rules on the Pod Affinity tab and Pod Anti-affinity tab. For more information, see Configure scheduling rules.