I was doing some testing/evaluation on a Kubernetes Helm chart created by a 3rd party and wanted to gain shell access to pods. This immediately lead to several questions:

  • How do I find which services are running on which pods?
  • How do I gain a shell on the desired pod?

1 Answer 1


Due to abstraction in K8s, different services can be running on different pods. So before you can connect to anything, you need to gather some further information:

Step 1: List pods

kubectl get pods -o wide

Which in this example shows we have (2) pods running on the same node "wordpress-w9ga":

NAME                 READY  STATUS   RESTARTS   AGE    IP           NODE          
my-release-mariadb   1/1    Running      0      2d2h   wordpress-w9ga
my-release-wordpress 1/1    Running      3      2d2h   wordpress-w9ga

Step 2: Use kubectl to gain shell on desired pod

The pod I want to get a shell on is "my-release-wordpress". HOWEVER: Although we see IP's in the output of kubectl get pods, SSH will NOT be running. So we're going to gain a shell with the kubectl command, specifying the name of the pod we want to access:

kubectl exec -it my-release-wordpress -- /bin/bash
  • Why not “restart” the pod using Kubernetes tools? Oct 18, 2019 at 7:17
  • Wouldn't that potentially restart other services?
    – F1Linux
    Oct 18, 2019 at 7:22
  • Assuming you’re still talking about services in the traditional sense (rather than the Kubernetes sense), yes, other services running in the pod would be stopped and started, but pods should only run single services or very tightly-coupled services anyway (which you would want to restart together). Going into running pods and changing things there directly is a big step on the road to a messed up Kubernetes setup. Oct 18, 2019 at 7:27
  • It was exactly for the reason you noted (that a pod can contain other services). I wanted to ensure I was working in isolation with a single service. BTW, I was just validating my understanding about how the gears were turning rather than doing any material changes. And also wanted the shell for purposes of snooping around inside the pod ;-)
    – F1Linux
    Oct 18, 2019 at 7:42
  • Right, I understand the appeal of poking around pods ;-). (I use kubebox for that.) Perhaps you could mention the context in your question and answer, because I don’t think your answer is good general-purpose advice. Oct 18, 2019 at 7:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .