Kubectl Cheat Sheet

This cheat sheet provides commonly used kubectl commands for managing Kubernetes clusters.

Basic Commands

List all pods

kubectl get pods

List all pods in a specific namespace

kubectl get pods -n <namespace>

List all nodes

kubectl get nodes

List all services

kubectl get services

How to check logs of the pods

kubectl logs <pod-name>

How to check logs of the pods in a specific namespace

kubectl logs <pod-name> -n <namespace>

How to check logs of the pods in a specific container

kubectl logs <pod-name> -c <container-name>

How to check logs of the pods in a specific container in a specific namespace

kubectl logs <pod-name> -c <container-name> -n <namespace>

How to check logs of the pods in a specific container in a specific namespace with timestamps

kubectl logs <pod-name> -c <container-name> -n <namespace> --timestamps

How to check logs of the pods in a specific container in a specific namespace with timestamps and limit the output to 10 lines

kubectl logs <pod-name> -c <container-name> -n <namespace> --timestamps --tail 10