TechDBzone

Kubernetes Troubleshooting Commands

March 12, 2024 | by techdbzone.com

DALL·E 2024-04-11 13.40.00 – Create an informative and engaging illustration that showcases a list of essential Kubernetes troubleshooting commands. The image should resemble a co

Kubernetes Troubleshooting Commands

Cluster-Level Troubleshooting

kubectl cluster-info
kubectl get nodes

Use this command to check the status of all the nodes in the cluster.

kubectl get pods --all-namespaces

This command lists all the pods in all namespaces, allowing you to identify any pods that are not running or are in a failed state.

kubectl get componentstatuses

This checks the health of core cluster components like the scheduler, controller-manager, and etcd.

Node-Level Troubleshooting

kubectl describe node

This command provides detailed information about a specific node, including its status, capacity, and allocated resources.

kubectl get pods --field-selector spec.nodeName

Pod-Level Troubleshooting

To troubleshoot issues at the pod level, you can use the following commands:

kubectl describe pod

This command provides detailed information about a specific pod, including its status, events, and container logs.

kubectl logs pod

Use this command to view the logs of a specific pod.

kubectl get pod --all-namespaces

This lists all pods across all namespaces, showing their status. Pods in Error, CrashLoopBackOff, or not in a Running state require further investigation.

Network Troubleshooting

To troubleshoot network-related issues, you can use the following commands:

kubectl get services

This command lists all the services in the cluster, allowing you to check if the required services are running.

kubectl get pod -o wide

Use this command to get detailed information about the pods, including their IP addresses and the nodes they are running on.

kubectl run -i --tty --rm debug --image=busybox --restart=Never -- nslookup  

Test DNS resolution within the cluster

Deployment and Service Troubleshooting

To troubleshoot issues related to deployments and services, you can use the following commands:

kubectl get deployments 

This command lists all the deployments in the cluster, allowing you to check their status and conditions.

kubectl get services -A

Use this command to list all the services in all namespaces, allowing you to check their status and endpoints.

kubectl describe deployment -n namespace

Inspect Deployment Status: This command helps in understanding the state of a deployment and possible reasons why it’s not progressing

Advanced Debugging

For advanced debugging, you can use the following commands:

kubectl exec -it

This command allows you to execute a command inside a running pod.

kubectl port-forward

Use this command to forward a local port to a port on a specific pod, allowing you to access the pod directly.

Use of Debug Containers: If you need to diagnose issues within a pod but the container does not have the necessary tools, you can use Ephemeral Containers

kubectl debug -it --image=busybox -n -- /bin/sh

This allows you to run a temporary container in the pod’s namespace to troubleshoot network or filesystem issues.

These commands should help you troubleshoot common issues at different stages in Kubernetes. Consult the official Kubernetes documentation for more detailed information and troubleshooting techniques.

Verified by MonsterInsights