<p>So, this is the setup: </p>

<ul>
<li>each pod will run one container (java application)</li>
<li>each pod provides its own UI</li>
<li>for each java app there is a mysql DB which it needs to access</li>
<li>for each java app its necessary to retrieve and provide information using rest calls</li>
</ul>

<p>It is some kind of the classic containerized microservice architecture.</p>

<p><strong>The requirement is to enable the applications to request and provide information for other application running on different pods.</strong> But as I need to set these calls up before I push them to the cluster I have, to be honest, no idea how it should work.</p>

<p>E.g. I got an application which is using another rest interface to request data:</p>

<pre><code>public List&lt;Article&gt; getArticles() {
        String url = http://ip:port/article/getAllArticles/;
        HttpEntity entity = prepareHttpEntity();
        ResponseEntity&lt;List&gt; response = restTemplate.exchange(url, HttpMethod.GET, entity, List.class);
        return response.getBody();
    }
</code></pre>

<p><strong>How I can make sure to it is connecting to the right service (pod)?</strong></p>

<p>Same for the DB setup. I need to tell the application the <code>datasource</code>, which is unknown yet. </p>

<p><strong>Is there some kind of best practice to deal with these issues?</strong></p>

elp
<p>Each <strong>Pod</strong> when created will have its own cluster-private IP, but you never depend on it, as pods are <em>ephemeral</em>. If you want to talk to a <strong>Pod</strong>, you create a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer"><strong><em>Service</em></strong></a> that routes traffic to the pod.</p>

<pre><code>restCall --&gt; Service --&gt; Pod
</code></pre>

<p>Let's say you have the following Pod definition</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: appAPod
  labels:
    app: appA
spec:
  containers:
  - name: aNameForApp1Container
    image: yourRepository/imageName:tag
    ports:
    - containerPort: 8080
  ...
</code></pre>

<p>Then, you make it accessible by creating a Service Definition:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: serviceA
spec:
  selector:
    app: appA
  ports:
  - name: serviceAPort
    protocol: TCP
    port: 80
    targetPort: 8080 
</code></pre>

<p>So the way you connect a <strong>Pod</strong> and a <strong>Service</strong> is via <em>labels</em> and <em>selector</em>. Now, you can hit your pod with the following url :</p>

<pre><code>http://serviceA:80
</code></pre>

<p>In your second app, you will have the following Pod Definition:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: appBPod
  labels:
    app: appB
spec:
  containers:
  - name: aNameForApp2Container
    image: yourRepository/imageName2:tag
    ports:
    - containerPort: 8080
    env:
    - name: "APP_A_ADDRESS"
      value: serviceA
    - name: "APP_A_PORT"
      value: 80
</code></pre>

<p>Since you're using RestTemplate, I assume you are using Spring. So in your application.properties :</p>

<pre><code>..
..
appA.baseUrl=http://${APP_A_ADDRESS}:${APP_A_PORT}
</code></pre>

<p>And in your code:</p>

<pre><code>@Value("${appA.baseUrl}")
String appABaseUrl;

public List&lt;Article&gt; getArticles() {
        String url = appABaseUrl + "/article/getAllArticles/";
        HttpEntity entity = prepareHttpEntity();
        ResponseEntity&lt;List&gt; response = restTemplate.exchange(url, HttpMethod.GET, entity, List.class);
        return response.getBody();
}
</code></pre>

<hr>

<p>You should consider <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deplyments</a>, instead of a Pod, as it offers you more flexibility and control over your containers.</p>

<p>If you are going to containerize your DB, then you might want to check out <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">Persistent Volume</a> </p>
