繁体   English   中英

Kubernetes nginx HTTPS 在 AWS 中的基于入口路径的路由

[英]Kubernetes nginx ingress path-based routing of HTTPS in AWS

Question: Within Kubernetes, how do I configure the nginx ingress to treat traffic from an elastic load balancer as HTTPS, when it is defined as TCP?


我正在 AWS 环境中使用 Kubernetes 集群。 我想使用 nginx 入口对 HTTPS 流量进行基于路径的路由; 但是,我不想在 AWS 弹性负载均衡器上执行 SSL 终止或重新加密。

所需的设置是:

客户端 -> 弹性负载均衡器 -> nginx 入口 -> pod

要求:
1. 流量是端到端加密的。
2. 必须使用AWS ELB(外部流量不能go直接进入Kubernetes)。

我遇到的问题是,要在 ELB 上进行 SSL 直通,我必须将 ELB 配置为 TCP 流量。 但是,当 ELB 定义为 TCP 时,所有流量都会绕过 nginx。

据我所知,我可以通过 ConfigMap 设置 TCP 直通,但这只是另一个直通; 它不允许我在 nginx 中进行基于路径的路由。

我正在寻找一种方法将 ELB 定义为 TCP(用于直通),同时仍然让入口将流量视为 HTTPS。

我可以将 ELB 定义为 HTTPS,但是在此过程中还有第二个不必要的协商/中断/重新加密步骤,我希望尽可能避免。

为了更清楚,我将从OSI model开始,它告诉我们TCP是 4 级协议, HTTP/HTTPS 是 7 级协议。 因此,坦率地说, HTTP/HTTP数据在进行 rest 级别封装以将数据包传输到另一个网络设备之前,被封装TCP数据。

如果您设置Classic (TCP) LoadBalancer ,它会在读取 TCP 部分后停止读取数据包数据,这足以决定(根据 LB 配置)该数据包应该发送到哪个IP address和哪个IP port 之后,LB 获取 TCP 有效负载数据,并用另一个 TCP 层数据将其包装起来,并将其发送到目标点(这反过来又会导致应用所有其他 OSI 层)。

为了使您的配置按预期工作,需要使用NodePort 服务公开nginx-ingress-controller Pod。 然后可以将经典 ELB 配置为将流量传送到任何集群节点到为该 NodePort 服务选择的端口。 通常它在3000032767之间。 Sou 你的 LB 池将如下所示:

假设集群节点有 IP 地址10.132.10.1...10和 NodePort 端口是30276

ELB Endpoint 1:  10.132.10.1:30276
ELB Endpoint 2:  10.132.10.2:30276
...
ELB Endpoint 10: 10.132.10.10:30276

注意:对于 AWS ELB,我猜应该使用节点 DNS 名称而不是 IP 地址。

因此它应该导致从客户端到 Kubernetes 应用程序 Pod 的流量分配顺序如下:

  1. 客户端将带有 HTTP/HTTPS 请求的 TCP 数据包发送到ELB_IP:ELB_port ( abc.d:80 )。
  2. ELB receives IP packet, analyze its TCP data, finds the appropriate endpoint from backend pool (whole list of Kubernetes cluster nodes), and creates another TCP packet with the same HTTP/HTTPS data inside, and also replaces destination IP and destination TCP port to集群节点 IPService NodePort TCP端口( lmnk:30xxx ),然后将其发送到选定的目的地。
  3. Kubernetes node receives TCP packet and using the iptables rules changes the destination IP and destination port of the TCP packet again, and forward the packet (according to the Nodeport Service configuration) to destination pod. 在这种情况下,它将是 nginx-ingress-controller pod。
  4. Nginx-ingress-controller pod receives the TCP packet, and because according to TCP data it have to be delivered locally, extracts HTTP/HTTP data out of it and send the data (HTTP/HTTPS request) to Nginx process inside the Nginx container in豆荚,
  5. 容器中的 Nginx 进程接收到 HTTP/HTTPS 请求,解密它(如果是 HTTPS)并分析所有 HTTP 标头。
  6. According to nginx.conf settings, Nginx process change HTTP request and deliver it to the cluster service, specified for the configured host and URL path.
  7. Nginx 进程将更改的 HTTP 请求发送到后端应用程序。
  8. 然后将 TCP header 添加到 HTTP 请求中,并将其发送到后端服务IP_address:TCP_port
  9. 为后端服务定义的 iptables 规则,将数据包传递到服务端点之一(应用程序 Pod)。

Note : To terminate SSL on ingress controller you have to create SSL certificates that includes ELB IP and ELB FQDN in the SAN section.

Note : If you want to terminate SSL on the application Pod to have end to end SSL encryption, you may want to configure nginx to bypass SSL traffic.

底线:配置为将 TCP 流量传送到 Kubernetes 集群的 ELB 与 nginx-ingress controller 完美配合,如果您以正确的方式配置它。

在 GKE(Google Kubernetes 引擎)中,如果您创建一个类型为:LoadBalancer 的服务,它会准确地为您创建 TCP LB,它将流量转发到服务 NodePort,然后 Z30136395F01879792198317C118 负责将它传递到 Pod。 AWS 的 EKS(弹性 Kubernetes 服务)的工作方式非常相似。

暂无
暂无

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

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