Throughout the years of using kubernetes as a developer I’ve collected a bunch of useful commands that helped me to debug issues and have better understanding of what is happening in the cluster.

List all namespaces

kubectl get namespace

List all pods in namespace site

kubectl get pods -n site

Set default namespace

kubectl config set-context --current --namespace=<namespace-name>

Watch for deploy of pods with label app: discounts-endpoint-app

kubectl get pods --selector=app=discounts-endpoint-app --watch

Explain what parameters in deployment mean

kubectl explain deploy  
kubectl explain deploy.spec
kubectl explain deploy.spec.strategy

Show pods sorted by how many times they were restarted

kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'

Watch for container logs

kubectl logs <pod-name> -f  

Show pod logs before restart

kubectl logs <pod-name> --previous

Show pods container image version

kubectl get pods -o custom-columns=',IMAGES:spec.containers[*].image'

Find pod by IP address

kubectl get pods -o wide|grep

List configmaps

kubectl get configmap

Show configmap content in YAML

kubectl get configmap <configmap-name> -o yaml

Useful links: