📖 Guide

Kubernetes & kubectl Cheat Sheet — Complete Reference

Every kubectl command you need for managing Kubernetes clusters, pods, deployments, and services.

129 commands across 12 categories

Cluster Info

CommandDescription
kubectl cluster-info
Display cluster endpoint and services info
kubectl version
Show kubectl client and server versions
kubectl config view
Show merged kubeconfig settings
kubectl config current-context
Display the current context
kubectl config use-context <context>
e.g. kubectl config use-context production
Switch to a different cluster context
kubectl config get-contexts
List all available contexts
kubectl config set-context --current --namespace=<ns>
e.g. kubectl config set-context --current --namespace=my-app
Set the default namespace for the current context
kubectl api-resources
List all supported API resources and their short names
kubectl api-versions
List all supported API versions
kubectl get componentstatuses
Check health of cluster components (scheduler, etcd, controller-manager)

Pods

CommandDescription
kubectl get pods
List all pods in the current namespace
kubectl get pods -A
List pods across all namespaces
kubectl get pods -o wide
List pods with extra details (node, IP)
kubectl get pods -w
Watch pods in real time
kubectl get pods --sort-by=.metadata.creationTimestamp
List pods sorted by creation time
kubectl get pods --field-selector=status.phase=Running
List only running pods
kubectl describe pod <pod>
Show detailed info about a pod (events, containers, volumes)
kubectl run <name> --image=<image>
e.g. kubectl run nginx --image=nginx:latest
Create and run a pod from an image
kubectl run <name> --image=<image> --rm -it -- <cmd>
e.g. kubectl run debug --image=busybox --rm -it -- sh
Run a temporary interactive pod (deleted on exit)
kubectl delete pod <pod>
Delete a pod
kubectl delete pod <pod> --grace-period=0 --force
Force delete a stuck pod immediately
kubectl exec -it <pod> -- <cmd>
e.g. kubectl exec -it my-pod -- /bin/bash
Execute a command inside a running pod
kubectl exec -it <pod> -c <container> -- <cmd>
Execute a command in a specific container within a multi-container pod
kubectl cp <pod>:<path> <local-path>
e.g. kubectl cp my-pod:/var/log/app.log ./app.log
Copy files from a pod to local machine
kubectl cp <local-path> <pod>:<path>
Copy files from local machine to a pod
kubectl get pod <pod> -o yaml
Output pod definition as YAML
kubectl get pod <pod> -o jsonpath='{.status.podIP}'
Get a specific field using JSONPath
kubectl label pod <pod> <key>=<value>
e.g. kubectl label pod my-pod env=production
Add or update a label on a pod
kubectl annotate pod <pod> <key>=<value>
Add or update an annotation on a pod

Deployments

CommandDescription
kubectl get deployments
List all deployments in the current namespace
kubectl describe deployment <name>
Show detailed deployment info including strategy and events
kubectl create deployment <name> --image=<image>
e.g. kubectl create deployment web --image=nginx:1.25
Create a deployment
kubectl apply -f <file>
e.g. kubectl apply -f deployment.yaml
Apply a deployment from a YAML file
kubectl set image deployment/<name> <container>=<image>
e.g. kubectl set image deployment/web nginx=nginx:1.26
Update the image for a deployment (rolling update)
kubectl rollout status deployment/<name>
Watch rollout progress of a deployment
kubectl rollout history deployment/<name>
View rollout history and revisions
kubectl rollout undo deployment/<name>
Rollback to the previous revision
kubectl rollout undo deployment/<name> --to-revision=<n>
e.g. kubectl rollout undo deployment/web --to-revision=3
Rollback to a specific revision number
kubectl rollout restart deployment/<name>
Restart all pods in a deployment (rolling restart)
kubectl rollout pause deployment/<name>
Pause a rollout to batch multiple changes
kubectl rollout resume deployment/<name>
Resume a paused rollout
kubectl delete deployment <name>
Delete a deployment and all its pods
kubectl edit deployment <name>
Edit a deployment in your default editor
kubectl patch deployment <name> -p '{"spec":{"replicas":5}}'
Patch a deployment inline with JSON

Services

CommandDescription
kubectl get services
List all services in the current namespace
kubectl get svc
List services (short alias)
kubectl describe service <name>
Show detailed service info including endpoints
kubectl expose deployment <name> --port=<port> --type=ClusterIP
e.g. kubectl expose deployment web --port=80 --type=ClusterIP
Create a ClusterIP service for a deployment
kubectl expose deployment <name> --port=<port> --type=NodePort
Create a NodePort service accessible on every node
kubectl expose deployment <name> --port=<port> --type=LoadBalancer
Create a LoadBalancer service (cloud only)
kubectl get endpoints <service>
Show the endpoint IPs backing a service
kubectl delete service <name>
Delete a service
kubectl port-forward svc/<name> <local>:<remote>
e.g. kubectl port-forward svc/web 8080:80
Forward a local port to a service
kubectl port-forward pod/<name> <local>:<remote>
Forward a local port directly to a pod

