kubectl apply vs kubectl create, What is the difference?

Coding > Kubernetes | By: Team Appsious | Friday, 29 January 2021
kubectl apply vs kubectl create, What is the difference?

The kubectl command-line tool supports multiple ways to manage Kubernetes objects.

  • Imperative commands
  • Imperative object configuration
  • Declarative object configuration

Management techniqueOperates onRecommended environment
Imperative commandsLive objectsDevelopment projects
Imperative object configurationIndividual filesProduction projects
Declarative object configurationDirectories of filesProduction projects

kubectl apply vs kubectl create, What is the difference?

1) kubectl apply vs kubectl create

  • kubectl create: This is called as Imperative Management approach. In this approach, you need to tell Kubernetes what to do with the object like create or delete or replace. Create - creates a new object, if the object does not exist. And throws an error if the object already exists.
  • kubectl apply: This is called as Declarative Management approach. Command makes incremental changes to an object. It creates all the objects which do not exist and updates if those objects already exist.

2) Kubernetes Object Management - Imperative Management vs Declarative Management

  • Imperative commands: The user operates directly on live objects in a cluster. The user provides operations to the kubectl command as arguments or flags.
    Examples - 

    kubectl create deployment nginx --image nginx

  • Imperative object configuration: In imperative object configuration, the kubectl command specifies the operation (create, replace, etc.), optional flags, and at least one file name.
    Example - 
    kubectl create -f <filename|url>

    kubectl replace -f <filename|url>

    kubectl delete -f <filename|url>
  • Declarative object configuration: In Declarative object configuration, the kubectl command specifies a file name or directory, the user does not define the operations to be taken on the files.
    Example-
    kubectl apply -f <directory>/
Related Articles