Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to expose multiple ports on the same ingress #1655

Closed
jonathan-kosgei opened this issue Nov 6, 2017 · 17 comments
Closed

How to expose multiple ports on the same ingress #1655

jonathan-kosgei opened this issue Nov 6, 2017 · 17 comments

Comments

@jonathan-kosgei
Copy link

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

@aledbf
Copy link
Member

aledbf commented Nov 6, 2017

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

@jonathan-kosgei
Copy link
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 ?

@aledbf
Copy link
Member

aledbf commented Nov 6, 2017

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?

@jonathan-kosgei
Copy link
Author

Is it possible to have them on the same path?

@aledbf
Copy link
Member

aledbf commented Nov 6, 2017

Is it possible to have them on the same path?

No.

What are you trying to do?

@jonathan-kosgei
Copy link
Author

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

@aledbf
Copy link
Member

aledbf commented Nov 6, 2017

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

@aledbf
Copy link
Member

aledbf commented Nov 12, 2017

Closing. Please reopen if you have more questions

@itskingori
Copy link
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?

@aledbf
Copy link
Member

aledbf commented Dec 25, 2017

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

@JulienCarnec
Copy link

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.

@JulienCarnec
Copy link

Created #2008 for my previous comment.

ccojocar added a commit to ccojocar/exposecontroller that referenced this issue Oct 24, 2018
It seems that ingress controller does not support multiple ports under the same host.

kubernetes/ingress-nginx#1655
@dmytropetryk
Copy link

@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

@codebard
Copy link

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.

@a-imran99
Copy link

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

Does this way of providing 2 backend service works?

@Leonardo-Ferreira
Copy link

Having the same problem over here

kvaps added a commit to aenix-io/cozystack that referenced this issue Jul 26, 2024
We need to separate HTTP and HTTPS traffic and send them into tenant
clusters.
Currently traffic was sending only on HTTPS port, this PR enables HTTP
traffic forwarding.

Nginx ingress does not support setting correct upstream according to
type of traffic (http or https)
There are set of issues in upstream.

- kubernetes/ingress-nginx#1655
- kubernetes/ingress-nginx#9061
- kubernetes/ingress-nginx#11334

Good to know that we found reliable workaround

fixes:
#209 (comment)
@kvaps
Copy link
Member

kvaps commented Jul 26, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants