Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

How to expose multiple ports on the same ingress #1655

Closed

Description

@jonathan-kosgei

I have a service with two ports exposed on ports 8000 and 8080, is it possible to expose them on the same ingress?

Activity

  1. aledbf commented on Nov 6, 2017

    @aledbf
    Member

    @jonathan-kosgei yes. Please keep in mind that ingress exposes port 80 and 443 to the internet

  2. jonathan-kosgei commented on Nov 6, 2017

    @jonathan-kosgei
    Author

    @aledbf
    Thanks for the reply. Okay, I have this

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: dspace
      namespace: testing
      annotations:
        kubernetes.io/ingress.class: traefik
    spec:
      rules:
      - host: myapp.us.com
        http:
          paths:
          - backend:
              serviceName: myapp
              servicePort: 8080
    

    Is there a way I specify multiple servicePorts ?

  3. aledbf commented on Nov 6, 2017

    @aledbf
    Member
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: dspace
      namespace: testing
    spec:
      rules:
      - host: myapp.us.com
        http:
          paths:
          - path: /
            backend:
              serviceName: myapp
              servicePort: 8080
          - path: /app-port-2
            backend:
              serviceName: myapp
              servicePort: 8081
    

    that?

  4. jonathan-kosgei commented on Nov 6, 2017

    @jonathan-kosgei
    Author

    Is it possible to have them on the same path?

  5. aledbf commented on Nov 6, 2017

    @aledbf
    Member

    Is it possible to have them on the same path?

    No.

    What are you trying to do?

  6. jonathan-kosgei commented on Nov 6, 2017

    @jonathan-kosgei
    Author

    Expose multiple ports on the same domain eg. expose port 8000 and 8080 on mydomain.com

  7. aledbf commented on Nov 6, 2017

    @aledbf
    Member

    @jonathan-kosgei ok, ingress cannot help with that use case.

  8. aledbf commented on Nov 12, 2017

    @aledbf
    Member

    Closing. Please reopen if you have more questions

  9. itskingori commented on Dec 25, 2017

    @itskingori
    Member

    @jonathan-kosgei I haven't tested this but what about ... 👇

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: some-app
    spec:
      rules:
      - host: app.example.com
        http:
          paths:
          - backend:
              serviceName: myapp
              servicePort: 8080
          - backend:
              serviceName: myapp
              servicePort: 8081

    ... did you try that?

  10. aledbf commented on Dec 25, 2017

    @aledbf
    Member

    @itskingori that example will not work. The ingress spec do not allows multiple backends for the same path

  11. JulienCarnec commented on Jan 29, 2018

    @JulienCarnec

    Hello,

    I have a service which exposes:

    • /foo on port 5611
    • /bar on port 5612

    I want the Ingress controller to load-balance both endpoint.

    I have tried this,

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: my-ingress
    spec:
      rules:
      - host: my.example.com
        http:
          paths:
          - path: /foo
            backend:
              serviceName: my-service
              servicePort: 5611
          - path: /bar
            backend:
              serviceName: my-service
              servicePort: 5612
    

    and this:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: my-ingress
    spec:
      rules:
      - host: my.example.com
        http:
          paths:
          - path: /foo
            backend:
              serviceName: my-service
              servicePort: 5611
      - host: my.example.com
        http:
          paths:
          - path: /bar
            backend:
              serviceName: my-service
              servicePort: 5612
    

    And both fails...

    my-service is properly exposing /foo on port 5611 and /bar on port 5612, each of them being assigned a different .htaccess file for basic authentication.

    When I try to access /foo, everything works fine

    When I try to access /bar, the login challenge is the one from /foo.

    If I remove basic auth, then, accessing /foo still works as expected while accessing /bar from the Ingress URL leads to HTTP 404.

    If I change the service type of my-service from ClusterIP to NodePort in order to access it directly (without Ingress), then both endpoints are working as expected (with and without basic auth).

    The problem clearly comes from the Ingress controller.

    Shouldn't this be considered as defect of the Ingress controller?

    Thanks.

  12. JulienCarnec commented on Jan 31, 2018

    @JulienCarnec

    Created #2008 for my previous comment.

  13. added a commit that references this issue on Oct 24, 2018
  14. dmytropetryk commented on Mar 5, 2021

    @dmytropetryk

    @jonathan-kosgei I haven't tested this but what about ...

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: some-app
    spec:
      rules:
      - host: app.example.com
        http:
          paths:
          - backend:
              serviceName: myapp
              servicePort: 8080
          - backend:
              serviceName: myapp
              servicePort: 8081

    ... did you try that?

    it works for apiVersion: networking.k8s.io/v1beta1 k8s v1.18.14

  15. codebard commented on Sep 18, 2022

    @codebard

    Mapping port 80 to port 80 and port 443 to port 443 is vital for hosting public websites that use mixed urls but amazingly it seems that ingress-nginx does not support that simple use case.

  16. a-imran99 commented on Oct 14, 2022

    @a-imran99

    it works for apiVersion: networking.k8s.io/v1beta1 k8s v1.18.14

    Does this way of providing 2 backend service works?

  17. Leonardo-Ferreira commented on Apr 30, 2024

    @Leonardo-Ferreira

    Having the same problem over here

  18. kvaps commented on Jul 26, 2024

    @kvaps
    Member

    Hey there, I was solving this problem for Cozystack, as we were needed to redirect traffic from infra-ingress-controller to user clusters. So, this rule works with no troubles:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        nginx.ingress.kubernetes.io/backend-protocol: AUTO_HTTP
        nginx.ingress.kubernetes.io/configuration-snippet: |
          if ($scheme = http) {
            set $proxy_upstream_name "mynamespace-myservice-80";
            set $proxy_host $proxy_upstream_name;
            set $service_port 80;
          }
        nginx.ingress.kubernetes.io/ssl-passthrough: "true"
        nginx.ingress.kubernetes.io/ssl-redirect: "false"
      labels:
        app.kubernetes.io/managed-by: Helm
      name: myservice
      namespace: mynamespace
    spec:
      ingressClassName: mynamespace
      rules:
      - host: example.org
        http:
          paths:
          - backend:
              service:
                name: myservice
                port:
                  number: 443
            path: /
            pathType: ImplementationSpecific
          - backend:
              service:
                name: myservice
                port:
                  number: 80
            path: /
            pathType: ImplementationSpecific
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions