In Kubernetes, a Service is an abstraction that exposes an application running on a group of pods as a network service. A Service provides a unified DNS name for these pods and enables load balancing among them. This topic describes how Kubernetes Services work, key considerations, and recommendations for choosing a Service type.
Terms
Service types
When the Cloud Controller Manager version is v2.5.0 or later, creating Classic Load Balancer (CLB) instances in the console is a whitelist feature. This feature supports only the pay-as-you-go billing method. To create a CLB-type Service in the console, you can submit a request on the Quota Platform.
Name | Description | Scenarios | Billing |
The default Service type. A ClusterIP Service assigns a virtual IP address that is accessible only from within the cluster. | This Service type is used when services need to communicate only within the cluster and do not require external exposure. For example, frontend application pods that are deployed in the cluster may need to access a backend database that is also deployed in the same cluster. The backend database can run as a ClusterIP Service. | No charge. | |
A NodePort Service opens a port on each node in the cluster. This allows external access to the Service at | For temporary or low-traffic applications, you can expose a port to the external network. For example, you can use a NodePort Service to deploy and debug a web application during testing. Unlike a LoadBalancer Service, a NodePort Service does not provide cross-node load balancing. Traffic is sent to a single node, which can easily cause resource bottlenecks. | This Service type is free of charge. To enable public network access, you can bind an EIP to the node. For more information about EIP billing, see Billing overview. | |
The LoadBalancer Service type builds on the NodePort Service type by adding an external load balancer. This enables the smooth distribution of external traffic to multiple pods in the cluster. The Service automatically provides an external IP address that clients can use to access the service. It supports both Layer 4 (transport layer) TCP and UDP traffic and Layer 7 (application layer) HTTP and HTTPS traffic management. | This Service type is used when you run applications on a public cloud and require a stable, easy-to-manage external entry point. For example, you can use this Service type for public services in production environments that must handle large volumes of external traffic and ensure high availability, such as web applications or API services. Important When you access a Service from within a Kubernetes cluster, we recommend that you use a In contrast, directly accessing a
Therefore, the behavior when you access a LoadBalancer IP address from within the cluster may vary significantly across different environments or Kubernetes versions. In some cases, the IP address may even become unreachable. Example scenario: Flannel + IPVS + externalTrafficPolicy=Local | You are charged for the Server Load Balancer instance. For more information, see | |
Headless Service | A Headless Service does not have a virtual IP address. When you perform a DNS query for the Service, a list of pod IP addresses is returned instead of a single Service IP address. This allows for direct discovery of and connection to specific pods. | The application needs to communicate directly with a specific backend pod (rather than through an agent or a load balancer). For example, when you deploy a stateful application such as ClickHouse, you can use a Headless Service so that application pods can directly access each ClickHouse pod. This allows the pods to read data evenly or write data selectively, which improves data processing efficiency. | No charge. |
ExternalName | An ExternalName Service maps an internal service name in the cluster to an external domain name. This mapping allows pods inside the cluster to access the external domain using the Service name. | The cluster needs to access a service exposed at a public domain name. For example, if application pods need to access an external database domain, you can use an ExternalName Service to map the domain to an internal Service name. This enables direct access from within the cluster using the Service name. | No charge. |
How Services work
ClusterIP
Creation and assignment
When you create a ClusterIP Service in an ACK cluster, the cluster control plane assigns a virtual IP address (ClusterIP) that is accessible only from within the cluster.
Traffic forwarding
When you access the ClusterIP, kube-proxy captures the traffic and forwards it to backend pods using round-robin scheduling.
Service discovery
When you create a ClusterIP Service, CoreDNS registers a DNS record. This enables access through service name resolution. The format is
service-name.namespace.svc.cluster.local:port, for example,nginx.default.svc.cluster.local:80.Pod labels and endpoint tracking
Each Service is defined by a label selector that determines which pods belong to its backend.
The cluster control plane monitors pod changes in real time. When pods that match the Service's label selector are added, updated, or deleted, the control plane updates the Endpoint.
NodePort
Creation and assignment
When you create a NodePort Service, the cluster opens a port (NodePort) on each node to allow external access.
Traffic forwarding
kube-proxy listens on the NodePort, which is automatically selected from the default range of 30000 to 32767. It routes external requests to the ClusterIP and then to the backend pods.
External access
You can access the Service using the node's IP address and the static NodePort in the
<NodeIP>:<NodePort>format as the external endpoint.
LoadBalancer
Creation and assignment
When you create a LoadBalancer Service, the cluster control plane automatically interacts with the load balancing service to create a load balancer instance for traffic handling. For more information, see Expose applications using a Service with an existing Server Load Balancer and Expose applications using a Service with an automatically created Server Load Balancer.
Traffic forwarding
When external traffic reaches the external IP address of the load balancer instance, it is routed to a port on the node and then forwarded to backend pods by kube-proxy.
Routing and health check configuration
The load balancer automatically configures listening ports and performs health checks to ensure traffic is routed only to healthy pods.
External traffic policy
LoadBalancer and NodePort Services support the externalTrafficPolicy configuration to control how external traffic is routed to the Service. This setting has different behaviors in clusters that use Terway and clusters that use Flannel.
Log on to the Container Service for Kubernetes (ACK) console. On the Clusters page, click the name of the target cluster. On the Basic Information tab, you can view the container network plugin that is used by the cluster.
Flannel network plugin
Comparison item | Local | Cluster |
Load balancer backend attachment behavior | Only nodes that host pods are attached to the load balancer backend. | All nodes in the cluster are attached to the load balancer backend. |
Load balancer quota usage | This mode uses less load balancer quota. For more information, see Quota limits. | Attaching all cluster nodes to the load balancer backend consumes a significant amount of quota. For more information, see Quota limits. |
Internal cluster access to Service | Only nodes that host backend pods for the Service can access it. | Any node in the cluster can access the Service. |
Pod load balancing | Pods are not balanced by default. To balance traffic across pods, you can specify the wrr scheduler by adding the | Pods are balanced by default. |
Preserve source IP | Supported. | Not supported. |
Session persistence | Supported. | Not supported. |
Scenarios | This mode is suitable for applications that require the preservation of the client's source IP address, for example, for logging purposes. | This mode is suitable for scenarios where high availability is critical and the preservation of the source IP address is not required, for example, for large-scale web application clusters. |
Terway network plugin
Comparison item | Local | Cluster |
Load balancer backend attachment behavior | Pods are directly attached to the load balancer backend. | |
Load balancer quota usage | Only application pods are attached, resulting in lower quota consumption. For details, see Quota limits. | |
Internal cluster access to Service | When accessing the Service from within the cluster, traffic passes through kube-proxy on the node and is subject to the | Any node in the cluster can access the Service. |
Pod load balancing | Pods are balanced by default. | |
Preserve source IP | Supported. | |
Session persistence | Supported. | |
Considerations
Before you use the load balancing features of Services, take note of the following considerations. For more information, see Considerations for Service load balancing configuration.