Ingress-nginx: How to expose multiple ports on the same ingress

Created on 6 Nov 2017  路  12Comments  路  Source: kubernetes/ingress-nginx

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

Most helpful comment

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

All 12 comments

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

@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 ?

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?

Is it possible to have them on the same path?

Is it possible to have them on the same path?

No.

What are you trying to do?

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

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

Closing. Please reopen if you have more questions

@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?

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

briananstett picture briananstett  路  3Comments

c-mccutcheon picture c-mccutcheon  路  3Comments

cehoffman picture cehoffman  路  3Comments

smeruelo picture smeruelo  路  3Comments

yuyang0 picture yuyang0  路  3Comments