kubectl run web --image=nginx --dry-run=client -o yaml
Generate YAML template
kubectl run job1 --image=alpine --restart=OnFailure
Create a Job
3. Listing Pods
kubectl get pods # current namespacekubectl get pods -A # all namespaceskubectl get pods -o wide # add node + IPkubectl get pods -l app=web,env=prod # label filterkubectl get pods --field-selector=status.phase=Running
Phase
Meaning
Pending
Accepted, not yet running (scheduling/pulling)
Running
At least one container started
Succeeded
All containers terminated successfully
Failed
All terminated; ≥1 with non-zero exit
Unknown
State could not be obtained
4. Describing Pod Details
Section
Use
Status / Conditions
PodScheduled, Initialized, Ready, ContainersReady
Containers
Image, ports, env, mounts, last state, restart count
Volumes
Mounted volumes
Events
Recent scheduling/pull/probe events
kubectl describe pod web -n prod
5. Viewing Pod Logs
Flag
Effect
-c CONTAINER
Multi-container pod
--previous
Logs from prior crashed container
--tail=100
Last N lines
--since=10m
Time window
--timestamps
RFC3339 timestamps
-l app=web
Across pods matching label
6. Following Log Streams
kubectl logs -f web # tail single podkubectl logs -f -l app=web --max-log-requests=10stern '^web-.*' -n prod # plugin: multi-pod follow
kubectl delete pod --field-selector=status.phase=Failed
Cleanup failed pods
10. Using Pod Selectors
Syntax
Meaning
-l app=web
Equality
-l 'env in (prod,staging)'
Set-based
-l 'env notin (dev)'
Negation
-l '!canary'
Label absent
-l 'tier,!debug'
Combined
11. Watching Pod Status
kubectl get pods -w # stream changeskubectl get pods --watch-onlywatch -n 1 kubectl get pods # shell watch
Flag
Effect
-w
Initial list + updates
--watch-only
Skip initial list
12. Getting Pod YAML
kubectl get pod web -o yamlkubectl get pod web -o yaml | kubectl neat # strip generated fieldskubectl get pod web -o jsonpath='{.spec.containers[*].image}'