Consul’s ingress gateway and service mesh sidecars do not currently support configuring regex rewrites in Envoy, although I think this would be a worthwhile feature to support.
In order to implement similar functionality with the string replacement functionality of the prefix rewrite feature, you would need to use the following configuration.
---
apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceRouter
metadata:
name: ingress-fanout-virtual-service
spec:
routes:
- match:
http:
pathExact: /analytics/spark/master
destination:
service: spark-master-svc
prefixRewrite: /
- match:
http:
pathPrefix: /analytics/spark/master/
destination:
service: spark-master-svc
# This will replace '/analytics/spark/master/' in the path with '/'.
# Any values proceeding the trailing slash will remain in the path.
# For example, a request to '/analytics/spark/master/foo' will be written to '/foo'
prefixRewrite: /
- match:
http:
pathExact: /analytics/jupyter/lab
destination:
service: jupyter-proxy-public
prefixRewrite: /
- match:
http:
pathPrefix: /analytics/jupyter/lab/
destination:
service: jupyter-proxy-public
prefixRewrite: /
---
apiVersion: consul.hashicorp.com/v1alpha1
kind: IngressGateway
metadata:
name: ingress-fanout-gateway
spec:
listeners:
- port: 80
protocol: http
services:
- name: ingress-fanout-virtual-service
Envoy’s documentation for the prefix_rewrite parameter explains the reason that multiple match directives are required.
I’m not sure whether Consul’s API Gateway currently supports using regular expressions to rewrite paths. In looking at the code, it appears it might support regex path matching, but not rewriting. My colleague @Jeff-Apple can confirm these details.