Bash

Connect to a Kubernetes Pod

Published on

To open a session it’s first required to know the Pod’s name. kubectl get pod -n <namespace> Then open a bash session by running: kubectl exec --stdin --tty <pod name> -n <namespace> -- /bin/bash It’s also possible to open a shell session: kubectl exec --stdin --tty <pod name> -n <namespace> -- /bin/sh Sometimes it’s need to spawn a new Pod from an image that has the required tooling to inspect something.

Interactive session in a Docker container

Published on

Opening a bash session in a given container: docker exec -it <container-name> /bin/bash In case the image is more bare bones you can still open a shell session: docker exec -it <container-name> /bin/sh You can only open sessions in containers that are running so check their status with docker ps before trying to open the session. If you are not sure about the container names you can list them with: