Bird
Raised Fist0
Kubernetesdevops~5 mins

kubectl describe for details in Kubernetes - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sometimes you need to see detailed information about a Kubernetes object to understand its current state and troubleshoot issues. The kubectl describe command shows you this detailed view, including events and status.
When you want to check why a pod is not starting properly by seeing its events and status.
When you need to see detailed information about a deployment, such as replicas and conditions.
When you want to inspect the configuration and status of a service or other Kubernetes resource.
When you want to debug issues by looking at recent events related to a resource.
When you want to verify labels, annotations, and other metadata on a Kubernetes object.
Commands
This command creates a deployment named example-deployment using the nginx image. It sets up the resource we will describe next.
Terminal
kubectl create deployment example-deployment --image=nginx
Expected OutputExpected
deployment.apps/example-deployment created
→
--image - Specifies the container image to use for the deployment
This command shows detailed information about the example-deployment, including its current state, replicas, and events.
Terminal
kubectl describe deployment example-deployment
Expected OutputExpected
Name: example-deployment Namespace: default CreationTimestamp: 2024-06-01T12:00:00Z Labels: <none> Annotations: deployment.kubernetes.io/revision: 1 Selector: app=example-deployment Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 25% max unavailable, 25% max surge Pod Template: Labels: app=example-deployment Containers: nginx: Image: nginx Port: <none> Environment: <none> Mounts: <none> Conditions: Type Status Reason ---- ------ ------ Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailable Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ScalingReplicaSet 10s deployment-controller Scaled up replica set example-deployment-xxxx to 1
This command shows detailed information about the pod(s) created by the deployment, filtered by the label app=example-deployment.
Terminal
kubectl describe pod -l app=example-deployment
Expected OutputExpected
Name: example-deployment-xxxx Namespace: default Priority: 0 Node: node-1/192.168.1.10 Start Time: 2024-06-01T12:00:10Z Labels: app=example-deployment Annotations: <none> Status: Running IP: 10.244.1.5 Containers: nginx: Container ID: docker://abcdef123456 Image: nginx Image ID: docker-pullable://nginx@sha256:xxxx Port: <none> State: Running Started: 2024-06-01T12:00:15Z Ready: True Restart Count: 0 Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 20s default-scheduler Successfully assigned default/example-deployment-xxxx to node-1 Normal Pulled 18s kubelet Container image "nginx" already present on machine Normal Created 18s kubelet Created container nginx Normal Started 17s kubelet Started container nginx
→
-l - Filters resources by label selector
Key Concept

If you remember nothing else from this pattern, remember: kubectl describe shows detailed status and events of Kubernetes objects to help you understand and debug them.

Common Mistakes
Using kubectl describe without specifying the resource name or label selector
The command will fail or show too much information, making it hard to find what you need.
Always specify the exact resource name or use a label selector to narrow down the output.
Expecting kubectl describe to show logs or container output
kubectl describe shows metadata and events, not container logs.
Use kubectl logs to see container output instead.
Summary
Create a deployment to have a resource to inspect.
Use kubectl describe deployment to see detailed info and events about the deployment.
Use kubectl describe pod with a label selector to see detailed info about pods created by the deployment.

Practice

(1/5)
1. What does the kubectl describe command primarily show about a Kubernetes resource?
easy
A. Detailed information including status, events, and configuration of the resource
B. Only the YAML configuration of the resource
C. The logs generated by the resource
D. The list of all resources in the cluster

Solution

  1. Step 1: Understand the purpose of kubectl describe

    This command provides detailed information about a specific Kubernetes resource, including its current status, configuration details, and recent events.
  2. Step 2: Compare with other kubectl commands

    Unlike kubectl get which lists resources or kubectl logs which shows logs, kubectl describe gives a detailed snapshot of the resource's state and events.
  3. Final Answer:

    Detailed information including status, events, and configuration of the resource -> Option A
  4. Quick Check:

    kubectl describe = detailed resource info [OK]
Hint: Remember: describe = detailed info + events [OK]
Common Mistakes:
  • Confusing describe with get for YAML output
  • Expecting logs from describe command
  • Using describe without specifying resource name
