apply kubectl vs create kubectl?

In the documentation, I realized that kubectl apply = kubectl create + kubectl replace . Link

As far as I understand, if I want to create a new k8s resource in a cluster, I should use the kubectl create operation . Now, if I want to update something in k8s live resources, I have to use the kubectl replace operation .

If I want to perform both operations (create a new k8s resource, as well as update k8s live resources), I must use the kubectl apply operation

My questions are: why are there three operations in a cluster to perform the same task? What are the use cases for these operations? How do they differ from each other under the hood?

I am currently using kubectl create to create new resources in the cluster. thank

+184
source share
6 answers

These are two different approaches. kubectl create- this is what we call imperative management . With this approach, you tell the Kubernetes API what you want to create, replace, or delete, and not how you want your K8s cluster world to look.

kubectl apply , , , , (.. scale), , apply .

Kubernetes Object Management.

+235

CI , create , .

, ( ) , --dry-run=true -o yaml:

kubectl create whatever --dry-run=true -o yaml | kubectl apply -f -

, ( ).

, (, Docker).

+26

, :

apply -
create -


DigitalOcean, - Kubernetes:

apply create , Ingress Controller , .

+15

, kubectl apply.

, , , , .

kubectl create , kubectl create ( ) .

+2

:

kubectl run = kubectl create deployment

:

  • , .
  • .

:

  • .
  • , .
  • , , .
  • .

:

kubectl create -f your-object-config.yaml

kubectl delete -f your-object-config.yaml

kubectl replace -f your-object-config.yaml

:

  • , Git.
  • , .
  • .

:

  • .
  • YAML.

:

  • .
  • Kubernetes 1.5.

:

  • , .
  • , .

kubectl diff -f configs/

kubectl apply -f configs/

:

  • , , , .
  • (, , ) .

:

  • , .
  • diffs .
+1

Source: https://habr.com/ru/post/1689132/


All Articles