Day 45 - Kubernetes Statefulset Tutorial For Beginners (2025)

About this video

### Summary of the Video Content: 1. **Introduction and Context**: - The video is part of a Kubernetes learning series by Pyush, focusing on Day 45: StatefulSets. - It emphasizes the importance of following the series sequentially due to prerequisites like Deployments, Services, Pods, and foundational Kubernetes concepts. 2. **StatefulSet Overview**: - **Definition**: StatefulSets are used for stateful applications requiring persistent storage and stable network identities. - **Key Differences from Deployments/ReplicaSets**: - Deployments/ReplicaSets are for stateless applications, while StatefulSets are for stateful applications. - Pods in Deployments have random names, whereas StatefulSet pods have predictable, ordinal-based names (e.g., `app-0`, `app-1`). - StatefulSet pods are created and deleted sequentially based on their ordinal index, unlike Deployments where operations happen in parallel or rolling updates. 3. **Demo Walkthrough**: - **Environment Setup**: - Used a sandbox environment with Kubernetes version 1.33. - Created directories (`/mounts/data/mongodb-0` to `/mounts/data/mongodb-4`) on the worker node for mounting as volumes. - **Headless Service**: - Created a headless service (`mongodb-service`) with `clusterIP: None` for stable network identity. - **StorageClass and Persistent Volumes (PVs)**: - Created a StorageClass with static provisioning (`no-provisioner`). - Defined 5 PVs (`pv-mongodb-0` to `pv-mongodb-4`) mounted to the directories created earlier. - **Persistent Volume Claims (PVCs)**: - Each pod in the StatefulSet gets a dedicated PVC, ensuring a 1:1 mapping between pods and PVs. - **StatefulSet Creation**: - Deployed a MongoDB StatefulSet with 3 replicas. - Pods were created sequentially (`mongodb-0`, `mongodb-1`, `mongodb-2`), demonstrating the ordinal-based naming and sequential lifecycle. 4. **Testing and Validation**: - Inserted dummy data into the MongoDB database running in `mongodb-0`. - Deleted `mongodb-0` to observe that the pod restarted with the same name and retained its data due to the PVC binding. - Verified that the PVC remained bound to the pod, preserving the state. 5. **Scaling and Cleanup**: - Scaled the StatefulSet from 3 to 5 replicas using `kubectl scale sts mongodb --replicas=5`. - Observed the sequential creation of new pods (`mongodb-3`, `mongodb-4`). - Verified all PVCs were bound and data persisted in the mounted directories. - Provided cleanup commands to delete resources (StorageClass, Service, PVCs, PVs, StatefulSet). 6. **Assignment and Learning Goals**: - Encouraged viewers to complete hands-on assignments from the GitHub repository. - Highlighted the relevance of StatefulSets for the Certified Kubernetes Administrator (CKA) exam. 7. **Conclusion**: - Summarized the importance of understanding StatefulSets for managing stateful applications in Kubernetes. - Encouraged viewers to practice hands-on and follow the series for comprehensive learning. --- ### Key Takeaways: - **StatefulSets** are essential for stateful applications requiring stable identities and persistent storage. - They differ from Deployments in naming conventions, pod lifecycle, and use cases. - Hands-on practice is crucial for mastering Kubernetes concepts and preparing for certifications like the CKA.


Course: Certified Kubernetes Administrator Full Course For beginners | CKA 2025

This playlist contains the complete CKA series for beginners, based on the latest 2025 curriculum. It includes 40+ videos with hands-on demos, assignments, and exam-based scenarios. We will cover everything from the basics to the Advanced, including fundamental concepts such as Docker, containers, Docker storage and networking, DNS, etc.

View Full Course