Cannot reach resource through ingress on GKE

纵然是瞬间 提交于 2019-12-24 18:26:07

问题


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/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  namespace: default
spec:
  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?


回答1:


If you're using the default ingress controller of GKE, then the yaml looks good to me. I will suggest you, to recheck the services (i.e. service1, service2) of NodePort type and make sure that they are working fine.

In case you're using the NGINX Ingress Controller of the version above or equal to nginx-0.20.0, you need to set the nginx.ingress.kubernetes.io/use-regex annotation to true (the default is false) to enable the case sensitive regular expression.

Just like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  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



回答2:


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/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  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 the nginx.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 anything but /service2/ exactly, this might help.


来源:https://stackoverflow.com/questions/59439811/cannot-reach-resource-through-ingress-on-gke

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!