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

← All kubectl commands · Docker vs Kubernetes