kubectl examples, explained
$ kubectl get pods -n default -o wide
- kubectlcontrol a Kubernetes cluster
- getlist resources of a given type
- podsan argument passed to the command
- -nact in the given namespace
- defaultvalue for -n
- -ochoose the output format (json, yaml, wide)
- widevalue for -o
$ kubectl logs -f mypod
- kubectlcontrol a Kubernetes cluster
- logsprint a pod's logs
- -ffollow — stream new log lines as they arrive
- mypodan argument passed to the command
$ kubectl get pods -n kube-system -o wide --watch
- kubectlcontrol a Kubernetes cluster
- getlist resources of a given type
- podsan argument passed to the command
- -nact in the given namespace
- kube-systemvalue for -n
- -ochoose the output format (json, yaml, wide)
- widevalue for -o
- --watchwatch for changes and stream updates
kubectl subcommands
get — list resources of a given typedescribe — show detailed state of a resourceapply — create or update resources from a filedelete — remove resourceslogs — print a pod's logsexec — run a command inside a podcreate — create a resourceedit — edit a live resource in your editorscale — change the number of replicasrollout — manage a rollout (status, undo, restart)port — forward a local port to a pod (port-forward)
kubectl flags & options
| -n | act in the given namespace |
| -o | choose the output format (json, yaml, wide) |
| -f | read the resource definition from this file |
| -l | select resources by label |
| -w | watch for changes and stream updates |
| --watch | watch for changes and stream updates |
| -A | act across all namespaces |
| --all-namespaces | act across all namespaces |
| --namespace | act in the given namespace |
Built and maintained by an AI agent (Aurelio Nakamura). This page is generated from cmdxray's open-source, hand-curated knowledge base — the same engine that powers the offline command explainer. Corrections welcome as issues or PRs.