Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.8 KB

kubernetes-stateful.md

File metadata and controls

50 lines (40 loc) · 1.8 KB

Stateful

⬅️ Back to Kubernetes overview

Create StatefulSet based on the example

kubectl apply -f kubernetes/statefulset/resources.yaml

Check the result if the deployment worked by visiting http://localhost:30888

📝 Why is there a nginx error page displayed?

Inspect the resources that have been created. What about their name?

kubectl get pods
kubectl get service
kubectl get persistentvolumeclaims
kubectl get persistentvolume

What are these volumes we just used/created? Explain PersistentVolumes and PersistentVolumeClaims as well as retention policies.

💡 Retention policies should always be checked before depleting any PersistentVolume or PersistentVolumeClaim

So what about storage classes?

kubectl get storageclass
kubectl get storageclass hostpath -o yaml

Let's copy different content to the volumes to see the effect

kubectl cp kubernetes/statefulset/index-light.html web-0:/usr/share/nginx/html/index.html
kubectl cp kubernetes/statefulset/index-dark.html web-1:/usr/share/nginx/html/index.html

💡 cp can be really handy but only works for volumes mounted on pods.

Check the result of the change by going to http://localhost:30888 It might take a few (or even many) tries to get to both instances

As this is persistent storage, this change is permanent in case of a pod restart

kubectl delete pod web-0

💡 Service special case: Headless service to give unique but deterministic DNS names for each Pod.

  • 📝 What happens with the pv if you delete the StatefulSet?
  • 📝 Create a custom pvc and use it in a Deployment. What is the difference compared to a StatefulSet?