I cannot get any of the paths under - host: api.mysite.com
work with the GKE Ingress and I dont understand why. I get 404 when I try the routes.
With the sample below, I expect api.mysite.com/v1/
and api.mysite.com/v2/
to route to the appropriate services (which I exposed via nodeport). Unfortunately I'm only getting 404 returned to me.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gce-ingress
namespace: default
annotations:
kubernetes.io/ingress.global-static-ip-name: my-global-ip
spec:
rules:
- host: mysite.com
http:
paths:
- backend:
serviceName: webserver
servicePort: 8080
- host: www.mysite.com
http:
paths:
- backend:
serviceName: webserver
servicePort: 8080
- host: api.mysite.com
http:
paths:
- path: /v2/*
backend:
serviceName: api-v2
servicePort: 9000
- path: /v1/*
backend:
serviceName: api-v1
servicePort: 8000
The nodeports exposing the services:
apiVersion: v1
kind: Service
metadata:
name: webserver
labels:
app: webserver
namespace: default
spec:
selector:
app: webserver
type: NodePort
ports:
- port: 8080
name: http
protocol: TCP
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: api-v2
labels:
app: api-v2
namespace: default
spec:
selector:
app: api-v2
type: NodePort
ports:
- port: 9000
name: http
protocol: TCP
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: api-v1
labels:
app: api-v1
namespace: default
spec:
selector:
app: api-v1
type: NodePort
ports:
- port: 8000
name: http
protocol: TCP
targetPort: 8080
The results when I test the ingress (real hostname and ip redacted):
$ curl api.mysite.com/v1/ -v
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v1/ HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: gunicorn/19.9.0
< Date: Mon, 24 Jun 2019 00:01:34 GMT
< Content-Type: text/html
< X-Frame-Options: SAMEORIGIN
< Content-Length: 77
< Via: 1.1 google
<
{ [77 bytes data]
100 77 100 77 0 0 77 0 0:00:01 --:--:-- 0:00:01 706
* Connection #0 to host api.mysite.com left intact
<h1>Not Found</h1><p>The requested resource was not found on this server.</p>
$ curl api.mysite.com/v2/ -v
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v2/ HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: gunicorn/19.9.0
< Date: Mon, 24 Jun 2019 00:01:37 GMT
< Content-Type: text/html
< X-Frame-Options: SAMEORIGIN
< Content-Length: 77
< Via: 1.1 google
<
{ [77 bytes data]
100 77 100 77 0 0 77 0 0:00:01 --:--:-- 0:00:01 987
* Connection #0 to host api.mysite.com left intact
<h1>Not Found</h1><p>The requested resource was not found on this server.</p>
$ curl api.mysite.com/v1 -v
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v1 HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Mon, 24 Jun 2019 00:01:40 GMT
< Content-Length: 21
< Content-Type: text/plain; charset=utf-8
< Via: 1.1 google
<
{ [21 bytes data]
100 21 100 21 0 0 21 0 0:00:01 --:--:-- 0:00:01 269
* Connection #0 to host api.mysite.com left intact
default backend - 404
$ curl api.mysite.com/v2 -v
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v2 HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Mon, 24 Jun 2019 00:01:44 GMT
< Content-Length: 21
< Content-Type: text/plain; charset=utf-8
< Via: 1.1 google
<
{ [21 bytes data]
100 21 100 21 0 0 21 0 0:00:01 --:--:-- 0:00:01 333
* Connection #0 to host api.mysite.com left intact
default backend - 404
In order to reproduce the issue I followed the next documentation which explains how to setup HTTP Load balancing with Ingress, then as an optional thing you can reserve an static IP address and serving multiple application on the same Load Balancer.
It works fine for me following the above URL step by step:
https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer
Hope it works for you.