DevOpsLesson
DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Kubernetes Cheatsheet

Showing 83 of 83 commands

Cluster Info

Inspect cluster health, contexts, nodes, and client configuration

10 commands
kubectl version --clientbeginner

Show the installed kubectl client version without querying the cluster

kubectl cluster-infobeginner

Display the cluster control plane and core service endpoints

kubectl get nodesbeginner

List all nodes and their readiness status in the current cluster

kubectl get nodes -o widebeginner

List nodes with extra details like internal IPs, OS image, and container runtime

kubectl describe node <name>intermediate

Show detailed capacity, conditions, labels, taints, and pod allocation for a node

kubectl top nodesintermediate

View live CPU and memory usage for nodes from Metrics Server

kubectl config viewintermediate

Print the merged kubeconfig with clusters, users, and contexts

kubectl config current-contextbeginner

Show the currently selected kubeconfig context

kubectl config get-contextsbeginner

List all available kubeconfig contexts and highlight the active one

kubectl config use-context <ctx>beginner

Switch kubectl to a different cluster and user context

Pods

Create, inspect, access, and troubleshoot running pods

13 commands
kubectl get podsbeginner

List pods in the current namespace with basic readiness and status info

kubectl get pods -Abeginner

List pods across every namespace in the cluster

kubectl get pods -n <ns>beginner

List pods only in a specific namespace

kubectl get pods -o widebeginner

Show pods with extra details like node placement and pod IPs

kubectl describe pod <name>intermediate

Inspect pod metadata, container states, events, probes, and mounts

kubectl logs <pod>beginner

Fetch logs from the main container in a pod

kubectl logs <pod> -fbeginner

Stream logs from a pod in real time

kubectl logs <pod> --previousintermediate

View logs from the previously terminated container instance in a restarting pod

kubectl exec -it <pod> -- /bin/shintermediate

Open an interactive shell inside a pod using the default container

kubectl exec -it <pod> -c <container> -- bashintermediate

Open a shell inside a specific container in a multi-container pod

kubectl delete pod <name>beginner

Delete a pod and let its controller recreate it if managed

kubectl run nginx --image=nginxbeginner

Create a quick standalone pod directly from an image

kubectl port-forward pod/<name> 8080:80intermediate

Forward a local port to a pod port for direct debugging access

Deployments

Manage application rollouts, scaling, updates, and revisions

12 commands
kubectl get deploymentsbeginner

List deployments in the current namespace with desired and ready replica counts

kubectl describe deployment <name>intermediate

Inspect a deployment strategy, pod template, rollout conditions, and events

kubectl create deployment nginx --image=nginxbeginner

Create a deployment from a single image directly from the CLI

kubectl scale deployment <name> --replicas=3beginner

Change the number of desired pod replicas for a deployment

kubectl set image deployment/<name> <container>=<image>:tagintermediate

Update a container image and trigger a rolling rollout

kubectl rollout status deployment/<name>intermediate

Watch the rollout until the deployment successfully completes or fails

kubectl rollout history deployment/<name>intermediate

Show previous rollout revisions for a deployment

kubectl rollout undo deployment/<name>intermediate

Roll back the deployment to the previous revision

kubectl rollout undo deployment/<name> --to-revision=2advanced

Roll back the deployment to a specific stored revision

kubectl delete deployment <name>beginner

Delete a deployment and its managed ReplicaSets and pods

kubectl apply -f deployment.yamlbeginner

Create or update a deployment declaratively from a manifest file

kubectl edit deployment <name>advanced

Open the live deployment manifest in your editor for an immediate change

Services & Networking

Expose workloads, inspect traffic paths, and work with ingress and endpoints

11 commands
kubectl get svcbeginner

List services in the current namespace with type and cluster IP

kubectl get svc -Abeginner

List services across all namespaces

kubectl describe svc <name>intermediate

Inspect service ports, selectors, endpoints, and load balancer details

kubectl expose deployment <name> --port=80 --type=ClusterIPbeginner

Expose a deployment internally within the cluster using a ClusterIP service

kubectl expose deployment <name> --port=80 --type=LoadBalancerintermediate

Expose a deployment externally through a cloud load balancer

kubectl expose deployment <name> --port=80 --type=NodePortintermediate

Expose a deployment on a static port on each cluster node

kubectl get ingressbeginner

List ingress resources and their configured hosts and addresses

kubectl describe ingress <name>intermediate

Inspect ingress rules, TLS configuration, and backend service routing

kubectl get endpointsintermediate

Show which pod IPs are currently backing each service

kubectl port-forward svc/<name> 8080:80intermediate

Forward a local port to a service for testing without external exposure

