简体   繁体   English

在Google Cloud Platform上不允许使用Django,Kubernetes和负载均衡器的主机

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

I'm just getting started with GCP and Kubernetes Engine. 我刚刚开始使用GCP和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. 到目前为止,我设法启动了Kubernetes集群,在pod中运行我的应用程序,并将其连接到Cloud SQL实例。 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. 我还添加了一个负载平衡器,因此现在我的应用程序具有静态IP,并且应该可以从外部连接到它。

However, I just get a DisallowedHost error? 但是,我刚收到DisallowedHost错误? Which IP should I allow? 我应该允许哪个IP? The IP of the pod that is completely random or the IP of the load balancer? 完全随机的Pod的IP或负载均衡器的IP?

Turns out, it's the IP of the load balancer. 原来,这是负载均衡器的IP。 In the settings.py file I changed the allowed hosts to 在settings.py文件中,我将允许的主机更改为

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: 在部署yaml中,我将负载均衡器IP作为环境变量添加到了我的容器中:

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. 这样,我可以使该应用程序在部署到kubernetes集群和在localhost上自动工作以进行开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM