What is the difference between using kubectl and replacing kubectl

I’ve been studying Kubernete lately, and I don’t really understand the difference between “kubectl apply” and “kubectl replace”. Is there a situation where we can use only one of them?

+25
source share
4 answers

The difference is that it replacefirst deletes the resources and then creates them from the file that you provided them; while it applytries to directly update in the current active resource only those attributes that you set to it in the file. See in-place updates and destructive updates .

, , apply, , , ; replace .

, apply , , - ; replace, - .

, apply ; , apply ( !), replace.

+6

apply replace apply create.

create/replace , apply .

If you used createto create a resource, then use replaceto update it. If you used applyto create a resource, use applyto update it.

Note that full specification is required for replaceand apply, and both first create new resources before deleting old ones (if not specified --force).

0
source

you can add the -v = 8 option when using kubectl and you will find a log like this

apply --force
patch 422
delete 200
get 200
get 200
get 404
post 201

replace --force
get 200
delete 200
get 404
post 201
0
source

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


All Articles