I set up a local kubernetes cluster with minikube. On my cluster I have only one deployment runnning and one service attached to it. I used a NodePort on port 30100 to expose the service, so I can access it from my browser or via curl.
here is the python-server.yml
file I use to setup the cluster:
apiVersion: apps/v1
kind: Deployment
metadata:
name: python-server-deployment
namespace: kubernetes-hello-world
labels:
app: python-server
spec:
replicas: 1
selector:
matchLabels:
app: python-server
template:
metadata:
labels:
app: python-server
spec:
containers:
- name: python-hello-world
image: hello-world-python:latest
imagePullPolicy: Never
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: python-server-internal-service
namespace: kubernetes-hello-world
spec:
type: NodePort
selector:
app: python-server
ports:
- protocol: TCP
port: 80
targetPort: 5000
nodePort: 30100
my python-hello-world
image is based on this python file:
from http.server import BaseHTTPRequestHandler, HTTPServer
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
html = """
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<meta charset="utf-8">
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
"""
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(html, "utf-8"))
def run():
addr = ('', 5000)
httpd = HTTPServer(addr, MyServer)
httpd.serve_forever()
if __name__ == '__main__':
run()
When I run the cluster I can as expected receive the hello world html with curl {node_ip}:30100
. But when I try to access my service via my browser with the same ip:port I get a time out.
I read that that can be caused by missing headers but I think I have all necessary ones covered in my python file, so what else could cause this?