ingress-nginx tcp/udp轉發

ingress-nginx設置tcp/udp轉發

第一步,更改ingress-nginx的deployment啓動參數,添加--tcp-services-configmap和--udp-services-configmap參數,開啓tcp與udp的支持node

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

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

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服務api

apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  9000: "default/example-go:8080"
  9005: "default/nginx:80"
相關文章
相關標籤/搜索