Kubernetes Django Disallowed Hosts

5/14/2018

I'm trying to deploy a Django app via Kubernetes. After creating my pod definition, LoadBalancer service, and routing DNS traffic to my LoadBalancer, I'm getting a Disallowed Hosts error.

I think I need to add the name of the LoadBalancer to my allowed hosts, but how do I do that when the LoadBalancer is created when I run kubectl create -f service.yaml?

pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test.example.com
  labels:
    app: my-pod
spec:
  containers:
  - name: my-container
    image: my-image:1.0
    ports:
    - name: my-port
      containerPort: 8000 

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mgmt-service
spec:
  ports:
  - port: 80
    targetPort: mgmt-port
    protocol: TCP
  selector:
    app: mgmt_reporting
  type: LoadBalancer
-- Sebastian
amazon-web-services
django
kubernetes

1 Answer

5/14/2018

So I needed to put the DNS name that I was routing traffic from into allowed hosts. The name of the LoadBalancer does not matter.

The DNS name is whatever you pointed at your load balancer. In my case, I created the DNS name app.kubernetes.mydomain.com Route53. This needs to go into allowed hosts

-- Sebastian
Source: StackOverflow