Search code examples
reactjskubernetesflasktimeout

Trying to deploy React+Flask app to K8s, getting timeout errors


I have an app with a React frontend and Flask backend that I can run successfully both locally and in Docker, and I'm now trying to deploy it to Kubernetes. The Flask part works fine, but when I try to access the React service and it sends requests back to the Flask service, I get an AxiosEror saying "timeout of 300000ms exceeded".

The YAML specs for the React deployment look like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: react-deployment
  labels:
    app: react
spec:
  replicas: 3
  selector:
    matchLabels:
      app: react
  template:
    metadata:
      labels:
        app: react
    spec:
      containers:
      - name: react-app
        image: host.docker.internal:5002/react-app:latest
        env:
        - name: REACT_APP_BACKEND_HOST
          value: http://flask-service.default.svc.cluster.local:5000
        ports:
        - containerPort: 3000
      imagePullSecrets:
      - name: hello-world-cred

Where REACT_APP_BACKEND_HOST is the URL that the React deployment sends requests to.

I've checked the YAML file and I've confirmed that the URL for the requests is the correct one to access the backend from within the K8s cluster. I SSHed into one of the pods for the React deployment and curled the URL to make sure, and it responded normally. I can't figure out why it's not responding when the requests are sent by the React deployment.


Solution

  • The error is resolved. I set up a reverse proxy server using NGINX to route my requests and deployed it to K8s along with the other layers. The app is working as intended now.