Kubectl Create vs Apply
The key difference between kubectl apply and create is that apply creates Kubernetes objects through a declarative syntax, while the create command is imperative.
The command set kubectl apply is used at a terminal's command-line window to create or modify Kubernetes resources defined in a manifest file. This is called a declarative usage. The state of the resource is declared in the manifest file, then kubectl apply is used to implement that state.
In contrast, the command set kubectl create is the command you use to create a Kubernetes resource directly at the command line. This is an imperative usage. You can also use kubectl create against a manifest file to create a new instance of the resource. However, if the resource already exists, you will get an error.
- The file is used for creating the process should be complete.
- Create and Works on each and every property of the resource defined in the file.
- It was an imperative approach
- It will directly update the current resource with the attributes defined in the file.
- Apply can be executed on incompleted spec.
- It works on the properties which are already working in the resource.
- It was a Declarative approach
Kubectl create is called Imperative Management. This approach will tell Kubernetes API what you want to create, replace or delete, not how you want your Kubernetes cluster world to look like.
Kubectl apply is part of the Declarative Management approach, where changes that you may have applied to a live object (i.e. through scale) are maintained even if you apply other changes to the object.
Both approaches are valid ways to work in production.