I have the following kubernetes ingress configuration (nginx ingress controller) which works fine.
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
name: test01-api-ingress
namespace: test01
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: test01-new-api-1
servicePort: 80
path: /test01/api1
- backend:
serviceName: test01-new-api-2
servicePort: 80
path: /test01/api2
The above creates the following configuration (mostly omitted)
location ~* "^/test01/api2\/?(?<baseuri>.*)" {
set $namespace "test01";
set $ingress_name "test01-api-ingress";
set $service_name "test01-new-api-2";
set $service_port "80";
set $location_path "/test01/api2";
rewrite "(?i)/test01/api2/(.*)" /$1 break;
rewrite "(?i)/test01/api2$" / break;
proxy_pass http://upstream_balancer;
proxy_redirect off;
}
location ~* "^/test01/api1\/?(?<baseuri>.*)" {
set $namespace "test01";
set $ingress_name "test01-api-ingress";
set $service_name "test01-new-api-1";
set $service_port "80";
set $location_path "/test01/api1";
rewrite "(?i)/test01/api1/(.*)" /$1 break;
rewrite "(?i)/test01/api1$" / break;
proxy_pass http://upstream_balancer;
proxy_redirect off;
}
For the upgrade of the nginx ingress controller, the following configuration should change (somehow). But when I apply it the ingress configuration:
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite "(?i)/test01/api1/(.*)" /$1 break;
rewrite "(?i)/test01/api1$" / break;
rewrite "(?i)/test01/ap21/(.*)" /$1 break;
rewrite "(?i)/test01/ap21$" / break;
name: test01-api-ingress
namespace: test01
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: test01-new-api-1
servicePort: 80
path: /test01/api1
- backend:
serviceName: test01-new-api-2
servicePort: 80
path: /test01/api2
I get the following, which doesn't work properly, because it adds api1/api2 at both locations.
location ~* "^/test01/api2" {
set $namespace "test01";
set $ingress_name "test01-api-ingress";
set $service_name "test01-new-api-2";
set $service_port "80";
set $location_path "/test01/api2";
rewrite "(?i)/test01/api1/(.*)" /$1 break;
rewrite "(?i)/test01/api1$" / break;
rewrite "(?i)/test01/ap21/(.*)" /$1 break;
rewrite "(?i)/test01/ap21$" / break;
proxy_pass http://upstream_balancer;
proxy_redirect off;
}
location ~* "^/test01/api1" {
set $namespace "test01";
set $ingress_name "test01-api-ingress";
set $service_name "test01-new-api-1";
set $service_port "80";
set $location_path "/test01/api1";
rewrite "(?i)/test01/api1/(.*)" /$1 break;
rewrite "(?i)/test01/api1$" / break;
rewrite "(?i)/test01/ap21/(.*)" /$1 break;
rewrite "(?i)/test01/ap21$" / break;
proxy_pass http://upstream_balancer;
proxy_redirect off;
}
Any ideas of how will the configuration should be? How can I split it into the relevant locations? thank you.