Pod is a group of containers and is a logical concept. So you can not really exec into a pod. All you can do is exec into one of the containers in the pod.
kubectl exec
command might make you think that you are execingy into a pod but you actually exec into the container.This command works only if its a single container pod.If there are multiple container in the pod i.e it's a multi container pod then you need to choose a container explicitly using -c
option.
Here is the output of kubectl exec -h
which mentions about containers too.
Execute a command in a container.
Examples:
# Get output from running 'date' command from pod mypod, using the first container by default
kubectl exec mypod -- date
# Get output from running 'date' command in ruby-container from pod mypod
kubectl exec mypod -c ruby-container -- date
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod mypod
# and sends stdout/stderr from 'bash' back to the client
kubectl exec mypod -c ruby-container -i -t -- bash -il
A pause
container gets created before any other actual container of the pod gets created.Responsibility of the pause
container is to create the linux namespaces which will be shared among the other containers of the pod.
There is no way to exec into that pause container using kubectl exec
but you can exec into it using docker exec
.
nsenter
to the process (if it has it's own namespace). I am not sure if a pod has it's own logical NS. – Bobettebobina