ConfigMaps & Secrets

CommandDescription
kubectl get configmaps
List all ConfigMaps
kubectl create configmap <name> --from-literal=<key>=<value>
e.g. kubectl create configmap app-config --from-literal=DB_HOST=db.example.com
Create a ConfigMap from literal key-value pairs
kubectl create configmap <name> --from-file=<path>
e.g. kubectl create configmap nginx-conf --from-file=nginx.conf
Create a ConfigMap from a file or directory
kubectl describe configmap <name>
Show ConfigMap details and data
kubectl get configmap <name> -o yaml
Output ConfigMap as YAML
kubectl delete configmap <name>
Delete a ConfigMap
kubectl get secrets
List all secrets in the current namespace
kubectl create secret generic <name> --from-literal=<key>=<value>
e.g. kubectl create secret generic db-creds --from-literal=password=s3cret
Create a secret from literal values
kubectl create secret tls <name> --cert=<cert> --key=<key>
e.g. kubectl create secret tls my-tls --cert=tls.crt --key=tls.key
Create a TLS secret from cert and key files
kubectl get secret <name> -o jsonpath='{.data.<key>}' | base64 -d
e.g. kubectl get secret db-creds -o jsonpath='{.data.password}' | base64 -d
Decode and view a secret value
kubectl delete secret <name>
Delete a secret

Namespaces

CommandDescription
kubectl get namespaces
List all namespaces
kubectl create namespace <name>
e.g. kubectl create namespace staging
Create a new namespace
kubectl delete namespace <name>
Delete a namespace and all resources within it
kubectl get all -n <namespace>
List all resources in a specific namespace
kubectl get all -A
List all resources across all namespaces

Nodes

CommandDescription
kubectl get nodes
List all nodes in the cluster
kubectl get nodes -o wide
List nodes with extra info (OS, kernel, container runtime)
kubectl describe node <name>
Show detailed node info (capacity, conditions, pods)
kubectl top nodes
Show CPU and memory usage per node (requires metrics-server)
kubectl cordon <node>
Mark a node as unschedulable (no new pods)
kubectl uncordon <node>
Mark a node as schedulable again
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
Evict all pods from a node for maintenance
kubectl taint nodes <node> <key>=<value>:<effect>
e.g. kubectl taint nodes node1 dedicated=gpu:NoSchedule
Add a taint to a node
kubectl taint nodes <node> <key>-
e.g. kubectl taint nodes node1 dedicated-
Remove a taint from a node

Logs & Debugging

CommandDescription
kubectl logs <pod>
View logs of a pod
kubectl logs <pod> -f
Stream logs in real time (follow)
kubectl logs <pod> --tail=100
Show only the last 100 log lines
kubectl logs <pod> --since=1h
Show logs from the last hour
kubectl logs <pod> -c <container>
View logs of a specific container in a multi-container pod
kubectl logs <pod> --previous
View logs of a previously crashed container
kubectl logs -l <label>=<value>
e.g. kubectl logs -l app=web
View logs from all pods matching a label
kubectl top pods
Show CPU and memory usage per pod
kubectl top pods --sort-by=cpu
Show pods sorted by CPU usage
kubectl get events --sort-by=.metadata.creationTimestamp
List cluster events sorted by time
kubectl get events --field-selector type=Warning
List only warning events
kubectl debug node/<node> -it --image=busybox
Start a debug container on a node
kubectl auth can-i <verb> <resource>
e.g. kubectl auth can-i create deployments
Check if you have permission to perform an action

Scaling

CommandDescription
kubectl scale deployment/<name> --replicas=<n>
e.g. kubectl scale deployment/web --replicas=5
Scale a deployment to N replicas
kubectl autoscale deployment/<name> --min=<n> --max=<n> --cpu-percent=<n>
e.g. kubectl autoscale deployment/web --min=2 --max=10 --cpu-percent=70
Create a Horizontal Pod Autoscaler
kubectl get hpa
List all Horizontal Pod Autoscalers
kubectl describe hpa <name>
Show HPA details including current/target metrics
kubectl delete hpa <name>
Delete a Horizontal Pod Autoscaler
kubectl scale statefulset/<name> --replicas=<n>
Scale a StatefulSet

Networking

