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
Syntax
kubectl get RESOURCE [NAME] [-n NAMESPACE] [-l SELECTOR] [-o FORMAT]
Parameters
| Parameter | Description |
|---|---|
-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
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.
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.
Related
kubectl describe· Show a detailed, human-readable view of a resource, including related events, the first place to look when debugging.kubectl explain· Show documentation for any resource field straight from the cluster's API schema, including nested fields.- kubectl Essentials · tutorial