I would like to perform path-based dynamic routing to Kubernetes services with support for WebSockets.
For example, this path:
http://10.0.0.1/myport/myservice/foo
should route traffic to service myservice at named port myport (namespace default) with path foo.
I got close to achieving this with Linkerd using the following ConfiMap router entry (using the io.l5d.k8s namer):
routers:
- protocol: http
dtab: |
/svc => /#/io.l5d.k8s/default;
identifier:
kind: io.l5d.path
segments: 2
consume: true
It worked except for that I need WebSocket support which is not available in Linkerd.
I tried NGINX using regular expressions for the location and rewrite rules. This looks something like this:
location ~ ^/(.*?)/.*$ {
rewrite ^/(.*?)/(.*)$ /$2 break;
proxy_pass http://$upstream:$1;
This worked except for that NGINX does not route to services that were created after NGINX was started. I'm not sure whether this is related to DNS caching issues in nginx or to support for SRV DNS records. This scenario should work in NGINX Plus but I must rely on open source software only.
Any ideas which reverse proxy / service mesh supports dynamic routing to K8s service:port as well as WebSockets?
Edit Can this be done with Istio? It seems that one must specify a hard-coded destination in the Istio routing configuration. I can specify a regex on the source (request) but cannot use regex capture groups to specify the destination.
There is no support for dynamically creating destinations based on regex capture groups. You need to define a routing rule per destination.