When multiple applications run in the same Kubernetes cluster, their pods need stable endpoints to communicate. Pods have independent IP addresses, but they are quickly created and deleted, making direct connections unreliable. A Kubernetes Service provides a fixed network endpoint that routes traffic to pods, regardless of pod lifecycle changes.
Add a Service to an application deployed in Enterprise Distributed Application Service (EDAS) to expose the application within or outside the cluster.
How Services work
An application deployed in a Container Service for Kubernetes (ACK) cluster through EDAS runs as a group of pods sharing the same Docker image. Each pod has its own IP address, but pods are quickly created and deleted. A Kubernetes Service solves this problem by providing a stable endpoint that automatically routes traffic to pods. Services also decouple frontends from backends, enabling a loosely coupled microservices architecture.
Service types
EDAS supports two Service types:
| Type | Access scope | Use case |
|---|---|---|
| ClusterIP (default) | Internal to the cluster only | Services within the same cluster need to communicate with each other |
| NodePort | External access at <NodeIP>:<NodePort> | External systems or users need to access the application by using the IP address and a port of a node |
ClusterIP: Exposes the application on an internal cluster IP address. Only workloads inside the same cluster can reach this Service. Use a ClusterIP Service when application services inside the cluster need to access each other, because they cannot communicate through an Internet-facing or internal-facing SLB instance.
NodePort: Exposes the application on a static port across every node in the cluster. Kubernetes automatically creates a backing ClusterIP Service and routes NodePort traffic to it.
You can also use an Internet-facing Server Load Balancer (SLB) instance or an internal-facing SLB instance to expose the application.
Prerequisites
Before you begin, make sure that you have:
An application deployed in a Kubernetes cluster in EDAS
Access to the EDAS console
Add a Service to an application
Log on to the EDAS console.
In the left-side navigation pane, choose Application Management > Applications.
In the top navigation bar, select a region and a Microservices Namespace. From the Cluster Type drop-down list, select Kubernetes Cluster. Click the name of the target application.
On the Application Overview page, in the Access configuration section, click the
icon next to service.NoteIf a Service already exists, its name and IP address are displayed. Click the
icon to modify the port or protocol, or click the
icon to remove the Service.In the Service dialog box, configure the following parameters and click OK.
Parameter
Description
Service Name
A unique name for the Service. The name must be 2 to 32 characters in length and can contain lowercase letters, digits, and hyphens (-). It must start with a letter and end with a letter or a digit.
Service Type
The access scope of the Service. Valid values:
Cluster IP: Exposes the Service on an internal cluster IP address. The Service is accessible only from within the cluster. This is the default value.
Node Port: Exposes the Service on a static port on every node. External clients connect at
<NodeIP>:<NodePort>. A ClusterIP Service is created automatically to back this NodePort Service.
External Traffic Policy
Controls how traffic from outside the cluster is distributed to pods. Valid values:
Local: Routes traffic only to pods on the node where the Service is deployed.
Cluster: Routes traffic to pods on other nodes in the cluster.
Service Port
The port on which the Service listens. Other services or external clients use this port to connect. Valid values: 1 to 65535.
Container Port
The port on which the application process listens inside the container. This port is defined by the application. Valid values: 1 to 65535.
Node Port
The port on each node used to expose the Service externally. This port is defined by the application. Valid values: 30000 to 32767. This parameter is available only when Service Type is set to Node Port.
Protocol
The transport protocol. Valid values: TCP (default), UDP.
Port mapping rules
A single Service supports multiple port mappings. To assign different port mappings to different Service names, repeat steps 4 and 5 to create additional Services.
When adding multiple port mappings to the same Service, each mapping must have a unique combination of Service port and protocol. For example,
80|8080|TCPand80|8081|TCPcannot be saved because both mappings share the same Service port (80) and protocol (TCP), and the message "Port mapping has duplicate entries" appears.
Verify the result
After adding the Service, verify connectivity by accessing the application from within the cluster using the Service IP address.
The following example tests a web application. Verification steps for other application types may differ.
Log on to the ACK console.
In the left-side navigation pane, click Clusters.
On the Clusters page, find the target cluster and choose in the Actions column.
Cloud Shell opens automatically at the bottom of the page and loads the kubeconfig file for the cluster.
List all pods in the cluster:
kubectl get podsSample output:
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 28hOpen a shell session in one of the pods:
Replace
<pod-name>with an actual pod name from the output, for example:kubectl exec -it <pod-name> /bin/shkubectl exec -it store-prod-***duct-group-1-1-****7f894-zh*** /bin/shSend a request to the Service IP address and port:
Replace
<service-ip>and<service-port>with the actual values. For example:wget <service-ip>:<service-port>wget 10.XX.XX.XX:8081If the connection succeeds, output similar to the following is returned:
Connecting to 10.XX.XX.XX:8081 (10.XX.XX.XX:8081) index.html 100% |*******************************************************| 2203 0:00:00 ETA
This example verifies a web application. For other application types, the output and verification method differ depending on the service.