<p>I'm a super beginner with Kubernetes and I'm trying to imagine how to split my monolithic application in different micro services.
Let's say i'm writing my micro services application in Flask and each of them exposes some endpoints like:</p>

<p>Micro service 1:</p>

<ul>
<li>/v1/user-accounts</li>
</ul>

<p>Micro service 2:</p>

<ul>
<li>/v1/savings</li>
</ul>

<p>Micro service 3:</p>

<ul>
<li>/v1/auth</li>
</ul>

<p>If all of them were running as blueprints in a monolithic application all of them would be prefixed with the same IP, that is the IP of the host server my application is running on, like 10.12.234.69, eg. </p>

<ul>
<li><a href="http://10.12.234.69:5000/v1/user-accounts" rel="nofollow noreferrer">http://10.12.234.69:5000/v1/user-accounts</a></li>
</ul>

<p>Now, deploying those 3 "blueprints" on 3 different POD/Nodes in Kubernetes will change the IP address of each endpoint having maybe 10.12.234.69, than 10.12.234.70 or 10.12.234.75</p>

<p>How can i write an application that keep the URL reference constant even if the IP address changes?</p>

<ul>
<li>Would a Load Balancer Service do the trick?</li>
<li>Maybe the Service Registry feature of Kubernetes does the "DNS" part for me?</li>
</ul>

<p>I know It can sounds very obvious question but still I cannot find any reference/example to this simple problem.</p>

<p>Thanks in advance!</p>

<p><strong>EDIT:</strong> (as follow up to simon answer)</p>

<p>questions: </p>

<ul>
<li><p>given the fact that the Ingress service spawns a load balancer and is possible to have all the routes reachable from the http/path prefixed by the IP (<code>http://&lt;ADDRESS&gt;/v1/savings</code>) of the load balancer, how can I associate IP to the load balancer to match the ip of the pod on which flask web server is running?</p></li>
<li><p>in case I add other sub routes to the same paths, like <code>/v1/savings/get</code> and <code>/v1/savings/get/id/&lt;var_id&gt;</code> , should i update all of them in the ingress http path in order for them to be reachable by the load balancer ? </p></li>
</ul>

<ol>
<li>A load balancer is what you are looking for.</li>
<li>Kubernetes services will make your pods accessible under a given hostname cluster-internally.</li>
</ol>

<p>If you want to make your services accessible from outside the cluster under a single IP and different paths, you can use a load balancer and Kubernetes HTTP <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingresses</a>. They define under which domain and path a service should be mapped and can be fetched by a load balancer to build its configuration. </p>

<p>Example based on your micro service architecture: </p>

<h2>Mocking applications</h2>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: user-accounts
spec:
  template:
    metadata:
      labels:
        app: user-accounts
    spec:
      containers:
      - name: server
        image: nginx
        ports:
        - containerPort: 80
        args: 
        - /bin/bash
        - "-c" 
        - echo 'server { location /v1/user-accounts { return 200 "user-accounts"; }}' &gt; /etc/nginx/conf.d/default.conf &amp;&amp; nginx -g 'daemon off;'
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: savings
spec:
  template:
    metadata:
      labels:
        app: savings
    spec:
      containers:
      - name: server
        image: nginx
        ports:
        - containerPort: 80
        command: 
        - /bin/bash 
        - "-c" 
        - echo 'server { location /v1/savings { return 200 "savings"; }}' &gt; /etc/nginx/conf.d/default.conf &amp;&amp; nginx -g 'daemon off;'
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: auth
spec:
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
      - name: server
        image: nginx
        ports:
        - containerPort: 80
        command: 
        - /bin/bash 
        - "-c" 
        - echo 'server { location /v1/auth { return 200 "auth"; }}' &gt; /etc/nginx/conf.d/default.conf &amp;&amp; nginx -g 'daemon off;'
</code></pre>

<p>These deployments represent your services and just return their name via HTTP under <code>/v1/name</code>. </p>

<h2>Mapping applications to services</h2>

<pre><code>---
kind: Service
apiVersion: v1
metadata:
  name: user-accounts
spec:
  type: NodePort
  selector:
    app: user-accounts
  ports:
  - protocol: TCP
    port: 80
---
kind: Service
apiVersion: v1
metadata:
  name: savings
spec:
  type: NodePort
  selector:
    app: savings
  ports:
  - protocol: TCP
    port: 80
---
kind: Service
apiVersion: v1
metadata:
  name: auth
spec:
  type: NodePort
  selector:
    app: auth
  ports:
  - protocol: TCP
    port: 80
</code></pre>

<p>These services create an internal IP and a domain resolving to it based on their names, mapping them to the pods found by a given selector. Applications running in the same cluster namespace will be able to reach them under <code>user-accounts</code>, <code>savings</code> and <code>auth</code>.  </p>

<h2>Making services reachable via load balancer</h2>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example
spec:
  rules:
  - http:
      paths:
      - path: /v1/user-accounts
        backend:
          serviceName: user-accounts
          servicePort: 80
      - path: /v1/savings
        backend:
          serviceName: savings
          servicePort: 80
      - path: /v1/auth
        backend:
          serviceName: auth
          servicePort: 80
</code></pre>

<p>This Ingress defines under which paths the different services should be reachable. Verify your Ingress via <code>kubectl get ingress</code>:</p>

<pre><code># kubectl get ingress
NAME      HOSTS     ADDRESS   PORTS     AGE
example   *                   80        1m
</code></pre>

<p>If you are running on Google Container Engine, there is an <a href="https://cloud.google.com/container-engine/docs/tutorials/http-balancer#step_3_create_an_ingress_resource" rel="nofollow noreferrer">Ingress controller running in your cluster</a> which will spawn a Google Cloud Load Balancer when you create a new Ingress object. Under the <code>ADDRESS</code>      column of the above output, there will be an IP displayed under which you can access your applications:</p>

<pre><code># curl http://&lt;ADDRESS&gt;/v1/user-accounts
user-accounts⏎
# curl http://&lt;ADDRESS&gt;/v1/savings
savings⏎
# curl http://&lt;ADDRESS&gt;/v1/auth
auth⏎
</code></pre>
