I'm trying to create an Ingress resource that fans out to two services that are running healthily. This is my very simple config:
apiVersion: extensions/v1beta1kind: Ingressmetadata: name: my-ingress namespace: defaultspec: rules: - http: paths: - path: /* backend: serviceName: service1 servicePort: 8080 - path: /service2/* backend: serviceName: service2 servicePort: 9090Only requests to the root (/) path seem to work. I've been trying to trouble shoot this using similar posts online, but nothing has worked for me.
What can I do?
Edit:
This config works fine on Minikube, but doesn't on GKE?
- What do you get on
service2? 404?suren– suren2019-12-21 23:46:37 +00:00CommentedDec 21, 2019 at 23:46 - 1Do you have actually anything serving on path
/service2of your backend?suren– suren2019-12-23 08:48:07 +00:00CommentedDec 23, 2019 at 8:48 - 1404 implies the request is reaching the backend, there is just nothing there. If you check the logs on one of the backends for service2, you should see the requests come in along with the error and that should help you debug this furtherPatrick W– Patrick W2019-12-23 18:14:18 +00:00CommentedDec 23, 2019 at 18:14
3 Answers3
If you're using the default ingress controller of GKE, then theyaml looks good to me. I will suggest you, to recheck the services (i.e. service1, service2) ofNodePort type and make sure that they are working fine.
In case you're using theNGINX Ingress Controller of the version above or equal tonginx-0.20.0, you need to set thenginx.ingress.kubernetes.io/use-regex annotation totrue (the default isfalse) toenable the case sensitive regular expression.
Just like:
apiVersion: extensions/v1beta1kind: Ingressmetadata: name: my-ingress namespace: default annotations: nginx.ingress.kubernetes.io/use-regex: "true"spec: rules: - http: paths: - path: /* backend: serviceName: service1 servicePort: 8080 - path: /service2/* backend: serviceName: service2 servicePort: 90901 Comment
NodePort fromLoadBalancer, I can now access the resources on my Minikube cluster. However, I am now gettingdefault backend - 404 when trying to accessservice2 through my GKE cluster.I have a working configuration on Azure, it's very simple yet differs from yours in a few ways. I rewrote your yaml accordingly, see if that helps:
apiVersion: extensions/v1beta1kind: Ingressmetadata: name: my-ingress namespace: default annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: /$1spec: rules: - http: paths: - path: /service2/?(.*) backend: serviceName: service2 servicePort: 9090 - path: /?(.*) backend: serviceName: service1 servicePort: 8080The notable differences are:
- Paths are flipped so that the more specific one is higher up. Not sure if that has any influence.
- Changed the simple wildcard to a look-ahead:
*=>?(.*). This allows me to use thenginx.ingress.kubernetes.io/rewrite-targetannotation to make sure that I don't lose the part of the url that follows/service2/. So if you were calling anythingbut /service2/ exactly, this might help.
2 Comments
nginx.ingress.kubernetes.io/use-regex: "true" tothis configuration, as suggested before?If you are usingnginx, please check-out thisgithub issue.
If you are usingtraefik try:
apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata: annotations: kubernetes.io/ingress.class: traefik name: my-ingressspec: rules: - http: paths: - path: / backend: serviceName: service1 - path: /service2/ backend: serviceName: service2Comments
Explore related questions
See similar questions with these tags.



