What I want to achieve is to run the simplest echo server using python
and tornado
, code here:
#!/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("Hello, world")
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
port = 8080
print ("Starting up echo server at port %d" % port)
enable_pretty_logging()
app = make_app()
app.listen(int(port))
tornado.ioloop.IOLoop.current().start()
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 minikube
.
Here are my configuration files, which I use to run kubernetes Deployment
and Service
:
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: ["python3"]
args: ["-u", "echo_tornado.py"]
ports:
- containerPort: 5020
restartPolicy: Always
apiVersion: v1
kind: Service
metadata:
name: testApp-svc
labels:
app: testApp
spec:
type: NodePort
ports:
- port: 5020
targetPort: 5020
nodePort: 5020
selector:
app: testApp
What is problem exactly ? I can sent request to my echo server by curl $NODE_IP:$NODE_PORT
and I'm getting a response, but I also want to be able do curl localhost:$NODE_PORT
and also (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.
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 ServiceType : NodePort
and I should use LoadBalancer
?
Maybe minikube
is a problem and I should use different tool ?