2021年4月30日星期五

Cannot access flask app running on minikube from local

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?

https://stackoverflow.com/questions/67342293/cannot-access-flask-app-running-on-minikube-from-local May 01, 2021 at 10:02AM

没有评论:

发表评论