I am putting docker image into POD. We can exec into a Docker container using "docker exec..." Similarly is there a way to exec into container in a POD to check some data ?
Asked
Active
Viewed 3,478 times
2
-
1Possible duplicate of [How to SSH to docker container in kubernetes cluster?](https://stackoverflow.com/questions/38485771/how-to-ssh-to-docker-container-in-kubernetes-cluster) – cookiedough Mar 04 '19 at 15:32
1 Answers
3
There are several ways of how to get inside the Kubernetes container in a Pod.
- kubectl exec (reference link) creates additional process in the Pod's namespace and connects your console to it's stdin/stdout.
Examples:
kubectl exec 123456-7890 date
kubectl exec 123456-7890 -c ruby-container date
kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il
kubectl exec 123456-7890 -i -t -- ls -t /usr
- kubectl attach (reference link) connects your console to stdin/stdout existing container process.
Example:
kubectl attach 123456-7890
kubectl attach 123456-7890 -c ruby-container
kubectl attach 123456-7890 -c ruby-container -i -t
kubectl attach rs/nginx
You can also connect to stdout/stderr of pod container(s) using kubectl logs command.
Examples:
kubectl logs nginx
kubectl logs nginx --all-containers=true
kubectl logs -lapp=nginx --all-containers=true
kubectl logs -p -c ruby web-1
kubectl logs -f -c ruby web-1
These answers on StackOverflow give you more information related to your question:

VAS
- 8,538
- 1
- 28
- 39