We have created a custom Docker image that can route UDP traffic in a Kubernetes cluster (Amazon EKS). The Docker image includes a Helm chart that can be used to deploy a UDP application to a Kubernetes cluster.

The UDP listener service listens on the specified UDP port and outputs to the container log. The Helm chart packages and deploys the application to Elastic Kubernetes Service (EKS)

Git Repository with Docker Image and Helm chart

Link – https://github.com/dev-coderise/udp-listener

Install UDP listener in Kubernetes cluster (Amazon EKS) using Helm

cd deploy/udp-listener
helm upgrade --install udp-listener .

Uninstall UDP listener from Kubernetes cluster 

helm uninstall udp-listener

Start UDP listener service locally

By default, you can run it like this

docker run -p 0.0.0.0:5005:5005 -p 0.0.0.0:5005:5005/udp --name udp-listener coderiseio/udp-listener

Run UDP listener on a different port

You can make it listen on another port

docker run -p 0.0.0.0:4444:4444 -p 0.0.0.0:4444:4444/udp -e UDPPORT=4444 --name udp-listener coderiseio/udp-listener

Assign Static IP to Load Balancer

We provisioned a service with LoadBalancer type which allows to route UDP traffic in Kubernetes. Optionally, a static IP can be assigned to the Load Balancer. This way the DNS always maps to the same IP. You can create a Elastic IP in AWS and then assign it using service annotations in the values.yaml ( LINK ). If this is not required, you can comment out these lines in values.yaml.

service.beta.kubernetes.io/aws-load-balancer-eip-allocations: eipalloc-057553b2156ec2c74
service.beta.kubernetes.io/aws-load-balancer-subnets: coderise_test_vpc_ca-Public1
service.beta.kubernetes.io/aws-load-balancer-security-groups: sg-0913f81f52beb4f4a

Testing to ensure we can route UDP Traffic in Kubernetes 

Use some tool like PacketSender or in another terminal:

#localhost
nc -u localhost 5005

And start sending data. You should see your text reflected in the docker run terminal

Use Docker Compose to install UDP Listerner service

udp:
  container_name: my-udp-listener
  image: coderiseio/udp-listener
  environment:
    - UDPPORT=4001
  ports:
  - "0.0.0.0:4001:4001"
  - "0.0.0.0:4001:4001/udp"

View UDP listener service logs

View its logs:

docker logs <udp-listener-pod>

Conclusion

In this blog, we discussed how to route UDP traffic in Kubernetes. We also covered how to use the Docker image and Helm charts to install the UDP listener service in a Kubernetes cluster. Finally, we looked at how to assign a static IP to the load balancer provisioned by the UDP listener service.

If you liked this blog, please leave a comment and let us know. Also, check out our other blogs here.

Leave a Reply

Your email address will not be published. Required fields are marked *