1

I'm trying to create some ingress rules for my Kubernetes cluster (currently, on localhost using Docker Desktop) and they are not working.

What I'm trying to do

- App #1 : Some database (e.g. mongodb or RavenDb or Postgres, etc).
- App #2 : Some queue (rabbitmq, etc)
- App #3 : Some web site api #1 
- App #4 : Some web site api #2

Routes to access each app

- App #1 : <anything>:port 5200
- App #2 : <anything>:port 5300
- App #3 : /account/*:80, /accounts:80
- App #4 : /order/*:80, /orders/*:80

[note -> i'm not including ssl/443 port yet because i've not handled that, etc]

So here's an example what I've got for the first app (which doesn't work):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: data-ravendb-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: data-ravendb-service
          servicePort: dashboard

---
apiVersion: v1
kind: Service
metadata:
  name: data-ravendb-service
  labels:
    app: hornet
    tier: backend
    component: data-ravendb
spec:
  ports:
  - name: dashboard
    port: 5200
    targetPort: 8080
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: data-ravendb-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: hornet
        tier: backend
        component: data-ravendb
    spec:
      containers:
      - name: data-ravendb-container
        image: ravendb/ravendb
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          name: dashboard

How can I setup my ingress to allow those 4 Apps to access the backend services appropriately?

Community
  • 1
  • 1
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

2 Answers2

2

That's currently not fully supported to route in Kubernetes Ingress any other traffic than HTTP/HTTPS protocols. Also Traefik which you use is HTTP reverse proxy so it will be either hard or not possible to do that using that ingress controller.

See Kubernetes: Routing non HTTP Request via Ingress to Container

Jakub Bujny
  • 4,400
  • 13
  • 27
  • Oh wow really? so the ingress can only accept ports 80 and 443 _regardless_ what ingress-controller is used? – Pure.Krome Jun 10 '19 at 11:15
  • There are some workarounds for that using nginx controller but they are more like "hacks" than production-ready solutions – Jakub Bujny Jun 10 '19 at 11:28
  • So would this mean I should stop trying to use `ingress` and try instead to use a `loadbalancer` instead? – Pure.Krome Jun 10 '19 at 23:23
1

As @Jakub mentioned, ingress supports only http/https ports.

You can create ingresses with different backend paths for your website apis and also for App1 & App2. But if you need expose with port, then consider using LoadBalancer service.

According your example of first app, why doesn't it works, because you didn't specify selectors in your service yaml. Try to change it like below, then it will work.

apiVersion: v1
kind: Service
metadata:
  name: data-ravendb-service
  labels:
    app: hornet
    tier: backend
    component: data-ravendb
spec:
  selector: # Mandatory to find backends
    app: hornet # Should match to pod label
    tier: backend # Should match to pod label
  ports:
  - name: dashboard
    port: 5200
    targetPort: 8080

Hope it helps!

clxoid
  • 2,577
  • 12
  • 21
  • Thanks heaps for the answer/help. I really want to do _some of my routes_ via PORTS (not hosts or paths) so looks like an LB is the way for me, right now. Time to learn more about that :/ – Pure.Krome Jun 11 '19 at 10:50