CodeBlanks Logo Icon CodeBlanks

kubectl describe

Learn resource details with kubectl describe.

kubectl describe

kubectl describe shows a human-readable detailed summary of an object and, at the bottom, the related events. The answers to why a pod doesn't start or keeps restarting are usually in the events:

$ kubectl describe pod web-7c5b9f6d8-abcde
Name:         web-7c5b9f6d8-abcde
Node:         worker-1/192.168.49.3
Status:       Running
Containers:
  nginx:
    Image:    nginx:1.27
    State:    Running
Events:
  Normal  Scheduled  10s  default-scheduler  Successfully assigned default/web-… to worker-1
  Normal  Pulled     8s   kubelet            Container image "nginx:1.27" already present

kubectl explain

When writing YAML, if you forget what a field means, kubectl explain fetches the documentation from the cluster's own definitions:

$ kubectl explain deployment.spec.replicas
KIND:     Deployment
FIELD:    replicas <integer>
DESCRIPTION:
    Number of desired pods. Defaults to 1.
$ kubectl explain pod.spec.containers --recursive | head

Practice Inspect and learn

Write three commands: show the web deployment in detail; show the documentation of the pod.spec.containers.image field; get the full definition of the web deployment as YAML.

Starter code

terminal
# buraya yaz

Sample solution

terminal
kubectl describe deployment web
kubectl explain pod.spec.containers.image
kubectl get deployment web -o yaml

Expected output

Name:                   web
Replicas:               2 desired | 2 updated | 2 total | 2 available
FIELD:    image <string>
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the difference between get -o yaml and describe?

  • describe gives a readable summary and events; -o yaml is the raw object Correct answer
  • They are the same
  • describe changes the object
  • -o yaml shows the events too

Explanation: Events are separate objects; describe links and shows them.

2 Show a field's documentation.

Question
kubectl ____ deployment.spec.replicas
Answer
kubectl explain deployment.spec.replicas

Explanation: explain gives the field type and description.

3 Match.

Term Meaning
describe Readable summary and events
get -o yaml Raw object
explain Field documentation
Events What happened

All lessons in Intermediate