kubectl run is deprecated - looking for alternative
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Kubernetes' kubectl run command, once a versatile tool for creating and managing pods, deployments, and other resources, is now deprecated for certain use cases. This article will explore why some functionalities of kubectl run are deprecated, provide alternatives, and guide you through making these changes seamlessly in your Kubernetes workflows.
Deprecation of kubectl run
kubectl run was initially designed to cover a variety of use cases, from running simple pods to more complex deployments. Over time, the Kubernetes community recognized that having a single command that served multiple purposes could lead to ambiguity and misuse. As Kubernetes evolved, finer-grained resources like kubectl create and specific API objects for deployments, jobs, and cronjobs were introduced, leading to a more declarative and resource-specific approach.
Why was kubectl run deprecated?
- Ambiguity and Overhead:
kubectl runattempted to manage both initial pod creation and rolling updates of deployments, leading to confusion. The overload of options made it cumbersome and less user-friendly.
- Declarative Model Preference:
- Kubernetes promotes a declarative model, where resources are described in manifests.
kubectl runleaned more on the imperative style, misaligning with best practices.
- Better API Coverage:
- As Kubernetes developed more specific API objects like
Deployment,Job, andCronJob, relying on these specific resources has become the norm.
How kubectl run Still Functions
While some functions of kubectl run are deprecated, especially those related to complex resource creation (like deployments), it stills retains usage for those looking to:
- Quickly spin up a temporary pod, primarily for testing or debugging.
Example:
However, for creating and managing more extensive setups like deployments, alternatives exist that align better with Kubernetes' practices.
Recommended Alternatives
kubectl create
For a more declarative and flexible approach, kubectl create covers the need for different resources. For instance, to create a deployment:
Here, kubectl create is used to specify the exact type of resource you intend to create, ensuring the intention is clear and aligned with Kubernetes' API resource types.
YAML Manifests
Defining resources in YAML manifests is a Kubernetes best practice. This method allows for a more controlled and versionable approach to application deployment.
To apply this manifest:
Additional Tools and Techniques
- Helm:
- A package manager for Kubernetes, Helm, simplifies the management of Kubernetes applications using charts – pre-configured templates for Kubernetes resources.
- Kustomize:
- Allows customizing Kubernetes resource configurations free from template restrictions.
- Operators:
- Application-specific controllers that extend Kubernetes' functionality, managing complex and domain-specific processes within a cluster.
Key Points Summary
| Aspect | kubectl run | Alternative Approach |
| Use | Quick pod creation (limited roles) | Comprehensive management of resources |
| Declarative Preference | No | Yes |
| Complex Use Cases | Not suited | Utilizing YAML Manifests and kubectl apply |
| Versioning & Auditing | Challenging | Easier via YAML manifests and VCS |
| Best Practices Compliance | Limited | Fully compliant with Kubernetes paradigms |
Conclusion
While kubectl run remains a useful tool for specific cases, its limitations make it essential for Kubernetes practitioners to pivot towards more suitable alternatives. Embracing kubectl create, YAML manifests, and complementary tools like Helm, ensures robust, transparent, and aligned deployments with Kubernetes' ecosystem, harnessing the platform's full potential for scalable and resilient applications.
Related reading
- Kubectl throws ImagePullBackOff Error while creating deployment via minikube
- kubectl top node error metrics not available yet . Using metrics-server as Heapster Depricated
- kubectl top nodes shows error metrics not available yet
- kubectl unable to connect to server x509 certificate signed by unknown authority
- Kubernetes-Helm Charts pointing to a local docker image
- Kubernetes - can a Deployment have multiple ReplicaSets?
- Kubectl update configMap
- kubectl Use custom-columns output with maps

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.