All Products
Search
Document Center

Container Service for Kubernetes:Create a Service

Last Updated:Dec 27, 2023

This topic describes how to create a Service in a Container Service for Kubernetes (ACK) Serverless cluster.

Prerequisites

An ACK Serverless cluster is created. For more information, see Create an ACK Serverless cluster.

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

Create a Deployment from an image. In this example, a Deployment named serverless-app-deployment is created. For more information, see Create an application from an image.

Step 2: Create a Service

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

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Network > Services in the left-side navigation pane.

  3. On the Services page, click Create.

  4. In the Create Service dialog box, configure the parameters and click Create.

    Parameter

    Description

    Name

    Enter a name for the Service. In this example, nginx-svc is used.

    Type

    The type of Service. This parameter specifies how the Service is accessed.

    • Cluster IP: The ClusterIP type Service. This type of Service exposes the Service by using an internal IP address of the cluster. If you select this type, the Service is accessible only within the cluster. This is the default type.

      Note

      You can configure Headless Service only if you set Type to Cluster IP.

    • Server Load Balancer: The LoadBalancer type Service. This type of Service exposes the Service by using a Server Load Balancer (SLB) instance. If you select this type, you can enable internal or external access to the Service. SLB instances can be used to route requests to NodePort and ClusterIP Services.

      Note

      You can create an SLB instance or use an existing SLB instance. You can also associate an SLB instance with multiple Services. However, you must take note of the following limits:

      • If you use an existing SLB instance, the listeners of the SLB instance overwrite the listeners of the Service.

      • If an SLB instance is created along with a Service, you cannot reuse this SLB instance when you create other Services. Otherwise, the SLB instance may be deleted. Only SLB instances that are manually created in the console or by calling the API can be used to expose multiple Services.

      • Kubernetes Services that share the same SLB instance must use different frontend listener ports. Otherwise, port conflicts may occur.

      • If multiple Kubernetes Services share the same SLB instance, you must use the listener names and the vServer group names as unique identifiers in Kubernetes. Do not modify the names of listeners or vServer groups.

      • You cannot share SLB instances across clusters.

    Backend

    Select the backend object for the Service. In this example, the serverless-app-deployment application that is created in Step 1 is selected. If you do not associate the Service with a backend application, no Endpoint object is created. You can also manually associate the Service with a backend application. For more information, see services-without-selectors.

    External Traffic Policy

    Valid values: Local and Cluster.

    Note

    The External Traffic Policy parameter is available only if you set Type to Server Load Balancer.

    Port Mapping

    Specify the Service port and the container port. The container port must be the same as the port opened by the backend pod.

    Annotations

    Add annotations to the Service. For example, you can add the service.beta.kubernetes.io/alicloud-loadbalancer-bandwidth:20 annotation to set the bandwidth limit of the LoadBalancer Service to 20 Mbit/s. This annotation limits the amount of traffic that flows to the Service. For more information, see Use annotations to configure load balancing.

    Label

    Add one or more labels to the Service. Labels are used to identify a Service.

    After the Service is created, you can view, update, or delete the Service in the Actions column of the Services page.