My goal is the following: I have two Flask apps in two separate Docker containers and I want to access them via different paths on the same IP address, like this: 127.0.0.1/app1, 127.0.0.1/app2 (but with a real IP address).
I want to do this with Kubernetes.
I have a Kubernetes cluster running (Azure Kubernetes Service), with a Deployment and Service for each of the two Docker containers. The pod for each app is running fine. I also installed an ingress controller (Nginx) in my cluster and now I am trying to make it work with a single Ingress resource.
If I do it as follows, it works perfectly for 1 single app (either one of them works on IP-address/):
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-name
namespace: my-namespace
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: service1 (or service2)
servicePort: 5000
But when I try the following it doesn't work:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-name
namespace: my-namespace
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /app1
backend:
serviceName: service1
servicePort: 5000
- path: /app2
backend:
serviceName: service2
servicePort: 5000
I am able to see the html page that gets rendered by the Flask app, for both applications on their respective paths, but none of the functionalities work.
Other than the fact that the paths don't always seem to work (I sometimes get redirected to IP-address/ when I try to connect to IP-address/app1 or IP-address/app1/), the problem is the following (I think):
Each of the Flask applications have a "/predict" route, that only accepts POST requests, where the respective calls for the apps are made (Each application is an AI application that makes a prediction for a given input).
The calls for both apps are made to IP-address/predict, instead of IP-address/app1/predict or IP-address/app2/predict. Also the static files cannot be accessed because of this path problem.
I don't know if this is the right way to do it? I tried playing around with the 'rewrite-target' as well, but haven't figured out a solution.
I hope someone can explain me what I'm doing wrong.