I want to have 2 apps running on kubernetes using a ingress resource to point to each app in the same port.
I should be able to access app1 version in app1.localhost:8181/cxf, and app2 version in app2.localhost:8181/cxf
Im using docker with kubernetes, mysql and karaf with a kar. I'm testing locally (localhost).
I tried a lot of things that I searched on the internet, including adding to the hosts the ip + hostname, but no luck. What happens is that it always shows the same app, doesn't matter the hostname I insert.
before sharing my yamls, I have some questions:
1:
I was thinking that maybe I should have 2 nodes? one with mysql and app1 and the other one with mysql and app2? so in one I could access app1.localhost/cxf services and in the other app2.localhost/cxf services... maybe doesn't make much sense... and I was reading that I need kubeadm for that, and there is no way to install it on windows. I think I must use minikube for that instead?
2:
shouldn't I be able to create another loadBalancer? I wanted to, so the selector would be app2 in that loadBalancer, but since I already have one, the new one just stays <pending> until I remove the first one.
But when I installed the nginx-ingress controller it came with a type loadBalancer, and if I create an yaml with the same content, changing the ports it will work and wont stay pending...why?
3: if I have 2 replicas of app1, and 2 replicas of app2, there should be a loadBalancer for each app right?
4: Should I include a loadBalancer for mysql? does it make sense having mysql replicas?
5: Since when I install nginx-controller, when I check my kubernetes dashboard there is a loadBalancer that came with it. Its ok to edit and add my karaf ports to expose the service?
Note that I installed the nginx ingress-controller using helm, since the ingress-resource would not work otherwise, at least thats what I have read. I used helm for that: https://github.com/kubernetes/ingress-nginx/blob/master/docs/deploy/index.md#using-helm
Note:mysql is working fine so Im not posting the yaml's here so it doesn't get too long.
These are my yaml's:
The load balancer: (That I can replace for nginx load balancer?)
apiVersion: v1
kind: Service
metadata:
name: lb-service
spec:
type: LoadBalancer
selector:
app: app1
ports:
- protocol: TCP
name: app1
port: 3306
targetPort: 3306
- protocol: TCP
name: app1-8080
port: 8080
targetPort: 8080
- protocol: TCP
name: app1-8101
port: 8101
targetPort: 8101
- protocol: TCP
name: app1-8181
port: 8181
targetPort: 8181
status:
loadBalancer:
ingress:
- hostname: localhost
app1:
apiVersion: v1
kind: Service
metadata:
name: app1-service
spec:
ports:
- port: 8101
selector:
app: app1
clusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: app1-deployment
spec:
selector:
matchLabels:
app: app1
replicas: 1
template:
metadata:
labels:
app: app1
spec:
containers:
- name: app1
image: app1:latest
app2: is the same as app1 but in a diferent version(older services)
ingress-resource: (this is nor working)
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: apps-ingress
#annotations:
#nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: app1.localhost
http:
paths:
- path: /
backend:
serviceName: app1-service
servicePort: 8181
- host: app2.localhost
http:
paths:
- path: /
backend:
serviceName: app2-service
servicePort: 8181
Huum, im missing something here...
Thanks for your time!
edit:
I guess I found the problem, and im now trying to resolve it. Seems like ingress works in port 80 only for http, and im using cxf to list my services under port 8181. and 8080 for soap services. so I guess I have to expose those ports and I will be fine? gonna try it
edit 2: I tried but it's not working, I followed this example: https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/
The example works fine, but when I change the ingress to work with my app it doesn't work.
I need to access the :8181/cxf for my app to work, is there any way to do that?
Since ingress uses port 80, when I put app1.localhost, its the same as app1.localhost:80 right?. the thing is, I need to app1.localhost:8181/cxf for me to access my services. but I guess that will be translated to: app1.localhost:80:8181/cxf ??
Can some one help? :(
When I say port 8181, I guess I can use another one using nodePort: that's basically the port forward right? but the problem if I do that, when I want to deploy my second app to access in app2.localhost if I put the same nodePort it will end in error since I want the port to be the same, but diferent hostname.