Not able to get shell of the running containers in kube-system namespace

Hi All,

I am trying to get shell of a control plane container e.g. I would like to get to the shell of the Etcd container running in tube-system namespace.

$ k exec -it etcd-master01 – /bin/bash -n kube-system
Error from server (NotFound): pods “etcd-master01” not found

$ k get pods -n kube-system
coredns-558bd4d5db-269lt 1/1 Running 8 30d
coredns-558bd4d5db-967d8 1/1 Running 8 30d
etcd-master01 1/1 Running 8 30d
kube-apiserver-master01 1/1 Running 16 16d
kube-controller-manager-master01 1/1 Running 42 30d
kube-proxy-q8mkb 1/1 Running 8 30d
kube-proxy-x6trg 1/1 Running 9 29d
kube-proxy-xxph9 1/1 Running 8 29d
kube-scheduler-master01 1/1 Running 37 30d
weave-net-rh2gb 2/2 Running 17 29d
weave-net-s2cg9 2/2 Running 19 29d
weave-net-wksk2 2/2 Running 19 30d

could you please help.

Thank you

Namespaces, they’re very important for organizing your workloads.

$ kubectl -n kube-system exec -it etcd-master01 -- /bin/bash

Edit: I copy/pasted a instead of --. Fixed, because necessary.
Edit 2: Copy paste just isn’t my friend.

Thank you @protosam, I also realised that bash was not the correct shell

vagrant@master01:~$ kubectl -n kube-system exec -it etcd-master01 – /bin/sh

Thank you

Yeah, it’s pretty common for bash to not be available. Some containers don’t seem to offer you any way to access them too. Like the apiserver doesn’t have a shell available as far as I can tell.

Edit: I found out why this is. Applications written in go don’t really need much in the way of OS. Using multi-stage builds, you can build a Go application and just copy it to an empty container pretty much.

Docker provides FROM scratch which I can only assume is a keyword to facilitate such a minimalistic container builds or building a new OS container.

Google also has ko for building Go based images.

1 Like