<p>We have a requirement to make an application available via port.
For example <code>http://example.com:8180</code> and <code>http://example.com:8181</code> should resolve to the application.<br />
The ports are opened with the <code>listen-ports</code> annotation:</p>
<pre><code>alb.ingress.kubernetes.io/listen-ports: '[{&quot;HTTP&quot;: 80}, {&quot;HTTPS&quot;:443}, {&quot;HTTP&quot;:8180}, {&quot;HTTP&quot;:8181}]'
</code></pre>
<p>I tried following rules:</p>
<pre><code>rules:
    - host: example.com
      http:
        paths:
          - path: /*
            backend:
              serviceName: ssl-redirect
              servicePort: use-annotation
          - path: /1.0/*
            backend:
              serviceName: some-server-side-app
              servicePort: 8080
          - path: /*
            backend:
              serviceName: some-webpage
              servicePort: 80
      8180:
        paths:
          - path: /*
            backend:
              serviceName: app-reachable-via-port
              servicePort: 8180
      8181:
        paths:
          - path: /*
            backend:
              serviceName: app-reachable-via-port
              servicePort: 8181
</code></pre>
<p>This throws an error because of malformed ingress-configuration</p>
<p>I also found this guide on github for ingress-nginx <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md</a> and tried to resemble it but with not luck so far.</p>
<p>Is anyone aware of how this can be achieved with ALB-Ingress?</p>

CodeChimpy
<p>If I'm understanding what you're looking, you want to differentiate your inbound traffic and send to services based on the port your inbound traffic comes in on?</p>
<p>You might be able to accomplish this with the <a href="https://aws.amazon.com/blogs/containers/introducing-aws-load-balancer-controller/" rel="nofollow noreferrer">AWS Load Balancer Controller</a>. I have not tested the object below in this configuration using http-header, but I do use something very similar myself. I think this might be worth testing based on the <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#http-header-conditions" rel="nofollow noreferrer">documentation from AWS here</a>. You'll need to experiment with this though. This example also assumes that each of your services in the cluster are listening on the same port you're using to direct traffic -- this could easily be changed to whatever port your services are actually listening on.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/group.name: example
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/security-groups: sg-01234567898765432
    alb.ingress.kubernetes.io/ip-address-type: ipv4
    alb.ingress.kubernetes.io/listen-ports: '[{&quot;HTTP&quot;: 80}, {&quot;HTTPS&quot;: 443}, {&quot;HTTP&quot;: 8180}, {&quot;HTTP&quot;: 8181}]'
    
    alb.ingress.kubernetes.io/actions.response-503: &gt;
      {&quot;type&quot;:&quot;fixed-response&quot;,&quot;fixedResponseConfig&quot;:{&quot;contentType&quot;:&quot;text/plain&quot;,&quot;statusCode&quot;:&quot;503&quot;,&quot;messageBody&quot;:&quot;Unknown Host&quot;}}

    alb.ingress.kubernetes.io/actions.some-webpage: &gt;
      {&quot;type&quot;:&quot;forward&quot;,&quot;forwardConfig&quot;:{&quot;targetGroups&quot;:[{&quot;serviceName&quot;:&quot;some-webpage&quot;,&quot;servicePort&quot;:80,&quot;weight&quot;:100}]}}
    alb.ingress.kubernetes.io/conditions.some-webpage: &gt;
      [{&quot;field&quot;:&quot;http-header&quot;,&quot;HttpHeaderConfig&quot;:{&quot;HttpHeaderName&quot;:&quot;Host&quot;,&quot;Values&quot;:[&quot;example.com:80&quot;]}}]

    alb.ingress.kubernetes.io/actions.app1-reachable-via-port: &gt;
      {&quot;type&quot;:&quot;forward&quot;,&quot;forwardConfig&quot;:{&quot;targetGroups&quot;:[{&quot;serviceName&quot;:&quot;app1-reachable-via-port&quot;,&quot;servicePort&quot;:8180,&quot;weight&quot;:100}]}}
    alb.ingress.kubernetes.io/conditions.app1-reachable-via-port: &gt;
      [{&quot;field&quot;:&quot;http-header&quot;,&quot;HttpHeaderConfig&quot;:{&quot;HttpHeaderName&quot;:&quot;Host&quot;,&quot;Values&quot;:[&quot;example.com:8180&quot;]}}]

    alb.ingress.kubernetes.io/actions.app2-reachable-via-port: &gt;
      {&quot;type&quot;:&quot;forward&quot;,&quot;forwardConfig&quot;:{&quot;targetGroups&quot;:[{&quot;serviceName&quot;:&quot;app2-reachable-via-port&quot;,&quot;servicePort&quot;:8181,&quot;weight&quot;:100}]}}
    alb.ingress.kubernetes.io/conditions.app2-reachable-via-port: &gt;
      [{&quot;field&quot;:&quot;http-header&quot;,&quot;HttpHeaderConfig&quot;:{&quot;HttpHeaderName&quot;:&quot;Host&quot;,&quot;Values&quot;:[&quot;example.com:8181&quot;]}}]

    alb.ingress.kubernetes.io/target-type: instance
    alb.ingress.kubernetes.io/load-balancer-attributes: routing.http2.enabled=true,idle_timeout.timeout_seconds=600
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-2:999999999999:certificate/11111111-1111-1111-1111-111111111111,arn:aws:acm:us-east-2:999999999999:certificate/22222222-2222-2222-2222-222222222222
    alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-2016-08
spec:
  backend:
    serviceName: response-503
    servicePort: use-annotation
  rules:
    - http:
        paths:
          - backend:
              serviceName: ssl-redirect
              servicePort: use-annotation
          - backend:
              serviceName: some-webpage
              servicePort: use-annotation
          - backend:
              serviceName: app1-reachable-via-port
              servicePort: use-annotation
          - backend:
              serviceName: app2-reachable-via-port
              servicePort: use-annotation
</code></pre>
<p>Another solution might be ALB TargetGroupBinding. You lose some of the advantage of allowing EKS to provision and manage your ALBs and Target Groups on your behalf, but you maintain full control over your ALB and Target Group configurations.  With TargetGroupBinding, you still need the <a href="https://aws.amazon.com/blogs/containers/introducing-aws-load-balancer-controller/" rel="nofollow noreferrer">AWS Load Balancer Controller</a> in your cluster, but you create the ALB and Target Groups yourself, then use the TargetGroupBinding object to map services from your cluster to specific Target Group ARNs:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: elbv2.k8s.aws/v1beta1
kind: TargetGroupBinding
metadata:
  name: demo1-tgb
spec:
  serviceRef:
    name: demo1-service 
    port: 80
  targetGroupARN: arn:aws:elasticloadbalancing:us-east-2:121212121212:targetgroup/my-target-group/cbc9f05b05caea6b
</code></pre>
<p>Good luck - please update again once you get it working as required.</p>
