DEV Community

Aishwary Prakash
Aishwary Prakash

Posted on

DevOps Interview: kubectl apply vs kubectl create

Kubernetes
Both kubectl create and kubectl apply are commands used to manage resources in a Kubernetes cluster.

Let’s check the differences!!

  1. “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.

  2. The “create” command will fail if resources are already present. But, “apply” will update the existing resources.

  3. “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.

  4. “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.

  5. Syntax:
    kubectl create -f your_manifest_file_name.yaml
    kubectl apply -f your_manifest_file_name.yaml

Top comments (2)

Collapse
 
grigorkh profile image
Grigor Khachatryan

Nice article.

Collapse
 
misterjacko profile image
Jakob Ondrey • Edited

Why would one ever want to use the non-idempotent "create" command when apply exists? Just to do something simple from the command line like create a namespace?