⎈ Kubernetes CLI Reference

Master kubectl
in one page

Every command you actually need. No fluff, no filler — just the terminal bible for Kubernetes operators.

kubectl — production-cluster
❯
60+commands
8categories
30+flags
1page
⌕
all
basics
workloads
debug
config
network
storage
rbac
🔭
Get & List Resources
kubectl get pods
List all pods in current namespace
kubectl get pods --all-namespaces
List pods across ALL namespaces
kubectl get pods -o wide
Show node IP and node name
kubectl get pod my-pod -o yaml
Output full resource spec as YAML
kubectl describe pod my-pod
Detailed info: events, conditions, volumes
kubectl get nodes -o wide
List cluster nodes with IPs and roles
kubectl get svc
List all services in namespace
kubectl get deployments
List all deployments
kubectl get all
Get pods, services, deployments, etc.
kubectl get pods -w
Watch pod status changes in real-time
kubectl get pods -l app=frontend
Filter by label selector
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
Extract specific fields with JSONPath
⚙️
Workloads & Deployments
kubectl apply -f manifest.yaml
Apply or update resource from file
kubectl run nginx --image=nginx
Create and run a pod from image
kubectl scale deployment my-app --replicas=5
Scale a deployment to N replicas
kubectl rollout restart deployment/my-app
Restart pods with zero downtime
kubectl rollout status deployment/my-app
Watch rollout progress until complete
kubectl rollout undo deployment/my-app
Roll back to previous revision
kubectl rollout history deployment/my-app
View revision history
kubectl set image deployment/my-app container=nginx:1.25
Update container image inline
kubectl delete pod my-pod
Delete a pod (will restart if managed)
kubectl delete pod my-pod --grace-period=0 --force
Force-delete a stuck/terminating pod
🐛
Debugging & Exec
kubectl logs -f my-pod
Stream live logs from pod
kubectl logs my-pod --previous
Logs from a previously crashed container
kubectl logs my-pod -c my-container
Logs from specific container in pod
kubectl exec -it my-pod -- /bin/bash
Interactive shell inside a running pod
kubectl exec my-pod -- env
Run a single command inside pod
kubectl get events --sort-by=.lastTimestamp
View cluster events sorted by time
kubectl top pods
CPU and memory usage per pod
kubectl top nodes
CPU and memory per node
kubectl cp my-pod:/app/logs ./logs
Copy files from pod to local
kubectl port-forward pod/my-pod 8080:80
Forward local port to pod port
🎛️
Config & Context
kubectl config get-contexts
List all available contexts (clusters)
kubectl config use-context my-cluster
Switch active cluster context
kubectl config current-context
Show active context name
kubectl config set-context --current --namespace=prod
Set default namespace for context
kubectl create namespace staging
Create a new namespace
kubectl create secret generic my-secret --from-literal=key=val
Create a generic secret from literal value
kubectl create configmap my-cfg --from-file=config/
Create ConfigMap from directory
kubectl label pod my-pod env=prod
Add or update a label on a resource
kubectl annotate pod my-pod description=web-server
Add annotation to a resource
kubectl edit deployment my-app
Edit resource live in $EDITOR
🌐
Networking & Services
kubectl expose deployment my-app --port=80 --type=LoadBalancer
Expose deployment as LoadBalancer service
kubectl get ingress
List all ingress resources
kubectl get endpoints my-svc
Check endpoints for a service
kubectl get networkpolicies
List all network policies
kubectl port-forward svc/my-svc 9090:80
Forward local port to a service
kubectl run tmp --image=busybox --rm -it -- nslookup my-svc
Debug DNS resolution inside cluster
💾
Storage & PersistentVolumes
kubectl get pvc
List PersistentVolumeClaims
kubectl get pv
List PersistentVolumes in cluster
kubectl get storageclasses
List available storage classes
kubectl describe pvc my-pvc
Debug PVC binding status and events
🔐
RBAC & Auth
kubectl get serviceaccounts
List service accounts in namespace
kubectl get clusterroles
List all cluster-level roles
kubectl get rolebindings
List role bindings in namespace
kubectl auth can-i create deployments
Check if current user has permission
kubectl auth can-i list pods --as=dev-user
Check permissions as another user
kubectl create token my-serviceaccount
Generate API token for service account
🏳️
Global Flags Reference
Flag Shorthand Description
--namespace -n Target a specific namespace
--all-namespaces -A Operate across all namespaces
--output -o Output format: yaml, json, wide, jsonpath
--watch -w Watch for real-time resource changes
--follow -f Follow log output continuously
--selector -l Filter by label selector
--filename -f Specify manifest file or directory
--container -c Target specific container in pod
--stdin + --tty -it Interactive terminal session
--dry-run=client — Preview command without applying changes
--context — Override current kubeconfig context
--kubeconfig — Path to kubeconfig file
--field-selector — Filter by field (e.g. status.phase=Running)
--grace-period — Seconds before force-killing (0 = immediate)
--record — Record command in resource annotations
⚡
Quick Reference — Resource Shortnames
po → pods
deploy → deployments
svc → services
cm → configmaps
ns → namespaces
no → nodes
pvc → persistentvolumeclaims
pv → persistentvolumes
sa → serviceaccounts
ep → endpoints
ds → daemonsets
rs → replicasets
sts → statefulsets
ing → ingresses
hpa → horizontalpodautoscalers
crd → customresourcedefinitions
rb → rolebindings
crb → clusterrolebindings