[英]Nginx ingress : Host based routing on TCP port
Usage the same TCP port for Rabbitmq 5672 and transfer requests to different namespaces/rabbitmq_service based on the host-based routing.为 Rabbitmq 5672 使用相同的 TCP 端口,并根据基于主机的路由将请求传输到不同的命名空间/rabbitmq_service。
What works:什么工作:
chart: nginx-git/ingress-nginx
version: 3.32.0
values:
- tcp:
5672: "cust1namespace/rabbitmq:5672"
Block reflected in nginx.conf :反映在 nginx.conf 中的块:
server {
preread_by_lua_block {
ngx.var.proxy_upstream_name="tcp-cust1namespace-services-rabbitmq-5672";
}
listen :5672;
proxy_pass upstream_balancer;
}
Note: this will transfer all the requests coming to port 5672 to cust1namespace/rabbitmq:5672, irrespective of the client domain name and we want host-based routing based on domain name注意:这会将所有到达端口 5672 的请求传输到 cust1namespace/rabbitmq:5672,而不管客户端域名如何,我们希望基于域名的基于主机的路由
What is expected :什么是预期:
chart: nginx-git/ingress-nginx
version: 3.32.0
values:
- tcp:
cust1domainname:5672: "cust1namespace/rabbitmq:5672"
cust2domainname:5672: "cust2namespace/rabbitmq:5672"
Error: Failed to render chart: exit status 1: Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: [ValidationError(Service.spec.ports[3].port): invalid type for io.k8s.api.core.v1.ServicePort.port: got "string", expected "integer", ValidationError(Service.spec.ports[4].port): invalid type for io.k8s.api.core.v1.ServicePort.port: got "string", expected "integer"]错误:无法呈现图表:退出状态 1:错误:无法从发布清单构建 kubernetes 对象:错误验证“”:错误验证数据:[ValidationError(Service.spec.ports[3].port):io 类型无效.k8s.api.core.v1.ServicePort.port:得到“字符串”,预期为“整数”,ValidationError(Service.spec.ports[4].port):io.k8s.api.core.v1 的无效类型。 ServicePort.port:得到“字符串”,应为“整数”]
The final nginx.conf should look like :最终的 nginx.conf 应如下所示:
server {
preread_by_lua_block {
ngx.var.proxy_upstream_name="tcp-cust1namespace-services-rabbitmq-5672";
}
listen cust1domainname:5672;
proxy_pass upstream_balancer;
}
server {
preread_by_lua_block {
ngx.var.proxy_upstream_name="tcp-cust2namespace-services-rabbitmq-5672";
}
listen cust2domainname:5672;
proxy_pass upstream_balancer;
}
Approach you're trying to implement is not possible due to network protocols implementation and difference between them.由于网络协议的实现和它们之间的差异,您尝试实现的方法是不可能的。
TCP
protocol works on transport layer, it has source and destination IPs and ports, it does not have any hosts information within. TCP
协议的工作原理传输层上,它的源和目的IP地址和端口,它没有任何内部主机的信息。 In turn HTTP
protocol works on application layer which seats on top of the TCP
and it does have information about host where this request is intended to be sent.反过来,
HTTP
协议在位于TCP
顶部的应用层上工作,并且它确实具有有关要发送此请求的主机的信息。
Please get familiar with OSI model and protocols which works on these levels .请熟悉适用于这些级别的 OSI 模型和协议。 This will help to avoid any confusion why this works this way and no other.
这将有助于避免任何混淆为什么以这种方式工作而不是其他方式。
Also there's a good answer on quora about difference between HTTP and TCP protocols . 在 quora 上也有一个关于 HTTP 和 TCP 协议之间差异的很好的答案。
At this point you have two options:此时你有两个选择:
request body
.request body
中呈现的主机将流量引导到服务。 All traffic should go through ingress endpoint (usually it's loadbalancer which is exposed outside of the cluster). Please find examples with请查找示例
Based on your example it will look like:根据您的示例,它将如下所示:
chart: nginx-git/ingress-nginx
version: 3.32.0
values:
- tcp:
5672: "cust1namespace/rabbitmq:5672" # port 5672 for customer 1
5673: "cust2namespace/rabbitmq:5672" # port 5673 for customer 2
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.