Create a service

更新时间:
复制 MD 格式

This topic describes how to create a Service in an 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 to access them, often referred to as a microservice. The set of pods targeted by a Service is typically determined by a label selector.

In Kubernetes, pods have their own IP addresses but are ephemeral—they can be created and destroyed dynamically. Exposing pods directly to external traffic prevents you from achieving a high availability architecture. A Service decouples the frontend from the backend, which allows the frontend to operate without knowing the specific backend pods. This enables a loosely coupled microservice design.

For more information, see Kubernetes Service.

Step 1: Create a Deployment

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

Step 2: Create a Service

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

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

  3. On the Services page, click Create.

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

    Parameter

    Description

    Service Name

    Enter a name for the Service. This example uses nginx-svc.

    Type

    Select how the Service is exposed.

    • Cluster IP: Exposes the Service on an internal IP address in the cluster. This is the default type, and is accessible only from within the cluster.

      Note

      You can configure a Headless Service only when Cluster IP is set to Cluster IP.

    • Server Load Balancer: Exposes the Service using an Alibaba Cloud Server Load Balancer (SLB) instance. This option creates a Kubernetes Service of the LoadBalancer type. You can enable public or internal access. An SLB instance can route traffic to both NodePort and ClusterIP Services.

      Note

      You can create a new SLB instance or use an existing one. Multiple Kubernetes Services can reuse the same SLB instance, but the following restrictions apply:

      • If you reuse an existing SLB instance, its existing listeners are overwritten.

      • Do not reuse an SLB instance that was automatically created by a Kubernetes Service, as this can cause it to be accidentally deleted.

      • Services that reuse the same SLB instance cannot have the same frontend listener port. Otherwise, a port conflict occurs.

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

      • You cannot reuse SLB instances across different clusters.

    Backend

    Select the backend object to bind to the Service. In this example, select serverless-app-deployment, which you created in Step 1. If you do not associate a backend, a corresponding Endpoint object is not created. You can bind it manually later. For more information, see Services without selectors.

    External Traffic Policy

    Valid values: Local and Cluster.

    Note

    The External Traffic Policy setting is available only when Server Load Balancer is set to Server Load Balancer.

    Port Mapping

    Add a service port and a container port. The container port must match the port that is exposed by the backend pods.

    Annotations

    Add an annotation to the Service to configure parameters for the Server Load Balancer. For example, adding the annotation service.beta.kubernetes.io/alicloud-loadbalancer-bandwidth:20 sets the peak bandwidth for the Service to 20 Mbit/s to control traffic. For more information, see Use annotations to configure a Server Load Balancer.

    Labels

    Add a label to identify the Service.

    After you create the Service, you can view, update, or delete it from the Actions column on the Services page.