<p>new to GKE and kubernetes just trying to get a simple project up and running. Here's what I'm trying to accomplish in GKE in a single cluster, single node pool, and single namespace:</p>

<p>nginx deployment behind LoadBalancer service accepting Http traffic on port 80 passing it on port 8000 to</p>

<p>front-end deployment (python Django) behind ClusterIP service accepting traffic on port 8000. </p>

<p>The front-end is already successfully communicating with a StatefulSet running Postgres database. The front-end was seen successfully serving Http (gunicorn) before I switched it's service from LoadBalancer to ClusterIP.</p>

<p>I don't know how to properly set up the Nginx configuration to pass traffic to the ClusterIP service for the front-end deployment. What I have is not working.</p>

<p>Any advice/suggestions would be appreciated. Here are the setup files:</p>

<p>nginx - etc/nginx/conf.d/nginx.conf</p>

<pre><code>upstream front-end {
    server front-end:8000;
}

server {

    listen 80;
    client_max_body_size 2M;

    location / {
        proxy_pass http://front-end;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

    location /static/ {
        alias /usr/src/app/static/;
    }

}
</code></pre>

<p>nginx deployment/service</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: "web-nginx"
  labels:
    app: "nginx"
spec:
  type: "LoadBalancer"
  ports:
  - port: 80
    name: "web"
  selector:
    app: "nginx"
---
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "nginx"
  namespace: "default"
  labels:
    app: "nginx"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: "nginx"
  template:
    metadata:
      labels:
        app: "nginx"
    spec:
      containers:
      - name: "my-nginx"
        image: "us.gcr.io/my_repo/my_nginx_image"  # this is nginx:alpine + my staicfiles &amp; nginx.conf
        ports:
        - containerPort: 80
        args:
        - /bin/sh 
        - -c
        - while :; do sleep 6h &amp; wait $${!}; nginx -s reload; done &amp; nginx -g "daemon off;"
</code></pre>

<p>front-end deployment/service</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: "front-end"
  labels:
    app: "front-end"
spec:
  type: "ClusterIP"
  ports:
  - port: 8000
    name: "django"
    targetPort: 8000
  selector:
    app: "front-end"
---
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "front-end"
  namespace: "default"
  labels:
    app: "front-end"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: "front-end"
  template:
    metadata:
      labels:
        app: "front-end"
    spec:
      containers:
      - name: "myApp"
        image: "us.gcr.io/my_repo/myApp"
        ports:
        - containerPort: 8000
        args:
          - /bin/sh 
          - -c
          - python manage.py migrate &amp;&amp; gunicorn smokkr.wsgi:application --bind 0.0.0.0:8000
---
</code></pre>

<p>It would be better to use <code>ingress</code> to forward traffic to service in Kubernetes.</p>

<p>You can find more deocumentation here : <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes" rel="nofollow noreferrer">https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes</a></p>

<p>On Kubernetes official doc : <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/ingress/</a></p>

<p>Simply deploy the nginx controller and apply the nginx rule in backend it deploy8 the nginx and convert YAML rule to nginx conf.</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        backend:
          serviceName: test
          servicePort: 80
</code></pre>
