How can I enter a Kubernetes managed container faster?

7/12/2021

Currently if I'm about to inspect my container, I have to do three steps: 1. kubectl get all -n {NameSpace} 2. kubectl describe {Podname from step 1} -n {NameSpace} 3. Find the Node Host and the container ID (My eyes are complaning!) 4. Switch to the host and execute "docker exec -ti -u root {Container ID} bash"

I am so mad about it right now. Wish somebody could offer some help to me and those who may share the same issue.

-- Steve Wu
kubernetes

1 Answer

7/12/2021

Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.

So, if you want to "enter" a container, you just need to "exec" into the pod in a particular namespace. Kubernetes will get you the shell/command for that pod.

kubectl -n somenamespace exec -it podname -- bash

There is no need to mention the node here as Kubernetes internally knows on which node the pod is scheduled.

If a Pod has more than one container, use --container or -c to specify a container in the kubectl exec command. For example, suppose you have a Pod named my-pod, and the Pod has two containers named main-app and helper-app. The following command would open a shell to the main-app container.

kubectl exec -it my-pod -c main-app -- /bin/bash

https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/

-- Rakesh Gupta
Source: StackOverflow