All Products
Search
Document Center

Container Compute Service:Expose an application using a Service

Last Updated:Jun 17, 2026

In Kubernetes, Pods are ephemeral and their IP addresses are not stable. A Service provides a stable IP address and routes traffic to a logical set of backend Pods, decoupling clients from individual Pod lifecycles. You can create and expose a Service by using the ACS console or the kubectl CLI.

Method 1: Create a service using the console

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

  2. On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Network > Services.

  3. On the Services page, click Create. In the Create Service dialog box, configure the parameters for the service.

    Parameter

    Description

    Example

    Name

    The name of the service.

    my-nginx-svc

    Service Type

    The access method for the service. The following types are available:

    • Cluster IP: Exposes the service on a cluster-internal IP address. The service is accessible only from within the cluster.

      Note

      When you select Cluster IP, you can configure a Headless Service. You can use a Headless Service to integrate with other service discovery mechanisms without being tied to the Kubernetes implementation.

    • Server Load Balancer: Uses an Alibaba Cloud Classic Load Balancer (CLB) instance to expose the service. You can select Public Access or Internal Access. The CLB routes traffic to the service's ClusterIP.

      • Create Resource: If you select Pay-by-specification, you can click Change Specification to modify the CLB specification.

      • Use Existing Resource: You can select an existing CLB instance from the list.

      Note
      • Using an existing CLB instance overwrites its existing listeners.

      • CLB instances created by a service cannot be reused and can be accidentally deleted.

      • Only CLB instances that you create manually in the console or by calling an API can be reused.

      • If multiple services reuse the same CLB instance, ensure that their frontend listener ports are different to avoid port conflicts.

      • SLB instances cannot be reused across clusters.

    Create Service:

    • Service Type: LoadBalancer

    • SLB Type: Classic Load Balancer (CLB)

    • Select Resource: Create Resource

    Create CLB Resource:

    • Access Method: internal access

    • Use the default values for other settings.

    Backend

    The backend application that receives traffic from the service. If you do not select a backend, Kubernetes does not create a corresponding Endpoints object. For more information, see Services without selectors.

    • Name: app

    • Value: nginx

    Port Mapping

    Add a service port (the port field in the service YAML) and a container port (the targetPort field in the service YAML). The container port must match the port exposed by the backend Pods.

    • Service Port: 80

    • Container Port: 80

    • Protocol: TCP

    Annotations

    Add an annotation to configure the ClusterIP or LoadBalancer resources for the service.

    Note

    Alibaba Cloud-specific annotations take effect only when the Service Type is set to Server Load Balancer. For example, the annotation service.beta.kubernetes.io/alicloud-loadbalancer-bandwidth:2 sets the peak bandwidth of the service to 2 Mbit/s to control traffic. For a full list of annotations, see Configure a Classic Load Balancer (CLB) by using annotations.

    None

    Label

    Add a label to identify the service.

    None

    After configuring the parameters, click OK.

  4. After the service is created, you can find the new service named my-nginx-svc on the Services page.

Method 2: Create a service using kubectl

  1. Connect to your Kubernetes cluster using kubectl in CloudShell.

  2. Create a file named my-nginx-svc.yaml with the following content.

    View my-nginx-svc.yaml

    apiVersion: v1
    kind: Service
    metadata:
      annotations:
        service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"
      labels:
        app: nginx
      name: my-nginx-svc
      namespace: default
    spec:
      ports:
      - port: 80
        protocol: TCP
        targetPort: 80
      selector:
        app: nginx
      type: LoadBalancer

    Field

    Description

    kind

    Defines the resource object type as Service.

    metadata

    Defines basic information about the service, such as its name, labels, and namespace.

    metadata.annotations

    ACS provides a rich set of annotations for configuring LoadBalancer services. In this example, the annotation service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type specifies intranet (internal access). For more annotations, see Configure a Classic Load Balancer (CLB) by using annotations.

    spec.selector

    The label selector for the service. The service matches Pods with these labels and routes traffic to them.

    spec.ports.port

    The port exposed on the service's ClusterIP. Clients inside the cluster access the service at clusterIP:port.

    spec.ports.targetPort

    The port on the backend Pods. Traffic arriving at the port is forwarded by kube-proxy to the targetPort on the backend Pod.

    spec.type

    Specifies how the service is exposed.

    • LoadBalancer: Exposes the service using an Alibaba Cloud CLB instance. If you do not specify an existing CLB instance for the service, a public-facing CLB instance is created by default. To create a service with internal access and a corresponding private CLB, set the service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type annotation to intranet.

    • ClusterIP: Exposes the service on a cluster-internal IP address for access from within the cluster.

    Important

    Alibaba Cloud Container Compute Service (ACS) does not support services of the NodePort type. Attempts to create a service of this type fail or the service does not take effect.

  3. Run the following command to create the service:

    kubectl apply -f my-nginx-svc.yaml
  4. Run the following command to verify that the service is created:

    kubectl get svc my-nginx-svc

    Expected output:

    NAME           TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)   AGE
    my-nginx-svc   LoadBalancer   172.16.XX.XX   192.168.XX.XX   80/TCP    13s

Related operations

Update a service

  • Method 1: To edit an existing service directly, run the following command. This opens the service configuration in your default editor.

    kubectl edit service my-nginx-svc
  • Method 2: To update a service from a manifest file, modify the local YAML file and apply the changes.

    kubectl apply -f my-nginx-svc.yaml

View a service

Run the following command to view details about the service:

kubectl get service my-nginx-svc

Expected output:

NAME           TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)   AGE
my-nginx-svc   LoadBalancer   172.16.XX.XX   192.168.XX.XX   80/TCP    13s

Delete a service

Run the following command to delete the service:

kubectl delete service my-nginx-svc