301 β€” StatefulSets and DaemonSets

Advanced

Master StatefulSets for stateful applications and DaemonSets for node-level services in Kubernetes.

Learning Objectives

1
Understand when to use StatefulSets vs Deployments
2
Create and manage stateful applications
3
Deploy DaemonSets for node-level services
4
Manage ordered deployment and scaling
Step 1

Create a headless Service for StatefulSet

StatefulSets require a headless Service for network identity.

Commands to Run

cat > headless-service.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  clusterIP: None
  selector:
    app: nginx-sts
  ports:
  - port: 80
EOF
kubectl apply -f headless-service.yaml

What This Does

Headless Services (clusterIP: None) provide stable network identities for StatefulSet pods.

Expected Outcome

Service created with ClusterIP: None. Used for pod DNS names.

Pro Tips

  • 1
    StatefulSets need headless Service for pod DNS
  • 2
    Each pod gets DNS: [pod-name].[service-name].[namespace].svc.cluster.local
  • 3
    Enables direct pod-to-pod communication
  • 4
    Essential for clustered applications
Was this step helpful?

All Steps (0 / 10 completed)