Kubernetes Cheatsheet Command For Troubleshooting

Kubernetes Cheatsheet Command For Troubleshooting

Here are some common Kubernetes commands for troubleshooting:

  • To list all Kubernetes components:
    kubectl get componentstatuses
  • To list all Kubernetes nodes:
     kubectl get nodes
  • To check the status of all Kubernetes pods:
     kubectl get pods -n <namespace>
  • To view the logs of a specific pod:
     kubectl logs <pod-name> -n <namespace>
  • To describe a specific pod and see its details:
     kubectl describe pod <pod-name> -n <namespace>
  • To view the events related to a specific pod:
     kubectl get events --field-selector involvedObject.name=<pod-name> -n <namespace>
  • To list all deployment in a specific namespace
     kubectl get deploy <deployment-name> -n <namespace>
  • To view the details of a specific deployment:
     kubectl describe deploy <deployment-name> -n <namespace>
  • To list all services in namespace
     kubectl get svc <service-name> -n <namespace>
  • To view the details of a specific service:
     kubectl describe svc <service-name> -n <namespace>
  • To access the shell of a specific container inside a pod:
     kubectl exec -it <pod-name> -c <container-name> -n <namespace> -- /bin/sh
  • To execute a command inside a specific container inside a pod:
     kubectl exec -it <pod-name> -c <container-name> -n <namespace> -- <command>
  • To view the resource utilization of all pods in a specific namespace:
     kubectl top pods -n <namespace>
  • To view the resource utilization of all nodes:
     kubectl top nodes
  • To force delete a stuck pod:
     kubectl delete pod <pod-name> --grace-period=0 --force -n <namespace>
  • To delete all pods in a specific namespace:
     kubectl delete pods --all -n <namespace>
  • To list PVC (Persistent Volume Claim) in a specific namespace
     kubectl get pvc <pvc-name> -n <namespace>
  • To view the status of a specific PVC (Persistent Volume Claim):
     kubectl describe pvc <pvc-name> -n <namespace>
  • To view the status of a specific PV (Persistent Volume):
     kubectl describe pv <pv-name> -n <namespace>
  • To list StorageClass in a specific namespace
     kubectl get sc <sc-name> -n <namespace>
  • To view the status of a specific StorageClass:
     kubectl describe sc <sc-name> -n <namespace>
  • To list StatefulSet in a specific namespace
     kubectl get statefulset <statefulset-name> -n <namespace>
  • To view the status of a specific StatefulSet:
     kubectl describe statefulset <statefulset-name> -n <namespace>
  • To view the status of a specific ConfigMap:
     kubectl describe configmap <configmap-name> -n <namespace>

These Kubernetes commands will help you in most use-cases when troubleshooting. 

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.