How to scale a CRD Controller in Kubernetes

7/17/2019

I'm reading a lot of documentation about CRD Controller

I've implemented one with my business logic, and sometimes I got this race condition:

  • I create a Custom Object, let's call it Foo with name bar
  • My business logic applies, let's says that it creates a Deployment with a generated name, and I save the name (as reference) it in the Foo object
  • I remove the Custom Object
  • I quickly recreate it with the same name, and sometimes I get this log:
error syncing 'default/bar': Operation cannot be fulfilled on Foo.k8s.io "bar": 
the object has been modified; please apply your changes to the latest version 
and try again, requeuing

The thing is because my Deployment has a generated name and maybe the save (Foo) has failed, I got two Deployment with two names.

I did not found a way to fix it for now, but it raises a question.

How if I've multiple controllers running ?

I've started two controllers, and I got the same race condition by just creating a new object.

So, what is the best design to scale a CRD controller and avoid this kind of race conditions?

-- XciD
kubernetes

1 Answer

7/17/2019

Generally you only run one copy of a controller, or at least only one is active at any given time. As long as you were careful to write your code convergently then it shouldn't technically matter, but there really isn't much reason to run multiple.

-- coderanger
Source: StackOverflow