Service
In one line
A Service is a Kubernetes resource that provides a stable network identity for a set of Pods, even as Pods are created and destroyed.
In simple words
In Kubernetes, Pods are ephemeral — they are created and destroyed, and each time they get a new IP address. This makes it hard to connect to them directly. A Service solves this problem by providing a stable IP address and DNS name that stays the same even as the underlying Pods change.
A Service acts as a load balancer: it receives traffic on a stable address and distributes it across all the Pods that match its selector. When a Pod dies and a new one is created, the Service automatically starts routing to the new Pod.
There are several types of Services: ClusterIP (internal only), NodePort (exposed on a node's port), and LoadBalancer (provisioned by a cloud load balancer).
Example
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: ClusterIP
selector:
app: my-app
ports:
- port: 80
targetPort: 8080This Service routes traffic from port 80 to port 8080 on all Pods labeled app: my-app.
How it works
- You define a Service with a selector that matches certain Pods.
- Kubernetes assigns the Service a stable ClusterIP and DNS name.
- Traffic sent to the Service is load-balanced across matching Pods.
- As Pods are created or destroyed, the Service updates its endpoints automatically.
Common confusions
Confused with: Ingress
The difference: A Service provides internal routing and load balancing; an Ingress manages external HTTP/HTTPS routing and host-based rules.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.