关于nginx:ingressnginx-tcpudp转发

ingress-nginx设置tcp/udp转发

第一步,更改ingress-nginx的deployment启动参数,增加–tcp-services-configmap和–udp-services-configmap参数,开启tcp与udp的反对

containers:
- args:
  - /nginx-ingress-controller
  - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
  - --udp-services-configmap=$(POD_NAMESPACE)/udp-services

第二步,更改ingress-nginx的service,申明tcp和udp用的端口号

  ports:
  - name: proxied-tcp
    nodePort: 30090
    port: 9000
    protocol: TCP
    targetPort: 9000
  - name: proxied-udp
    nodePort: 30091
    port: 9001
    protocol: UDP
    targetPort: 9001
  - name: nginx
    port: 9005
    protocol: TCP
    targetPort: 9005   

第三步,定义configmap,格局为<ingress-controller-svc-port>:”<namespace>/<service-name>:<port>”,例如上面配置的data第一行示意将default命名空间下的example-go服务的8080端口映射到ingress-controller service的9000端口,即可通过ingress-controller的service ip加9000端口拜访到example-go服务

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  9000: "default/example-go:8080"
  9005: "default/nginx:80"

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理