kubectl delete svc <name>beginner

Delete a service resource by name

Namespaces

Organize workloads and scope kubectl operations by environment or team

8 commands
kubectl get namespacesbeginner

List all namespaces in the cluster

kubectl create namespace <name>beginner

Create a new namespace for an application, team, or environment

kubectl delete namespace <name>intermediate

Delete a namespace and everything contained inside it

kubectl get all -n <namespace>beginner

List the main workload and service resources in a target namespace

kubectl config set-context --current --namespace=<name>intermediate

Set the default namespace for the current context to reduce repeated -n flags

kubectl get pods --all-namespacesbeginner

List pods across every namespace using the long-form namespace flag

kubectl get quota -n <namespace>intermediate

View resource quota usage and hard limits for a namespace

kubectl describe namespace <name>intermediate

Inspect a namespace including labels, annotations, quotas, and limit ranges

ConfigMaps & Secrets

Manage runtime configuration, credentials, and image pull secrets

9 commands
kubectl get configmapsbeginner

List ConfigMaps in the current namespace

kubectl describe configmap <name>intermediate

Show the keys and metadata stored in a ConfigMap

kubectl create configmap my-config --from-literal=key=valuebeginner

Create a ConfigMap from one or more literal key-value pairs

kubectl create configmap my-config --from-file=config.envintermediate

Create a ConfigMap from a local file such as an env file or config artifact

kubectl get secretsbeginner

List secrets in the current namespace

kubectl describe secret <name>intermediate

Inspect secret metadata and available keys without printing decoded values

kubectl create secret generic my-secret --from-literal=password=abcbeginner

Create a generic secret from literal key-value pairs

kubectl create secret docker-registry regcred --docker-server=... --docker-username=... --docker-password=...advanced

Create an image pull secret for a private container registry

kubectl get secret <name> -o jsonpath='{.data.key}' | base64 -dadvanced

Decode a specific secret key value from base64 for troubleshooting

Storage

Inspect persistent volumes, claims, and storage classes backing workloads

8 commands
kubectl get pvbeginner

List cluster-wide persistent volumes and their binding state

kubectl get pvcbeginner

List persistent volume claims in the current namespace

kubectl get pvc -n <namespace>beginner

List persistent volume claims in a specific namespace

kubectl describe pv <name>intermediate

Inspect a persistent volume including reclaim policy, capacity, and claim binding

kubectl describe pvc <name>intermediate

Inspect a claim including requested size, access modes, and mounted workloads

kubectl delete pvc <name>intermediate

Delete a persistent volume claim and release its bound volume according to policy

kubectl get storageclassbeginner

List available storage classes and identify the default provisioner

kubectl describe storageclass <name>intermediate

Inspect provisioner parameters, reclaim policy, and binding mode for a storage class

Troubleshooting

Trace failures, inspect events, and safely manage node maintenance operations

12 commands
kubectl get events --sort-by=.metadata.creationTimestampintermediate

List cluster events in chronological order to surface the newest failures last

kubectl get events -n <ns> --field-selector=reason=Failedintermediate

Filter namespace events down to failure-related entries only

kubectl describe pod <name> | grep -A 10 Eventsadvanced

Extract the events section from a pod description for quick CLI triage

kubectl logs <pod> --since=1hintermediate

Show logs generated within the last hour to narrow noisy output

kubectl logs <pod> --tail=100beginner

Show only the most recent log lines from a pod

kubectl top podsintermediate

View CPU and memory usage for pods in the current namespace

kubectl top pods -n <namespace>intermediate

View CPU and memory usage for pods in a specific namespace

kubectl get pods --field-selector=status.phase=Pendingintermediate

List only pods that are still waiting to schedule or start

kubectl get pods --field-selector=status.phase=Failedintermediate

List pods whose last phase is Failed for cleanup or investigation

kubectl drain <node> --ignore-daemonsetsadvanced

Safely evict workloads from a node before maintenance or termination

kubectl cordon <node>advanced

Mark a node unschedulable so new pods are not placed on it

kubectl uncordon <node>advanced

Mark a node schedulable again after maintenance is complete

Kubernetes Cheatsheet

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

83 commands8 categories

Cluster Info

10 commands
kubectl version --clientbeginner

Show the installed kubectl client version without querying the cluster

kubectl version --client
kubectl cluster-infobeginner

Display 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 nodesbeginner

List all nodes and their readiness status in the current cluster

kubectl get nodes
kubectl get nodes -o widebeginner

List nodes with extra details like internal IPs, OS image, and container runtime

kubectl get nodes -o wide
kubectl describe node <name>intermediate

Show 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 nodesintermediate

