You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Running applications in Kubernetes means choosing the right workload resource for the job. This lesson covers Deployments, StatefulSets, DaemonSets, Jobs, and CronJobs, along with resource management, QoS classes, and pod disruption budgets.
| Resource | Use Case | Pod Identity | Scaling |
|---|---|---|---|
| Deployment | Stateless apps (web servers, APIs) | Interchangeable | Horizontal |
| StatefulSet | Stateful apps (databases, caches) | Stable, ordered | Ordered |
| DaemonSet | One pod per node (monitoring, logging) | Per-node | N/A |
| Job | Run-to-completion tasks | Temporary | Parallel |
| CronJob | Scheduled tasks | Temporary | Per schedule |
Deployments manage stateless applications through ReplicaSets. They support rolling updates, rollbacks, and horizontal scaling.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-api
labels:
app: web-api
spec:
replicas: 3
selector:
matchLabels:
app: web-api
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # 1 extra pod during update
maxUnavailable: 0 # zero downtime
template:
metadata:
labels:
app: web-api
spec:
containers:
- name: api
image: myapp/web-api:v2.1.0
ports:
- containerPort: 8080
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 15
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
# Apply a deployment
kubectl apply -f deployment.yaml
# Check rollout status
kubectl rollout status deployment/web-api
# View rollout history
kubectl rollout history deployment/web-api
# Roll back to previous version
kubectl rollout undo deployment/web-api
# Roll back to a specific revision
kubectl rollout undo deployment/web-api --to-revision=3
# Scale the deployment
kubectl scale deployment/web-api --replicas=5
StatefulSets provide stable network identities and persistent storage for stateful applications.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
serviceName: postgres
replicas: 3
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:16
ports:
- containerPort: 5432
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: password
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: fast-ssd
resources:
requests:
storage: 50Gi
StatefulSet pods get predictable names: postgres-0, postgres-1, postgres-2, and each gets its own PersistentVolumeClaim.
| Feature | Deployment | StatefulSet |
|---|---|---|
| Pod names | Random suffix | Ordered index (0, 1, 2) |
| Startup order | Parallel | Sequential |
| Storage | Shared or none | Per-pod PVC |
| DNS | Via Service only | Headless per-pod DNS |
| Rolling update | Any order | Reverse ordinal order |
DaemonSets ensure exactly one pod runs on every (or selected) node. Ideal for node-level agents.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.