Reputation: 1
I am running a very basic blogging app using Flask. Its runs fine when I run it using Docker i.e. docker run -it -d -p 5000:5000 app
.
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://10.138.0.96:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 144-234-816
This runs on my localhost:5000 just fine.
But when I deploy this in Minikube, it says
This site can’t be reached 34.105.79.215 refused to connect.
I use this workflow in Kubernetes
$ eval $(minikube docker-env)
$ docker build -t app:latest .
$ kubectl apply -f deployment.yaml (contains deployment & service)
kubectl logs app-7bf8f865cc-gb9fl
returns
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://172.17.0.3:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 713-503-298
Dockerfile
FROM ubuntu:18.04
WORKDIR /app
COPY . /app
RUN apt-get update && apt-get -y upgrade
RUN apt-get -y install python3 && apt-get -y install python3-pip
RUN pip3 install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["app.py"]
deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
app: app
ports:
- protocol: "TCP"
port: 5000
targetPort: 5000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
selector:
matchLabels:
app: app
replicas: 1
template:
metadata:
labels:
app: app
spec:
containers:
- name: app
image: app:latest
imagePullPolicy: Never
ports:
- containerPort: 5000
Also I noticed that on running from Docker container when I do docker ps
I get PORTS as
0.0.0.0:5000->5000/tcp
but the kubernetes ports shows
127.0.0.1:32792->22/tcp, 127.0.0.1:32791->2376/tcp, 127.0.0.1:32790->5000/tcp, 127.0.0.1:32789->8443/tcp, 127.0.0.1:32788->32443/tcp
Upvotes: 0
Views: 184
Reputation: 54267
The port:
on a Service only controls the internal port, the one that's part of the ClusterIP service. By default the node port is randomly assigned from the available range. This is because while the port
value only has to be unique within the Service itself (couldn't have the same port go to two places, would make no sense), node ports are a global resource and have to be globally unique. You can override it via nodePort: whatever
in the Service definition but I wouldn't recommend it.
Minikube includes a helper to manage this for you, run minikube service app-service
and it will load the URL in your browser mapped through the correct node port.
Upvotes: 3