Kubernetes Service: A Stable Address for Ephemeral Pods

A Kubernetes Service provides a stable IP address and DNS name for a group of ephemeral Pods. It acts like a load balancer, distributing traffic so you don't have to track individual Pod IPs, which can change at any time.
Why it exists
Pods in Kubernetes are ephemeral; they can be created, destroyed, and rescheduled at any moment, each time getting a new IP address. Relying on direct Pod IPs for communication is brittle and destined to fail. A Service solves this by providing a stable abstraction layer.
The mental model
A Kubernetes Service is like a company's main phone number. You don't call individual employees (Pods) directly because they might be at a different desk, on vacation, or have left the company (restarted with a new IP). Instead, you call the stable main number (the Service), and a receptionist (kube-proxy) automatically routes your call to an available employee in the correct department (a healthy Pod matching the label selector).
How it works
You define a Service in a YAML file, specifying a 'selector' that targets a set of Pods based on their labels (e.g., 'app: my-api'). Kubernetes assigns a persistent virtual IP address, called the ClusterIP, to this Service. On every node in the cluster, a process called kube-proxy watches for these Services. When traffic is sent to a Service's ClusterIP, kube-proxy intercepts it and forwards it to the real IP address of one of the healthy backend Pods. This forwarding is a form of load balancing. The most common Service types are ClusterIP (internal only), NodePort (exposes on each node's IP), and LoadBalancer (uses a cloud provider's external load balancer).
When to use it
Use a Service whenever you need a stable endpoint for a set of replica Pods, such as for a backend API, a database, or a web frontend. It is the standard way to enable service discovery and load balancing within a Kubernetes cluster. Use the LoadBalancer or NodePort types to expose your application to external traffic.
When not to use it
Avoid using a Service for workloads that don't need a stable network endpoint, like one-off batch jobs. For complex HTTP routing based on hostnames or URL paths (e.g., api.example.com/users vs api.example.com/orders), an Ingress controller is the correct tool. An Ingress manages L7 traffic and routes it to different backend Services, which handle L4 distribution to Pods.
One canonical example
A Deployment is running three replicas of a stateless web server, all labeled with 'app: web-frontend'. You create a Service of type ClusterIP with a selector for 'app: web-frontend'. Now, any other Pod in the cluster can reliably send requests to the web servers by using the Service's DNS name (e.g., 'web-frontend-svc'), without ever knowing the individual, changing IPs of the three server Pods.
Interview question
What is the main reason to use a Kubernetes Service for a group of application Pods?
- a.To provide a stable, single point of access and load balancing for Pods whose IPs frequently change.Correct
- b.To guarantee that all Pods in the group always run on the same physical node.
- c.To manage the lifecycle, scaling, and self-healing of the Pods within the group.
- d.To define complex HTTP routing rules based on hostnames or URL paths for external access.
Why? this is the answer
A Kubernetes Service provides a stable network identity (IP and DNS) and load balancing for a set of ephemeral Pods whose individual IPs can change. Option C describes the function of a Deployment or ReplicaSet, which manages the Pods' lifecycle, not their stable network access.
Just read this? Test yourself on what you have been reading.
Read the original → kubernetes.io
- #kubernetes
- #networking
- #service discovery
- #devops
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.
See open roles