2. Which of the following is the correct syntax to describe a pod named web-server in the default namespace?
easy
A. kubectl describe pod web-server -n default
B. kubectl describe pods web-server default
C. kubectl describe web-server pod -n default
D. kubectl describe pod web-server

Solution

  1. Step 1: Identify correct resource type and name syntax

    The command format is kubectl describe <resource-type> <resource-name>. For pods, resource type is pod (singular or plural works but singular is preferred).
  2. Step 2: Specify namespace correctly

    To specify the namespace, use the -n or --namespace flag after the resource name. The correct placement is kubectl describe pod web-server -n default.
  3. Final Answer:

    kubectl describe pod web-server -n default -> Option A
  4. Quick Check:

    Correct syntax = resource type + name + -n namespace [OK]
Hint: Use '-n' flag for namespace after resource name [OK]
Common Mistakes:
  • Placing namespace as a positional argument
  • Swapping resource name and type order
  • Omitting the namespace flag when needed
3. Given the command kubectl describe node worker-node-1, what key information would you expect to see in the output?
medium
A. List of all pods in the cluster
B. Pod logs running on worker-node-1
C. Detailed node status including capacity, conditions, and allocated resources
D. YAML configuration of the node

Solution

  1. Step 1: Understand what describing a node shows

    kubectl describe node shows detailed info about the node's status, including CPU and memory capacity, conditions like Ready or NotReady, and resource allocation.
  2. Step 2: Differentiate from other outputs

    It does not show pod logs (that's kubectl logs), nor does it list all pods or show YAML (that's kubectl get node -o yaml).
  3. Final Answer:

    Detailed node status including capacity, conditions, and allocated resources -> Option C
  4. Quick Check:

    Describe node = status + capacity + conditions [OK]
Hint: Describe node shows status and capacity, not logs [OK]
Common Mistakes:
  • Expecting pod logs from node describe
  • Confusing describe output with get -o yaml
  • Thinking it lists all pods in cluster
4. You run kubectl describe pod myapp-pod but get an error: Error from server (NotFound): pods "myapp-pod" not found. What is the most likely cause?
medium
A. You need to add --all-namespaces to describe pods
B. The kubectl describe command does not support pods
C. The Kubernetes cluster is down
D. The pod name is incorrect or does not exist in the current namespace

Solution

  1. Step 1: Analyze the error message

    The error says the pod "myapp-pod" was not found. This usually means the pod name is wrong or it does not exist in the current namespace.
  2. Step 2: Check command and cluster status

    kubectl describe supports pods, and the cluster being down would cause different errors. Also, --all-namespaces is not required but can help find pods in other namespaces.
  3. Final Answer:

    The pod name is incorrect or does not exist in the current namespace -> Option D
  4. Quick Check:

    NotFound error = wrong pod name or namespace [OK]
Hint: Check pod name and namespace if NotFound error appears [OK]
Common Mistakes:
  • Assuming describe doesn't support pods
  • Ignoring namespace context
  • Thinking cluster is down without checking
5. You want to check why a deployment named frontend is not creating pods as expected. Which kubectl describe command and output section will help you diagnose the issue?
hard
A. kubectl describe pod frontend; check the Status section for pod readiness
B. kubectl describe deployment frontend; check the Events section for errors
C. kubectl describe service frontend; check the Endpoints section
D. kubectl describe node frontend; check the Capacity section

Solution

  1. Step 1: Identify the correct resource to describe

    Since the issue is with a deployment named frontend, you should describe the deployment resource, not pods, services, or nodes.
  2. Step 2: Locate the useful output section

    The Events section in the deployment description shows recent errors or warnings related to pod creation or scaling issues, which helps diagnose why pods are not created.
  3. Final Answer:

    kubectl describe deployment frontend; check the Events section for errors -> Option B
  4. Quick Check:

    Describe deployment + Events = diagnose pod creation issues [OK]
Hint: Check deployment Events for pod creation errors [OK]
Common Mistakes:
  • Describing pod instead of deployment
  • Checking service or node instead of deployment
  • Ignoring Events section in output
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard