What are Services?
Pods come and go. Their IP addresses change. How do you reliably connect to a set of Pods? That’s where Kubernetes Services come in.
A Service is an abstraction that defines a logical set of Pods and a policy to access them. It provides a stable IP address and DNS name, and load‑balances traffic across the Pods.
A Service enables network access to a set of Pods, decoupling the client from the Pod lifecycle.
Why Services?
- Stable endpoint: Even if Pods die and restart, the Service IP and DNS stay the same.
- Load balancing: Distributes traffic among healthy Pods.
- Service discovery: Kubernetes automatically injects DNS records for Services.
- Different access types: Internal only, external via port mapping, or cloud load balancers.
Service YAML Example
Here’s a basic Service that selects Pods with the label
app: nginx:apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80selector– which Pods this Service targets.ports– mapping from Service port to Pod container port.
Creating and Inspecting a Service
Assume you have a Deployment with
app: nginx labels. Apply the Service:kubectl apply -f service.yamlView Services:kubectl get servicesSee endpoints (the actual Pod IPs behind the Service):kubectl get endpointsService Types
Kubernetes supports several Service types:
- ClusterIP (default): Exposes the Service on an internal IP. Only reachable within the cluster.
- NodePort: Exposes the Service on each Node’s IP at a static port.
- LoadBalancer: Provisions a cloud load balancer (AWS, GCP, Azure) to expose the Service externally.
- ExternalName: Maps the Service to an external DNS name.
Two Minute Drill
- A Service provides a stable IP and DNS for a dynamic set of Pods.
- It load‑balances traffic to Pods matching its selector.
- Define Service with
kind: Service, specifyselectorandports. - Common types: ClusterIP (internal), NodePort, LoadBalancer, ExternalName.
Need more clarification?
Drop us an email at career@quipoinfotech.com
