<p><strong>Requirement</strong> :
I have two docker containers where both expose to different ports. (For eg port 9001 and 9002)</p>

<p>From the requirement,  I try to design the kubernetes objects and their relationships but I am unsure whether A or B is correct.</p>

<p>A) 1 Ingres connect to 1 service. And 1 service connect to 1 statefulset with 1 pod of 2 containers</p>

<p>B) 2 Ingres connect to 2 services. And 2 service connect to 2 statefulset with 2 pod. Every pod have 1 container.</p>

<p>I want to ask the following questions:</p>

<ol>
<li>Can 1 Ingres or 1 service or 1 statefulset or 1 pod serves 2 ports? If can then probably A is correct, else B is correct.</li>
<li>Also base on my question, can anyone tell me whether my understanding of kubernetes is correct or wrong?</li>
</ol>

Charles Brown
<p>From what I understood, you only need 1 stateful app, the other one can be stateless and persist data in the first app. If you are following the microsservices paradigm you should separate your apps in stateless and stateful services.<br>
It's also important to note that unless two containers are tightly coupled they shouldn't be on the same pod. The separations allows a more flexible scalability, as you don't need to have the same number of replicas of both containers.<br>
In conclusion, I would do the following:</p>

<ul>
<li>Create a Deployment containing only the image  of your stateless app.</li>
<li>Create a StatefulSet for the stateful app.</li>
<li>Create 2 services, one for each app.</li>
<li>Create 1 ingress for your stateless app.</li>
</ul>

<p>The ingress will allow routing from request coming from outside the cluster to your app's service. Even if yout statefull app doesn't communicate with the external world, creationg a service for him will allow easier communication between the apps inside the cluster (you can use a fixed IP or <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">even DNS</a>)</p>
