In Kubernetes, a Service is an abstraction that exposes an application running on a set of pods as a network service. It provides a stable DNS name and load balancing for the pods. This topic explains how Kubernetes Services work, outlines important considerations, and provides recommendations for choosing a Service type.
Key concepts
Service types
If the Cloud Controller Manager version is v2.5.0 or later, using a CLB instance to create a Service in the console becomes a whitelisted feature that only supports pay-as-you-go billing. To create a CLB-type Service in the console, submit a request on the Quota Center page.
Name | Description | Use cases | Billing |
The default Service type. A ClusterIP Service is assigned a virtual IP address that is only reachable from within the cluster. | Ideal for services that only need to communicate within the same cluster. For example, if a frontend application pod needs to access a backend database within the same cluster, you can expose the database as a ClusterIP Service. | Free of charge. | |
A NodePort Service opens a specific port on every node in the cluster. You can access the Service from outside the cluster using | Suitable for exposing a service to the internet for development, testing, or other low-traffic applications. For example, you can use a NodePort Service to deploy and debug a web application in a test environment. Unlike a LoadBalancer Service, it does not provide load balancing across nodes. Traffic is sent to only one node, which can easily become a resource bottleneck. | Free of charge. To enable public internet access, you must associate an EIP with the node. For more information about EIP billing, see Billing overview. | |
A LoadBalancer Service extends the NodePort type by provisioning an external load balancer that distributes traffic across pods in the cluster. The Service automatically provides an external IP address that clients can use to access it. It supports both Layer 4 (TCP/UDP) and Layer 7 (HTTP/HTTPS) traffic management. | Ideal for applications running on a public cloud that require a stable, easy-to-manage external entry point. For example, public services in a production environment that need to be accessed from the internet and must handle large volumes of external traffic with high availability, such as web applications or API services. Important For intra-cluster communication, always use a In contrast, accessing a
Therefore, accessing a LoadBalancer IP from within the cluster may vary significantly or even fail across different environments and Kubernetes versions. Example scenario: Flannel + IPVS + externalTrafficPolicy=Local | For information about fees for load balancing instances, see | |
Headless Service | A Headless Service has no virtual IP address. A DNS query for the service name returns a list of pod IP addresses instead of a single service IP. This allows you to discover and connect to specific pods directly. | Ideal for applications that need to communicate directly with specific backend pods rather than through a proxy or load balancer. For example, if you deploy a stateful application like a ClickHouse database service, you can use a Headless Service. This allows application pods to directly access each ClickHouse pod, balancing data reads or performing targeted writes to improve data processing efficiency. | Free of charge. |
ExternalName | An ExternalName Service maps an internal service name to an external domain name. This allows pods inside the cluster to access the external domain using the internal service name. | Ideal when a cluster needs to access a service exposed under a public domain name. For example, if your application pods need to access an external database domain, you can use an ExternalName Service to map the domain to an internal service name, which allows direct access from within the cluster. | Free of charge. |
How it works
ClusterIP
Creation and allocation
When you create a ClusterIP Service in an ACK cluster, the control plane assigns it a virtual IP address (ClusterIP) that is accessible only from within the cluster.
Traffic forwarding
When you access the ClusterIP, kube-proxy intercepts the traffic and forwards it to a backend pod using a round-robin scheduling algorithm.
Service discovery
When a ClusterIP Service is created, CoreDNS registers a DNS record for it, allowing the service to be resolved and accessed by its name. The format is
service-name.namespace.svc.cluster.local:port, for example,nginx.default.svc.cluster.local:80.Pod labels and endpoint tracking
A Service uses a label selector to identify its backend pods.
The control plane continuously monitors pod changes. When pods that match the Service's label selector are added, updated, or removed, the control plane updates the endpoint.
NodePort
Creation and allocation
When you create a NodePort Service, the cluster opens a port (the NodePort) on its nodes to allow external access.
Traffic forwarding
kube-proxy listens on the NodePort, which is automatically chosen from a default range of 30000-32767. It routes external requests to the ClusterIP, which then forwards them to the backend pods.
External access
You can access the Service externally using the node's IP address and the static port (NodePort) in the format
<NodeIP>:<NodePort>.
LoadBalancer
Creation and allocation
When you create a LoadBalancer Service, the control plane automatically interacts with the load balancing service to create a load balancer instance to handle traffic. For more information, see Use an existing Server Load Balancer instance to expose an application and Expose an application with an auto-provisioned LoadBalancer Service.
Traffic forwarding
When external traffic reaches the external IP of the load balancer instance, it is routed to the port on the nodes. Then, kube-proxy forwards the traffic to the backend pods.
Route and health check configuration
The load balancer automatically configures listener ports and performs health checks to ensure traffic is routed only to healthy pods.
External traffic policy
LoadBalancer and NodePort Services have an externalTrafficPolicy setting that controls how external traffic is routed. The behavior of this setting differs between clusters that use the Terway-Eniip and Flannel network plugins.
Log on to the ACK console. On the Clusters page, click the name of your cluster. On the Basic Information tab, you can view the CNI network plugin that your cluster uses.
Flannel network plugin
Item | Local | Cluster |
Backend server attachment | Only nodes that host backend pods are added as backend servers to the load balancer. | All nodes in the cluster are added as backend servers to the load balancer. |
Load balancer quota | Consumes fewer load balancer quota resources. For more information, see Quota limits. | Consumes a large number of load balancer quota resources because all cluster nodes are attached as backends. For more information, see Quota limits. |
Intra-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 | Load balancing between pods is disabled by default. To enable load balancing, set the scheduler to WRR by adding the annotation | Load balancing between pods is enabled by default. |
Source IP preservation | Supported. | Not supported. |
Session persistence | Supported. | Not supported. |
Use cases | Applications that need to preserve the original client IP address, such as for logging based on the source IP. | When high service availability is required and source IP preservation is not a concern, such as in large web application clusters. |
Terway-Eniip network plugin
Item | Local | Cluster |
Backend server attachment | Pods are directly added to the load balancer as backend servers. | |
Load balancer quota | Consumes fewer load balancer quota resources because only application pods are attached. For more information, see Quota limits. | |
Intra-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 | Load balancing between pods is enabled by default. | |
Source IP preservation | Supported. | |
Session persistence | Supported. | |
Usage notes
Before using the Service load balancing feature, review the relevant considerations. For more information, see Considerations for configuring Service load balancing.