Skip to content

Instantly share code, notes, and snippets.

@DoZator
Last active April 8, 2025 07:54
Show Gist options
  • Save DoZator/61f37d6b41c827ba9f73f55eef527d24 to your computer and use it in GitHub Desktop.
Save DoZator/61f37d6b41c827ba9f73f55eef527d24 to your computer and use it in GitHub Desktop.
Kubernetes cheatsheet

Cluster & Context

  • List all available contexts
kubectl config get-contexts
  • Show current context
kubectl config curret-context
  • Switch to a different context
kubectl config use-context {ctx_name}
  • Set default namespace for a context
kubectl config set-context {ctx_name} --namespace={ns_name}
  • Show cluster info
kubectl cluster-info

Namespaces

  • List all namespaces
kubectl get namespaces
  • Create namespace
kubectl create namespace {ns_name}
  • Delete namespace
kubectl delete namespace {ns_name}

Pods

  • List pods across all namespaces
kubectl get pods --all-namespaces

or

kubectl get pods --A
  • List pods in current namespace (default)
kubectl get pods
  • List pods for namespace
kubectl get pods --namespace {ns_name}
  • List pods for namespace with more details
kubectl get pods --namespace {ns_name} -o wide
  • Show details of a specific pod
kubectl describe pod {pod_name}
  • Show CPU and memory usage for pods in namespace
kubectl top pod --namespace {ns_name}
  • Fetch logs of a pod
kubectl logs {pod_name} --namespace {ns_name}
  • Stream logs of a pod (stdout)
kubectl -f logs {pod_name} --namespace {ns_name}
  • Access a running pod's shell
kubectl exec -it {pod_name} -- bash
  • Show pod's ENV
kubectl exec -n {ns_name} {pod_name} -- env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment