<p>I have the following ingress.yml:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress 
metadata:
  name: ingress 
  namespace: default 
  annotations:
    kubernetes.io/ingress.class: "nginx" 
    nginx.ingress.kubernetes.io/ssl-redirect: "false" 
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  labels: 
    app: ingress 
spec:
  rules:  
    - host: 
      http:   
        paths:
          - path: /apistarter(/|$)(.*)
            backend:
              serviceName: svc-aspnetapistarter
              servicePort: 5000
          - path: //apistarter(/|$)(.*)
            backend:
              serviceName: svc-aspnetapistarter
              servicePort: 5000
</code></pre>

<p>After deploying my ASP.Net Core 2.2 API application and navigate to <code>http://localhost/apistarter/</code>, browser debugger console shows errors loading the static content and Javascripts. In addition, navigating to <code>http://localhost/apistarter/swagger/index.html</code> results in</p>

<pre><code>Fetch error Not Found /swagger/v2/swagger.json
</code></pre>

<p>I am using the SAME ingress for multiple micro-services using different path prefix. It is running on my local kubernetes cluster using microk8s. Not on any cloud provider yet. I have checked out <a href="https://stackoverflow.com/questions/52404475/how-to-configure-an-asp-net-core-multi-microservice-application-and-azure-aks-in">How to configure an ASP.NET Core multi microservice application and Azure AKS ingress routes so that it doesn&#39;t break resources in the wwwroot folder</a> and <a href="https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1</a> but none of these helps.</p>

Kok How Teh
<p>Follow these steps to run your code:</p>

<ol>
<li><strong>ingress</strong>: remove URL-rewriting from <em>ingress.yml</em></li>
</ol>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress 
metadata:
  name: ingress 
  namespace: default 
  annotations:
    kubernetes.io/ingress.class: "nginx" 
    nginx.ingress.kubernetes.io/ssl-redirect: "false" 
  labels: 
    app: ingress 
spec:
  rules:  
    - host: 
      http:   
        paths:
          - path: /apistarter # &lt;---
            backend:
              serviceName: svc-aspnetapistarter
              servicePort: 5000
</code></pre>

<ol start="2">
<li><strong>deployment</strong>: pass environment variable with <em>path base</em> in <em>ingress.yml</em></li>
</ol>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
# ..
spec:
  # ..
  template:
    # ..
    spec:
      # ..
      containers:
        - name: test01
          image: test.io/test:dev
          # ...
          env:
            # define custom Path Base (it should be the same as 'path' in Ingress-service)
            - name: API_PATH_BASE # &lt;---
              value: "apistarter"
</code></pre>

<ol start="3">
<li><strong>program</strong>: enable loading environment params in <em>Program.cs</em></li>
</ol>

<pre class="lang-cs prettyprint-override"><code>var builder = new WebHostBuilder()
    .UseContentRoot(Directory.GetCurrentDirectory())
    // ..
    .ConfigureAppConfiguration((hostingContext, config) =&gt;
    {
        // ..  
        config.AddEnvironmentVariables(); // &lt;---
        // ..
    })
    // ..
</code></pre>

<ol start="4">
<li><strong>startup</strong>: apply <em>UsePathBaseMiddleware</em> in <em>Startup.cs</em></li>
</ol>

<pre class="lang-cs prettyprint-override"><code>public class Startup
{
    public Startup(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    private readonly IConfiguration _configuration;

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        var pathBase = _configuration["API_PATH_BASE"]; // &lt;---

        if (!string.IsNullOrWhiteSpace(pathBase))
        {
            app.UsePathBase($"/{pathBase.TrimStart('/')}");
        }

        app.UseStaticFiles(); // &lt;-- StaticFilesMiddleware must follow UsePathBaseMiddleware

        // ..

        app.UseMvc();
    }

    // ..
}
</code></pre>
