Kubernetes Reference Guide

kubectl Command Cheat Sheet

A practical quick-reference for the kubectl commands used throughout the Kubernetes Field Notes training path.

How to use this page

This is a field reference for common Kubernetes commands. Use it when you know what you are trying to inspect, but need the command quickly.

Habit: Before changing anything, confirm your current context and Namespace.

Context and Namespace

kubectl config current-context
kubectl config get-contexts
kubectl config use-context <context-name>
kubectl config view --minify --output 'jsonpath={..namespace}'
kubectl config set-context --current --namespace=<namespace>
kubectl get namespaces
kubectl get all -n <namespace>
kubectl get all -A

Nodes and cluster information

kubectl cluster-info
kubectl get nodes
kubectl get nodes -o wide
kubectl get nodes --show-labels
kubectl describe node <node-name>
kubectl top nodes

Note: kubectl top requires metrics-server or another metrics pipeline.

Pods

kubectl get pods
kubectl get pods -n <namespace>
kubectl get pods -A
kubectl get pods -o wide
kubectl get pods --show-labels
kubectl describe pod <pod-name> -n <namespace>
kubectl get pod <pod-name> -n <namespace> -o yaml
kubectl delete pod <pod-name> -n <namespace>

Logs and exec

kubectl logs <pod-name> -n <namespace>
kubectl logs -f <pod-name> -n <namespace>
kubectl logs <pod-name> -n <namespace> --previous
kubectl logs deployment/<deployment-name> -n <namespace>
kubectl exec -it <pod-name> -n <namespace> -- /bin/sh
kubectl exec -it <pod-name> -n <namespace> -- /bin/bash

Deployments and rollouts

kubectl get deployments -n <namespace>
kubectl describe deployment <deployment-name> -n <namespace>
kubectl create deployment <name> --image=<image> -n <namespace>
kubectl scale deployment <deployment-name> --replicas=3 -n <namespace>
kubectl set image deployment/<deployment-name> <container>=<image> -n <namespace>
kubectl rollout status deployment/<deployment-name> -n <namespace>
kubectl rollout history deployment/<deployment-name> -n <namespace>
kubectl rollout undo deployment/<deployment-name> -n <namespace>
kubectl delete deployment <deployment-name> -n <namespace>

Services and endpoints

kubectl get services -n <namespace>
kubectl describe service <service-name> -n <namespace>
kubectl expose deployment <deployment-name> --port=80 --target-port=80 --type=ClusterIP -n <namespace>
kubectl get endpoints -n <namespace>
kubectl get endpoints <service-name> -n <namespace>
kubectl port-forward -n <namespace> service/<service-name> 8080:80

Ingress

kubectl get ingress -n <namespace>
kubectl describe ingress <ingress-name> -n <namespace>
kubectl get ingressclass
kubectl get pods -n ingress-nginx
kubectl logs -n ingress-nginx <controller-pod-name>
kubectl port-forward -n ingress-nginx service/ingress-nginx-controller 8080:80
curl.exe -H "Host: example.localhost" http://localhost:8080

ConfigMaps and Secrets

kubectl get configmaps -n <namespace>
kubectl describe configmap <configmap-name> -n <namespace>
kubectl get configmap <configmap-name> -n <namespace> -o yaml
kubectl create configmap <name> --from-literal=KEY=value -n <namespace>

kubectl get secrets -n <namespace>
kubectl describe secret <secret-name> -n <namespace>
kubectl get secret <secret-name> -n <namespace> -o yaml
kubectl create secret generic <name> --from-literal=KEY=value -n <namespace>

Storage

kubectl get storageclass
kubectl get pvc -n <namespace>
kubectl describe pvc <pvc-name> -n <namespace>
kubectl get pv
kubectl describe pv <pv-name>

Jobs and CronJobs

kubectl get jobs -n <namespace>
kubectl describe job <job-name> -n <namespace>
kubectl get cronjobs -n <namespace>
kubectl describe cronjob <cronjob-name> -n <namespace>
kubectl logs <job-pod-name> -n <namespace>

RBAC

kubectl get serviceaccounts -n <namespace>
kubectl describe serviceaccount <serviceaccount-name> -n <namespace>
kubectl get roles -n <namespace>
kubectl get rolebindings -n <namespace>
kubectl auth can-i <verb> <resource> -n <namespace>
kubectl auth can-i list pods --as=system:serviceaccount:<namespace>:<serviceaccount> -n <namespace>

NetworkPolicies

kubectl get networkpolicies -n <namespace>
kubectl describe networkpolicy <policy-name> -n <namespace>
kubectl get pods --show-labels -n <namespace>
kubectl get namespaces --show-labels

Events and output formatting

kubectl get events -n <namespace> --sort-by=.metadata.creationTimestamp
kubectl get events -A --sort-by=.metadata.creationTimestamp
kubectl get pod <pod-name> -o yaml
kubectl get pod <pod-name> -o json
kubectl get pods -o wide
kubectl apply -f file.yaml
kubectl diff -f file.yaml
kubectl delete -f file.yaml
Bottom line: Start broad with get, go deeper with describe, confirm app behavior with logs, and use events to understand what Kubernetes tried to do.
← Back to Kubernetes Field Notes Series index Final Project →