ingress-nginx tcp/udp转发

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,格式为:"/:",例如下面配置的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"

你可能感兴趣的:(nginx,运维,kubernetes)