简体   繁体   English

在Kubernetes入口之前的Nginx反向代理

[英]Nginx reverse proxy in front of a Kubernetes Ingress

We're running a 6-node bare-metal K8s cluster (3-nodes control and 3-nodes compute plane). 我们正在运行一个6节点的裸机K8s集群(3节点的控制和3节点的计算平面)。 The ingress is deployed and it's working well for path-based routes. 入口已部署,并且对于基于路径的路由运行良好。 Recently we've built a HA-loadbalancing cluster in front of the Ingress in order to achieve high-availability of the Ingress itself. 最近,我们在Ingress之前建立了HA负载均衡集群,以实现Ingress本身的高可用性。

+---------------+       +---------+      +---------+
| Loadbalancers |  -->  | Ingress |  --> | Jenkins |
+---------------+       +---------+      +---------+

The loadbalancers basically run nginx in reverse proxy mode with floating IP address that has a DNS A-type record with wildcard: 负载平衡器基本上以反向代理模式运行nginx,其浮动IP地址具有带通配符的DNS A类型记录:

*.cnk8sv.infra A <private-IP>

However in this setup we are unable to apply virtual-host-based routing. 但是,在此设置中,我们无法应用基于虚拟主机的路由。 In such a mode the Ingress rules don't catch any traffic. 在这种模式下,Ingress规则不会捕获任何流量。 I have a suspicion that the nginx in front of the K8s is dropping some information in the HTTP headers and hence the Ingress controllers are unable to do the host-based routing. 我怀疑K8前面的nginx正在HTTP头中丢弃一些信息,因此Ingress控制器无法执行基于主机的路由。

This is the configuration of the nginx loadbalancers: 这是nginx负载均衡器的配置:

   location / {
      proxy_pass https://backend;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Proto https;
      proxy_redirect off;
   }

The Ingress object: Ingress对象:

spec:
  rules:
  - host: jenkins.cnk8sv.infra
    http:
      paths:
      - backend:
          serviceName: jenkins
          servicePort: 8080
        path: /

As soon as we remove the host filter in the rule the traffic stars flowing (so yes, the backend is up and running). 在规则中删除主机过滤器后,流量便开始流动(因此,后端已启动并正在运行)。 Any help would be greatly appreciated. 任何帮助将不胜感激。

解决方法是在nginx配置中将X-Forwarded-Proto值更改为http ,因为我们将Ingress定位在端口80(即HTTP)上。

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

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