|
| 1 | +--- |
| 2 | +slug: open-tcp-udp-same-port |
| 3 | +title: Easily open TCP and UDP protocols on the same port |
| 4 | +authors: lucia |
| 5 | +tags: [DevOps, PlatformEngineering, ALB, TCP, UDP, Kubernetes, Networking, AWS] |
| 6 | +image: img/2025-07-04-tcp-udp/image.jpg |
| 7 | +--- |
| 8 | +If you’ve ever tried to expose both TCP and UDP on the same port using Kubernetes with AWS Load Balancers, you’ve probably run into a common limitation: you can only choose one protocol per port, which complicates applications that need both (such as real-time communications or gaming). |
| 9 | + |
| 10 | +The good news is that AWS has released a feature that allows configuring listeners for both TCP and UDP on the same port, avoiding complex workarounds. |
| 11 | + |
| 12 | +To implement this, it’s important to verify two things: |
| 13 | +- That your **AWS Load Balancer Controller** is version **v2.13.0 or higher**. |
| 14 | +- That the **Helm chart** is **1.13.0 or higher** to ensure compatibility. |
| 15 | + |
| 16 | +Once that’s set, you only need to do two steps to enable both protocols on the same port: |
| 17 | +1. In the ALB Controller’s `values.yaml` file, add: |
| 18 | + ```yaml |
| 19 | + controllerConfig: |
| 20 | + featureGates: |
| 21 | + EnableTCPUDPListener: true |
| 22 | + ``` |
| 23 | +2. In the LoadBalancer type Service manifest where you want to enable this functionality, add this annotation: |
| 24 | + ```yaml |
| 25 | + service.beta.kubernetes.io/aws-load-balancer-enable-tcp-udp-listener: 'true' |
| 26 | + ``` |
| 27 | +After that, you just need to define the port twice in your Service: once for TCP and once for UDP. Here is a complete example of a Service manifest that opens the same port for both TCP and UDP: |
| 28 | +```yaml |
| 29 | +apiVersion: v1 |
| 30 | +kind: Service |
| 31 | +metadata: |
| 32 | + name: ejemplo-tcp-udp |
| 33 | + annotations: |
| 34 | + service.beta.kubernetes.io/aws-load-balancer-enable-tcp-udp-listener: "true" |
| 35 | +spec: |
| 36 | + type: LoadBalancer |
| 37 | + selector: |
| 38 | + app: mi-aplicacion |
| 39 | + ports: |
| 40 | + - name: tcp-12345 |
| 41 | + protocol: TCP |
| 42 | + port: 12345 |
| 43 | + targetPort: 12345 |
| 44 | + - name: udp-12345 |
| 45 | + protocol: UDP |
| 46 | + port: 12345 |
| 47 | + targetPort: 12345 |
| 48 | +``` |
| 49 | +
|
| 50 | +>⚠️ **If you already had the load balancer created and you add this functionality now, I recommend deleting it and recreating it** to ensure the configuration is applied correctly. |
| 51 | +
|
| 52 | +
|
| 53 | +### 💬 References |
| 54 | +This new feature addresses several community-reported issues, such as [#2759](https://github.com/kubernetes-sigs/aws-load-balancer-controller/issues/2759) and [1608](https://github.com/kubernetes-sigs/aws-load-balancer-controller/issues/1608). I hope this is helpful to those following those threads! |
0 commit comments