CommandDescription
kubectl get ingress
List all Ingress resources
kubectl describe ingress <name>
Show detailed Ingress info (rules, backends)
kubectl get networkpolicies
List all NetworkPolicies
kubectl apply -f ingress.yaml
Create or update an Ingress from a YAML file
kubectl run tmp --image=busybox --rm -it -- wget -qO- <service>:<port>
e.g. kubectl run tmp --image=busybox --rm -it -- wget -qO- web:80
Test service connectivity from within the cluster
kubectl run tmp --image=busybox --rm -it -- nslookup <service>
Test DNS resolution inside the cluster
kubectl get svc -n kube-system
Check core DNS and system services

RBAC

CommandDescription
kubectl get roles
List Roles in the current namespace
kubectl get clusterroles
List all ClusterRoles
kubectl get rolebindings
List RoleBindings in the current namespace
kubectl get clusterrolebindings
List all ClusterRoleBindings
kubectl create role <name> --verb=<verbs> --resource=<resources>
e.g. kubectl create role pod-reader --verb=get,list,watch --resource=pods
Create a Role with specific permissions
kubectl create rolebinding <name> --role=<role> --user=<user>
e.g. kubectl create rolebinding read-pods --role=pod-reader --user=jane
Bind a Role to a user
kubectl create clusterrolebinding <name> --clusterrole=<role> --serviceaccount=<ns>:<sa>
Bind a ClusterRole to a service account
kubectl auth can-i --list
List all permissions for the current user
kubectl auth can-i <verb> <resource> --as=<user>
e.g. kubectl auth can-i create pods --as=jane
Check permissions as another user (impersonate)

Helm

CommandDescription
helm repo add <name> <url>
e.g. helm repo add bitnami https://charts.bitnami.com/bitnami
Add a Helm chart repository
helm repo update
Update all Helm repo indexes
helm search repo <keyword>
e.g. helm search repo nginx
Search for charts in added repos
helm install <release> <chart>
e.g. helm install my-nginx bitnami/nginx
Install a Helm chart as a release
helm install <release> <chart> -f values.yaml
Install with custom values file
helm install <release> <chart> --set <key>=<value>
e.g. helm install my-nginx bitnami/nginx --set replicaCount=3
Install with inline value overrides
helm upgrade <release> <chart>
Upgrade a release to a new chart version or values
helm rollback <release> <revision>
e.g. helm rollback my-nginx 1
Rollback a release to a previous revision
helm list
List all Helm releases in the current namespace
helm list -A
List releases across all namespaces
helm status <release>
Show status and notes for a release
helm history <release>
Show revision history of a release
helm uninstall <release>
Uninstall a release
helm template <release> <chart>
Render chart templates locally without installing
helm show values <chart>
e.g. helm show values bitnami/nginx
Show default values of a chart

More Guides

🌿
Git Commands
Complete Git command reference — from basics to advanced workflows. Searchable, with examples.
📝
Vim Commands
Complete Vim/Vi command reference — modes, motions, editing, search, and advanced features.
🐳
Docker Commands
Complete Docker & Docker Compose command reference — containers, images, volumes, networks, and orchestration.
🔤
Regex Reference
Complete regular expression reference — syntax, patterns, quantifiers, groups, lookaheads, and common recipes.
🐧
Linux Commands
Complete Linux/Bash command reference — file management, text processing, networking, system admin, and shell scripting.
🐍
Python Reference
Complete Python reference — syntax, data structures, string methods, file I/O, comprehensions, and common patterns.
🗃️
SQL Reference
Complete SQL reference — queries, joins, aggregation, subqueries, indexes, and database management.
🌐
Nginx Reference
Complete Nginx configuration reference — server blocks, locations, proxying, SSL, load balancing, and caching.
🔐
SSH Commands
Complete SSH reference — connections, key management, tunneling, config, SCP/SFTP, and security hardening.
👷
Jenkins Reference
Complete Jenkins reference — pipeline syntax, Jenkinsfile, plugins, CLI, agents, and CI/CD patterns.
☁️
AWS CLI Reference
Complete AWS CLI reference — EC2, S3, IAM, Lambda, ECS, RDS, CloudFormation, and common operations.
🐹
Go Reference
Complete Go (Golang) reference — syntax, types, functions, concurrency, error handling, and common patterns.
💠
PowerShell Reference
Complete PowerShell reference — cmdlets, pipelines, scripting, file operations, remote management, and Active Directory.
💾
Redis Commands
Complete Redis command reference — strings, hashes, lists, sets, sorted sets, pub/sub, transactions, and server management.
🏗️
Terraform Commands
Complete Terraform reference — init, plan, apply, state management, modules, workspaces, and HCL syntax.
⚙️
Ansible Commands
Complete Ansible reference — playbooks, modules, inventory, roles, vault, and ad-hoc commands.

📖 Free, searchable command reference. Bookmark this page for quick access.