kubectl 1.37 cheatsheet

kubectl 1.37: Logs and debugging

8 common kubectl 1.37 tasks.

View a pod's logs

Print the logs of a pod. Add -c CONTAINER when the pod runs more than one container.

kubectl logs web-7d9f8c6b5-abcde

Follow logs

Stream logs as they arrive.

kubectl logs -f deploy/web

View logs from before a crash

Print the logs of the previous container instance.

kubectl logs web-7d9f8c6b5-abcde --previous

Open a shell in a pod

Run an interactive shell inside a container.

kubectl exec -it web-7d9f8c6b5-abcde -- sh

Forward a local port

Reach a service from your machine at localhost:8080.

kubectl port-forward svc/web 8080:80

Run a temporary debug pod

Start a pod with a shell, and delete it when you exit.

kubectl run tmp --rm -it --image=busybox -- sh

Attach a debug container

Add an ephemeral container to a running pod to inspect it.

kubectl debug -it web-7d9f8c6b5-abcde --image=busybox --target=web

Copy a file from a pod

Copy a file out of a container.

kubectl cp web-7d9f8c6b5-abcde:/tmp/app.log ./app.log

Was this page helpful?