Module #57 · beginner Article
Kubernetes Deployment Spec: Pod Templates, Replicas, and Rollout Controls
A Deployment is the standard way to run stateless applications — it manages ReplicaSets, handles rolling updates, and maintains desired pod count through sel...
4 min read+10 XPPublished 2026-06-16
Quick Answer: A Deployment is the standard way to run stateless applications — it manages ReplicaSets, handles rolling updates, and maintains desired pod count through self-healing.
Detailed Answer:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: production
labels:
app: my-app
spec:
# ── HOW MANY ────────────────────────────────────────────────
replicas: 3
# ── WHICH PODS ──────────────────────────────────────────────
selector:
matchLabels:
app: my-app # MUST match pod template labels exactly
# ── HOW TO UPDATE ───────────────────────────────────────────
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # Max extra pods during update
maxUnavailable: 0 # Never reduce below desired count
# Rollback history (default: 10)
revisionHistoryLimit: 5
# ── WHAT TO RUN ─────────────────────────────────────────────
template: # This IS a pod spec
metadata:
labels:
app: my-app # Must match selector.matchLabels
version: v1.2.3
spec:
containers:
- name: app
image: myrepo/my-app:v1.2.3
ports:
- containerPort: 8080
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
memory: "512Mi"
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 15
failureThreshold: 3
The Selector Contract:
The selector.matchLabels in the Deployment and the template.metadata.labels must match — this is how the Deployment knows which pods belong to it. If they don't match, the API server rejects the manifest.
Key Takeaway: A Deployment's selector is immutable after creation — if you need to change labels, you must delete and recreate the Deployment.
Finished reading?
Mark as complete to claim your +10 XP and track progress.
