Ingress won't route to something other than / (kubernetes, gcp)

11/18/2019

So I am trying to get a basic gcp kubernetes cluster up and running by following this tutorial https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/

However I am stuck on making ingress route to my image using any route other than /, I tried for a long time different approaches, I think I might be missing something obvious here because I'm actually starting to go crazy.

For context, I am on google cloud plateform, I built a basic flask app, dockerize it and saved it on google container registry. I created a basic deployment for the flask image:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: flask-app-tutorial
  labels:
    name: flask-app-tutorial
spec:
  replicas: 1
  selector:
    matchLabels:
      name: flask-app-tutorial
  template:
    metadata:
      name: flask-app-tutorial
      labels:
        name: flask-app-tutorial
    spec:
      containers:
        - name: flask-app-tutorial
          image: gcr.io/my-project/flask-app:v1
          ports:
            - containerPort: 8080
          resources:
            requests:
              memory: 256Mi
            limits:
              memory: 512Mi
          env:
            - name: DEBUG_MODE
              value: "1"

I then exposed this deployment using this command line:

kubectl expose deployment flask-app-tutorial --target-port=8080 --type=NodePort

a service is then created.

Then when I try to expose a route via this ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: flask-app-tutorial
          servicePort: 8080
      - path: /server/*
        backend:
          serviceName: flask-app-tutorial
          servicePort: 8080

Ingress is created and all backends are healthy after a while ip-address/ is reachable and would request the appropriate server:

curl -I ip-address
HTTP/1.1 200 OK
Server: gunicorn/19.9.0
Date: Mon, 18 Nov 2019 15:45:23 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 12
Via: 1.1 google

However ip-address/server/ is giving me a 404:

curl -I ip-address/server/
HTTP/1.1 404 NOT FOUND
Server: gunicorn/19.9.0
Date: Mon, 18 Nov 2019 15:46:06 GMT
Content-Type: text/html
Content-Length: 233
Via: 1.1 google

I read somewhere that an ingress controller should be involved somehow, I really don't understand why since when I try to route the same /server but using another image (hashicorp/http-echo for example) then everything works fine.

The flask app is nothing special, a basic hello world: https://gist.github.com/pyk/f9c183466062e8ff63efaa46e7c5485f#file-app-py https://gist.github.com/pyk/51a7db451f2ab66d9764df04cfb0222b#file-config-py

Any advice is welcome since I exhausted a lot of hours trying to figure out what went wrong, I don't have a devops background as you might imagine.

Thank you in advance!

-- stuckoningress
docker
flask
google-cloud-platform
kubernetes

0 Answers