Kubectl replace vs force

Hello,

I see during these labs many times we see a

kubectl replace and we see a kubectl apply -f

my question is how do we know when we want to use the replace configuration instead of the apply -f

for example in the lab for multiple container pods there was a question where the instructor used the kubectl replace,

im unsure how to determine when to use the replace command , thanks

Typically you can use use kubectl -f replace anywhere you’d use kubectl delete RESTYPE RESNAME ; kubectl apply -f updated-yaml.yaml. It’s mostly personal preference.

Quick addition: the -f in k replace -f, k delete -f, and k apply -f means “file”, rather than “force”. All of these commands take a file as an argument for the -f.

thank you

working through these labs I see that one of the instructors always prefers to use:

kubectl get pod “name” -o yaml > “name”.yaml

the other works with the replace -f command

so I am guessing its personal preference on how you work with pods/yaml files