<p>I need help to figure out how to port a current-working VM-based solution to a container-based solution using Kubernetes.</p>

<p><strong>Scenario</strong></p>

<p>An application is made of two components (lets'call them master and slave). A master instance is always up, while 0 or more slaves can be running.</p>

<p><strong>Current flow is:</strong></p>

<ol>
<li>master is assumed up</li>
<li>one (or more) slaves start-up</li>
<li>slave sends a HELLOWORLD message to <a href="https://MASTER_IP:9090">https://MASTER_IP:9090</a>, with some specs like own CPU and RAM</li>
<li>slave start listening on port 8080</li>
<li>master infers slave's IP from TCP headers (step 3)</li>
<li>master fills a running-slaves table with information found during steps 3 and 5</li>
<li>when a new job is available, master sends it to <a href="https://A_SPECIFIC_SLAVE_IP:8080">https://A_SPECIFIC_SLAVE_IP:8080</a></li>
<li>slave does its job</li>
<li>slave sends output to <a href="https://MASTER_IP:9090">https://MASTER_IP:9090</a></li>
</ol>

<p><strong>Notes and requirements:</strong></p>

<p>A. during steps 3 and 9 slave acts as client and master acts as server    (I mean slave begins the comunication, while master is listening)</p>

<p>B. during step 3 slave doesn't need to discover master's IP, it's a configuration setting.</p>

<p>C. during step 7 slave acts as server and master acts as client (opposite to A)</p>

<p>D. slaves never sends their own IP explicitly to the master (steps 3 and 5)</p>

<p>E. slaves will be containerized but not the master</p>

<p>F. Master lives on the same local network where k8s-nodes live, but master is out of kubernetes' control. It should be seen as an external service/api to connect to.</p>

<p>Using a POD for each slave, I can get an IP for each slave, but as far as I can see, this IP is part of k8s' internal network:</p>

<p>X. how to let the master deduce POD's IP? (step 3-4)</p>

<p>Y. how to reach a specific POD from the outside? (step 7)</p>

<p>I'm looking into ingress now, but I feel something is still missing.</p>

<p>Thank you.</p>

<p>Does it matter what job goes to what slave?
Because in Kubernetes, you would have a load balancer (like an nginx instance) as your proxy from the outside, and then you need to use a Kubernetes Service targeting the slave Pods.</p>

<p>The point of Kubernetes is not to worry about where the Pods live, just to be able to reach one of them when needed, which is what a Service does: it looks at Pod with a specific label (or set of labels) and proxies traffic to one of them in a round robin or client-IP based fashion.</p>

<p>There are some ways you could reach specific Pods: </p>

<ul>
<li><p>use a Service per slave Pod: then your nginx proxy can forward traffic to (a) specific Pod, wherever it is in the cluster. Obviously this is not very convenient to automate.</p></li>
<li><p>use StatefulSets (formerly PetSets) behind an Ingress: with StatefulSet you can get access a Pod by name+index, and with Ingress you can specify a parametric URL to proxy your traffic.</p></li>
<li><p>maybe the easiest: use a VPN into the cluster: then you can access each Pod by their FQDN (usually servicename.svc.namespace.cluster.local) </p></li>
</ul>
