Kubernetes Topics (3)Tap to view
    Kubernetes·Container Orchestration·Topic 1 of 3

    Kubernetes Pods Cheat Sheet

    Commands for managing and diagnosing Pods, checking status, reading live logs, executing interactive commands, and forwarding ports.

    1. Pod Management & Inspection

    1. kubectl get pods -A

      What 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

      Examplekubectl get pods -A -o wide

    2. kubectl get pods -n <ns> -w

      What 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

      Examplekubectl get pods -n production -w

    3. kubectl 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

      Examplekubectl describe pod api-server-79bbd8f-4x9zq -n production

    4. kubectl 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

      Examplekubectl logs web-service-7db5c -f -n production

    5. kubectl 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

      Examplekubectl logs crash-service-xyz -p -n production

    6. kubectl exec -it <pod-name> -n <ns> -- /bin/sh

      What 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

      Examplekubectl exec -it redis-master-0 -n database -- sh

    7. kubectl 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

      Examplekubectl port-forward pod/postgres-0 5432:5432 -n database

    8. kubectl delete pod <pod-name> -n <ns> --grace-period=0 --force

      What 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

      Examplekubectl delete stuck pod-pod-99 -n default --grace-period=0 --force

    Offline · Reading cached copy