<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>

konkrer
<p>Kubernetes ingress is the way to go about this. GKE uses Google cloud load balancer behind the scenes to provision your Kubernetes ingress resource; so when you create an Ingress object, the GKE ingress controller creates a Google Cloud HTTP(S) load balancer and configures it according to the information in the Ingress and its associated Services.</p>

<p>This way you get access to some custom resource types from Google like <code>ManagedCertificates</code> and <code>staticIP</code> addresses, which could be associated with the ingress in kubernetes to achieve loadbalancing between services or between clients and services. </p>

<p>Follow the documentation here to understand how to setup HTTP(s) load balancing with GKE using K8s ingress - <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/concepts/ingress</a></p>

<p>This tutorial is really helpful too - </p>

<p><a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer</a></p>
