When backend pods are replaced, rescheduled, or scaled, their IP addresses change. A frontend application that connects directly to pod IPs loses connectivity every time this happens. A Service solves this by providing a stable virtual IP that routes traffic to healthy backend pods, regardless of which specific pods are running.
This topic shows how to create a ClusterIP Service in the ACS console. ClusterIP exposes the Service on a cluster-internal IP address, making it accessible only from within the cluster. It is the default Service type.
Prerequisites
Before you begin, ensure that you have:
An Alibaba Cloud Container Service (ACS) cluster
Access to the ACS console
What you'll do
Create an Nginx Deployment with two replicas.
Create a ClusterIP Service that routes traffic to the Deployment.
Step 1: Create a Deployment
Log on to the ACS console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster you want to manage and click its ID. In the left-side navigation pane of the cluster details page, choose Workloads > Deployments.
On the Deployments page, click Create from YAML.
Select a sample template or a custom template, then click Create. The following YAML creates an Nginx Deployment with two replicas:
apiVersion: apps/v1 kind: Deployment metadata: name: my-nginx-svc namespace: default spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginxdemos:latest ports: - containerPort: 80On the Deployments page, click the application name or Details in the Actions column, and wait for all pod instances to become available.
Step 2: Create a ClusterIP Service
In the left-side navigation pane of the cluster details page, choose Network > Services.
On the Services page, click Create. In the Create Service dialog box, configure the following parameters and click OK.
Parameter Description Example Name The name of the Service. my-nginx-svc Service Type Select Cluster IP. This type exposes the Service on a cluster-internal IP address, making it accessible only from within the cluster. It is the default Service type. To use a Headless Service — for example, to integrate with a custom service discovery mechanism — enable Headless Service. Cluster IP Backend The backend application to attach to the Service. A label selector matches backend pods. If you do not associate the Service with a backend, no Endpoint object is created. For more information, see Services without selectors. Name: app, Value: nginx Port Mapping The service port ( portin the Service YAML) and the container port (targetPortin the Service YAML). The container port must match the port exposed by the backend pod.Service Port: 80, Container Port: 80, Protocol: TCP Annotations An annotation to add to the Service. None Label A label to identify the Service. None After the Service is created, you can find it on the Services page and click Update, Edit YAML, or Delete in the Actions column.
For more information about Kubernetes Services, see Kubernetes Services.