Reputation: 307
I am trying to setting up a load balance on kubernetes on GCP and got stucked now. So I was following this tutorial (Tutorial) but I can't get past Step 6: (Optional) Serve multiple applications on a load balancer
I am using a node simple app that only prints a name from a config map. After following every step my paths can not be found (404).
This is my deployment example (both my services uses "the same" deployment, only changing names and image):
kind: Deployment
metadata:
name: nodetestfoo
namespace: default
spec:
selector:
matchLabels:
run: nodetestfoo
template:
metadata:
labels:
run: nodetestfoo
spec:
containers:
- image: gcr.io/e3-dev-227917/nodetestfoo:v4
imagePullPolicy: IfNotPresent
name: nodetestfoo
ports:
- containerPort: 3333
protocol: TCP
envFrom:
- configMapRef:
name: env-config
---
apiVersion: v1
kind: Service
metadata:
name: nodetestfoo
namespace: default
spec:
ports:
- port: 3333
protocol: TCP
targetPort: 3333
selector:
run: nodetestfoo
type: NodePort
This is my ingress:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: api-ingress
spec:
rules:
- http:
paths:
- path: /test
backend:
serviceName: nodetest
servicePort: 3333
- path: /foo
backend:
serviceName: nodetestfoo
servicePort: 3333
My kubectl describe ingress output:
The response of a request using a path
The response of a request without a path (this default back-end really does not exists, so I believe it's the expected behavior)
What should I do to make it work? I'm kinda lost here. (obviously I'm new to cloud, in the beginning of my studies)
Upvotes: 1
Views: 677
Reputation: 8786
Let me tell you what you did. You got a functional configuration, but didn't give it enough time to deploy the load balancer. It usually takes about 5 minutes to have a functional http
load balancer. But you probably got anxious, and never let it to get fully configured. So, just get back to your original Ingress
, create it, and wait. after like 5 minutes, curl it.
You are saying "I had to add this annotation...". By adding that annotation, you switched to a different Ingress Controller (which you had to install previously). Nginx Ingress Controller takes milliseconds to get ready, as is just has to update nginx server config file. Also the traffic goes through a tcp
load balancer, which gets ready very quick too, to the Ingress Controller, which is a pod. So here you have a load balancer that gets ready in about 30 seconds, therefor it seems that it works, while the other one doesn't.
Now, I am telling this because you seem to be a little confused about what happened, not because I'm advising getting back to GKE Ingress Controller. You still might want to stick to nginx Ingress Controller. It is reliable. I personally like it more then GKE, for several reasons. Or you might end up with any other. There are tens of Ingress Controllers now out there.
Upvotes: 2
Reputation: 307
So, turns out the ingress-nginx project brought up by Rexovas on the comments really helped me out! I will have to take more time to read and understand the project, but on a quick test I got it working fine!
I had to add it to my kubernetes and add the following annotations to my ingress:
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
now I can access my different paths without a problem! :D
Currently I have no idea how reliable this solution really is.Just feels wierd having to use an "third-part" project to make it work
I'll be updating this post if any problem comes up
Upvotes: 0
Reputation: 6471
According to this modify the ingress like following
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: api-ingress
spec:
rules:
- http:
paths:
- path: /test/*
backend:
serviceName: nodetest
servicePort: 3333
- path: /foo/*
backend:
serviceName: nodetestfoo
servicePort: 3333
Upvotes: 1