简体   繁体   English

如何在Kubernetes中扩展CRD控制器

[英]How to scale a CRD Controller in Kubernetes

I'm reading a lot of documentation about CRD Controller 我正在阅读很多关于CRD控制器的文档

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 我创建了一个自定义对象,让我们用名称bar称它为Foo
  • 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 我的业务逻辑适用,让我们说它创建一个带有生成名称的Deployment ,并将其保存在Foo对象中的名称(作为参考)
  • 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. 问题是因为我的Deployment有一个生成的名称,也许save(Foo)失败了,我有两个Deployment有两个名字。

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? 那么,扩展CRD控制器并避免这种竞争条件的最佳设计是什么?

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. 只要你小心地编写你的代码,那么它在技术上并不重要,但实际上没有多少理由可以运行多个代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM