I've seen many examples online of doing the following, straight from the rewrite docs:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: rewrite
namespace: default
spec:
ingressClassName: nginx
rules:
- host: rewrite.bar.com
http:
paths:
- path: /something(/|$)(.*)
pathType: Prefix
backend:
service:
name: http-svc
port:
number: 80
However, we have an API that dynamically creates services, and would like to have a single ingress to manage them. All I'm asking is, does this work? Or something like it?
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: direct-to-service-by-name
namespace: default
spec:
ingressClassName: nginx
rules:
- host: rewrite.bar.com
http:
paths:
# Match any character but / and put it in capture group $1
- path: /([^\/]+)
pathType: Prefix
backend:
service:
# Name the service based on capture group 1
name: $1
port:
number: 80