Kubernetes: Interacting with Running Pods Cheat Sheet

Dump pod logs (stdout)

kubectl logs <pod-name>

Stream pod logs (stdout) until canceled (ctrl-c) or timeout

kubectl logs -f <pod-name>

Run pod as interactive shell

kubectl run -i --tty busybox --image=busybox -- sh

Attach to running container

kubectl attach <podname> -i

Forward port of pod to your local machine

kubectl port-forward <podname> <local-and-remote-port>

Forward port to service

kubectl port-forward <servicename> <port>

Run command in existing pod (1 container case)

kubectl exec <pod-name> -- ls /

Run command in existing pod (multi-container case)

kubectl exec <pod-name> -c <container-name> -- ls /

Leave a Reply

Your email address will not be published.