Eliot
Eliot

Reputation: 85

Cannot reach resource through ingress on GKE

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?

Upvotes: 0

Views: 1069

Answers (3)

fluktuid
fluktuid

Reputation: 155

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

Upvotes: 0

Avius
Avius

Reputation: 6244

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.

Upvotes: 0

Kamol Hasan
Kamol Hasan

Reputation: 13456

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

Upvotes: 1

Related Questions