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

6/9/2020

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
-- Artur Drożdżyk
kubernetes
statefulset

2 Answers

6/9/2020

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

-- hoque
Source: StackOverflow

6/9/2020

It should be same because both StatefulSet and Deployment creates pod at the end.

kubectl exec -it podname -n namespacename -- sh
-- Arghya Sadhu
Source: StackOverflow