<p>What I want to achieve is to run the simplest echo server using <code>python</code> and <code>tornado</code>, code here:</p>
<pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python3
import tornado.ioloop
import tornado.web
from tornado.log import enable_pretty_logging

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(&quot;Hello, world&quot;)

def make_app():
    return tornado.web.Application([
        (r&quot;/&quot;, MainHandler),
    ])

if __name__ == &quot;__main__&quot;:
    port = 8080
    print (&quot;Starting up echo server at port %d&quot; % port)
    enable_pretty_logging()
    app = make_app()
    app.listen(int(port))
    
    tornado.ioloop.IOLoop.current().start()
</code></pre>
<p>I want to run it inside docker that is running inside kubernetes's Pod.
I already achieved it but only partly. I'm running kubernetes cluster on physical machine, which is in my local network. To run cluster I used <code>minikube</code>.
Here are my configuration files, which I use to run kubernetes <code>Deployment</code> and <code>Service</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: testApp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testApp
  template:
    metadata:
      labels:
        app: testApp
    spec:
      containers:
      - name: testApp-container
        image: testApp-docker:latest
        imagePullPolicy: Never
        command: [&quot;python3&quot;]
        args: [&quot;-u&quot;, &quot;echo_tornado.py&quot;]

        ports:
        - containerPort: 5020
      restartPolicy: Always
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: testApp-svc
  labels:
    app: testApp
spec:
  type: NodePort
  ports:
  - port: 5020
    targetPort: 5020
    nodePort: 5020
  selector:
    app: testApp
</code></pre>
<p>What is problem exactly ? I can sent request to my echo server by <code>curl $NODE_IP:$NODE_PORT</code> and I'm getting a response, but I also want to be able do <code>curl localhost:$NODE_PORT</code> and also (what is crucial for me) I must be able to do <code>curl $MY_LOCAL_MACHINE_IP:$NODE_PORT</code> from other machine inside same local network.</p>
<p>Is it possible to achieve it ? Should I use some kind of forwarding my local IP and port to node's ip ?
Maybe I shouldn't use <code>ServiceType : NodePort</code> and I should use <code>LoadBalancer</code> ?
Maybe <code>minikube</code> is a problem and I should use different tool ?</p>

AnDevi
<p><a href="https://minikube.sigs.k8s.io/docs/start/" rel="nofollow noreferrer">Minikube</a> is a tool that spawn your single node Kubernetes cluster for development purposes on your machine (PC, Laptop, Server, etc.).</p>
<p>It uses different <code>--drivers</code> to run Kubernetes (it can be deployed as <code>bare-metal</code>, in <code>docker</code>, in <code>virtualbox</code>, in <code>kvm</code>, etc.). This allows for isolation from host and other devices. <strong>It also means that there are differences when it comes to the networking part of this setup.</strong></p>
<p>There is a lot to cover when it comes to the networking part of Kubernetes. I encourage you to check the official docs:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Services networking: Service</a></em></li>
</ul>
<hr />
<p>As the <code>driver</code> used and the <code>OS</code> is unknown it could be hard to pinpoint the exact solution. <strong>Some</strong> of the pointers that could help you:</p>
<ul>
<li>When you are using Linux distribution you can opt to use driver <code>--none</code>. It will use <code>Docker</code> but everything (containers like <code>kubeapi-server</code>, <code>etcd</code>, etc.) will be provisioned directly on your host. By that you could run: <code>$ curl $MY_LOCAL_MACHINE_IP:$NODE_PORT</code>). With <code>--driver=docker</code> everything I mentioned will be put in a <code>Docker</code> container.</li>
</ul>
<blockquote>
<p>A side note!</p>
<p><code>--driver=none</code> have some limitations/issues (for example decreased security). You can read more about it by following this documentation:</p>
<ul>
<li><em><a href="https://minikube.sigs.k8s.io/docs/drivers/none/" rel="nofollow noreferrer">Minikube.sigs.k8s.io: Docs: Drivers: None</a></em></li>
</ul>
</blockquote>
<ul>
<li><p>As a workaround/<strong>temporary solution</strong> you can use previously mentioned (run on your host):</p>
<ul>
<li><code>$ kubectl port-forward svc/testApp-svc 5020:5020 --address 0.0.0.0</code> - this command will forward requests coming to your machine on port <code>5020</code> directly to the <code>Service: testApp-svc</code> on port <code>5020</code>.</li>
</ul>
</li>
<li><p>With other driver like for example <code>Virtualbox</code> you will need to reach the documentation of it for ability to expose your <code>minikube</code> instance on the LAN.</p>
</li>
</ul>
<hr />
<p>Seeing this part of the question:</p>
<blockquote>
<p>(what is crucial for me) I must be able to do curl $MY_LOCAL_MACHINE_IP:$NODE_PORT from other machine inside same local network.</p>
</blockquote>
<p>It could beneficiary to add that there are other solution outside of <code>minikube</code> that could provision your Kubernetes cluster. There are some differences between them and you would need to chose the one that suits your requirements the most. <strong>Some</strong> of them are:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/" rel="nofollow noreferrer">Kubeadm</a></em></li>
<li><em><a href="https://github.com/kubernetes-sigs/kubespray" rel="nofollow noreferrer">Kubespray</a></em></li>
<li><em><a href="https://microk8s.io/" rel="nofollow noreferrer">MicroK8S</a></em></li>
<li><em><a href="https://rancher.com/docs/k3s/latest/en/installation/install-options/" rel="nofollow noreferrer">K3S</a></em></li>
<li><em><a href="https://github.com/kelseyhightower/kubernetes-the-hard-way" rel="nofollow noreferrer">Kubernetes: The hard way</a></em></li>
</ul>
<blockquote>
<p>A side note!</p>
<p>For assigning the <code>IP addresses</code> for a <code>LoadBalancer</code> type of <code>Service</code> you could look on <a href="https://metallb.universe.tf/" rel="nofollow noreferrer">metallb</a> (when using above options).</p>
</blockquote>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://stackoverflow.com/questions/65872990/how-to-route-traffic-from-pysical-servers-port-to-minikube-cluster">Stackoverflow.com: Questions: How to route traffic from physical servers port to minikube cluster</a></em></li>
<li><em><a href="https://kubernetes.io/docs/home/" rel="nofollow noreferrer">Kubernetes: Docs</a></em></li>
</ul>
