<p>I am trying to create an architecture where every deployment deploys with a cluster IP and the rule get automatically added to the ingress rule as a new path.</p>
<p>My initial thinking was to give the <code>Deployment</code> a <code>ServiceAccount</code> that has access to manage ingress rule and before the main pod would run, an init container would fetch the YAML and add the ruleset, while deleting maybe delete that as well?</p>
<p>But the more I think about it, more loopholes start coming to mind. For eg: What happens when 2 <code>Deployment</code>'s start at the same time?<br />
and things like that.</p>
<p>Any idea on how to tackle this would be appreciated.</p>
<p>My background: I am a cloud engineer trying to shift to DevOps, have beginner-intermediate level knowledge of Kubernetes.</p>

Aniket Paul
<blockquote>
<p>I am trying to create an architecture where every deployment deploys with a cluster IP and the rule gets automatically added to the ingress rule as a new path.</p>
</blockquote>
<hr />
<p><a href="https://i.stack.imgur.com/LJRH9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LJRH9.png" alt="enter image description here" /></a></p>
<hr />
<h2>Few options:</h2>
<h3>Init container (You figured this one out and mentioned it in your question)</h3>
<ul>
<li>ADd init container to your Deployment which will add the desired rule to your Ingress</li>
</ul>
<h3>Probes</h3>
<ul>
<li>Add a post-start probe which will be executed once your pod is running and kicking will update the Ingress rules</li>
</ul>
<h3>CronJob</h3>
<ul>
<li>Add a CronJob which will &quot;scan&quot; for changes and will update the Ingress again</li>
</ul>
