Kubectl Logs and Exec
Debug live workloads: stream logs and run commands in pods.
- kubectl logs
- kubectl exec
- crashed container
- follow logs
- kubectl cp
Kubectl Logs and Exec
Debug live workloads: stream logs and run commands in pods.
Commands
| Command | What it does |
|---|---|
kubectl logs -f deploy/api | Follow aggregated deployment logs |
kubectl logs -p <pod> | Previous (crashed) container logs |
kubectl logs <pod> --since=10m --tail=200 | Bounded recent logs |
kubectl exec -it <pod> -- sh | Interactive shell |
kubectl cp <pod>:/app/out ./out | Copy files from a pod |
Example
kubectl logs -f deploy/api -n shop
kubectl logs -p api-7d9c5f6b9-abcde -n shop
kubectl exec -it api-7d9c5f6b9-abcde -n shop -- sh
FAQ
Logs are gone after restart — why?
kubelet keeps few rotated files; ship stdout to Loki/ES for anything beyond quick debugging.
exec fails with no shell?
Distroless images have none — use kubectl debug with an ephemeral debug container instead.
Întrebări frecvente
Logs are gone after restart — why?
kubelet keeps few rotated files; ship stdout to Loki/ES for anything beyond quick debugging.
exec fails with no shell?
Distroless images have none — use kubectl debug with an ephemeral debug container instead.
Kubernetes
Kubectl Config and Context
Point kubectl at the right cluster and switch contexts safely.
Kubectl Pods
Inspect pods, describe failures, and get a shell inside.
Kubectl Deployments
Create, update, and inspect Deployments that own your pods.
Kubectl Services
Expose pods stably with ClusterIP, NodePort, and LoadBalancer.