<p>In kubernetes, I have the following service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: test-service
  namespace: default
spec:
  ports:
    - name: tcp
      protocol: TCP
      port: 5555
      targetPort: 5555    
    - name: udp
      protocol: UDP
      port: 5556
      targetPort: 5556
  selector:
    tt: test
</code></pre>
<p>Which exposes two ports, 5555 for TCP and 5556 for UDP. How can expose these ports externally using the same ingress? I tried using nginx to do something like the following but it doesn't work. It complains that mixed ports are not supported.</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  5555: &quot;default/test-service:5555&quot;
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: udp-services
  namespace: ingress-nginx
data:
  5556: &quot;default/test-service:5556&quot;
---
apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: LoadBalancer
  ports:
    - name: tcp
      port: 5555
      targetPort: 5555
      protocol: TCP
    - name: udp
      port: 5556
      targetPort: 5556
      protocol: UDP
  args:
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
</code></pre>
<p>Is there a way to do this?</p>

<p>You can enable <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/" rel="nofollow noreferrer">feature gates</a> <code>MixedProtocolLBService</code>. For instructions on how to enable function gates, see below.</p>
<ul>
<li><a href="https://stackoverflow.com/questions/59814862/how-do-you-enable-feature-gates-in-k8s">How do you enable Feature Gates in K8s?</a></li>
</ul>
<p>Restart (delete and re-create) the Ingress controller after enabling it for the settings to take effect.</p>
<p><code>MixedProtocolLBService</code> is a beta feature since Kubernetes 1.20. Whether it becomes stable or depprecated remains to be seen.</p>
