inspection
kubectl get
Lists one or more resources of a given type from the cluster. It is the primary read command for pods, services, deployments, and any other Kubernetes object, with flexible output formats for scripting and inspection.
kubectl get [TYPE[.VERSION][.GROUP]] [NAME | -l label] [flags] Common flags
| Flag | Purpose |
|---|---|
| -o, --output | Output format: json, yaml, wide, name, jsonpath, go-template, custom-columns. |
| -n, --namespace | Limit results to a specific namespace. |
| -A, --all-namespaces | List the resource across every namespace. |
| -l, --selector | Filter results by label selector (e.g. app=web,tier=frontend). |
| --field-selector | Filter by field (e.g. status.phase=Running, metadata.name=foo). |
| -w, --watch | Stream updates to the matched resources instead of exiting. |
| --show-labels | Append a LABELS column to the tabular output. |
| --sort-by | Sort output rows by a JSONPath expression against the resource. |
Examples
kubectl get pods -A -o wide List every pod in every namespace with node and IP columns.
kubectl get deploy nginx -o yaml Dump the live YAML of the nginx Deployment.
kubectl get pods -l app=web --field-selector=status.phase=Running Filter running pods by label.
kubectl get events --sort-by=.lastTimestamp Recent events ordered chronologically for triage.
Gotcha
Without -n or -A you only see the current context's default namespace. -o name is the safest format for piping into xargs.
Related commands
kubectl describe
Shows a human-readable, aggregated view of a resource including its spec, status, related events, and controllers. It is the go-to command for debugging why a pod is Pending, CrashLoopBackOff, or otherwise misbehaving.
kubectl explain
Prints documentation for a resource kind and its fields, sourced from the live cluster's OpenAPI schema. It is the offline-safe reference for authoring manifests against the exact API version your cluster serves.
kubectl config
Reads and modifies kubeconfig files that define clusters, users, and contexts. It is how you switch between clusters, change the active namespace, and register new credentials.
kubectl cluster-info
Prints the endpoints of the control-plane services for the current context. The dump subcommand collects a large diagnostic bundle of cluster state for offline analysis.
kubectl top
Displays CPU and memory usage for nodes or pods, powered by the metrics.k8s.io API. Requires the metrics-server (or an equivalent aggregator) to be installed in the cluster.