Kubernetes kubectl Commands Cheatsheet 2026
Complete guide to kubectl, managing pods, services, deployments, configmaps, secrets, troubleshooting, and cluster context.
Interactive Skill Mastery
Mark commands as learned to build your customized reference tracker. Retained locally in this browser.
Context & Config
When to Use
When managing, viewing, or switching cluster profiles, contexts, credentials, and access paths.
Common Mistakes
Accidentally modifying global kubeconfig credentials, locking out active terminal sessions.
Shortcut / Pro-Tip
Use 'kubectl config current-context' to quickly check your current environment target.Example
kubectl config viewOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When listing existing k8s resources (pods, services, deployments) inside the current active namespace.
Common Mistakes
Assuming resources are missing when they are simply located in a different namespace. Use the '-A' or '--all-namespaces' flag.
Shortcut / Pro-Tip
Use '-o wide' to retrieve extra resource columns like node name, IP address, and status details.Example
kubectl config get-contextsOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When managing, viewing, or switching cluster profiles, contexts, credentials, and access paths.
Common Mistakes
Accidentally modifying global kubeconfig credentials, locking out active terminal sessions.
Shortcut / Pro-Tip
Use 'kubectl config current-context' to quickly check your current environment target.Example
kubectl config current-contextOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When managing, viewing, or switching cluster profiles, contexts, credentials, and access paths.
Common Mistakes
Accidentally modifying global kubeconfig credentials, locking out active terminal sessions.
Shortcut / Pro-Tip
Use 'kubectl config current-context' to quickly check your current environment target.Example
kubectl config use-context <context-name>Output Example
Success (Resource updated on Kubernetes cluster)Pod Operations
When to Use
When listing existing k8s resources (pods, services, deployments) inside the current active namespace.
Common Mistakes
Assuming resources are missing when they are simply located in a different namespace. Use the '-A' or '--all-namespaces' flag.
Shortcut / Pro-Tip
Use '-o wide' to retrieve extra resource columns like node name, IP address, and status details.Example
kubectl get podsOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When listing existing k8s resources (pods, services, deployments) inside the current active namespace.
Common Mistakes
Assuming resources are missing when they are simply located in a different namespace. Use the '-A' or '--all-namespaces' flag.
Shortcut / Pro-Tip
Use '-o wide' to retrieve extra resource columns like node name, IP address, and status details.Example
kubectl get pods -o wideOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl run <pod-name> --image=<image-name>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl delete pod <pod-name>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl describe pod <pod-name>Output Example
Success (Resource updated on Kubernetes cluster)Deployments
When to Use
When listing existing k8s resources (pods, services, deployments) inside the current active namespace.
Common Mistakes
Assuming resources are missing when they are simply located in a different namespace. Use the '-A' or '--all-namespaces' flag.
Shortcut / Pro-Tip
Use '-o wide' to retrieve extra resource columns like node name, IP address, and status details.Example
kubectl get deploymentsOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl create deployment <name> --image=<image>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl scale deployment <name> --replicas=<num>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl rollout status deployment/<name>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl rollout undo deployment/<name>Output Example
Success (Resource updated on Kubernetes cluster)Services
When to Use
When listing existing k8s resources (pods, services, deployments) inside the current active namespace.
Common Mistakes
Assuming resources are missing when they are simply located in a different namespace. Use the '-A' or '--all-namespaces' flag.
Shortcut / Pro-Tip
Use '-o wide' to retrieve extra resource columns like node name, IP address, and status details.Example
kubectl get servicesOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl expose deployment <name> --port=<port> --type=<type>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl port-forward <pod-name> <host-port>:<pod-port>Output Example
Success (Resource updated on Kubernetes cluster)Troubleshooting
When to Use
When debugging or troubleshooting running containers inside active cluster pods.
Common Mistakes
Targeting an incorrect pod name or assuming logs persist after a pod has been deleted and recreated.
Shortcut / Pro-Tip
Use the '-f' flag to follow log output streams in real-time as they are written.Example
kubectl logs <pod-name>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When debugging or troubleshooting running containers inside active cluster pods.
Common Mistakes
Targeting an incorrect pod name or assuming logs persist after a pod has been deleted and recreated.
Shortcut / Pro-Tip
Use the '-f' flag to follow log output streams in real-time as they are written.Example
kubectl logs -f <pod-name>Output Example
Success (Resource updated on Kubernetes cluster)When to Use
When debugging or troubleshooting running containers inside active cluster pods.
Common Mistakes
Targeting an incorrect pod name or assuming logs persist after a pod has been deleted and recreated.
Shortcut / Pro-Tip
Use the '-f' flag to follow log output streams in real-time as they are written.Example
kubectl exec -it <pod-name> -- shOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl top podOutput Example
Success (Resource updated on Kubernetes cluster)Secrets & Configs
When to Use
When listing existing k8s resources (pods, services, deployments) inside the current active namespace.
Common Mistakes
Assuming resources are missing when they are simply located in a different namespace. Use the '-A' or '--all-namespaces' flag.
Shortcut / Pro-Tip
Use '-o wide' to retrieve extra resource columns like node name, IP address, and status details.Example
kubectl get configmapsOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When listing existing k8s resources (pods, services, deployments) inside the current active namespace.
Common Mistakes
Assuming resources are missing when they are simply located in a different namespace. Use the '-A' or '--all-namespaces' flag.
Shortcut / Pro-Tip
Use '-o wide' to retrieve extra resource columns like node name, IP address, and status details.Example
kubectl get secretsOutput Example
Success (Resource updated on Kubernetes cluster)When to Use
When administering, monitoring, or deploying applications and service structures to a Kubernetes cluster container.
Common Mistakes
Executing kubectl commands on the wrong cluster context, namespace, or active cloud project environment.
Shortcut / Pro-Tip
Set an alias 'k' for 'kubectl' in your bash/zsh profile to speed up administrative tasks.Example
kubectl create secret generic <name> --from-literal=key=valueOutput Example
Success (Resource updated on Kubernetes cluster)Kubernetes Best Practices
1Use Declarative YAML Files
Avoid using 'kubectl run' or imperatively modifying resources directly. Define your infrastructure in YAML files and apply them using 'kubectl apply -f' for version-controlled, reproducible setups.
2Configure Resource Requests & Limits
Always set CPU and Memory requests (what a container is guaranteed to get) and limits (the maximum a container can consume) on all Pods to ensure stable cluster scheduling.
3Leverage Namespaces for Environment Isolation
Organize your workloads using distinct namespaces to enforce clear access controls, isolate workloads, and keep clusters clean.
4Implement Liveness and Readiness Probes
Define probes to let Kubernetes know when a container is healthy and ready to receive traffic, preventing routing to broken instances.
5Keep Container Images Small and Clean
Build lightweight images (e.g. alpine base) to reduce cluster download latency, lower resource consumption, and limit security vulnerabilities.
Common Kubernetes Errors & Solutions
ErrImagePull / ImagePullBackOff
The cluster is unable to download the specified container image. Solution: Verify image name/tag spelling, and ensure registry secrets are configured for private registries.
CrashLoopBackOff
A container starts, fails, and restarts repeatedly. Solution: Review pod logs using 'kubectl logs <pod-name>' to debug application startup crashes.
OOMKilled
The container was terminated because it exceeded its allocated memory limit. Solution: Increase memory limits in your Deployment YAML spec.
CreateContainerConfigError
A required ConfigMap or Secret referenced by the Pod specification is missing. Solution: Create the missing ConfigMap/Secret or update the reference.
Pending Status
Pods cannot be scheduled onto any cluster nodes. Solution: Run 'kubectl describe pod <pod-name>' to check resource constraints, taint mismatches, or missing volumes.
Common Kubernetes Interview Questions
Q1What is a Pod in Kubernetes?
A Pod is the smallest, most basic deployable object in Kubernetes. It represents a single instance of a running process in your cluster and can contain one or more tightly coupled containers.
Q2What is the difference between a Deployment and a ReplicaSet?
A ReplicaSet ensures that a specified number of pod replicas are running at any given time. A Deployment is a higher-level resource that manages ReplicaSets and provides declarative updates to Pods and ReplicaSets (e.g. rolling updates, rollbacks).
Q3What is a Kubernetes Service and why is it needed?
A Service is an abstract way to expose an application running on a set of Pods as a network service. Since Pods are ephemeral and their IP addresses change frequently, a Service provides a stable IP address and DNS name to route traffic to them.
Q4How do ConfigMaps and Secrets differ in Kubernetes?
ConfigMaps are used to store non-sensitive configuration data in key-value pairs. Secrets are specifically designed to store sensitive data (like passwords, keys, or tokens) and are stored in a base64-encoded format, often backed by encryption at rest.
Q5What is a Namespace and when should you use it?
A Namespace is a virtual cluster inside a physical Kubernetes cluster. It is used to partition cluster resources among multiple users, teams, or environments (e.g., dev, staging, prod) to avoid naming collisions and enforce resource quotas.
Related Resources
REST API Tester
Test API routes and endpoints directly in your browser with full request controls.
JSON Formatter & Validator
Beautify, validate, and minify JSON structures instantly.
Best Free Online Developer Tools
An expert review of must-have online utilities for developers.
Git Cheatsheet
Essential command reference for local and remote version control repositories.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com