<p>I've rather a teoretical question which I can't answer  with the reousrces found online. The question is: <strong>what's the rule to decide how to compose containers in POD?</strong> . Let me explain with an example.</p>

<p>I've these microservices:</p>

<ul>
<li>Authentication </li>
<li>Authorization </li>
<li>Serving content</li>
<li>(plus) OpenResty to forward the calls form one to the other and orhcestarate the flow. (is there a possibility to do so natively in K8?, it seems to have services base on nginx+lua, but not sure how it works)</li>
</ul>

<p><em>For the sake of the example I avoid Databases and co, I assume they are external and not managed by kubernetes</em></p>

<p>Now, what's the correct way here <em>LEFT</em> or <em>RIGHT</em> of the image?
<a href="https://i.stack.imgur.com/b0VwE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/b0VwE.png" alt="enter image description here"></a></p>

<p><em>LEFT</em> : this seems easier to make it working, everything works on "localhost" , the downside is that it looses a bit the benefit of the microservices. For example, if the auth become slows and it would need more instances, I've to duplicate the whole pod and not just that service.</p>

<p><em>RIGHT</em> seems a bit more complex, need services to expose each POD to the other PODs. Yet, here, I could duplicate auth as I need without duplicating the other containers. On the other hand I'll have a lot of pods since each pod is basically a container.</p>

<p>It is generally recommended to keep different services in different pods or better deployments that will scale independently. The reasons are what is generally discussed as benefits of a microservices architecture. </p>

<ul>
<li><p>A more loose coupling allowing the different services to be developed independently in their own languages/technologies, </p></li>
<li><p>be deployed and updated independently and </p></li>
<li><p>also to scale independently. </p></li>
</ul>

<p>The exception are what is considered a "<em>helper application</em>" to assist a "primary application". Examples given in the k8s docs are data pullers, data pushers and proxies. In those cases a share file system or exchange via loopback network interface can help with critical performance use cases. A data puller can be a side-car container for an nginx container pulling a website to serve from a GIT repository for example. </p>
