0
0
Kubernetesdevops~30 mins

StatefulSet ordering and naming in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
StatefulSet Ordering and Naming in Kubernetes
📖 Scenario: You are managing a Kubernetes cluster that runs a database application. You want to deploy multiple instances of this database using a StatefulSet. StatefulSets give each pod a unique name and ensure they start in order, which is important for your database to work correctly.
🎯 Goal: Learn how to create a StatefulSet with 3 replicas, understand how Kubernetes names each pod, and see the order in which pods start.
📋 What You'll Learn
Create a StatefulSet YAML manifest with 3 replicas
Set the container image to nginx:latest
Use a volumeClaimTemplates section for persistent storage
Observe pod names and startup order
💡 Why This Matters
🌍 Real World
StatefulSets are used to deploy applications that need stable network IDs and persistent storage, like databases or clustered services.
💼 Career
Understanding StatefulSets is important for Kubernetes administrators and DevOps engineers managing stateful applications in production.
Progress0 / 4 steps
1
Create a StatefulSet YAML with 3 replicas
Create a YAML file named statefulset.yaml with a StatefulSet resource named web. Set replicas to 3. Use nginx:latest as the container image. Include a volumeClaimTemplates section with a persistent volume claim named www requesting 1Gi storage.
Kubernetes
Need a hint?

Remember to set replicas to 3 and include volumeClaimTemplates with the correct storage size.

2
Add a headless service for the StatefulSet
Add a YAML manifest for a headless Service named nginx with clusterIP: None and selector app: nginx. This service is required for the StatefulSet to manage network identities.
Kubernetes
Need a hint?

The headless service must have clusterIP: None and select pods with label app: nginx.

3
Deploy the StatefulSet and check pod names
Use the command kubectl apply -f statefulset.yaml to deploy the StatefulSet and Service. Then use kubectl get pods -l app=nginx to list the pods. Notice the pod names are web-0, web-1, and web-2.
Kubernetes
Need a hint?

Use kubectl apply -f statefulset.yaml to deploy and kubectl get pods -l app=nginx to see pod names.

4
Observe pod startup order and print pod names
Write a command to print the pod names in order using kubectl get pods -l app=nginx -o custom-columns=NAME:.metadata.name --no-headers. This shows pods named web-0, web-1, and web-2 in startup order.
Kubernetes
Need a hint?

Use kubectl get pods -l app=nginx -o custom-columns=NAME:.metadata.name --no-headers to list pod names.