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?
This config works fine on Minikube, but doesn't on GKE?
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
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:
*
=> ?(.*)
. 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.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