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

<p>How can I achieve this?</p>

Sandeep Makhiija
<p>You can write a special Kubernetes program called a <a href="https://kubernetes.io/docs/concepts/architecture/controller/" rel="nofollow noreferrer">controller</a>.  This is an ordinary program, running in an ordinary pod, that uses the <a href="https://kubernetes.io/docs/reference/using-api/api-overview/" rel="nofollow noreferrer">Kubernetes API</a> to watch some set of objects and modify some other set of objects.</p>

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

<ol>
<li><a href="https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes" rel="nofollow noreferrer">Watch</a> all of the Ingress objects (in a namespace, matching some labels, ...)</li>
<li>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.)</li>
<li>Generate the file you want to output into a ConfigMap object.</li>
</ol>

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

<p>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.</p>
