Cannot access flask app running on minikube from local

5/1/2021

I created a flask app to run in container.

Dockerfile

FROM python:3.7
LABEL MAINTAINER="Anirban"
RUN mkdir /app
WORKDIR /app
COPY . /app/
RUN pip install -r requirements.txt
RUN python setup.py install
ENV PORT 5000
ENV SERVER_NAME "0.0.0.0:5000"
EXPOSE 5000
CMD [ "python", "userapp/app.py" ]

My application structure

[project] 
    |
    --userapp
    |    |
    |     --app.py
    --Dockerfile

Flask configuration

def initialize_app(flask_app):
    flask_app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL)
    flask_app.register_blueprint(user_endpoints.REQUEST_API)
    flask_app.config['SERVER_NAME'] = os.environ.get('SERVER_NAME', settings.FLASK_SERVER_NAME)


if __name__ == "__main__":
    initialize_app(app)
    app.run(debug=os.environ.get('FLASK_DEBUG', settings.FLASK_DEBUG))

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: userauthapp
  labels:
    app: userauthapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: userauthapp
  template:
    metadata:
      labels:
        app: userauthapp
    spec:
      containers:
        - name: userauthapp
          image: <my image>
          ports:
            - containerPort: 5000
          imagePullPolicy: Always

Loadbalancer

apiVersion: v1
kind: Service
metadata:
  name: userauthapp-lb-svc
spec:
  selector:
    app: userauthapp
  ports:
    - protocol: "TCP"
      port: 8080
      targetPort: 5000
  type: LoadBalancer

When I deploy both of them on minikube, I can see them running as below:

NAME                               READY   STATUS    RESTARTS   AGE
pod/userauthapp-6cc76bd66b-vst5n   1/1     Running   0          38s

NAME                         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/kubernetes           ClusterIP      10.96.0.1        <none>        443/TCP          267d
service/userauthapp-lb-svc   LoadBalancer   10.107.117.254   <pending>     8080:31145/TCP   2s

But I cannot access them with: curl 10.107.117.254:8080/ (which is health check api) or curl 10.107.117.254:8080/swagger. Does any one have an idea what was wrong with it?

-- Anirban B
docker
flask
kubernetes
minikube
python

1 Answer

5/2/2021

I got the issue. As it runs on minikube, it would be minikube IP that I needed to hit. Below command gives the minikube IP:

minikube ip

Below command returns IP and corresponding service port

minikube service --url userauthapp-lb-svc
-- Anirban B
Source: StackOverflow