When Should I Use Update Instead of Patch in Kubernetes?

0
8
Asked By CuriousDev123 On

Hey everyone! I'm diving deep into Kubernetes development and I'm a bit stuck on when to choose the update operation over patch. It seems like patching is often the better option, even if it does come with its complexities and the need to understand different patch types. I've noticed one downside to using patch is the potential issues that could arise when not using optimistic concurrency, but I think that can be managed within patch operations. I'd really appreciate any insights or examples you all can share to help clarify this for me!

4 Answers

Answered By DevDude On

You should opt for update when you really need guaranteed optimistic locking or if you want conflicts to halt reconciliation altogether. It’s best for cases when you're working with the entire object state or replacing the entire spec. On the flip side, patch is ideal for tweaking a few fields, avoiding unrelated changes, or when multiple controllers might be modifying different fields of the same object.

Answered By HelmHero On

Haha, edit gang rise up! But seriously, I ran into a similar situation this week with Helm when trying to add something to a previous helm install. The update route would have caused big conflicts, which made me stick to patching. If you’re familiar with the Linux patch command, it definitely helps to understand this scenario better, especially in relation to HTTP PUT versus PATCH.

Answered By CodeNinja On

Using update can be much easier when your controller fully owns the object. It’s a straightforward approach since you just create the object in the desired state and send it out, rather than getting into the nitty-gritty of merge semantics involved with patching. Patch works better for smaller changes or partial ownership.

Answered By TechieTina On

I'm a bit puzzled about the necessity of kubectl update. Patch operations let you change specific values in a file without the need for recreation, which is helpful since some resources can’t be created multiple times. So, patching usually makes a lot of sense in those cases. Just wondering how update fits into this picture?

KubeFan99 -

Oh, I see the confusion! My point was actually about the update and patch operations when you’re writing controllers or working directly with the Kubernetes API, not specifically kubectl.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.