kubectl get -o yaml: Usage, Options & Common CI Errors
Dump a live object exactly as the API server stores it.
kubectl get -o yaml prints the complete server representation of a resource - spec, status, and metadata. It is how you inspect what actually got applied and how you capture a baseline for debugging in CI.
What it does
kubectl get RESOURCE NAME -o yaml serialises the live object, including server-defaulted fields, status, and bookkeeping metadata (resourceVersion, uid, creationTimestamp, managedFields). It reflects reality after admission and defaulting, not just what you submitted.
Common usage
kubectl get deploy/web -o yaml
kubectl get deploy/web -o yaml > web.snapshot.yaml
kubectl get configmap app-cfg -o yaml | grep -A20 '^data:'
kubectl get pod my-pod -o yaml | yq '.status.conditions'Common errors in CI
The big gotcha is re-applying this output: a live -o yaml dump carries status, resourceVersion, uid, and managedFields, so kubectl apply -f it back errors or behaves oddly ("resourceVersion should not be set", metadata conflicts). To round-trip an object, strip the runtime fields first (or use kubectl get ... -o yaml --show-managed-fields=false plus a yq scrub). The dump can also be huge because of managedFields noise - pass --show-managed-fields=false to quiet it. Remember Secrets print base64-encoded data, not plaintext.
Using this in CI
A runner has no kubeconfig, no cached context, and no interactive auth. Every kubectl invocation in CI needs the context supplied explicitly, and most confusing CI failures here are the command running against the wrong cluster or no cluster at all.
# never rely on the ambient context on a runner
kubectl --context "$KUBE_CONTEXT" -n "$NAMESPACE" get pods
# confirm what you are actually connected to before mutating anything
kubectl config current-context
kubectl cluster-info
# fail fast instead of hanging on an unreachable API server
kubectl --request-timeout=30s get nodes