简体   繁体   English

如何使用 nginx-ingress controller 公开 TCP 的多个服务?

[英]How to expose multiple services with TCP using nginx-ingress controller?

I have multiple deployments running of RDP application and they all are exposed with ClusterIP service.我有多个运行 RDP 应用程序的部署,它们都通过 ClusterIP 服务公开。 I have nginx-ingress controller in my k8s cluster and to allow tcp I have added --tcp-services-configmap flag in nginx-ingress controller deployment and also created a configmap for the same that is shown below我在我的 k8s 集群中有 nginx-ingress controller 并允许 tcp 我在 nginx-ingress Z594C103F2C6E04C3D8AB059F0C31 中添加了--tcp-services-configmap标志

apiVersion: v1 
kind: ConfigMap
metadata:
name: tcp-services
namespace: ingress-nginx
data:
  3389: “demo/rdp-service1:3389”

This will expose “rdp-service1” service.这将公开“rdp-service1”服务。 And I have 10 more such services which needed to be exposed on the same port number but if I add more service in the same configmap like this而且我还有 10 个这样的服务需要在同一个端口号上公开,但是如果我在同一个 configmap 中添加更多服务,就像这样

...
data
  3389: “demo/rdp-service1:3389”
  3389: “demo/rdp-service2:3389”

Then it will remove the previous service data and since here I have also deployed external-dns in k8s, so all the records created by ingress using host: ... will starts pointing to the deployment attached with the newly added service in configmap.然后它会删除之前的服务数据,因为这里我也在 k8s 中部署了 external-dns,所以所有由 ingress 使用host: ...创建的记录都将开始指向附加到 configmap 中新添加的服务的部署。

Now my final requirement is as soon as I append the rule for a newly created deployment(RDP application) in the ingress then it starts allowing the TCP connection for that, so is there any way to achieve this.现在我的最终要求是,只要我 append 是入口中新创建的部署(RDP 应用程序)的规则,它就会开始允许 TCP 连接,所以有什么方法可以实现这一点。 Or is there any other Ingress controller available that can solve such type of use case and can also easily be integrated with external-dns?或者有没有其他可用的 Ingress controller 可以解决这种类型的用例并且也可以很容易地与 external-dns 集成?

Note:- I am using AWS EKS Cluster and Route53 with external-dns.注意:- 我正在使用 AWS EKS 集群和带有外部 DNS 的 Route53。

Posting this answer as a community wiki to explain some of the topics in the question as well as hopefully point to the solution.将此答案发布为社区 wiki,以解释问题中的一些主题,并希望指出解决方案。

Feel free to expand/edit it.随意扩展/编辑它。


NGINX Ingress main responsibility is to forward the HTTP / HTTPS traffic. NGINX Ingress主要负责转发HTTP / HTTPS流量。 With the addition of the tcp-services / udp-services it can also forward the TCP / UDP traffic to their respective endpoints:通过添加tcp-services / udp-services它还可以将TCP / UDP流量转发到各自的端点:

The main issue is that the Host based routing for Ingress resource in Kubernetes is targeting specifically HTTP / HTTPS traffic and not TCP ( RDP ). The main issue is that the Host based routing for Ingress resource in Kubernetes is targeting specifically HTTP / HTTPS traffic and not TCP ( RDP ).

You could achieve a following scenario:您可以实现以下场景:

  • Ingress controller : Ingress controller
    • 3389 - RDP Deployment #1 3389 - RDP Deployment #1
    • 3390 - RDP Deployment #2 3390 - RDP Deployment #2
    • 3391 - RDP Deployment #3 3391 - RDP Deployment #3

Where there would be no Host based routing.没有基于Host的路由。 It would be more like port-forwarding.它更像是端口转发。

A side note!旁注! This setup would also depend on the ability of the LoadBalancer to allocate ports (which could be limited due to cloud provider specification)此设置还取决于LoadBalancer分配端口的能力(这可能会受到云提供商规范的限制)


As for possible solution which could be not so straight-forward I would take a look on following resources:至于可能不太直接的解决方案,我会看看以下资源:

I'd also check following links:我还会检查以下链接:

Actually, I really don't know why you are using that configmap.实际上,我真的不知道您为什么要使用该 configmap。

In my knowledge, nginx-ingress-controller is routing traffic coming in the same port and routing based on host.据我所知,nginx-ingress-controller 正在路由来自同一端口的流量并基于主机进行路由。 So if you want to expose your applications on the same port, try using this:因此,如果您想在同一端口上公开您的应用程序,请尝试使用:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ .Chart.Name }}-ingress
  namespace: your-namespace
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: your-hostname
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          serviceName: {{ .Chart.Name }}-service
          servicePort: {{ .Values.service.nodeport.port }}

Looking in your requirement, I feel that you need a LoadBalancer rather than Ingress查看您的要求,我觉得您需要一个 LoadBalancer 而不是 Ingress

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

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