All Products
Search
Document Center

Enterprise Distributed Application Service:Add a Service

Last Updated:Jul 13, 2023

This topic describes how to add a Service to an application to enable communication between application services in a cluster.

Background information

An application that is deployed in a Container Service for Kubernetes (ACK) cluster in Enterprise Distributed Application Service (EDAS) usually consists of a group of pods that run the same docker image. These pods have independent IP addresses, but they are quickly created and deleted. Therefore, you cannot access the application by accessing pods that may be deleted one after one.

Services decouple the frontend from the backend, which provides a loosely-coupled microservices architecture.

If you deploy an application in a Kubernetes cluster in EDAS, you can use an Internet-facing Server Load Balancer (SLB) instance or an internal-facing SLB instance to expose the application. You can also add a Service of the NodePort type to the application to enable external access by using the IP address and a port of a node. After multiple application services are created in the same Kubernetes cluster in EDAS, the application services inside the cluster may need to access each other. However, the application services cannot access each other by using an Internet-facing or internal-facing SLB instance. In this case, you can add a Service of the ClusterIP type to enable internal communication in the cluster.

Procedure

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, choose Application Management > Applications. In the top navigation bar, select a region. In the upper part of the page, select a microservice namespace. From the Cluster Type drop-down list, select Kubernetes Cluster. Then, find the application that you want to manage and click the name in the Application Name column.

  3. On the Application Overview page, click the Plus icon icon next to service in the Access configuration section.
    Note If you have configured a Service, the Service name and IP address are displayed. You can click the Edit icon icon to change the port and protocol type of the Service, or click the Delete icon to remove the Service.
  4. In the Service dialog box, set the parameters as required and click OK.
    ParameterDescription
    Service NameThe name of the Service. The Service name must be unique.

    The name must be 2 to 32 characters in length and can contain lowercase letters, digits, and hyphens (-). The name must start with a letter and end with a letter or a digit.

    Service Type
    • The type of the Service. Valid values: Cluster IP: a ClusterIP Service. This type of Service exposes application services by using the internal IP address of the cluster. This is the default value. If you select this option, application services are accessible only from within the cluster.
    • Node Port: a NodePort Service. This type of Service exposes application services by using the IP address and a static port of each node. A NodePort Service can be used to route requests to a ClusterIP Service, which is automatically created by the system. You can access a NodePort Service from outside the cluster by sending requests to <NodeIP>:<NodePort>.
    External Traffic Policy
    • The policy to distribute external traffic. Valid values: Local: This policy routes traffic only to pods on the node where the Service is deployed.
    • Cluster: This policy can route traffic to pods on other nodes in the cluster.
    Service PortThe frontend port of the Service. The application is accessed by using this port. Valid values: 1 to 65535.
    Container PortThe port on which a process listens. This port is defined by the application. Valid values: 1 to 65535.
    Node PortThe port used by the node to expose the Service. This port is defined by the application. Valid values: 30000 to 32767.
    Note This parameter is available if you set the Service Type parameter to NodePort.
    ProtocolThe Service protocol. Valid values: TCP and UDP. Default value: TCP.
    Note
    Take note of the following two items when you add a Service to an application:
    • You can add multiple port mappings for the same Service. However, if you need to set different port mappings to different Service names, repeat Step 3 to Step 4 to add multiple Services.
    • When you add multiple port mappings for the same Service, set both Service ports and protocols to different values for the port mappings. For example, if you set two port mappings to 80|8080|TCP and 80|8081|TCP, the two port mappings cannot be saved, and the message Port mapping has duplicate entries appears.

Verify the result

After you add a Service to the current application, you can log on to a pod in the ACK cluster and access the application by using the fixed IP address of the Service in the pod.

The following example verifies access to a web application service. The methods of verifying access to services of other types are different.

  1. Log on to the ACK console.
  2. In the left-side navigation pane, click Clusters.
  3. On the Clusters page, find the cluster that you want to manage and choose More > Open Cloud Shell in the Actions column.
    Cloud Shell that is associated with the cluster is automatically opened in the lower part of the page. When Cloud Shell that is associated with the cluster is opened, the system automatically loads the kubeconfig file of the cluster. Then, you can use kubectl to manage the cluster.
  4. Run the following command to query all the pods in the cluster:
    kubectl get pods
    The following pods are returned:
    NAME                                             READY   STATUS             RESTARTS   AGE
    store-pre-****-group-1-19-****7569b-f7***        1/1     Running            0          28h
    store-prod-***duct-group-1-1-****7f894-zh***     1/1     Running            0          28h
  5. Run the following command to log on to one of the returned pods:
    kubectl exec -it store-prod-***duct-group-1-1-****7f894-zh*** /bin/sh
  6. Run the following command to access the application by using the fixed IP address of the Service:
    wget 10.XX.XX.XX:8081    // The IP address and port must be consistent with those of your Service. 
    A log that is similar to the following one is returned:
    Connecting to 10.XX.XX.XX:8081 (10.XX.XX.XX:8081)
    index.html           100% |*******************************************************|  2203  0:00:00 ETA
    Note This example verifies access to a sample web service. If you verify access to a service of another type, the returned logs are different and vary based on the service type.