1
votes

Backend: python (Django) Frontend: angular6

I just deployed my backend and frontend on same cluster in Google Kubernetes. They are two individual services inside same cluster. The pods on the clusters look like:

NAME                               READY     STATUS    RESTARTS   AGE
backend-f4f5df588-nbc9p     1/1       Running   0          1h
frontend-85885799d9-92z5f   1/1       Running   0          1h

And the service looks like:

NAME              TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)          AGE
backend    LoadBalancer   10.3.249.148   35.232.61.116    8000:32291/TCP   26m
frontend   LoadBalancer   10.3.248.72    35.224.112.111   8081:31444/TCP   3m
kubernetes        ClusterIP      10.3.240.1     <none>           443/TCP          1h

My backend just works on the django server, starting by using python manage.py runserver command, everything works fine. I built the frontend and deployed on Nginx server. So there're two Docker images, one for django, one for nginx, as two pods in cluster.

Then there're two ingress for both of them. Exposing 80 port for frontend and 8000 for backend. Holding on the load balancer nginx controller. After assigning a domain, I can visit https://abc/project as front end. But when I want to make API requests, ERR 502 appears. The error message in nginx is:

38590 connect() failed (111: Connection refused) while connecting to upstream, client: 163.185.148.245, server: _, request: "GET /project/api HTTP/1.1", upstream: "http://10.0.0.30:8000/dataproject/api", host: "abc" 

The upstream in error message is the correct IP for the backend service, but still gets a 502 error. I can curl from nginx server to frontend. But cannot cur to backend. Any help? PS. Everything works fine before deployment.

1
Can you curl -v http://backend:8000 from the frontend pod?mdaniel
My supervisor asked me to reconstruct the project. I used ingress for both front and back end. Built nginx controller and had a domain for the front end. Now the front end still works good but connecting to backend also get 502, I dont know whether its the same cause. If I use port forward, then I can get 200 from my backend at localhost.Dilemma

1 Answers

0
votes

Fixed. Django runserver cmd use 0.0.0.0 so it wont prevent from outside connections:

python runserver 0.0.0.0:8000