Kubernetes + Metallb: Nginx pod not receiving traffic with Local traffic Policy, Layer 2 mode

7/31/2018

What happened: I changed my nginx service's externalTrafficPolicy to Local and now my nginx pod no longer receives traffic

What you expected to happen: The nginx pod will continue to get traffic, but with the source ip intact. Using Layer 2 mode

Environment:

MetalLB version: 0.7.1 Kubernetes version: latest OS (e.g. from /etc/os-release): centos7 Kernel (e.g. uname -a): Linux K8SM1 3.10.0-862.3.2.el7.x86_64 #1 SMP Mon May 21 23:36:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

I have an nginx pod that listens for UDP on port 80, and redirects the UDP packet to 192.168.122.206:8080 I have a simple udp server that listens on 192.168.122.206:8080. This was working fine, but I needed to know the original source IP and port of the packet so I changed my service's traffic policy to local. Now, the pod doesn't seem to get traffic. I am running a single node bare metal cluster. I have tried doing "kubectl logs pod-name" but nothing shows up, leading me to believe the pod isn't getting traffic at all. I am making sure that my UDP packet is being sent to the external ip of the nginx service and port 80.

my nginx.conf from which I built the image:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}

stream {
server {
        listen 80 udp;
        proxy_pass 192.168.122.206:8080;
    }
}

My nginx deployment and service

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: asvilla/custom_nginx2:first
        ports:
        - name: http
          containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  externalTrafficPolicy: Local
  ports:
  - name: http
    port: 80
    protocol: UDP
    targetPort: 80
  selector:
    app: nginx
  type: LoadBalance

I have set verbosity of my pods and containers logs to 9. They show nothing new when I send the packet. I also set verbosity to 9 for "kubectl describe service nginx" and that doesn't show anything new when I send the packet. My best guess here is that something is going wrong with kube-proxy? Also the fact that my master is my only node might be affecting something, although when I set it up I untainted it and allowed the scheduler to treat it as a worker node.

-- alexv9
docker
kubernetes
nginx

1 Answer

8/1/2018

Due to the fact that you have already pointed Service to route the network traffic via UDP protocol, I guess this should also be allowed for Nginx Deployment, adding protocol: UDP parameter:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: asvilla/custom_nginx2:first
        ports:
        - name: http
          containerPort: 80
          protocol: UDP
-- mk_sta
Source: StackOverflow