0

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: 9090

Only 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?

askedDec 21, 2019 at 21:01
Eliot's user avatar
4
  • What do you get onservice2? 404?CommentedDec 21, 2019 at 23:46
  • Yes, I get a404 onservice2.CommentedDec 22, 2019 at 22:23
  • 1
    Do you have actually anything serving on path/service2 of your backend?CommentedDec 23, 2019 at 8:48
  • 1
    404 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 furtherCommentedDec 23, 2019 at 18:14

3 Answers3

1

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: 9090
answeredDec 21, 2019 at 23:13
Kamol Hasan's user avatar
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This seems to work on Minikube, but I'm still having issues on GKE. By changing my services to kindNodePort 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.
0

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: 8080

The notable differences are:

  1. Paths are flipped so that the more specific one is higher up. Not sure if that has any influence.
  2. Changed the simple wildcard to a look-ahead:* =>?(.*). This allows me to use thenginx.ingress.kubernetes.io/rewrite-target annotation 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.
answeredDec 22, 2019 at 23:58
Avius's user avatar

2 Comments

Interesting. This works exactly as my config does on Minikube, but on GKE I get this error: ``` Error during sync: error running load balancer syncing routine: loadbalancer default-my-ingress--cbc24f100656b420 does not exist: CreateUrlMap: googleapi: Error 400: Invalid value for field 'resource': '{ "name": "k8s-um-default-my-ingress--cbc24f100656b420", "hostRule": [{ "host": ["*"], ...'. Invalid path pattern, invalid ```
Have you tried addingnginx.ingress.kubernetes.io/use-regex: "true" tothis configuration, as suggested before?
0

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: service2
answeredJan 8, 2020 at 9:49
fluktuid's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.