1. Pod Management & Inspection
kubectl get pods -AWhat it doesDisplays all running Pods across the entire namespaces in the cluster
When to use itTo get a quick overview of the health of services across the cluster
Example
kubectl get pods -A -o widekubectl get pods -n <ns> -wWhat it doesMonitors the status of the Pods in real time and prints the changes as they occur (Watch mode)
When to use itWhile deploying a new update or while monitoring a disabled Pod restart
Example
kubectl get pods -n production -wkubectl describe pod <pod-name> -n <ns>What it doesDisplays comprehensive details about the Pod, including recent events and statuses of installed containers and drives
When to use itWhen encountering CrashLoopBackOff or ImagePullBackOff conditions to find out the cause of the failure in the Events section
Example
kubectl describe pod api-server-79bbd8f-4x9zq -n productionkubectl logs <pod-name> -f -n <ns>What it doesPrints the container logs inside the Pod and follows the live broadcast of the logs (-f /follow)
When to use itto track requests or diagnose errors while the application is running
Example
kubectl logs web-service-7db5c -f -n productionkubectl logs <pod-name> -p -n <ns>What it doesDisplays the logs of the previous version of the container that crashed just before it was restarted (-p /previous)
When to use itWhen the application quickly crashes and restarts without the ability to read the live log
Example
kubectl logs crash-service-xyz -p -n productionkubectl exec -it <pod-name> -n <ns> -- /bin/shWhat it doesOpens an interactive terminal session inside the Pod container to execute direct commands
When to use itto test the internal network or examine configuration files and environments inside the container
Example
kubectl exec -it redis-master-0 -n database -- shkubectl port-forward pod/<pod-name> <local>:<remote> -n <ns>What it doesForward a port from your local device directly to a specific port within the Pod in the Cluster
When to use itTo access internal service and development databases without creating an Ingress or LoadBalancer
Example
kubectl port-forward pod/postgres-0 5432:5432 -n databasekubectl delete pod <pod-name> -n <ns> --grace-period=0 --forceWhat it doesForce the cluster to delete the Pod immediately without waiting for a soft shutdown (Force delete)
When to use itWhen the Pod gets stuck in a Terminating state due to a problem with the node
Example
kubectl delete stuck pod-pod-99 -n default --grace-period=0 --force