In this article, I will show you how to check Stateful and Stateless Pods in Kubernetes Cluster. Pods are the smallest unit of application runs in Kubernetes Cluster. It can represent a Single Application Container or cluster of application containers and volumes running in the same execution environment. A pod can be stateful or stateless depends on the application task it is going to perform. We will try to understand the concept of stateful and stateless in more detail with the help of examples.
What is Stateful Pod
A pod which maintains its state in Kubernetes Cluster is Known as Stateful Pod. Here pods are not interchangeable within the Cluster and each of the pod has its own unique identifier. Kubernetes will use the Statefulset features to deploy Stateful pods.
What is Stateless Pod
A pod which does not maintains its state in Kubernetes Cluster is Known as Stateless Pod. Here pods are interchangeable within the Cluster and it does not have any unique identifier. Kubernetes deploys stateless applications as uniform pods through deployment controller. It helps managing the state of the dynamically changing pods.
Difference between Stateful and Stateless Pods
- Stateful pods are sometimes addresses by their hostname whereas stateless pods usually don't.
- Stateful pods are unique and are different from each other whereas stateless pods are usually looks same so any pod can be picked.
- Stateful pods requires persistent storage whereas stateless pods does not have any persistent storage.
- Front end applications are usually configured as stateless pods whereas backend applications are usually configured as stateful pods.
How to Check Stateful Pods in Kubernetes Cluster
If you want to check all the Stateful pods running in your Kubernetes cluster then you need to use
kubectl get statefulset command as shown below. The output shows the ready state of the pods and the number of days since pods are running.
[root@localhost ~]# kubectl get statefulset NAME READY AGE stateful-example 1/1 160d stateful-example-1 1/1 160d stateful-example-2 1/1 160d stateful-example-3 1/1 160d example-app-4 1/1 160d example-app-5 1/1 160d
You can also use
kubectl get sts to check the stateful pods as shown below.
[root@localhost ~]# kubectl get sts NAME READY AGE stateful-example 1/1 160d stateful-example-1 1/1 160d stateful-example-2 1/1 160d stateful-example-3 1/1 160d example-app-1 1/1 160d example-app-2 1/1 160d
How to Check Stateless Pods in Kubernetes Cluster
If you want to check all the running stateless pods in your Kubernetes cluster then you need to run
kubectl get deployments command as shown below.
[root@localhost ~]# kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE stateless-app 1/1 1 1 160d stateless-app-1 1/1 1 1 160d stateless-deployment 1/1 1 1 160d nginx-deployment 1/1 1 1 160d apache-app-1 1/1 1 1 160d sts-example-app-2 1/1 1 1 160d hello-world 1/1 1 1 160d sts-example-app-3 1/1 1 1 160d sts-example-conf-1 1/1 1 1 160d sts-example-conf-2 1/1 1 1 160d hello-world-app 1/1 1 1 160d stateless-deploy 1/1 1 1 160d apache-deploy-1 1/1 1 1 160d
You can also verify the number of nodes running in your Kubernetes cluster by using kubectl get nodes command as shown below.
[root@localhost ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION 192.168.0.106 Ready master 28d v1.18.0 192.168.0.107 Ready master 28d v1.18.0 192.168.0.108 Ready master 28d v1.18.0
Similarly there are other Kubernetes commands which you can use to know more about the pods. For example, If you want to check the status of the pods then you need to use
kubectl get pods command.
[root@localhost ~]# kubectl get pods
If you want to know more about a pod then you need to use
kubectl describe <pod>. Here we are trying to know more about example-app-2 pod using kubectl describe example-app-2 command.
[root@localhost ~]# kubectl describe example-app-2
If you want to delete some pod then you need to use
kubectl delete pod <pod-name>. Here we are trying to delete
example-app-2 pod using
kubectl delete pod example-app-2 command as shown below.
[root@localhost ~]# kubectl delete pod example-app-2