View live CPU and memory usage for nodes from Metrics Server

kubectl top nodes
kubectl config viewintermediate

Print the merged kubeconfig with clusters, users, and contexts

kubectl config view
kubectl config current-contextbeginner

Show the currently selected kubeconfig context

kubectl config current-context
kubectl config get-contextsbeginner

List 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>beginner

Switch kubectl to a different cluster and user context

kubectl config use-context prod-eu-west-1

Pods

13 commands
kubectl get podsbeginner

List pods in the current namespace with basic readiness and status info

kubectl get pods
kubectl get pods -Abeginner

List pods across every namespace in the cluster

kubectl get pods -A
kubectl get pods -n <ns>beginner

List pods only in a specific namespace

kubectl get pods -n production
kubectl get pods -o widebeginner

Show pods with extra details like node placement and pod IPs

kubectl get pods -o wide
kubectl describe pod <name>intermediate

Inspect 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>beginner

Fetch logs from the main container in a pod

kubectl logs my-app-6d9d7f8c6c-7kq2m
kubectl logs <pod> -fbeginner

Stream logs from a pod in real time

kubectl logs my-app-6d9d7f8c6c-7kq2m -f
kubectl logs <pod> --previousintermediate

View 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/shintermediate

Open an interactive shell inside a pod using the default container

kubectl exec -it nginx-5d59d67564-92x8m -- /bin/sh
kubectl exec -it <pod> -c <container> -- bashintermediate

Open a shell inside a specific container in a multi-container pod

kubectl exec -it payments-6f96d4b7c7-vr8zs -c app -- bash
kubectl delete pod <name>beginner

Delete 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=nginxbeginner

Create a quick standalone pod directly from an image

kubectl run nginx --image=nginx
kubectl port-forward pod/<name> 8080:80intermediate

Forward a local port to a pod port for direct debugging access

kubectl port-forward pod/my-app-6d9d7f8c6c-7kq2m 8080:8080

Deployments

12 commands
kubectl get deploymentsbeginner

List deployments in the current namespace with desired and ready replica counts

kubectl get deployments
kubectl describe deployment <name>intermediate

Inspect a deployment strategy, pod template, rollout conditions, and events

kubectl describe deployment my-app
kubectl create deployment nginx --image=nginxbeginner

Create a deployment from a single image directly from the CLI

kubectl create deployment nginx --image=nginx
kubectl scale deployment <name> --replicas=3beginner

Change the number of desired pod replicas for a deployment

kubectl scale deployment my-app --replicas=6
kubectl set image deployment/<name> <container>=<image>:tagintermediate

Update 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>intermediate

Watch the rollout until the deployment successfully completes or fails

kubectl rollout status deployment/my-app
kubectl rollout history deployment/<name>intermediate

Show previous rollout revisions for a deployment

kubectl rollout history deployment/my-app
kubectl rollout undo deployment/<name>intermediate

Roll back the deployment to the previous revision

kubectl rollout undo deployment/my-app
kubectl rollout undo deployment/<name> --to-revision=2advanced

Roll 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>beginner

Delete a deployment and its managed ReplicaSets and pods

kubectl delete deployment my-app
kubectl apply -f deployment.yamlbeginner

Create 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>advanced

Open the live deployment manifest in your editor for an immediate change

kubectl edit deployment my-app

Services & Networking

11 commands
kubectl get svcbeginner

List services in the current namespace with type and cluster IP

kubectl get svc
kubectl get svc -Abeginner

List services across all namespaces

kubectl get svc -A
kubectl describe svc <name>intermediate

Inspect service ports, selectors, endpoints, and load balancer details

kubectl describe svc my-app
kubectl expose deployment <name> --port=80 --type=ClusterIPbeginner

Expose a deployment internally within the cluster using a ClusterIP service

kubectl expose deployment my-app --port=8080 --target-port=8080 --type=ClusterIP
kubectl expose deployment <name> --port=80 --type=LoadBalancerintermediate

Expose 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=NodePortintermediate

Expose a deployment on a static port on each cluster node

kubectl expose deployment my-app --port=80 --target-port=8080 --type=NodePort
kubectl get ingressbeginner

List ingress resources and their configured hosts and addresses

kubectl get ingress
kubectl describe ingress <name>intermediate

Inspect ingress rules, TLS configuration, and backend service routing

kubectl describe ingress production-web
kubectl get endpointsintermediate

Show 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:80intermediate

Forward a local port to a service for testing without external exposure

kubectl port-forward svc/my-app 8080:80
kubectl delete svc <name>beginner

Delete a service resource by name

kubectl delete svc my-app

Namespaces

