This topic describes how to create a service in a serverless Kubernetes cluster.


A Serverless Kubernetes cluster is created. For more information, seeCreate a serverless Kubernetes cluster.

Background information

A Kubernetes service, generally called a microservice, is an abstraction which defines a logical set of Pods and a policy by which to access the Pods. A label selector usually determines whether the set of Pods can be accessed by the service.

Each Pod has its own IP address. However, Pods are created and deleted dynamically and quickly. Using Pods to provide services externally is therefore not a high availability solution. The service abstraction enables the decoupling between the frontend and the backend. The frontend does not need to be aware of how the backend is implemented, which leads to a loosely coupled microservices based architecture.

For more information, see Kubernetes Service.

Step 1: Create a deployment

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

Step 2: Create a service

  1. Log on to the Container Service console.
  2. Select the cluster and namespace. Then click Create in the upper-right corner.
  3. In the Create Service dialog box that appears, set the following parameters.
    • Name: The service name. In this example, enter nginx-svc.
    • Type: The service type, namely, how to expose the service.
      • Cluster IP: Expose the service through an internal IP address in the cluster. When this option is selected, the service is only accessible within the cluster. This is the default service type.
        Note The Headless Service option is only available when you set the service type to Cluster IP.
      • Server Load Balancer: Expose the service through an SLB instance, which supports Internet access or internal access. An SLB instance can route requests to Node Port and Cluster IP services.
        Note You can create a new SLB instance or use an existing SLB instance. Multiple services can reuse the same SLB instance. However, the following limits apply:
        • If you use an existing SLB instance, its existing listeners will be overwritten.
        • If you choose to create a new SLB instance when you create a service, you cannot reuse this SLB instance when you create other services. Otherwise, the SLB instance may be accidentally deleted. You can only reuse SLB instances that were manually created in the console or by calling open APIs.
        • Services that reuse the same SLB instance cannot have the same frontend listening port. Otherwise, port conflicts may occur.
        • When you reuse an SLB instance, the listener name and the VServer group name are used as unique identifiers in Kubernetes. Do not modify the names of listeners and VServer groups.
        • You cannot reuse SLB instances across clusters.
    • Backend: The backend object that you want to associate with the service. In this example, select nginx-deployment-basic created from the previous step. If you do not specify a deployment, no Endpoint object will be created. You can manually bind the service to an Endpoint object. For more information, see services-without-selectors.
    • External Traffic Policy: Valid values include Local and Cluster.
      Note The External Traffic Policy option is only available when you set the service type to Node Port or Server Load Balancer.
    • Port Mapping: Set the service port and container port. The container port must be the same as the one exposed by the backend Pod.
    • Annotations: Add annotations to the service and configure SLB parameters. For example, indicates that the service bandwidth is set to 20 Mbit/s. For more information, see Use SLB to access services.
    • Label: Add labels to the service.
  4. Click Create. You can then find the nginx-svc service on the Services page.
    View the service