Ingress nginx TCP / UDP forwarding

Time:2021-4-30
Setting TCP / UDP forwarding with ingress nginx

The first step is to change the deployment startup parameter of ingress nginx, add — TCP services configmap and — UDP services configmap parameters, and enable the support of TCP and UDP

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

Second, change the service of ingress nginx and declare the port number for TCP and 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   

The third step is to define configmap in the format of < address controller SVC port >: “< namespace > / < service name >: < port >”, for example, the first line of data configured below indicates that the 8080 port of the example go service in the default namespace is mapped to the 9000 port of the address controller service, and the example go service can be accessed through the service IP plus 9000 port of the address controller

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