on
Pods, Deployments, and Services: How Kubernetes Runs and Exposes Your App
Kubernetes can feel overwhelming at first, but most day‑to‑day work hinges on three simple concepts: Pods, Deployments, and Services. Think of them as: where containers run (Pod), who keeps the right number of them running and updates them (Deployment), and how other software finds and reaches them (Service). This article explains each concept, shows how they connect, and includes a small example to make the flow concrete.
Quick conceptual map
- Pod: the smallest deployable unit in Kubernetes — one or more containers that share storage, networking, and runtime namespaces. (kubernetes.io)
- Deployment: a controller that declaratively manages a set of Pods (via ReplicaSets), keeping the desired number alive and handling rollouts and rollbacks. (kubernetes.io)
- Service: a stable network endpoint (IP + DNS) and load‑balancer that routes traffic to the right Pods, selected by labels. Services hide Pod churn so clients don’t need to track Pod IPs. (kubernetes.io)
What is a Pod?
A Pod groups containers that must run together on the same node and share the same network namespace and possibly volumes. The “one container per Pod” pattern is common — a Pod often wraps a single application container — but sidecar containers (for logging, proxying, etc.) can live in the same Pod when they need to share localhost networking or disk. Kubernetes manages Pods, not containers directly, so understanding Pod semantics helps with debugging and resource configuration. (kubernetes.io)
Important points:
- Pods get their own IP address inside the cluster; containers in a Pod share that IP and localhost. (kubernetes.io)
- Pods are ephemeral: if a Pod dies, the controller (like a Deployment) recreates a replacement Pod using the Pod template, but the original Pod object is gone. (kubernetes.io)
What is a Deployment?
A Deployment is a higher‑level construct used to declare the desired state for a set of Pods. You tell the Deployment how many replicas you want and what template to use for each Pod; the Deployment creates and manages a ReplicaSet that in turn manages the Pods. Deployments handle rolling updates, rollbacks, and declarative changes so you don’t manage Pods one‑by‑one. (kubernetes.io)
Deployment features beginners should know:
- Declarative: update the Deployment manifest and Kubernetes will perform a controlled rollout. (kubernetes.io)
- ReplicaSets: Deployments create ReplicaSets to maintain Pod counts; you can inspect ReplicaSets to see rollout history. (kubernetes.io)
- Health checks (readiness/liveness probes) influence rollouts by telling the controller when Pods are ready to receive traffic. (kubernetes.io)
What is a Service?
A Service provides a stable network endpoint and load‑balancing across a changing set of Pods. Services use label selectors to identify which Pods are members; clients resolve the Service name (DNS or ClusterIP) and do not need to know Pod IPs. This decouples consumers from Pod lifecycle and scaling. (kubernetes.io)
Common Service types:
- ClusterIP (default): reachable only inside the cluster; useful for internal microservice communication. (kubernetes.io)
- NodePort: opens a port on every node to expose the Service externally (simple but less flexible). (kubernetes.io)
- LoadBalancer: requests a cloud provider load balancer that fronts the Service (recommended on managed clusters). (kubernetes.io)
Also note headless Services (no virtual IP) when you want direct endpoint discovery (e.g., for stateful apps or service discovery use cases). (kubernetes.io)
How they fit together (short flow)
- You define a Deployment that includes a Pod template (containers, ports, probes, labels). The Deployment ensures the desired number of Pods run. (kubernetes.io)
- Each Pod gets its own IP. As the Deployment scales or rolls out updates, Pod objects are created and removed; their IPs change. (kubernetes.io)
- You create a Service with a label selector that matches the Pods you want to expose. The Service provides a stable ClusterIP and DNS name that routes to whichever Pods match the selector. Clients use the Service, not Pod IPs. (kubernetes.io)
This separation (Deployment manages pods; Service provides a stable address) is what makes Kubernetes reliable and flexible.
Example: a minimal nginx app (illustrative)
Below are compact manifests that show the core pieces. These examples are intentionally minimal to highlight the relationships.
Deployment manifest (deployment.yaml)
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:stable
ports:
- containerPort: 80
Service manifest (service.yaml)
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: ClusterIP
selector:
app: nginx
ports:
- port: 80
targetPort: 80
What’s happening:
- The Deployment asks for three replicas of the Pod template labeled app=nginx. The controller creates a ReplicaSet and three Pod objects. (kubernetes.io)
- The Service selects Pods with app=nginx and exposes port 80 under a stable ClusterIP and DNS name (nginx-service). Clients inside the cluster can reach the app at nginx-service:80. (kubernetes.io)
If you wanted to expose the app outside the cluster on cloud infrastructure, you would switch the Service type to LoadBalancer; on small local clusters NodePort is another option. (kubernetes.io)
Common beginner pitfalls
- Label mismatch: Services route traffic by label selectors. If the Service selector doesn’t match any Pod labels you’ll see “0 endpoints” and no traffic reaches your app. Always check Pod labels, Service selectors, and label keys/values. (kubernetes.io)
- Creating Pods directly: you can create Pods by applying a Pod manifest, but they are ephemeral and not auto‑replaced. For running production workloads, use higher‑level controllers (Deployments, StatefulSets) so the cluster can heal and scale them. (kubernetes.io)
- Expecting Pod IP stability: Pod IPs change whenever Pods are recreated. Use Services (ClusterIP/DNS) to give clients a stable address. (kubernetes.io)
- Readiness vs Liveness probes: readiness gates whether a Pod receives traffic; misconfigured readiness probes can keep Pods out of Service endpoints and make the app appear unavailable during rollouts. (kubernetes.io)
A few useful commands (reference)
These common kubectl commands help you inspect the three pieces:
- kubectl get pods — list Pod objects.
- kubectl get deployments — see Deployment status and replica counts.
- kubectl get svc — list Services and external IPs/ports.
- kubectl describe
— inspect events, selectors, and probe status.
The official docs and tutorials include hands‑on examples and the exact kubectl usage for exposing Deployments with Services. (kubernetes.io)
Why these three matter
Most application troubleshooting in Kubernetes centers on these resources. Pods show runtime failures and container logs; Deployments reveal rollout behavior and replica counts; Services explain connectivity and discovery. Mastering their relationship gives you the levers to deploy, scale, and expose apps reliably without wrestling with individual containers or node IPs. (kubernetes.io)
Closing summary
Pods are where your containers run; they’re transient and tied to the node. Deployments are the declarative controllers that keep the right number of Pods running and let you update them safely. Services present stable addresses and load balancing so clients can reach the right Pods no matter how often they change. Together these three form the simplest, most useful vocabulary for running apps on Kubernetes. The official Kubernetes documentation has clear, practical references and tutorials for each concept if you want the authoritative details. (kubernetes.io)