Let's now create a StafulSet.
kubectl apply -f statefulset.yaml
kubectl get pods -o wide
kubectl get pvc
Open a session in nginx-sts-2 and create a file in the folder mapped to the volume.
kubectl exec nginx-sts-2 -it -- /bin/sh
cd var/www
echo Hello > hello.txt
cd /usr/share/nginx/html
cat > index.html
Hello
Ctrl-D
exit
kubectl exec nginx-sts-0 -it -- /bin/sh
curl http://nginx-sts-2.nginx-headless
exit
Delete a pod and watch as it is recreated with the same name.
kubectl delete pod nginx-sts-2
Open a session in nginx-sts-2 and see if the file is still present.
kubectl exec nginx-sts-2 -it -- /bin/sh
ls var/www
exit
kubectl delete -f statefulset.yaml
kubectl delete pvc www-nginx-sts-0
kubectl delete pvc www-nginx-sts-1
kubectl delete pvc www-nginx-sts-2