DEV Community

Jution Candra Kirana
Jution Candra Kirana

Posted on

Kubernetes: Exec

Let's return to the docker material for a moment. In Docker, you can enter a running container using the docker exec command. Similarly, in Kubernetes, you can enter a container within a pod using the kubectl exec command.

Catatan: Since a pod can have more than one container, you can specify the container you want to enter by using the -c {container_name} option. The full command looks like this:

kubectl exec -it {nama_pod} -c {nama_container} -- /bin/sh
Enter fullscreen mode Exit fullscreen mode

So, if you want to enter the container that was created earlier, the command would be:

kubectl exec -it sample-nginx -- /bin/sh

/ # ls
bin                   home                  proc                  sys
dev                   lib                   root                  tmp
docker-entrypoint.d   media                 run                   usr
docker-entrypoint.sh  mnt                   sbin                  var
etc                   opt                   srv
/ #
Enter fullscreen mode Exit fullscreen mode

Top comments (0)