All Products
Search
Document Center

Container Compute Service:Create a ClusterIP service

Last Updated:Dec 03, 2025

In Kubernetes, pods are created and deleted rapidly, and their IP addresses are not fixed. This makes them unsuitable for directly providing services. A Service provides a stable IP address that allows external clients (the frontend) to access backend pods without knowing their specific IP addresses. This decouples the frontend from the backend and ensures service stability. This topic describes how to create a ClusterIP service in the console.

Background information

In Kubernetes, a Service is an abstraction that defines a logical set of pods and a policy that is used to access the pods. This pattern is known as a microservice. A label selector is used to determine which set of pods is accessed by a Service.

Each pod in Kubernetes clusters has its own IP address. However, pods are frequently created and deleted. Therefore, directly exposing pods to external access does not comply with the rules for ensuring high availability. Services decouple the frontend from the backend. The frontend clients do not need to be aware of which backend pods are used. This provides a loosely decoupled microservices architecture.

For more information, see Kubernetes Services.

Step 1: Create a deployment

  1. Log on to the ACS console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, find the cluster that you want to manage and click its ID. In the left-side navigation pane of the cluster details page, choose Workloads > Deployments.

  3. On the Deployments page, click Create from YAML.

  4. Select a sample template or a custom template and then click Create.

    This sample template is for an Nginx deployment.

    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: 80
  5. On the Deployments page, click the name of the target application or Details in the Actions column to view the status of the deployment. Wait for all pod instances to become available.

Step 2: Create a service

  1. On the Clusters page, find the cluster that you want to manage and click its ID. In the left-side navigation pane of the cluster details page, choose Network > Services.

  2. On the Services page, click Create. In the Create Service dialog box, configure the 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. If you select this type, the service is accessible only from within the cluster. This is the default service type.

    Note

    You can enable Headless Service as needed. After you enable this feature, you can use the headless service to interface with other service discovery mechanisms without being tied to the Kubernetes implementation.

    Cluster IP

    Backend

    Select the backend application to which you want to attach the service. If you do not associate the service with a backend, no Endpoint object is created. For more information about service association, see services-without-selectors.

    • Name: app

    • Value: nginx

    Port Mapping

    Add a service port (which corresponds to port in the Service YAML file) and a container port (which corresponds to targetPort in the Service YAML file). The container port must be the same as the port exposed by the backend pod.

    • Service Port: 80

    • Container Port: 80

    • Protocol: TCP

    Annotations

    Add an annotation to the service.

    None

    Label

    Add 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.