1

I have an application (demoapp) in GKE which is exposed to internet with a GCE ingress like this:

- host: demoapp.com                                                                                                                                                                                                                
  http:                                                                                                                                                                                                                                 
    paths:                                                                                                                                                                                                                              
    - backend:                                                                                                                                                                                                                          
        serviceName: demoapp-service                                                                                                                                                                                                
        servicePort: 80            

The application has many customers with each customer having their own page with a path scheme like demoapp.com/customers/customer1 I'm rolling out a new version of the application (demoapp2) and would like to gather some feedback first from certain customers. Thus I'd like to route certain customer paths to the new application instead of the old so that the e.g. demoapp.com/customers/customer1 would resolve to demoapp2-service's path instead of demoapp-service's. This however doesn't seem work:

- host: demoapp.com                                                                                                                                                                                                                
  http:                                                                                                                                                                                                                                 
    paths:
    - backend:
        serviceName: demoapp2-service
        servicePort: 80
      path: /customers/customer1                                                                                                                                                                                                        
    - backend:                                                                                                                                                                                                                          
        serviceName: demoapp-service                                                                                                                                                                                                
        servicePort: 80            

I've tried other variations, like adding path: / or path: /* to demoapp-service routing but I guess the working url would be demoapp.com/customers/customer1/customers/customer1 even if the default didn't override the path. So next I thought that I could have something like this in demoapp nginx configuration:

location /customers/customer1 {                                                                                                                                                                                  
      proxy_pass http://demoapp2-service/customers/customer1;
}

But that doesn't seem to work either and I don't see anything in logs. Does anyone know how to pull this scheme off?

Fleuri
  • 145
  • 12

1 Answers1

1

You can dig in the NGINX Plus Ingress Controller rewrite annotation functionality and fit it for your needs.

PLease find official example here.

Example: In the following example we load balance two applications that require URI rewriting:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
  annotations:
    nginx.org/rewrites: "serviceName=tea-svc rewrite=/;serviceName=coffee-svc rewrite=/beans/"
spec:
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea/
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee/
        backend:
          serviceName: coffee-svc
          servicePort: 80
Vit
  • 445
  • 2
  • 10
  • In the end I worked around this problem by rerouting the request in nginx within the target container, but I'll be sure to revisit this answer if I need something more permanent in the future. Marking it as the correct answer now. – Fleuri Feb 04 '19 at 07:05