Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →