All Products
Search
Document Center

Container Compute Service:Expose an application using a Service

Last Updated:Jan 27, 2026

In Kubernetes, Pods are frequently created and destroyed, so their IP addresses are not stable. This prevents the direct use of Pod IPs to provide a stable Service. A Service solves this problem by providing a fixed IP address and DNS name. Clients connect to the Service without needing to know the IP addresses of the backend Pods. This decouples the frontend from the backend and ensures stable service delivery. This topic describes how to create and expose a Service by using the Alibaba Cloud Container Compute Service (ACS) console and the kubectl CLI.

Method 1: Create a Service by 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 method used to access the Service. The following types are available:

    • Cluster IP: Exposes the Service on a cluster-internal IP address. This type of service is reachable only from within the cluster.

      Note

      A Headless Service can be configured to interface with other service discovery mechanisms, independent of the Kubernetes native implementation.

    • SLB: Corresponds to the LoadBalancer type. It uses an Alibaba Cloud Server Load Balancer (SLB) instance to expose the service. Select Public Access or Internal Access. It routes external traffic to the internal ClusterIP service.

      • Create Resource: For Pay-by-specification, click Change Specification to modify the SLB specification.

      • Use Existing Resource: Select an existing SLB specification from the list.

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

      • To prevent accidental deletion, you cannot reuse SLB instances that are automatically provisioned by a service. You can only reuse SLB instances that you create manually.

      • If multiple Services reuse the same SLB instance, ensure their frontend listener ports are unique to avoid conflicts.

      • When you reuse an SLB instance, Kubernetes uses the listener name and virtual server group name as unique identifiers. Do not modify these names.

      • Reusing an SLB instance across different clusters is not supported.

    Create Service:

    • Service Type: SLB

    • SLB Type: CLB

    • Select Resource: Create Resource

    Create CLB Instance:

    • Access Method: Internal Access

    • Use the default values for other configurations.

    Backend

    Select the backend application to which the Service will be bound. If no backend is selected, Kubernetes does not create the 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 file) and a container port (the targetPort field in the Service YAML file). 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 Service.

    Note

    Alibaba Cloud-specific annotations take effect only when Service Type is set to SLB.

    For example, setting service.beta.kubernetes.io/alicloud-loadbalancer-bandwidth: 2 sets the peak bandwidth of the service to 2 Mbit/s to control traffic.

    For more annotations, see Configure a Classic Load Balancer (CLB) instance using annotations.

    None

    Label

    Add a label to identify the Service.

    None

    After you configure the parameters, click OK.

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

Method 2: Create a service by using kubectl

  1. Connect to a Kubernetes cluster using kubectl.

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

    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

    Specifies that the resource type is Service.

    metadata

    Defines basic information for the Service, such as its name, label, and namespace.

    metadata.annotations

    ACK provides many annotations for configuring SLB instances. For example, in the YAML file, service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet" specifies that the access method of the service is internal. For more annotations, see Configure a Classic Load Balancer (CLB) instance using annotations.

    spec.selector

    Defines the selector for the service. The Service uses the selector to find Pods with matching labels and routes traffic to them.

    spec.ports.port

    Defines the port exposed by the service's ClusterIP. This is the entry point for clients inside the cluster to access the service (clusterIP:port).

    spec.ports.targetPort

    Specifies the port on the backend Pods. Traffic entering through the port is forwarded by kube-proxy to the targetPort of the Pod, and finally to the container.

    spec.type

    Defines the access method of the service.

    • LoadBalancer: Exposes the Service using an Alibaba Cloud SLB instance.

      • If you do not specify an existing SLB instance, a public-facing SLB instance is created by default.

      • To create an internal-facing service and a corresponding internal SLB instance, set the service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type annotation to intranet.

    • ClusterIP: Exposes the service on an internal IP address within the cluster. This type is used for internal access only.

    Important

    Alibaba Cloud Container Compute Service (ACS) does not support the NodePort Service type. Creating a Service of this type will fail or the Service will 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 was 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: Edit in-place

    To edit the service configuration directly on the cluster, run the following command. This opens your default text editor.

    kubectl edit service my-nginx-svc
  • Method 2: Apply from file

    To update the service from a modified YAML file, run the following command.

    kubectl apply -f my-nginx-svc.yaml

View a Service

To view the details of the Service, run the following command:

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

To delete the Service, run the following command:

kubectl delete service my-nginx-svc