The kubectl run command is frequently misunderstood due to its evolving behavior, ambiguous use cases, and overlap with other Kubernetes commands. Below is a breakdown of why confusion persists, especially among beginners and those preparing for the CKA exam:
1. Behavior Changed Drastically Across Kubernetes Versions
-
Pre-1.18:
kubectl runcreated a Deployment by default. For example:
kubectl run nginx --image=nginx
This generated a Deployment, ReplicaSet, and Pod. Users familiar with older versions might still expect this behavior. Post-1.18: The command was simplified to create a Pod directly. The same command now creates a single Pod, not a Deployment. This change caused confusion for users upgrading their Kubernetes clusters or learning from outdated tutorials.
2. Imperative vs. Declarative Workflow Confusion-
kubectl run is an imperative command (directly creates resources), while Kubernetes emphasizes a declarative approach (using YAML manifests).
- Beginners often misuse
kubectl runfor complex or permanent workloads, not realizing it’s designed for quick, temporary tasks. - Example: Using
kubectl runto start a Pod instead of writing a Deployment YAML for long-running applications (which is error-prone and not scalable).
3. Misleading Flags and Overlapping Commands
-
Flags like
--replicasor--portsuggest it can create Deployments or Services, but this is no longer true post-1.18. - Users might confuse
kubectl runwith similar commands: -
kubectl create deployment: Creates a Deployment. -
kubectl create job: Creates a Job. -
kubectl expose: Creates a Service. - Example: Running
kubectl run web --image=nginx --port=80only creates a Pod. To expose it as a Service, you must separately runkubectl expose.
4. Lack of Clarity in Documentation
- The
kubectl run --helpoutput includes legacy flags (e.g.,--generator,--schedule) that are deprecated or irrelevant in newer versions. - Users often misinterpret flags like
--restart=Never(creates a Pod) vs.--restart=Always(default for Pods) vs.--restart=OnFailure(used for Jobs).
5. Assumptions About Scalability
- Users might assume a Pod created with
kubectl runis scalable, but a standalone Pod is not managed by a controller (e.g., Deployment, ReplicaSet). If the Pod crashes, Kubernetes will restart it (due to the defaultrestartPolicy: Always), but it won’t self-heal if the node fails. - Example:
kubectl run myapp --image=myapp
This creates a single Pod. For scalability, you need a Deployment:
kubectl create deployment myapp --image=myapp --replicas=3
6. Misuse for Non-Pod Workloads
- Users might try to create Jobs, CronJobs, or Deployments with
kubectl run, leading to errors. - Example:
kubectl run job --image=busybox --restart=OnFailure -- echo "Hello"
This works (creates a Job) but is inconsistent with the post-1.18 behavior. The safer approach is to use kubectl create job.
7. Confusion with Interactive Pods
- While
kubectl runcan start interactive Pods (e.g.,kubectl run -it debug --image=busybox -- sh), users might not realize these Pods are temporary and not production-ready.
8. CKA Exam Pitfalls
- In the CKA exam, time pressure leads candidates to use
kubectl runfor quick fixes. However, misunderstanding its behavior can lead to mistakes: - Expecting a Deployment but getting a Pod.
- Forgetting to add
--dry-run=client -o yamlto generate YAML templates. - Not cleaning up temporary Pods (using--rmfor auto-deletion).
How to Avoid Misunderstandings
-
Use
kubectl runonly for temporary tasks:
kubectl run -it --rm test --image=busybox --command -- sleep 3600
- Prefer declarative YAML for production workloads.
-
Learn the modern behavior (post-1.18): Assume it creates Pods unless flags like
--schedule(for CronJobs) are used. -
Use
kubectl createfor controllers:
kubectl create deployment nginx --image=nginx
-
Generate YAML with
--dry-run:
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
Summary of Key Reasons for Confusion
| Reason | Example Misunderstanding |
|---|---|
| Version behavior changes | Expecting Deployments but getting Pods. |
| Imperative vs. declarative | Using run for production instead of YAML. |
| Overlapping commands | Confusing run with create deployment or expose. |
| Deprecated flags | Trying to use --generator in newer versions. |
| Lack of scalability | Assuming Pods created by run are self-healing. |
By understanding these pitfalls, you’ll avoid common mistakes and use kubectl run effectively—especially in time-sensitive scenarios like the CKA exam!

Top comments (0)