Kubernetes build django + uwsgi + nginx show failed (111: Connection refused) while connecting to upstream

9/1/2019

when I create my.yaml, then nginx will show failed (111: Connection refused) while connecting to upstream

have any sugesstion about this? Is there pod network do not connnect?

uwsgi:

[uwsgi]
module          = myapp.wsgi
master          = true
processes       = 10
socket          = 127.0.0.1:8001
chmod-socket = 777
vacuum          = true
enable-threads = True

nginx:

upstream django_api {
server 127.0.0.1:8001 max_fails=20 fail_timeout=10s;
}
server {
    listen 80;

    #location /media  {
    #    alias /media;  # your Django project's media files - amend as required
    #}
    location /static {
    alias /usr/share/apps/static; # your Django project's static files - amend as required
    }
    location / {
    uwsgi_read_timeout 60;
    uwsgi_pass  django_api;
    include     ./uwsgi_params; # the uwsgi_params file you installed
    uwsgi_param Host $host;
    uwsgi_param X-Real-IP $remote_addr;
    uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
    uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
    }

}

-- Frank Liao
django
kubernetes
nginx
uwsgi

1 Answer

9/5/2019

So just a thought, maybe set your uwsgi to 0.0.0.0:8001 then on your podSpec set container port values with just 8001:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
  labels:
    component: web
spec:
  containers: 
    - name: django
      image: myimage
      ports:
        - containerPort: 8001
    - name: nginx
      image: nginx:alpine
      ....

this should make it available in localhost:8001/127.0.0.1:8001

-- Spazzy757
Source: StackOverflow