Read spec and status in Kubernetes YAML · Kubernetes
Separate what you request from what the system has observed.
Learn with progress and quizzesFirst, understand the concepts.
Resource identity
apiVersion and kind identify the resource type; metadata.name and namespace identify the object. The same name in another namespace is a different object.
Spec and status
spec describes the requested state. status records observations from controllers and nodes, so their difference can indicate reconciliation in progress.
API schema
kubectl explain reads field descriptions from the connected API. Use it to check field locations and types before copying YAML.
Why it matters
Read an API object as an address, desired state, and observed state. The same name in another kind or namespace identifies a different object.
Work through the reasoning
Read each document region
apiVersion and kind identify the schema. metadata carries identity and labels, spec contains requested settings, and status reports system observations.
Compare with the server schema
Use kubectl explain to inspect field types and descriptions. For unfamiliar fields, read warnings or errors and inspect the stored object instead of assuming the setting took effect.
Learn by doing.
Use kubectl, a personal practice Kubernetes cluster, and a POSIX shell. Check the context and use the dedicated namespace in each lab. Cleanup deletes all resources in that practice namespace.
Declare a ConfigMap in a practice namespace and inspect API resources and schemas. A ConfigMap holds configuration; it is not a running object with Pod-like execution status.
kubectl config current-context
kubectl create namespace study-k8s-api --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -n study-k8s-api -f - <<'YAML'
apiVersion: v1
kind: ConfigMap
metadata:
name: settings
data:
mode: practice
YAML
kubectl get configmap settings -n study-k8s-api -o yaml
kubectl api-resources --namespaced=true
kubectl explain pod.spec
kubectl explain pod.statusHow to check your result
Confirm mode=practice and namespace study-k8s-api. Compare the Pod spec and status schemas and write down one user-specified field and one observed field.
Clean up practice resources
Run after checking the result. Confirm these resources belong to your practice run and contain no data you need to keep.
kubectl delete namespace study-k8s-apiApply what you learned
Should you edit status.replicas to request a different Deployment replica count?
Reveal the reasoning after trying
No. Declare the desired count in spec.replicas. status.replicas reports what the controller observes. After applying, compare how observed state converges toward intent.
Ready to check your understanding?
Which Pod field primarily records observed current state?
- metadata.name
- status
- apiVersion
- kind
Reveal the reasoning after trying
status
status contains observed state. spec declares desired behavior, while metadata identifies the object.
Official documentation · Read spec and status in Kubernetes YAML