<p>I've explored k8s, yet couldn't find an answer to a not trivial setup I have.  </p>

<p>I have 2 apps (2 containers) which work together but not related.<br>
<code>app1</code> receives and filters data, then sends to <code>app2</code>.  </p>

<ol>
<li>I've decided to have <code>deployment</code> per application;<br>
1.1. (And not both containers reside in the same <code>POD</code>) because they shouldn't share anything - communication take place on standard network.<br>
1.2. Each could scale independently  </li>
</ol>

<p>-> <strong>Q1</strong> is this approach correct ?</p>

<p>So I have 2 deployments corresponding to these 2 apps. Defined in <code>deployment1.yaml</code> and <code>deployment2.yaml</code>.
Each could scale independently with <code>kubectl scale</code>.</p>

<p>My two deployments should work together, so in case of scale I would like to:  </p>

<ol start="2">
<li>Scale both <code>deployment1</code> and <code>deployment2</code>  </li>
</ol>

<p>-> <strong>Q2</strong> Is there a way to perform multi deployment scale with <code>k8s</code> ?  </p>

<ol start="3">
<li>Do something for the newly created instance of <code>deployment1</code> so it would know of new instance of <code>deployment2</code> existence (ip address, etc...). i.e. I would like to send some request to it with <code>deployment2</code> ip.  </li>
</ol>

<p>-> <strong>Q3</strong> Is there a way to have some kind of hook for <code>after-successful-scale</code> in order to run some code? e.g. bash script? If there is - who runs it? the master node? Some init container?</p>

<p>Regardless of <code>3.</code> I would like also <code>deployment1</code> to pull its configuration from somewhere when it starts. Or alternatively somehow attach files to it when it starts.  </p>

<p>-> <strong>Q4</strong> Is there a way to do it dynamically? First instance of <code>deployment1</code> might have different configuration than the second instance. I understand I might use <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">StatefulSets</a> instead of <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deployments</a> so I would recognize unique instance.<br>
I thought of using some shared volume / ConfigMap so all instances would read their own unique configuration with their instance number. But I also thought there's a more standard way to do it, so I ask.</p>

<hr>

<p>I thought what is the way to perform these requirements in the trivial setup of web apps, and thought:  </p>

<ol>
<li>Both <code>deployments</code> scale automatically when need to according to some trigger.  </li>
<li>Both <code>deployments</code> export a LoadBalancer, so <code>app1</code> always talks to <code>app2</code>'s LoadBalancer - then <code>deployment1</code> is really independent from <code>deployment2</code>; both scale and LoadBalancer handles the load.  </li>
</ol>

<p>-> <strong>Q5</strong> Is that thought correct for the trivial case?</p>

hudac
<p>For q5: Just create a Service, let the applications talk inside the kubernetes cluster and the Service will handle load balancing (per request). You don't need a Service of type <code>LoadBalancer</code> and make the applications use an external IP.</p>

<p>q1-q4: You can write your own operator using the kubernetes API (and probably client libraries). There is a watch API so you cat notified automatically of changes that are relevant for your operator, so you don't have to poll.</p>
