Skip to content
Latchkey

kubectl get: Usage, Options & Common CI Errors

List and inspect any resource type in one command.

kubectl get is the primary read command: it lists one or more resources and prints them as a table, YAML, JSON, or a custom layout. It is the first thing you run when a deploy looks wrong.

What it does

kubectl get RESOURCE [NAME] queries the API server and prints matching objects. With no name it lists all objects of that type in the current namespace; add -A (--all-namespaces) to span every namespace. -o controls output (wide, yaml, json, name, jsonpath, custom-columns), -w streams changes, and -l filters by label.

Common usage

Terminal
kubectl get pods                       # pods in current namespace
kubectl get pods -A -o wide            # all namespaces, node + IP columns
kubectl get deploy,svc -l app=web      # multiple types, filtered by label
kubectl get pod my-pod -o yaml         # full object as YAML
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
kubectl get events --sort-by=.lastTimestamp

Common errors in CI

In a pipeline you often see "No resources found in <namespace> namespace." - get exited 0 with an empty list because the objects are in a different namespace (you forgot -n) or have not been created yet. A script that greps that output silently passes. Pin the namespace and assert on the count: kubectl get pods -n prod --no-headers | wc -l, or use kubectl wait instead of polling get. "Error from server (NotFound)" means you named a specific object that does not exist; "the server doesn't have a resource type" means a CRD is not installed.

Options

FlagEffect
-A, --all-namespacesList across every namespace
-o wide|yaml|json|nameOutput format
-l, --selectorFilter by label (app=web)
-w, --watchStream changes as they happen
--field-selectorFilter by field (status.phase=Running)
--no-headersOmit the header row (scripting)

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →