devops/materials/05-kubectl-for-pods.md
2026-01-01 00:00:00 +00:00

42 lines
863 B
Markdown

---
id: mat-05-kubectl-for-pods
title: "kubectl for Pods"
---
# kubectl for Pods
## Apply a manifest
Deploy a Pod:
- `kubectl apply -f pod.yml`
Check Pods:
- `kubectl get pods`
- watch continuously:
- `kubectl get pods --watch`
## Inspect pods with kubectl get
Useful output formats:
- `-o wide` (more columns)
- `-o yaml` (full YAML output)
Tip:
- compare desired state (`spec`) vs observed state (`status`).
## kubectl describe
- `kubectl describe pods <pod-name>`
Useful for events and deep status information.
## kubectl logs
- `kubectl logs <pod-name>`
- for a specific container:
- `kubectl logs <pod-name> --container <container-name>`
## kubectl exec
Run a command in a running Pod:
- `kubectl exec <pod-name> -- <cmd>`
Get a tty:
- `kubectl exec -it <pod-name> -- sh`
For multi-container pods, add `--container <container-name>` as needed.