Search code examples
kubernetesstatefulset

How to open a shell within Statefulset POD in Kubernetes using namespace


When it comes to PODS with:

kind: Deployment

the command has a following format:

kubectl exec -it [# POD_NAME #] -- sh

I am not sure how to accomplish the same, when I do have PODs defined using:

apiVersion: apps/v1
kind: StatefulSet

Solution

  • In Statefulset number of pods will be created defined in spec.replicas. The Pods' names take the form <statefulset name>-<ordinal index>. If your StatefulSet has two replicas, it creates two Pods, <statefulset-name>-0 and <statefulset-name>-1

    You can exec

    $ kubectl exec -it **<statefulset name>-<ordinal index>** -- sh
    

    You can see the created pod by your satefulset using

    kubectl get pods -l <label in spec.template.metadata.labels>
    

    More details click