Skip to main content

Kubectl Command Cheatsheet

This cheatsheet covers the most commonly used kubectl commands for daily Kubernetes cluster management, including Pod operations, workload management, networking, debugging, and cluster maintenance.

Updated: 2026-07-16·41 commands

Pod Management

Create, view, and manage Pods.

``bash # List all Pods kubectl get pods

# List Pods in all namespaces kubectl get pods --all-namespaces

# Show more info (node, IP, etc.) kubectl get pods -o wide

# Watch Pod status changes kubectl get pods -w

# Show Pod details kubectl describe pod my-pod

# Get Pod YAML definition kubectl get pod my-pod -o yaml

# Show Pod labels kubectl get pods --show-labels

# Filter by labels kubectl get pods -l app=nginx,env=prod

# Delete a Pod kubectl delete pod my-pod

# Force delete a Pod kubectl delete pod my-pod --force --grace-period=0

# Run a Pod (one-shot) kubectl run nginx --image=nginx --restart=Never

# Run a Pod and expose a port kubectl run web --image=nginx --port=80

# Export Pod definition to file kubectl get pod my-pod -o yaml --export > pod.yaml `

Workload Management

Manage Deployments, StatefulSets, DaemonSets, etc.

`bash # Create a Deployment kubectl create deployment myapp --image=nginx

# List Deployments kubectl get deployments

# Show Deployment details kubectl describe deployment myapp

# Scale a Deployment kubectl scale deployment myapp --replicas=5

# Auto-scale a Deployment kubectl autoscale deployment myapp --min=2 --max=10 --cpu-percent=80

# Rolling update image kubectl set image deployment/myapp myapp=myapp:v2

# Check rollout status kubectl rollout status deployment/myapp

# View rollout history kubectl rollout history deployment/myapp

# Rollback to previous version kubectl rollout undo deployment/myapp

# Rollback to specific revision kubectl rollout undo deployment/myapp --to-revision=2

# Pause/resume rollout kubectl rollout pause deployment/myapp kubectl rollout resume deployment/myapp

# List DaemonSets kubectl get daemonsets --all-namespaces

# List StatefulSets kubectl get statefulsets

# Manage CronJobs kubectl get cronjobs kubectl create cronjob backup --image=busybox --schedule="0 0 * * *" -- /bin/sh -c "date" `

Networking

Manage Services, Ingress, and network policies.

`bash # List all Services kubectl get services

# List Services in all namespaces kubectl get svc --all-namespaces

# Expose a Deployment as a Service kubectl expose deployment myapp --port=80 --target-port=8080 --type=ClusterIP

# Create NodePort Service kubectl expose deployment myapp --port=80 --type=NodePort

# Create LoadBalancer Service kubectl expose deployment myapp --port=80 --type=LoadBalancer

# Port forward to a Pod kubectl port-forward pod/my-pod 8080:80

# Port forward to a Service kubectl port-forward svc/my-service 8080:80

# View Endpoints kubectl get endpoints

# View Ingress kubectl get ingress

# View Network Policies kubectl get networkpolicies

# Create a Service (using YAML shorthand) kubectl create service clusterip my-svc --tcp=80:8080 `

Configuration

Manage ConfigMaps, Secrets, quotas, and resource configs.

`bash # Create ConfigMap from literals kubectl create configmap app-config --from-literal=key1=val1 --from-literal=key2=val2

# Create ConfigMap from file kubectl create configmap app-config --from-file=config.properties

# View ConfigMaps kubectl get configmaps kubectl describe configmap app-config

# Create Secret from literals kubectl create secret generic db-secret --from-literal=password=mysecret

# Create Secret from files kubectl create secret generic tls-secret --from-file=tls.crt --from-file=tls.key

# View Secrets kubectl get secrets kubectl get secret db-secret -o yaml

# Encode/decode Secret values echo -n "mysecret" | base64 echo "bXlzZWNyZXQ=" | base64 -d

# View ResourceQuotas kubectl get resourcequotas

# View LimitRanges kubectl get limitranges

# View ServiceAccounts kubectl get serviceaccounts

# Edit a resource (default editor) kubectl edit deployment myapp

# Apply YAML configuration kubectl apply -f deployment.yaml

# Delete resources from config kubectl delete -f deployment.yaml `

Debugging

Logs, exec, events, and troubleshooting.

`bash # View Pod logs kubectl logs my-pod

# Follow logs kubectl logs -f my-pod

# View last N log lines kubectl logs --tail=100 my-pod

# View logs since a duration kubectl logs --since=1h my-pod

# View logs for a specific container in multi-container Pod kubectl logs my-pod -c sidecar-container

# Exec into a container shell kubectl exec -it my-pod -- /bin/sh

# Run a single command in a container kubectl exec my-pod -- env kubectl exec my-pod -- ls -la /app

# Copy files to a Pod kubectl cp /local/file.txt my-pod:/remote/path/

# Copy files from a Pod kubectl cp my-pod:/remote/path/file.txt /local/file.txt

# View cluster events kubectl get events kubectl get events --sort-by='.lastTimestamp' kubectl get events -w

# Filter events kubectl get events --field-selector type=Warning

# List API resources kubectl api-resources

# Explain resource fields kubectl explain pod kubectl explain pod.spec.containers

# Test API access permissions kubectl auth can-i create deployments kubectl auth can-i delete pods --as=system:serviceaccount:default:my-sa `

