kubectl apply vs kubectl create?

前端 未结 9 1425
[愿得一人]
[愿得一人] 2020-11-29 15:06

What I understood by the documentation is that:

  • kubectl create = Creates a new k8s resource in the cluster
  • kubectl replace
相关标签:
9条回答
  • 2020-11-29 15:29

    We love Kubernetes is because once we give them what we want it goes on to figure out how to achieve it without our any involvement.

    "create" is like playing GOD by taking things into our own hands. It is good for local debugging when you only want to work with the POD and not care abt Deployment/Replication Controller.

    "apply" is playing by the rules. "apply" is like a master tool that helps you create and modify and requires nothing from you to manage the pods.

    0 讨论(0)
  • 2020-11-29 15:39

    These are imperative commands :

    kubectl run = kubectl create deployment

    Advantages:

    • Simple, easy to learn and easy to remember.
    • Require only a single step to make changes to the cluster.

    Disadvantages:

    • Do not integrate with change review processes.
    • Do not provide an audit trail associated with changes.
    • Do not provide a source of records except for what is live.
    • Do not provide a template for creating new objects.

    These are imperative object config:

    kubectl create -f your-object-config.yaml

    kubectl delete -f your-object-config.yaml

    kubectl replace -f your-object-config.yaml

    Advantages compared to imperative commands:

    • Can be stored in a source control system such as Git.
    • Can integrate with processes such as reviewing changes before push and audit trails.
    • Provides a template for creating new objects.

    Disadvantages compared to imperative commands:

    • Requires basic understanding of the object schema.
    • Requires the additional step of writing a YAML file.

    Advantages compared to declarative object config:

    • Simpler and easier to understand.
    • More mature after Kubernetes version 1.5.

    Disadvantages compared to declarative object configuration:

    • Works best on files, not directories.
    • Updates to live objects must be reflected in configuration files, or they will be lost during the next replacement.

    These are declarative object config

    kubectl diff -f configs/

    kubectl apply -f configs/

    Advantages compared to imperative object config:

    • Changes made directly to live objects are retained, even if they are not merged back into the configuration files.
    • Better support for operating on directories and automatically detecting operation types (create, patch, delete) per-object.

    Disadvantages compared to imperative object configuration:

    • Harder to debug and understand results when they are unexpected.
    • Partial updates using diffs create complex merge and patch operations.
    0 讨论(0)
  • 2020-11-29 15:39

    The explanation below from the official documentation helped me understand kubectl apply.

    This command will compare the version of the configuration that you’re pushing with the previous version and apply the changes you’ve made, without overwriting any automated changes to properties you haven’t specified.

    kubectl create on the other hand will create (should be non-existing) resources.

    0 讨论(0)
提交回复
热议问题