<p>I am having a problem using Kubernetes Ingress with a ASP.NET core web API.</p>
<p>Lets say I have a web API with three controllers (simplified code to demonstrate three routes /, /ep1, /ep2):</p>
<pre><code>endpoints.MapGet(&quot;/&quot;, async context =&gt;
{
    await context.Response.WriteAsync(&quot;##&quot;);
});

endpoints.MapGet(&quot;/ep1&quot;, async context =&gt;
{
    await context.Response.WriteAsync(&quot;1&quot;);
});

endpoints.MapGet(&quot;/ep2&quot;, async context =&gt;
{
    await context.Response.WriteAsync(&quot;2&quot;);
});
</code></pre>
<p>What I want is to define an ingress rule that will pass the internal route to the application:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: myhost.com
    http:
      paths:
      - path: /(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: myservice
            port:
              number: 80
</code></pre>
<p>Then what I expect to happen is that browsing to myhost.com/ will return &quot;##&quot;, myhost.com/ep1 will return &quot;1&quot; and myhost.com/ep2 will return &quot;2&quot;
However, all three routes return &quot;##&quot;</p>
<p>Am I doing something wrong while configuring the ingress? Is it something that even possible when using ingress rules? If not, how do you create a controller that is using dynamic parameters? Let's say I want a web API that returns the amount in bank for some user ID, when specifying its ID in the GET path: myhost.com/balance/1312323, how can I implement this using a web API and ingress rules with Kubernetes?</p>
<p>Thanks for helping</p>

Ohad
<p>Routing within the app should be handled by the app. So, there should be no need to define dynamic paths. Try this.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: myhost.com
    http:
      paths:
      - path: /
        backend:
          service:
            name: myservice
            port:
              number: 80
</code></pre>
