Cannot reach resource through ingress on GKE

12/21/2019

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?

-- E. Scott
devops
google-cloud-platform
google-kubernetes-engine
kubernetes
kubernetes-ingress

3 Answers

1/8/2020

If you are using nginx, please check-out this github issue.

If you are using traefik try:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
  name: my-ingress
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: service1
      - path: /service2/
        backend:
          serviceName: service2
-- fluktuid
Source: StackOverflow

12/22/2019

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.
-- Avius
Source: StackOverflow

12/21/2019

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
-- Kamol Hasan
Source: StackOverflow