Showing 83 of 83 commands
Inspect cluster health, contexts, nodes, and client configuration
kubectl version --clientbeginnerShow the installed kubectl client version without querying the cluster
kubectl cluster-infobeginnerDisplay the cluster control plane and core service endpoints
kubectl get nodesbeginnerList all nodes and their readiness status in the current cluster
kubectl get nodes -o widebeginnerList nodes with extra details like internal IPs, OS image, and container runtime
kubectl describe node <name>intermediateShow detailed capacity, conditions, labels, taints, and pod allocation for a node
kubectl top nodesintermediateView live CPU and memory usage for nodes from Metrics Server
kubectl config viewintermediatePrint the merged kubeconfig with clusters, users, and contexts
kubectl config current-contextbeginnerShow the currently selected kubeconfig context
kubectl config get-contextsbeginnerList all available kubeconfig contexts and highlight the active one
kubectl config use-context <ctx>beginnerSwitch kubectl to a different cluster and user context
Create, inspect, access, and troubleshoot running pods
kubectl get podsbeginnerList pods in the current namespace with basic readiness and status info
kubectl get pods -AbeginnerList pods across every namespace in the cluster
kubectl get pods -n <ns>beginnerList pods only in a specific namespace
kubectl get pods -o widebeginnerShow pods with extra details like node placement and pod IPs
kubectl describe pod <name>intermediateInspect pod metadata, container states, events, probes, and mounts
kubectl logs <pod>beginnerFetch logs from the main container in a pod
kubectl logs <pod> -fbeginnerStream logs from a pod in real time
kubectl logs <pod> --previousintermediateView logs from the previously terminated container instance in a restarting pod
kubectl exec -it <pod> -- /bin/shintermediateOpen an interactive shell inside a pod using the default container
kubectl exec -it <pod> -c <container> -- bashintermediateOpen a shell inside a specific container in a multi-container pod
kubectl delete pod <name>beginnerDelete a pod and let its controller recreate it if managed
kubectl run nginx --image=nginxbeginnerCreate a quick standalone pod directly from an image
kubectl port-forward pod/<name> 8080:80intermediateForward a local port to a pod port for direct debugging access
Manage application rollouts, scaling, updates, and revisions
kubectl get deploymentsbeginnerList deployments in the current namespace with desired and ready replica counts
kubectl describe deployment <name>intermediateInspect a deployment strategy, pod template, rollout conditions, and events
kubectl create deployment nginx --image=nginxbeginnerCreate a deployment from a single image directly from the CLI
kubectl scale deployment <name> --replicas=3beginnerChange the number of desired pod replicas for a deployment
kubectl set image deployment/<name> <container>=<image>:tagintermediateUpdate a container image and trigger a rolling rollout
kubectl rollout status deployment/<name>intermediateWatch the rollout until the deployment successfully completes or fails
kubectl rollout history deployment/<name>intermediateShow previous rollout revisions for a deployment
kubectl rollout undo deployment/<name>intermediateRoll back the deployment to the previous revision
kubectl rollout undo deployment/<name> --to-revision=2advancedRoll back the deployment to a specific stored revision
kubectl delete deployment <name>beginnerDelete a deployment and its managed ReplicaSets and pods
kubectl apply -f deployment.yamlbeginnerCreate or update a deployment declaratively from a manifest file
kubectl edit deployment <name>advancedOpen the live deployment manifest in your editor for an immediate change
Expose workloads, inspect traffic paths, and work with ingress and endpoints
kubectl get svcbeginnerList services in the current namespace with type and cluster IP
kubectl get svc -AbeginnerList services across all namespaces
kubectl describe svc <name>intermediateInspect service ports, selectors, endpoints, and load balancer details
kubectl expose deployment <name> --port=80 --type=ClusterIPbeginnerExpose a deployment internally within the cluster using a ClusterIP service
kubectl expose deployment <name> --port=80 --type=LoadBalancerintermediateExpose a deployment externally through a cloud load balancer
kubectl expose deployment <name> --port=80 --type=NodePortintermediateExpose a deployment on a static port on each cluster node
kubectl get ingressbeginnerList ingress resources and their configured hosts and addresses
kubectl describe ingress <name>intermediateInspect ingress rules, TLS configuration, and backend service routing
kubectl get endpointsintermediateShow which pod IPs are currently backing each service
kubectl port-forward svc/<name> 8080:80intermediateForward a local port to a service for testing without external exposure
kubectl delete svc <name>beginnerDelete a service resource by name
Organize workloads and scope kubectl operations by environment or team
kubectl get namespacesbeginnerList all namespaces in the cluster
kubectl create namespace <name>beginnerCreate a new namespace for an application, team, or environment
kubectl delete namespace <name>intermediateDelete a namespace and everything contained inside it
kubectl get all -n <namespace>beginnerList the main workload and service resources in a target namespace
kubectl config set-context --current --namespace=<name>intermediateSet the default namespace for the current context to reduce repeated -n flags
kubectl get pods --all-namespacesbeginnerList pods across every namespace using the long-form namespace flag
kubectl get quota -n <namespace>intermediateView resource quota usage and hard limits for a namespace
kubectl describe namespace <name>intermediateInspect a namespace including labels, annotations, quotas, and limit ranges
Manage runtime configuration, credentials, and image pull secrets
kubectl get configmapsbeginnerList ConfigMaps in the current namespace
kubectl describe configmap <name>intermediateShow the keys and metadata stored in a ConfigMap
kubectl create configmap my-config --from-literal=key=valuebeginnerCreate a ConfigMap from one or more literal key-value pairs
kubectl create configmap my-config --from-file=config.envintermediateCreate a ConfigMap from a local file such as an env file or config artifact
kubectl get secretsbeginnerList secrets in the current namespace
kubectl describe secret <name>intermediateInspect secret metadata and available keys without printing decoded values
kubectl create secret generic my-secret --from-literal=password=abcbeginnerCreate a generic secret from literal key-value pairs
kubectl create secret docker-registry regcred --docker-server=... --docker-username=... --docker-password=...advancedCreate an image pull secret for a private container registry
kubectl get secret <name> -o jsonpath='{.data.key}' | base64 -dadvancedDecode a specific secret key value from base64 for troubleshooting
Inspect persistent volumes, claims, and storage classes backing workloads
kubectl get pvbeginnerList cluster-wide persistent volumes and their binding state
kubectl get pvcbeginnerList persistent volume claims in the current namespace
kubectl get pvc -n <namespace>beginnerList persistent volume claims in a specific namespace
kubectl describe pv <name>intermediateInspect a persistent volume including reclaim policy, capacity, and claim binding
kubectl describe pvc <name>intermediateInspect a claim including requested size, access modes, and mounted workloads
kubectl delete pvc <name>intermediateDelete a persistent volume claim and release its bound volume according to policy
kubectl get storageclassbeginnerList available storage classes and identify the default provisioner
kubectl describe storageclass <name>intermediateInspect provisioner parameters, reclaim policy, and binding mode for a storage class
Trace failures, inspect events, and safely manage node maintenance operations
kubectl get events --sort-by=.metadata.creationTimestampintermediateList cluster events in chronological order to surface the newest failures last
kubectl get events -n <ns> --field-selector=reason=FailedintermediateFilter namespace events down to failure-related entries only
kubectl describe pod <name> | grep -A 10 EventsadvancedExtract the events section from a pod description for quick CLI triage
kubectl logs <pod> --since=1hintermediateShow logs generated within the last hour to narrow noisy output
kubectl logs <pod> --tail=100beginnerShow only the most recent log lines from a pod
kubectl top podsintermediateView CPU and memory usage for pods in the current namespace
kubectl top pods -n <namespace>intermediateView CPU and memory usage for pods in a specific namespace
kubectl get pods --field-selector=status.phase=PendingintermediateList only pods that are still waiting to schedule or start
kubectl get pods --field-selector=status.phase=FailedintermediateList pods whose last phase is Failed for cleanup or investigation
kubectl drain <node> --ignore-daemonsetsadvancedSafely evict workloads from a node before maintenance or termination
kubectl cordon <node>advancedMark a node unschedulable so new pods are not placed on it
kubectl uncordon <node>advancedMark a node schedulable again after maintenance is complete
A production-ready Kubernetes reference with daily kubectl commands for operating clusters, debugging workloads, managing rollouts, and handling networking, config, and storage.
devopslesson.com/tools/cheatsheets/kubernetes
kubectl version --clientbeginnerShow the installed kubectl client version without querying the cluster
kubectl version --clientkubectl cluster-infobeginnerDisplay the cluster control plane and core service endpoints
kubectl cluster-info💡 Use this first when validating access to a newly configured cluster context.
kubectl get nodesbeginnerList all nodes and their readiness status in the current cluster
kubectl get nodeskubectl get nodes -o widebeginnerList nodes with extra details like internal IPs, OS image, and container runtime
kubectl get nodes -o widekubectl describe node <name>intermediateShow detailed capacity, conditions, labels, taints, and pod allocation for a node
kubectl describe node ip-10-0-12-34.ec2.internal💡 Check the Conditions and Allocated resources sections when investigating scheduling issues.
kubectl top nodesintermediateView live CPU and memory usage for nodes from Metrics Server
kubectl top nodeskubectl config viewintermediatePrint the merged kubeconfig with clusters, users, and contexts
kubectl config viewkubectl config current-contextbeginnerShow the currently selected kubeconfig context
kubectl config current-contextkubectl config get-contextsbeginnerList all available kubeconfig contexts and highlight the active one
kubectl config get-contexts💡 Name contexts consistently by environment and region so switching is less error-prone.
kubectl config use-context <ctx>beginnerSwitch kubectl to a different cluster and user context
kubectl config use-context prod-eu-west-1kubectl get podsbeginnerList pods in the current namespace with basic readiness and status info
kubectl get podskubectl get pods -AbeginnerList pods across every namespace in the cluster
kubectl get pods -Akubectl get pods -n <ns>beginnerList pods only in a specific namespace
kubectl get pods -n productionkubectl get pods -o widebeginnerShow pods with extra details like node placement and pod IPs
kubectl get pods -o widekubectl describe pod <name>intermediateInspect pod metadata, container states, events, probes, and mounts
kubectl describe pod my-app-6d9d7f8c6c-7kq2m💡 Describe is often faster than logs for spotting image pull, probe, and scheduling failures.
kubectl logs <pod>beginnerFetch logs from the main container in a pod
kubectl logs my-app-6d9d7f8c6c-7kq2mkubectl logs <pod> -fbeginnerStream logs from a pod in real time
kubectl logs my-app-6d9d7f8c6c-7kq2m -fkubectl logs <pod> --previousintermediateView logs from the previously terminated container instance in a restarting pod
kubectl logs api-7c67f9bbd8-jm2t4 --previous💡 Essential for CrashLoopBackOff debugging because the current container may restart before you inspect it.
kubectl exec -it <pod> -- /bin/shintermediateOpen an interactive shell inside a pod using the default container
kubectl exec -it nginx-5d59d67564-92x8m -- /bin/shkubectl exec -it <pod> -c <container> -- bashintermediateOpen a shell inside a specific container in a multi-container pod
kubectl exec -it payments-6f96d4b7c7-vr8zs -c app -- bashkubectl delete pod <name>beginnerDelete a pod and let its controller recreate it if managed
kubectl delete pod my-app-6d9d7f8c6c-7kq2m💡 Deleting a pod is a safe way to force a restart when it belongs to a Deployment or StatefulSet.
kubectl run nginx --image=nginxbeginnerCreate a quick standalone pod directly from an image
kubectl run nginx --image=nginxkubectl port-forward pod/<name> 8080:80intermediateForward a local port to a pod port for direct debugging access
kubectl port-forward pod/my-app-6d9d7f8c6c-7kq2m 8080:8080kubectl get deploymentsbeginnerList deployments in the current namespace with desired and ready replica counts
kubectl get deploymentskubectl describe deployment <name>intermediateInspect a deployment strategy, pod template, rollout conditions, and events
kubectl describe deployment my-appkubectl create deployment nginx --image=nginxbeginnerCreate a deployment from a single image directly from the CLI
kubectl create deployment nginx --image=nginxkubectl scale deployment <name> --replicas=3beginnerChange the number of desired pod replicas for a deployment
kubectl scale deployment my-app --replicas=6kubectl set image deployment/<name> <container>=<image>:tagintermediateUpdate a container image and trigger a rolling rollout
kubectl set image deployment/my-app app=ghcr.io/acme/my-app:2.4.1💡 Pair this with rollout status to confirm the new version becomes healthy before continuing.
kubectl rollout status deployment/<name>intermediateWatch the rollout until the deployment successfully completes or fails
kubectl rollout status deployment/my-appkubectl rollout history deployment/<name>intermediateShow previous rollout revisions for a deployment
kubectl rollout history deployment/my-appkubectl rollout undo deployment/<name>intermediateRoll back the deployment to the previous revision
kubectl rollout undo deployment/my-appkubectl rollout undo deployment/<name> --to-revision=2advancedRoll back the deployment to a specific stored revision
kubectl rollout undo deployment/my-app --to-revision=2💡 Use rollout history first so you can target the exact known-good revision.
kubectl delete deployment <name>beginnerDelete a deployment and its managed ReplicaSets and pods
kubectl delete deployment my-appkubectl apply -f deployment.yamlbeginnerCreate or update a deployment declaratively from a manifest file
kubectl apply -f deployment.yaml💡 Use apply for GitOps-style workflows so the manifest stays the source of truth.
kubectl edit deployment <name>advancedOpen the live deployment manifest in your editor for an immediate change
kubectl edit deployment my-appkubectl get svcbeginnerList services in the current namespace with type and cluster IP
kubectl get svckubectl get svc -AbeginnerList services across all namespaces
kubectl get svc -Akubectl describe svc <name>intermediateInspect service ports, selectors, endpoints, and load balancer details
kubectl describe svc my-appkubectl expose deployment <name> --port=80 --type=ClusterIPbeginnerExpose a deployment internally within the cluster using a ClusterIP service
kubectl expose deployment my-app --port=8080 --target-port=8080 --type=ClusterIPkubectl expose deployment <name> --port=80 --type=LoadBalancerintermediateExpose a deployment externally through a cloud load balancer
kubectl expose deployment my-app --port=80 --target-port=8080 --type=LoadBalancer💡 Cloud environments may take time to provision an external IP; watch the EXTERNAL-IP field.
kubectl expose deployment <name> --port=80 --type=NodePortintermediateExpose a deployment on a static port on each cluster node
kubectl expose deployment my-app --port=80 --target-port=8080 --type=NodePortkubectl get ingressbeginnerList ingress resources and their configured hosts and addresses
kubectl get ingresskubectl describe ingress <name>intermediateInspect ingress rules, TLS configuration, and backend service routing
kubectl describe ingress production-webkubectl get endpointsintermediateShow which pod IPs are currently backing each service
kubectl get endpoints💡 Empty endpoints usually mean your service selector does not match any healthy pods.
kubectl port-forward svc/<name> 8080:80intermediateForward a local port to a service for testing without external exposure
kubectl port-forward svc/my-app 8080:80kubectl delete svc <name>beginnerDelete a service resource by name
kubectl delete svc my-appkubectl get namespacesbeginnerList all namespaces in the cluster
kubectl get namespaceskubectl create namespace <name>beginnerCreate a new namespace for an application, team, or environment
kubectl create namespace stagingkubectl delete namespace <name>intermediateDelete a namespace and everything contained inside it
kubectl delete namespace sandbox💡 Use with care because namespace deletion removes all contained workloads, services, and secrets.
kubectl get all -n <namespace>beginnerList the main workload and service resources in a target namespace
kubectl get all -n productionkubectl config set-context --current --namespace=<name>intermediateSet the default namespace for the current context to reduce repeated -n flags
kubectl config set-context --current --namespace=production💡 This is a huge quality-of-life improvement for daily operations in a single namespace.
kubectl get pods --all-namespacesbeginnerList pods across every namespace using the long-form namespace flag
kubectl get pods --all-namespaceskubectl get quota -n <namespace>intermediateView resource quota usage and hard limits for a namespace
kubectl get quota -n productionkubectl describe namespace <name>intermediateInspect a namespace including labels, annotations, quotas, and limit ranges
kubectl describe namespace productionkubectl get configmapsbeginnerList ConfigMaps in the current namespace
kubectl get configmapskubectl describe configmap <name>intermediateShow the keys and metadata stored in a ConfigMap
kubectl describe configmap app-configkubectl create configmap my-config --from-literal=key=valuebeginnerCreate a ConfigMap from one or more literal key-value pairs
kubectl create configmap app-config --from-literal=LOG_LEVEL=infokubectl create configmap my-config --from-file=config.envintermediateCreate a ConfigMap from a local file such as an env file or config artifact
kubectl create configmap app-config --from-file=config.env💡 Use --dry-run=client -o yaml when you want to generate manifests instead of creating resources directly.
kubectl get secretsbeginnerList secrets in the current namespace
kubectl get secretskubectl describe secret <name>intermediateInspect secret metadata and available keys without printing decoded values
kubectl describe secret app-secretkubectl create secret generic my-secret --from-literal=password=abcbeginnerCreate a generic secret from literal key-value pairs
kubectl create secret generic db-credentials --from-literal=password=S3cr3tP@sskubectl create secret docker-registry regcred --docker-server=... --docker-username=... --docker-password=...advancedCreate an image pull secret for a private container registry
kubectl create secret docker-registry regcred --docker-server=ghcr.io --docker-username=acme-ci --docker-password=ghp_xxx💡 Pair the secret with a service account so workloads automatically inherit private registry access.
kubectl get secret <name> -o jsonpath='{.data.key}' | base64 -dadvancedDecode a specific secret key value from base64 for troubleshooting
kubectl get secret db-credentials -o jsonpath='{.data.password}' | base64 -dkubectl get pvbeginnerList cluster-wide persistent volumes and their binding state
kubectl get pvkubectl get pvcbeginnerList persistent volume claims in the current namespace
kubectl get pvckubectl get pvc -n <namespace>beginnerList persistent volume claims in a specific namespace
kubectl get pvc -n productionkubectl describe pv <name>intermediateInspect a persistent volume including reclaim policy, capacity, and claim binding
kubectl describe pv pvc-7fd3d6b2-0d1c-43f5-8ae0-31ef1b1c9a93kubectl describe pvc <name>intermediateInspect a claim including requested size, access modes, and mounted workloads
kubectl describe pvc postgres-data💡 Describe the PVC when a pod is Pending because unbound claims often block scheduling.
kubectl delete pvc <name>intermediateDelete a persistent volume claim and release its bound volume according to policy
kubectl delete pvc scratch-cachekubectl get storageclassbeginnerList available storage classes and identify the default provisioner
kubectl get storageclasskubectl describe storageclass <name>intermediateInspect provisioner parameters, reclaim policy, and binding mode for a storage class
kubectl describe storageclass gp3kubectl get events --sort-by=.metadata.creationTimestampintermediateList cluster events in chronological order to surface the newest failures last
kubectl get events --sort-by=.metadata.creationTimestamp💡 Events often reveal the root cause faster than controller logs when pods are stuck Pending.
kubectl get events -n <ns> --field-selector=reason=FailedintermediateFilter namespace events down to failure-related entries only
kubectl get events -n production --field-selector=reason=Failedkubectl describe pod <name> | grep -A 10 EventsadvancedExtract the events section from a pod description for quick CLI triage
kubectl describe pod api-7c67f9bbd8-jm2t4 | grep -A 10 Eventskubectl logs <pod> --since=1hintermediateShow logs generated within the last hour to narrow noisy output
kubectl logs worker-54df9f7cf9-kpjl2 --since=1hkubectl logs <pod> --tail=100beginnerShow only the most recent log lines from a pod
kubectl logs worker-54df9f7cf9-kpjl2 --tail=100kubectl top podsintermediateView CPU and memory usage for pods in the current namespace
kubectl top podskubectl top pods -n <namespace>intermediateView CPU and memory usage for pods in a specific namespace
kubectl top pods -n production💡 Compare usage against requests and limits to spot pods being throttled or under-provisioned.
kubectl get pods --field-selector=status.phase=PendingintermediateList only pods that are still waiting to schedule or start
kubectl get pods --field-selector=status.phase=Pendingkubectl get pods --field-selector=status.phase=FailedintermediateList pods whose last phase is Failed for cleanup or investigation
kubectl get pods --field-selector=status.phase=Failedkubectl drain <node> --ignore-daemonsetsadvancedSafely evict workloads from a node before maintenance or termination
kubectl drain ip-10-0-15-22.ec2.internal --ignore-daemonsets💡 Add --delete-emptydir-data only when you understand the impact on ephemeral workload data.
kubectl cordon <node>advancedMark a node unschedulable so new pods are not placed on it
kubectl cordon ip-10-0-15-22.ec2.internalkubectl uncordon <node>advancedMark a node schedulable again after maintenance is complete
kubectl uncordon ip-10-0-15-22.ec2.internal