8 commands
kubectl get namespacesbeginner

List all namespaces in the cluster

kubectl get namespaces
kubectl create namespace <name>beginner

Create a new namespace for an application, team, or environment

kubectl create namespace staging
kubectl delete namespace <name>intermediate

Delete 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>beginner

List the main workload and service resources in a target namespace

kubectl get all -n production
kubectl config set-context --current --namespace=<name>intermediate

Set 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-namespacesbeginner

List pods across every namespace using the long-form namespace flag

kubectl get pods --all-namespaces
kubectl get quota -n <namespace>intermediate

View resource quota usage and hard limits for a namespace

kubectl get quota -n production
kubectl describe namespace <name>intermediate

Inspect a namespace including labels, annotations, quotas, and limit ranges

kubectl describe namespace production

ConfigMaps & Secrets

9 commands
kubectl get configmapsbeginner

List ConfigMaps in the current namespace

kubectl get configmaps
kubectl describe configmap <name>intermediate

Show the keys and metadata stored in a ConfigMap

kubectl describe configmap app-config
kubectl create configmap my-config --from-literal=key=valuebeginner

Create a ConfigMap from one or more literal key-value pairs

kubectl create configmap app-config --from-literal=LOG_LEVEL=info
kubectl create configmap my-config --from-file=config.envintermediate

Create 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 secretsbeginner

List secrets in the current namespace

kubectl get secrets
kubectl describe secret <name>intermediate

Inspect secret metadata and available keys without printing decoded values

kubectl describe secret app-secret
kubectl create secret generic my-secret --from-literal=password=abcbeginner

Create a generic secret from literal key-value pairs

kubectl create secret generic db-credentials --from-literal=password=S3cr3tP@ss
kubectl create secret docker-registry regcred --docker-server=... --docker-username=... --docker-password=...advanced

Create 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 -dadvanced

Decode a specific secret key value from base64 for troubleshooting

kubectl get secret db-credentials -o jsonpath='{.data.password}' | base64 -d

Storage

8 commands
kubectl get pvbeginner

List cluster-wide persistent volumes and their binding state

kubectl get pv
kubectl get pvcbeginner

List persistent volume claims in the current namespace

kubectl get pvc
kubectl get pvc -n <namespace>beginner

List persistent volume claims in a specific namespace

kubectl get pvc -n production
kubectl describe pv <name>intermediate

Inspect a persistent volume including reclaim policy, capacity, and claim binding

kubectl describe pv pvc-7fd3d6b2-0d1c-43f5-8ae0-31ef1b1c9a93
kubectl describe pvc <name>intermediate

Inspect 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>intermediate

Delete a persistent volume claim and release its bound volume according to policy

kubectl delete pvc scratch-cache
kubectl get storageclassbeginner

List available storage classes and identify the default provisioner

kubectl get storageclass
kubectl describe storageclass <name>intermediate

Inspect provisioner parameters, reclaim policy, and binding mode for a storage class

kubectl describe storageclass gp3

Troubleshooting

12 commands
kubectl get events --sort-by=.metadata.creationTimestampintermediate

List 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=Failedintermediate

Filter namespace events down to failure-related entries only

kubectl get events -n production --field-selector=reason=Failed
kubectl describe pod <name> | grep -A 10 Eventsadvanced

Extract the events section from a pod description for quick CLI triage

kubectl describe pod api-7c67f9bbd8-jm2t4 | grep -A 10 Events
kubectl logs <pod> --since=1hintermediate

Show logs generated within the last hour to narrow noisy output

kubectl logs worker-54df9f7cf9-kpjl2 --since=1h
kubectl logs <pod> --tail=100beginner

Show only the most recent log lines from a pod

kubectl logs worker-54df9f7cf9-kpjl2 --tail=100
kubectl top podsintermediate

View CPU and memory usage for pods in the current namespace

kubectl top pods
kubectl top pods -n <namespace>intermediate

View 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=Pendingintermediate

List only pods that are still waiting to schedule or start

kubectl get pods --field-selector=status.phase=Pending
kubectl get pods --field-selector=status.phase=Failedintermediate

List pods whose last phase is Failed for cleanup or investigation

kubectl get pods --field-selector=status.phase=Failed
kubectl drain <node> --ignore-daemonsetsadvanced

Safely 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>advanced

Mark a node unschedulable so new pods are not placed on it

kubectl cordon ip-10-0-15-22.ec2.internal
kubectl uncordon <node>advanced

Mark a node schedulable again after maintenance is complete

kubectl uncordon ip-10-0-15-22.ec2.internal
devopslesson.comFree DevOps Cheatsheets · Tutorials · Roadmaps