Disallowed host with Django, Kubernetes and a Load Balancer on Google Cloud Platform

5/11/2018

I'm just getting started with GCP and Kubernetes Engine. So far I managed to start a Kubernetes cluster, run my app in a pod and connect it to a Cloud SQL instance. I also added a load balancer so now my app has a static IP and I should be able to connect to it from the outside.

However, I just get a DisallowedHost error? Which IP should I allow? The IP of the pod that is completely random or the IP of the load balancer?

-- tarikki
django
google-cloud-platform
google-kubernetes-engine
kubernetes

1 Answer

5/11/2018

Turns out, it's the IP of the load balancer. In the settings.py file I changed the allowed hosts to

ALLOWED_HOSTS = [os.environ.get('LOAD_BALANCER_IP', '127.0.0.1')]

and in my deployment yaml I added the load balancer IP as an evironment variable to my container:

spec:
  containers:
    - env:
      - name: LOAD_BALANCER_IP
        value: xx.xx.xx.xx

This way I can have the app work automatically both on deploy to the kubernetes cluster and on localhost for development.

-- tarikki
Source: StackOverflow