Getting Shell Access to a Kubernetes Container
Frederick Ollinger

Frederick Ollinger @frederickollinger

About: Linux / Python / DevOps / Crypto / Cloud

Joined:
Jun 22, 2022

Getting Shell Access to a Kubernetes Container

Publish Date: May 30
0 0

Problem: You have a running Kubernetes deployment, and you want to examine inside a container so you need to get shell access.

First find the pod that you are interested in.

NOTE: If you are running in a namespace, you need to include that as part of your listing with the -n flag, if not, you can skip -n. In this case, we'll name our namespace: namespace.

kubectl -n namespace get pods
Enter fullscreen mode Exit fullscreen mode

This shows:

NAME      READY   STATUS    RESTARTS   AGE
fun-pod-0   1/1     Running   0          21h
Enter fullscreen mode Exit fullscreen mode

To connect to fun-pod-0, we do:

kubectl exec -it pod/fun-pod-0 -n namespace -- sh
Enter fullscreen mode Exit fullscreen mode

NOTE: That we use sh for our shell as it's found in most linux pods. But your milage may vary and you might want to use bash or even /bin/bash instead of sh depending upon what shell is installed and what path.

Comments 0 total

    Add comment