The Kubernetes command line tool,
kubectl, allows you to run different commands against a Kubernetes cluster. You can manipulate Kubernetes API objects, manage worker nodes, inspect cluster, execute commands inside running container, and get an interactive shell to a running container.
Suppose you have a
hello-ssh. To get a shell to the running container on this
pod, just run:
kubectl exec -it hello-ssh -- /bin/bash # see shell prompt ... root@hello-ssh:/#
kubectl exec invokes Kubernetes API Server and it "asks" a
Kubelet "node agent" to run an
exec command against CRI (Container Runtime Interface), most frequently it is a Docker runtime.
docker exec API/command creates a new process, sets its namespaces to a target container's namespaces and then executes the requested command, handling also input and output streams for created process.