2

I am trying to create a custom kubernetes controller which keeps the track of the number kubernetes resources, for example count the number services created in a cluster.

there are 2 parts to the above question:

  1. 1st I need to create a controller which listens to when a service is created, lets call this counter as svc_count. This is easy, as I can write a custom controller to listen on services.

  2. I need to store the svc_count in the etcd, so that I can show the value when some user queries for the svc_count. So I thought of using the CRD's. I can do that by following the example in https://github.com/yaronha/kube-crd. This has the Rest-API-client to POST,PUT,GET.

  3. The 3rd part is relating the part 1 and part 2. Whenever a Service is created, then in the ADD eventhandler of the controller I need make changes to the CRD, so that the user can see the update.

Issue/Question: My question how to update a CRD from the custom controller's eventhandler??. Can I save the CRD rest-api-client in the custom controller and call the respective Update function.

Please, let me know if there is any other way of doing this.

Thanks

Invictus
  • 2,653
  • 8
  • 31
  • 50
  • Just for clarity: if you merely want a count of the number of `Service`s or `Namespace`s, the prometheus metrics will likely get you further down that road than a _custom resource definition,_ which feels like a very, very heavy tool for solving that problem. However, if you are merely using those as an example, feel free to disregard this comment. – mdaniel Jun 16 '18 at 06:04
  • Thanks for the reply, but, my goal is to play around the CRD and custom controllers to get a better understand of the kubernetes internals. Thanks – Invictus Jun 17 '18 at 02:31

0 Answers0