All Products
Search
Document Center

Container Compute Service:Create ClusterIP service

Last Updated:Aug 30, 2024

In Kubernetes, although pods have their own independent IP addresses, they are often created and deleted rapidly, which makes it impractical to expose them directly as services. To address this, Services can be used to decouple the frontend and backend components that implement a microservices architecture. This topic describes how to create a ClusterIP service through the console.

Prerequisites

An ACS cluster is created. For more information, see Create an ACS 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

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

  2. On the Clusters page, find the cluster that you want to manage and click its ID. In the left-side pane, choose Workloads > Deployments.

  3. On the Deployments page, click Create from YAML in the upper-right corner.

  4. Select a sample template or customize, then click Create.

    A sample template of an Nginx deployment.

    apiVersion: apps/v1 
    kind: Deployment
    metadata:
       name: nginx-deployment-basic
       labels:
         app: nginx
    spec:
       replicas: 2
       selector:
         matchLabels:
           app: nginx
       template:
         metadata:
           labels:
             app: nginx
         spec:
           containers:
           - name: nginx
             image: nginx:1.7.9                # Please replace with your actual image, in the format <image_name:tags>.
             ports:
             - containerPort: 80               # This port needs to be exposed in the service.
  5. On the Deployments page, click the target application name or Details on the right. You can then monitor and wait for the status of all pod instances to become Running.

Step 2: Create a Service

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

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

  3. On the Services page, click Create on the right, configure the relevant information in the Create Service dialog box, and then click OK.

    Configuration item

    Description

    Name

    The name of the Service.

    Service Type

    Select Cluster IP, this type is the default service type. If you select this type, the service can only be accessed within the cluster, which exposes the service through the internal IP of the cluster.

    Note

    You can choose whether to enable Headless Service as needed. After enabling, you can use the headless service to interact with other service discovery mechanisms, which decouples it from the Kubernetes.

    Backend

    Select the backend application to which the Service is to be bound. If no association deployment is performed, the related endpoints object is not created. For more information, see services-without-selectors.

    Port Mapping

    Add the service port (corresponding to the port in the service YAML file) and the container port (corresponding to the targetPort in the service YAML file). The container port needs to be consistent with the container port exposed in the backend pod.

    Annotations

    Add an annotation to the service.

    Label

    Add a tag to the service to identify the service.

    After creation, you can Update, Edit YAML, or Delete the target service in the Actions column on the Services page.

    Note

    You can click the service name to enter the detailed service page and click the link behind External endpoint to access the application.