DevOps Interview: kubectl apply vs kubectl create


Both kubectl create and kubectl apply are commands used to manage resources in a Kubernetes cluster.
Let’s check the differences!!
“create” is an imperative command meaning it requires you to specify all the details of the resource you want to create, including its name, labels, selectors, and other configuration options.
“apply” is a declarative command meaning it compares the desired state of a resource to its current state and makes the necessary changes.The “create” command will fail if resources are already present. But, “apply” will update the existing resources.
“kubectl create” is not idempotent, running it multiple times will create multiple instances of the resource.
“kubectl apply” is idempotent, meaning that you can run it multiple times without affecting the resource’s state.“kubectl create “can be used to create resources from manifest files or command-line.
“kubectl apply” can only be used to apply resources from manifest files.Syntax:
kubectl create -f <your_manifest_file_name.yaml>
kubectl apply -f <your_manifest_file_name.yaml>
Subscribe to my newsletter
Read articles from Aishwary Prakash directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Aishwary Prakash
Aishwary Prakash
Hi Aspirants, my name is Aishwary Prakash and I'm a DevOps/ Site Reliability Engineer (SRE) with 4 years of experience. I'm passionate about using technology to solve real-world problems. In my current role, I'm responsible for the reliability, scalability, and performance of a large-scale cloud platform. I'm also interested in DevOps, monitoring, automation, fitness, cloud, and CI/CD. Some of the topics I write about include: SRE: I write about Site Reliability Engineering (SRE) best practices, tools, and technologies. DevOps: I write about DevOps practices, tools, and technologies that can help teams to deliver software more quickly and reliably. Monitoring: I write about monitoring tools and techniques that can be used to identify and resolve problems with software systems before they impact users. Automation: I write about automation tools and techniques that can be used to automate repetitive tasks, improve efficiency, and reduce errors. Fitness: I write about fitness tips, workouts, and nutrition advice that can help people to improve their overall health and well-being. Cloud: I write about cloud computing platforms, tools, and technologies that can be used to build and deploy scalable software systems. DevOps/SRE Interview: I write about DevOps/SRE related interview based on my experience and other professionals. I hope you enjoy my blog! Connect with me at aishwaryprakash98@gmail.com