0

Basically, I want a create a sidecar container to scan ingress objects in my cluster and copy the generated file to other containers.

How can I achieve this?

  • please describe more not sure want you ultimately want to achieve. what i understand you want to share file across containers in single pod ? in that case you can use volume RWO will work. – Harsh Manvar Feb 26 '20 at 16:40

1 Answers1

1

You can write a special Kubernetes program called a controller. This is an ordinary program, running in an ordinary pod, that uses the Kubernetes API to watch some set of objects and modify some other set of objects.

The main loop of a controller that does what you're describing can be pretty straightforward:

  1. Watch all of the Ingress objects (in a namespace, matching some labels, ...)
  2. Keep some state about the current combined set of Ingresses in ordinary variables in your controller. (If the controller exits and restarts, the watch will begin by replaying all of the current objects into the new controller process.)
  3. Generate the file you want to output into a ConfigMap object.

Then other pods can mount the ConfigMap like any other ConfigMap, it just happens to be owned by your controller rather than manually maintained.

This process isn't a great match for a "sidecar" container; it runs basically a completely independent process that's not tightly bound to a specific pod. This also avoids trying to manually modify container filesystems, which gives you resiliency in a couple of ways: if a new pod starts up it will automatically get the existing ConfigMap content; if your controller outright fails in some way then pods can keep using the old ConfigMap content until it restarts.

David Maze
  • 130,717
  • 29
  • 175
  • 215