Cluster Management

Node management, context switching, cluster info.

`bash # List nodes kubectl get nodes

# Show node details kubectl describe node worker-1

# Show node resource usage kubectl top node kubectl top pod

# Mark node as unschedulable kubectl cordon worker-1

# Drain pods from a node kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data

# Restore node scheduling kubectl uncordon worker-1

# Add/remove taints kubectl taint nodes worker-1 key=value:NoSchedule kubectl taint nodes worker-1 key=value:NoSchedule-

# Add/remove labels kubectl label node worker-1 disktype=ssd kubectl label node worker-1 disktype-

# Add/remove annotations kubectl annotate pod my-pod description="my annotation" kubectl annotate pod my-pod description-

# View cluster info kubectl cluster-info

# View current context kubectl config current-context

# List all contexts kubectl config get-contexts

# Switch context kubectl config use-context production

# View kubeconfig kubectl config view

# Set cluster context kubectl config set-context my-context --namespace=prod --cluster=my-cluster --user=my-user

# Merge kubeconfig files export KUBECONFIG=file1:file2 kubectl config view --flatten > merged-config

# View API versions kubectl api-versions

# View all resources in cluster kubectl get all --all-namespaces ``

Pod(7)

CommandLevel
kubectl get pods
List all Pods
Basic
kubectl get pods --all-namespaces
List Pods in all namespaces
Basic
kubectl describe pod my-pod
Show detailed Pod information
Basic
kubectl get pod my-pod -o yaml
Export Pod YAML definition
Intermediate
kubectl get pods -l app=nginx,env=prod
Filter Pods by labels
Intermediate
kubectl delete pod my-pod --force --grace-period=0
Force delete a Pod
Intermediate
kubectl run nginx --image=nginx --restart=Never
Create a one-shot Pod
Basic

Workloads(6)

CommandLevel
kubectl create deployment myapp --image=nginx
Create a Deployment
Basic
kubectl scale deployment myapp --replicas=5
Scale a Deployment
Basic
kubectl set image deployment/myapp myapp=myapp:v2
Rolling update Deployment image
Intermediate
kubectl rollout status deployment/myapp
Check Deployment rollout status
Intermediate
kubectl rollout undo deployment/myapp
Rollback Deployment to previous version
Intermediate
kubectl rollout history deployment/myapp
View Deployment rollout history
Intermediate

Networking(4)

CommandLevel
kubectl expose deployment myapp --port=80 --target-port=8080 --type=ClusterIP
Expose Deployment as a ClusterIP Service
Intermediate
kubectl expose deployment myapp --port=80 --type=NodePort
Create a NodePort Service
Intermediate
kubectl port-forward pod/my-pod 8080:80
Port forward to a Pod (local debugging)
Intermediate
kubectl get ingress
View Ingress resources
Intermediate

Config(6)

CommandLevel
kubectl create configmap app-config --from-literal=key1=val1
Create ConfigMap from literal values
Basic
kubectl create configmap app-config --from-file=config.properties
Create ConfigMap from file
Basic
kubectl create secret generic db-secret --from-literal=password=mysecret
Create Secret from literal values
Intermediate
kubectl edit deployment myapp
Edit a Deployment resource
Intermediate
kubectl apply -f deployment.yaml
Apply YAML configuration file
Basic
kubectl delete -f deployment.yaml
Delete resources defined in YAML config
Basic

Debug(6)

CommandLevel
kubectl logs -f my-pod
Follow Pod logs
Basic
kubectl logs --tail=100 my-pod
View last N lines of Pod logs
Basic
kubectl exec -it my-pod -- /bin/sh
Enter container interactive shell
Basic
kubectl cp /local/file.txt my-pod:/remote/path/
Copy files to a Pod
Intermediate
kubectl get events --sort-by='.lastTimestamp'
View cluster events sorted by timestamp
Intermediate
kubectl explain pod.spec.containers
View resource field documentation
Basic

Cluster(12)

CommandLevel
kubectl auth can-i create deployments
Check if current user can create Deployments
Expert
kubectl get nodes
List cluster nodes
Basic
kubectl describe node worker-1
Show node details
Intermediate
kubectl top node
Show node resource usage
Intermediate
kubectl top pod
Show Pod resource usage
Intermediate
kubectl cordon worker-1
Mark node as unschedulable
Expert
kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data
Drain Pods from a node for maintenance
Expert
kubectl taint nodes worker-1 key=value:NoSchedule
Add taint to node to prevent scheduling
Expert
kubectl cluster-info
View cluster information
Basic
kubectl config current-context
View current context
Basic
kubectl config use-context production
Switch to a different context
Basic
kubectl get all --all-namespaces
View all resources in the cluster
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-16.