DevOps & Orchestration
Updated for 2026

Kubernetes kubectl Commands Cheatsheet 2026

Complete guide to kubectl, managing pods, services, deployments, configmaps, secrets, troubleshooting, and cluster context.

Target Version Compatibility

Interactive Skill Mastery

Mark commands as learned to build your customized reference tracker. Retained locally in this browser.

Level:Novice
Command Mastery Progress0 of 24 Mastered (0%)

Context & Config

kubectl config view
BeginnerBasics
Display merged kubeconfig settings or a specified kubeconfig file.

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 view

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl config get-contexts
BeginnerBasics
List all available cluster contexts.

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-contexts

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl config current-context
BeginnerBasics
Display the current-context.

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-context

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl config use-context <context-name>
BeginnerBasics
Set the current-context to the specified context.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)

Pod Operations

kubectl get pods
BeginnerBasics
List all pods in the current namespace.

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

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl get pods -o wide
BeginnerBasics
List pods with more detailed information (like node IP).

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 wide

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl run <pod-name> --image=<image-name>
BeginnerBasics
Create and run a specific pod using an image.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl delete pod <pod-name>
AdvancedRecovery
Delete a specified pod.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl describe pod <pod-name>
BeginnerBasics
Display detailed state of a specific pod.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)

Deployments

kubectl get deployments
BeginnerBasics
List all deployments in the current namespace.

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 deployments

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl create deployment <name> --image=<image>
BeginnerBasics
Create a deployment using a specified container image.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl scale deployment <name> --replicas=<num>
BeginnerBasics
Scale a deployment to a specified number of replicas.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl rollout status deployment/<name>
IntermediateDebugging
Check the status of a rolling upgrade rollout.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl rollout undo deployment/<name>
BeginnerBasics
Rollback a deployment to the previous revision.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)

Services

kubectl get services
BeginnerBasics
List all services in the active namespace.

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 services

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl expose deployment <name> --port=<port> --type=<type>
BeginnerBasics
Expose a deployment as a new Kubernetes service.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl port-forward <pod-name> <host-port>:<pod-port>
BeginnerBasics
Forward one or more local ports to a pod.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)

Troubleshooting

kubectl logs <pod-name>
IntermediateDebugging
Print the logs for a specified container in a pod.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl logs -f <pod-name>
IntermediateDebugging
Stream and follow the container logs in real-time.

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

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl exec -it <pod-name> -- sh
BeginnerBasics
Execute an interactive terminal shell inside a running pod container.

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> -- sh

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl top pod
BeginnerBasics
Show CPU and Memory metrics for active pods.

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 pod

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)

Secrets & Configs

kubectl get configmaps
BeginnerBasics
List all ConfigMaps in the namespace.

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 configmaps

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl get secrets
BeginnerBasics
List all Secrets in the namespace.

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 secrets

Output Example

Console / Terminal
Success (Resource updated on Kubernetes cluster)
kubectl create secret generic <name> --from-literal=key=value
BeginnerBasics
Create a generic secret from a literal key-value pair.

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=value

Output Example

Console / Terminal
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

Error

ErrImagePull / ImagePullBackOff

Solution

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.

Error

CrashLoopBackOff

Solution

A container starts, fails, and restarts repeatedly. Solution: Review pod logs using 'kubectl logs <pod-name>' to debug application startup crashes.

Error

OOMKilled

Solution

The container was terminated because it exceeded its allocated memory limit. Solution: Increase memory limits in your Deployment YAML spec.

Error

CreateContainerConfigError

Solution

A required ConfigMap or Secret referenced by the Pod specification is missing. Solution: Create the missing ConfigMap/Secret or update the reference.

Error

Pending Status

Solution

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.