Skip to content

Latest commit

 

History

History

StatefulSet

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

StatefulSet 101

Open a watching terminal

kubectl get pods --watch -l app=nginx

Deploy

Open another terminal, then:

cd k8sHub
kubectl apply -f k8s101/StatefulSet/statefulset_sample.yaml

Verify

Check object

kubectl get service nginx
kubectl get statefulset web

Check hostname

for i in 0 1; do kubectl exec "web-$i" -- sh -c 'hostname'; done

Scale up

Scale up to 5 replicas

kubectl scale sts web --replicas=5

Now watch the scale up process in the watching terminal, sample result:

~ kubectl get pods --watch -l app=nginx
NAME    READY   STATUS    RESTARTS   AGE
web-0   0/1     Pending   0          0s
web-0   0/1     Pending   0          4s
web-0   0/1     ContainerCreating   0          4s
web-0   1/1     Running             0          16s
web-1   0/1     Pending             0          0s
web-1   0/1     Pending             0          4s
web-1   0/1     ContainerCreating   0          4s
web-1   1/1     Running             0          5s
web-2   0/1     Pending             0          0s
web-2   0/1     Pending             0          4s
web-2   0/1     ContainerCreating   0          4s
web-2   1/1     Running             0          6s
web-3   0/1     Pending             0          0s
web-3   0/1     Pending             0          4s
web-3   0/1     ContainerCreating   0          4s
web-3   1/1     Running             0          5s
web-4   0/1     Pending             0          0s
web-4   0/1     Pending             0          4s
web-4   0/1     ContainerCreating   0          4s
web-4   1/1     Running             0          5s

Scale down

Scale down to 3 replicas

kubectl scale sts web --replicas=3

Now watch the scale up process in the watching terminal, sample result:

web-4   0/1     ContainerCreating   0          4s
web-4   1/1     Running             0          5s
web-4   1/1     Terminating         0          114s
web-4   0/1     Terminating         0          115s
web-4   0/1     Terminating         0          115s
web-4   0/1     Terminating         0          115s
web-4   0/1     Terminating         0          115s
web-3   1/1     Terminating         0          2m
web-3   0/1     Terminating         0          2m1s
web-3   0/1     Terminating         0          2m1s
web-3   0/1     Terminating         0          2m1s
web-3   0/1     Terminating         0          2m1s

Cleanup

cd k8sHub
kubectl delete -f k8s101/StatefulSet/statefulset_sample.yaml