DEV Community

Aishwary Prakash
Aishwary Prakash

Posted on

2 1 1

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

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

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?

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs