Kubernetes Describe Command

KubernetesKubernetesBeginner
Practice Now

Introduction

The Kubernetes describe command is a powerful tool for viewing detailed information about Kubernetes resources. With the describe command, you can view information such as resource status, events, labels, annotations, and more. This can be useful for troubleshooting issues in your Kubernetes cluster.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL kubernetes(("`Kubernetes`")) -.-> kubernetes/TroubleshootingandDebuggingCommandsGroup(["`Troubleshooting and Debugging Commands`"]) kubernetes(("`Kubernetes`")) -.-> kubernetes/BasicCommandsGroup(["`Basic Commands`"]) kubernetes(("`Kubernetes`")) -.-> kubernetes/AdvancedCommandsGroup(["`Advanced Commands`"]) kubernetes(("`Kubernetes`")) -.-> kubernetes/ConfigurationandVersioningGroup(["`Configuration and Versioning`"]) kubernetes(("`Kubernetes`")) -.-> kubernetes/ClusterInformationGroup(["`Cluster Information`"]) kubernetes/TroubleshootingandDebuggingCommandsGroup -.-> kubernetes/describe("`Describe`") kubernetes/TroubleshootingandDebuggingCommandsGroup -.-> kubernetes/exec("`Exec`") kubernetes/BasicCommandsGroup -.-> kubernetes/get("`Get`") kubernetes/AdvancedCommandsGroup -.-> kubernetes/apply("`Apply`") kubernetes/ConfigurationandVersioningGroup -.-> kubernetes/version("`Version`") kubernetes/ClusterInformationGroup -.-> kubernetes/cluster_info("`Cluster Info`") subgraph Lab Skills kubernetes/describe -.-> lab-8101{{"`Kubernetes Describe Command`"}} kubernetes/exec -.-> lab-8101{{"`Kubernetes Describe Command`"}} kubernetes/get -.-> lab-8101{{"`Kubernetes Describe Command`"}} kubernetes/apply -.-> lab-8101{{"`Kubernetes Describe Command`"}} kubernetes/version -.-> lab-8101{{"`Kubernetes Describe Command`"}} kubernetes/cluster_info -.-> lab-8101{{"`Kubernetes Describe Command`"}} end

Start Minikube and Verify the Cluster

Before working with Kubernetes, you need a running cluster. Minikube provides a lightweight local Kubernetes cluster.

  1. Navigate to your project directory:

    Open your terminal and navigate to the default working directory:

    cd /home/labex/project
  2. Start Minikube:

    Start Minikube to initialize the cluster:

    minikube start
    • Minikube creates a single-node Kubernetes cluster. This step may take a few minutes.
  3. Verify Minikube status:

    Check if Minikube started successfully:

    minikube status

    Look for components like apiserver and kubelet listed as Running.

  4. Confirm Kubernetes configuration:

    Ensure kubectl is connected to the Minikube cluster:

    kubectl cluster-info

    This displays details about the API server and other components.

If Minikube fails to start. Use minikube delete to reset and try again.

Explore the kubectl describe Command

The kubectl describe command is used to show detailed information about a specific resource or group of resources. It provides insights into the resource's configuration, status, and related events.

Run the following command to view the available options for kubectl describe:

kubectl describe -h

You will see the following output:

Show details of a specific resource or group of resources.

Print a detailed description of the selected resources, including related resources such as events or controllers. You
may select a single object by name, all objects of that type, provide a name prefix, or label selector. For example:

  $ kubectl describe TYPE NAME_PREFIX

will first check for an exact match on TYPE and NAME_PREFIX. If no such resource exists, it will output details for
every resource that has a name prefixed with NAME_PREFIX.

Use "kubectl api-resources" for a complete list of supported resources.

Examples:
  ## Describe a node
  kubectl describe nodes kubernetes-node-emt8.c.myproject.internal

  ## Describe a pod
  kubectl describe pods/nginx

  ## Describe a pod identified by type and name in "pod.json"
  kubectl describe -f pod.json

  ## Describe all pods
  kubectl describe pods

  ## Describe pods by label name=myLabel
  kubectl describe po -l name=myLabel

  ## Describe all pods managed by the 'frontend' replication controller
  ## (rc-created pods get the name of the rc as a prefix in the pod name)
  kubectl describe pods frontend

Describe a Pod

In this step, you will learn how to use the describe command to view information about a Kubernetes Pod.

  1. Create a simple pod that will be used as the template for the replicas. Create a file called myapp-pod.yaml with the following contents:

    apiVersion: v1
    kind: Pod
    metadata:
      name: myapp-pod
    spec:
      containers:
        - name: myapp-container
          image: nginx
          ports:
            - containerPort: 80

    Create the pod using the following command:

    kubectl apply -f myapp-pod.yaml
  2. Then describe the pod:

    kubectl describe pod myapp-pod

This command will retrieve detailed information about the specified Pod, including status, labels, annotations, events, and more.

Describe a Deployment

In this step, you will learn how to use the describe command to view information about a Kubernetes Deployment.

  1. Create a file called myapp-deployment.yaml with the following content:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: myapp-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: myapp-deployment
      template:
        metadata:
          labels:
            app: myapp-deployment
        spec:
          containers:
            - name: myapp-container
              image: nginx:latest
              ports:
                - containerPort: 80

    Create the deployment using the following command:

    kubectl apply -f myapp-deployment.yaml
  2. Describe the deployment:

    kubectl describe deployment myapp-deployment

This command will retrieve detailed information about the specified Deployment, including status, labels, annotations, events, and more.

Describe a Service

In this step, you will learn how to use the describe command to view information about a Kubernetes Service.

  1. Create a file called myapp-service.yaml with the following content:

    apiVersion: v1
    kind: Service
    metadata:
      name: myapp-service
    spec:
      selector:
        app: myapp-deployment
      ports:
        - protocol: TCP
          port: 80
          targetPort: 80

    Create the service using the following command:

    kubectl apply -f myapp-service.yaml
  2. Use the following command to describe the service:

    kubectl describe service myapp-service

This command will retrieve detailed information about the specified Service, including status, labels, annotations, events, and more.

Summary

In this lab, you learned how to use the Kubernetes describe command to view detailed information about Kubernetes resources. You learned how to describe a Pod, Deployment, and Service.

Other Kubernetes Tutorials you may like