kubectl 1.37 reference · Basics

kubectl get Command (kubectl)

List resources in a table, or print them as YAML, JSON, JSONPath or custom columns for scripts and debugging.

kubectl 1.37

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

kubectl get RESOURCE [NAME] [-n NAMESPACE] [-l SELECTOR] [-o FORMAT]

Parameters

ParameterDescription
-n NAMESPACE / -A One namespace, or all namespaces.
-l SELECTOR Filter by labels, e.g. app=web.
-o wide|yaml|json|jsonpath=...|custom-columns=... Output format.
--watch Keep printing changes.

Examples

Custom columns
kubectl create namespace rc-ref-get > /dev/null
trap 'kubectl delete namespace rc-ref-get --wait=false > /dev/null' EXIT
kubectl -n rc-ref-get create deployment web --image=nginx:1.29-alpine --replicas=2 > /dev/null
kubectl -n rc-ref-get rollout status deployment/web --timeout=120s > /dev/null
kubectl -n rc-ref-get get deployment web -o custom-columns=NAME:.metadata.name,READY:.status.readyReplicas,IMAGE:.spec.template.spec.containers[0].image

Output

NAME   READY   IMAGE
web    2       nginx:1.29-alpine

Run this on your computer — see “Get Started” for setup.

JSONPath
kubectl create namespace rc-ref-get2 > /dev/null
trap 'kubectl delete namespace rc-ref-get2 --wait=false > /dev/null' EXIT
kubectl -n rc-ref-get2 create configmap app --from-literal=MODE=demo > /dev/null
kubectl -n rc-ref-get2 get configmap app -o jsonpath='{.data.MODE}{"\n"}'
kubectl get namespace rc-ref-get2 -o jsonpath='{.status.phase}{"\n"}'

Output

demo
Active

Run this on your computer — see “Get Started” for setup.

Was this page helpful?