kubectl get: Command Reference for CI/CD
List and inspect any resource type, in any output format.
kubectl get is the primary read command and the first thing a pipeline runs when a deploy looks wrong. This reference covers output formats and selectors, plus a CI pattern that asserts on a count instead of trusting an empty success.
Common flags and usage
- -A, --all-namespaces: list across every namespace
- -o wide|yaml|json|name: choose the output format
- -o jsonpath='{...}': extract a specific field for scripting
- -l, --selector: filter by label (app=web)
- --field-selector: filter by field (status.phase=Running)
- --no-headers: omit the header row for clean parsing
Example
shell
# Fail the job if no ready pods match the app label
READY=$(kubectl get pods -n prod -l app=web \
--field-selector=status.phase=Running --no-headers | wc -l)
[ "$READY" -gt 0 ] || { echo "no running pods"; exit 1; }
kubectl get deploy web -o jsonpath='{.status.readyReplicas}'In CI
get exits 0 even when it finds nothing, so a script that greps its output can silently pass. Pin the namespace with -n and assert on a count or a jsonpath value, or prefer kubectl wait to gate on an actual condition.
Key takeaways
- get returns exit 0 on empty results; assert on counts, not on success.
- jsonpath extracts single fields cleanly for shell logic.
- Always pin -n in CI; objects in another namespace look like a missing object.
Related guides
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…
kubectl describe: Command Reference for CI/CDReference for kubectl describe: render a resource plus its Events to debug ImagePullBackOff, CrashLoopBackOff…
kubectl wait: Command Reference for CI/CDReference for kubectl wait: block on a condition (Ready, Available, complete, delete) with a timeout, the rig…
kubectl top: Command Reference for CI/CDReference for kubectl top: show live CPU and memory for nodes and pods, sorting and per-container breakdown,…