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"
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。