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.
Start Minikube and Verify the Cluster
Before working with Kubernetes, you need a running cluster. Minikube provides a lightweight local Kubernetes cluster.
Navigate to your project directory:
Open your terminal and navigate to the default working directory:
cd /home/labex/projectStart Minikube:
Start Minikube to initialize the cluster:
minikube start- Minikube creates a single-node Kubernetes cluster. This step may take a few minutes.
Verify Minikube status:
Check if Minikube started successfully:
minikube statusLook for components like
apiserverandkubeletlisted asRunning.Confirm Kubernetes configuration:
Ensure
kubectlis connected to the Minikube cluster:kubectl cluster-infoThis 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.
Create a simple pod that will be used as the template for the replicas. Create a file called
myapp-pod.yamlwith the following contents:apiVersion: v1 kind: Pod metadata: name: myapp-pod spec: containers: - name: myapp-container image: nginx ports: - containerPort: 80Create the pod using the following command:
kubectl apply -f myapp-pod.yamlThen 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.
Create a file called
myapp-deployment.yamlwith 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: 80Create the deployment using the following command:
kubectl apply -f myapp-deployment.yamlDescribe 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.
Create a file called
myapp-service.yamlwith the following content:apiVersion: v1 kind: Service metadata: name: myapp-service spec: selector: app: myapp-deployment ports: - protocol: TCP port: 80 targetPort: 80Create the service using the following command:
kubectl apply -f myapp-service.yamlUse 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.


