CloudsArk
Cheat Sheets Kubernetes

kubectl Cheat Sheet — Every Command You Need

The kubectl commands you reach for daily, grouped by task — pods, deployments, services, logs, debugging, and cluster management. Ready to copy.

Get resources

kubectl get pods
kubectl get pods -n kube-system
kubectl get pods -A                    # all namespaces
kubectl get pods -o wide               # show node and IP
kubectl get pod my-pod -o yaml         # full manifest
kubectl get all                        # pods, services, deployments
kubectl get nodes
kubectl get events --sort-by=.lastTimestamp

Describe and inspect

kubectl describe pod my-pod
kubectl describe node my-node
kubectl describe service my-svc
kubectl explain pod.spec.containers    # API field docs

Logs

kubectl logs my-pod
kubectl logs my-pod -c my-container    # multi-container pod
kubectl logs my-pod --previous         # crashed container
kubectl logs my-pod -f                 # follow
kubectl logs my-pod --tail=100
kubectl logs -l app=my-app             # by label

Execute commands

kubectl exec -it my-pod -- bash
kubectl exec -it my-pod -c sidecar -- sh
kubectl exec my-pod -- env | grep DB
kubectl exec my-pod -- cat /etc/config/app.conf

Port forwarding

kubectl port-forward pod/my-pod 8080:80
kubectl port-forward svc/my-svc 9090:80
kubectl port-forward deployment/my-dep 3000:3000

Apply and delete

kubectl apply -f manifest.yaml
kubectl apply -f ./k8s/                # directory
kubectl delete -f manifest.yaml
kubectl delete pod my-pod
kubectl delete pod my-pod --grace-period=0 --force

Deployments

kubectl rollout status deployment/my-dep
kubectl rollout history deployment/my-dep
kubectl rollout undo deployment/my-dep
kubectl rollout undo deployment/my-dep --to-revision=3
kubectl scale deployment my-dep --replicas=5
kubectl set image deployment/my-dep app=my-image:2.0

Namespaces

kubectl create namespace staging
kubectl config set-context --current --namespace=staging
kubectl get pods --namespace=staging

ConfigMaps and Secrets

kubectl create configmap app-config --from-file=config.yaml
kubectl create secret generic db-secret \
  --from-literal=password=mysecret
kubectl get secret db-secret -o jsonpath='{.data.password}' | base64 -d

Context and cluster

kubectl config get-contexts
kubectl config use-context my-cluster
kubectl config current-context
kubectl cluster-info
kubectl api-resources

Debugging

# Ephemeral debug container (Kubernetes 1.23+)
kubectl debug -it my-pod --image=busybox --target=app

# Run a temporary pod in the same network
kubectl run debug --image=nicolaka/netshoot --rm -it --restart=Never

# Copy files from a pod
kubectl cp my-pod:/var/log/app.log ./app.log

Labels and selectors

kubectl label pod my-pod env=prod
kubectl get pods -l env=prod
kubectl get pods -l 'env in (prod,staging)'
kubectl annotate pod my-pod description="my app"