How to fix routes configuration for the gce ingress?

6/3/2019

The ingress calls random services on requests, and also it calls the root (/). I need ingress to call the specified in the configuration service and send the full path to the service (I use MVC pattern so I need to provide the application with the full path to resolve the correct controller)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: whatever
  annotations:
    ingress.kubernetes.io/add-base-url: "true"
    ingress.kubernetes.io/rewrite-target: "/"
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.global-static-ip-name: "my-static-ip-name"
spec:
  tls:
  - secretName: my-tls-secret
    hosts:
      - whatever.my-awesome-project.com
  rules:
  - host: whatever.my-awesome-project.com
    http:
      paths:
      - path: /api/whatever
        backend:
          serviceName: whatever-service
          servicePort: 80
      - path: /api/not-whatever
        backend:
          serviceName: not-whatever-service
          servicePort: 80
      - path: /images/*
        backend:
          serviceName: not-whatever-service
          servicePort: 80
-- Lex
google-cloud-platform
kubernetes-ingress

1 Answer

7/3/2019

From what I see in your question:

1) you are trying to use rewrite-target with gce ingress --> this wont work. rewrite-target is a nginx ingress controller feature. Btw starting from 0.22.0 version you should use nginx.ingress.kubernetes.io/rewrite-target: "/" instead of ingress.kubernetes.io/rewrite-target: "/"

2)The annotation add-base-url was removed in 0.22.0. And this is also was nginx annotation, not gce. More info here an here.

3)Also I believe you dont need rewrite-target annotation if you would like to have correct path

From my pow there should be something like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: whatever
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/ingress.global-static-ip-name: "my-static-ip-name"
spec:
  tls:
  - secretName: my-tls-secret
    hosts:
      - whatever.my-awesome-project.com
  rules:
  - host: whatever.my-awesome-project.com
    http:
      paths:
      - path: /api/whatever
        backend:
          serviceName: whatever-service
          servicePort: 80
      - path: /api/not-whatever
        backend:
          serviceName: not-whatever-service
          servicePort: 80
      - path: /images/*
        backend:
          serviceName: not-whatever-service
          servicePort: 80

A lot of things depends on what ingress and version you use. Do you have a possibility to move to nginx?

-- VKR
Source: StackOverflow