I'm trying to create some ingress rules for my Kubernetes cluster (currently, on localhost using Docker Desktop) and they are not working.
- 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
- 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?
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
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!