How to configure an ASP.NET Core multi microservice application and Azure AKS ingress routes so that it doesn't break resources in the wwwroot folder

I have two ASP.NET Core apps. One is a Headless CMS (API), and the other one is a Razor Pages blog front-end (with a REST client that communicates with the Headless CMS/API).

I then have an Azure AKS cluster. In it I have an ingress resource with the following routes (as per the instructions from the following AKS docs: https://docs.microsoft.com/en-us/azure/aks/ingress-tls#create-an-ingress-route ). Each route is mapped to each of the apps/services mentioned above:

spec:
  rules:
  - host: mydomain.westeurope.cloudapp.azure.com
    http:
      paths:
      - backend:
          serviceName: headless-cms-svc
          servicePort: 80
        path: /
      - backend:
          serviceName: blog-svc
          servicePort: 80
        path: /blog

When I now navigate to the first route, mydomain.westeurope.cloudapp.azure.com, the headless CMS app works as expected but when I navigate to the second route , mydomain.westeurope.cloudapp.azure.com/blog, I get a bunch of 404:s because the blog apps root path is now relative to the /blog ingress route which in turn breaks all the resources (css, javascript, images etc) in the wwwroot folder.

How should I configure my ASP.NET Core blog app and/or my ingress object?

404:s

https://mydomain.westeurope.cloudapp.azure.com/css/site.min.css?v=kHvJwvVAK1eJLN4w8xygUR3nbvlLmRwi5yr-OuAO90E

https://mydomain.westeurope.cloudapp.azure.com/images/banner1.svg

https://mydomain.westeurope.cloudapp.azure.com/images/banner2.svg

https://mydomain.westeurope.cloudapp.azure.com/js/site.min.js?v=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU

If I add the URL segment /blog the resources get served properly. https://mydomain.westeurope.cloudapp.azure.com/blog/images/banner1.svg <- works

And here is a regular img tag in the Index.cshtml Razor page (from a default ASP.NET Core 2.1 Razor Pages web application). I haven't changed anything in the code.

<img src="~/images/banner1.svg" alt="ASP.NET" class="img-responsive" />

Microservices architecture on Azure Kubernetes Service (AKS , How to configure an ASP.NET Core multi microservice application and Azure AKS ingress routes so that it doesn't break resources in the wwwroot folder. This reference architecture shows a microservices application deployed to Azure Kubernetes Service (AKS). It describes a basic AKS configuration that can be the starting point for most deployments. This article assumes basic knowledge of Kubernetes. The article focuses mainly on the infrastructure and DevOps considerations of running a

You want to annotate your Ingress with nginx.ingress.kubernetes.io/rewrite-target. For example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: mydnsname.westeurope.cloudapp.azure.com
    http:
      paths:
      - backend:
          serviceName: headless-cms-svc
          servicePort: 80
        path: /
      - backend:
          serviceName: blog-svc
          servicePort: 80
        path: /blog

Hope it helps!

Implementing API Gateways with Ocelot, An ingress exposes HTTP(S) routes to services inside the cluster. Note that AKS does not require Azure Container Registry. Apply resource constraints to a namespace, so that the total set of The base layers include the OS image and application framework images, such as ASP.NET Core or Node.js. Azure Application Gateway is used to expose an SSL-enabled endpoint to clients running in the browser and to the native Xamarin app, and routes requests to the Web applications deployed in AKS. Azure Active Directory (Azure AD) is used to authenticate the users of the admin portal while Azure Active Directory B2C (Azure AD B2C) is used for the

Follow these steps to run your code:

  1. deployment: pass environment variable with path base in k8s-yaml-file
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 # <---
              value: "blog"
  1. program: enable loading environment params in Program.cs
var builder = new WebHostBuilder()
    .UseContentRoot(Directory.GetCurrentDirectory())
    // ..
    .ConfigureAppConfiguration((hostingContext, config) =>
    {
        // ..  
        config.AddEnvironmentVariables(); // <---
        // ..
    })
    // ..
  1. startup: apply UsePathBaseMiddleware in Startup.cs
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"]; // <---

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

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

        // ..

        app.UseMvc();
    }

    // ..
}

Create ingress with automatic TLS, Learn how to implement API Gateways with Ocelot and how to use NET Core Web API project with several controllers and methods like in the FROM mcr.​microsoft.com/dotnet/core/aspnet:3.1 AS base WORKDIR /app EXPOSE 80 But the application is configured so it accesses all the microservices  How to configure an ASP.NET Core multi microservice application and Azure AKS ingress routes so that it doesn't break resources in the wwwroot folder Problem It seems that your proxy rewrites the path.

Create an ingress controller, Learn how to install and configure an NGINX ingress controller that Using an ingress controller and ingress rules, a single IP address can be used to route Finally, two applications are run in the AKS cluster, each of which is with client source IP preservation enabled, TLS pass-through will not work. Congrats!! You have just built an ASP.NET Core Web API and deployed it as a containerized microservice on Azure Kubernetes Service!! In the next section, we will define a Release Pipeline in Azure DevOps to automate containerized application deployments on AKS. H. Define and execute Claims API Release Pipeline in Azure DevOps Services

NGINX Ingress Controller Configuration In AKS, Learn how to install and configure a basic NGINX ingress controller in an Azure Kubernetes Service (AKS) cluster. Python .NET · JavaScript · Java · Go with client source IP preservation enabled, SSL pass-through will not work. To route traffic to each application, create a Kubernetes ingress resource. Azure hosting recommendations for ASP.NET Core web apps. 06/06/2019; 9 minutes to read; In this article "Line-of-business leaders everywhere are bypassing IT departments to get applications from the cloud (also known as SaaS) and paying for them like they would a magazine subscription.

service-fabric-acs-kubernetes-multi-container-app/README.md at , Ocp-Apim-Subscription-Key and Ocp-Apim-Trace are custom headers which we need to use to make use of Azure API management resource. So far you've been running your application's code as if you were the only developer working on the app. In this section, you'll learn how Azure Dev Spaces streamlines team development: Enable a team of developers to work in the same environment, by working in a shared dev space or in distinct dev spaces as needed.

Comments
  • If I got you correctly, your proxy path rewriting works. It should add some info about original path, host, protocol to http headers. Now your app must respect these headers. That's described here: docs.microsoft.com/en-us/aspnet/core/host-and-deploy/…
  • Tried some of the examples but can't get it to work. In particular I've tested all three examples in "Deal with path base and proxies that change the request path". Not sure though if I'm doing it right because I'm finding it very difficult to debug since the execution takes place in Startup.cs plus I'm using Azure AKS with an ingress which makes it difficult to test locally.
  • Your problem is, that your app generates wrong links. Correct? - Can you add one link including expected and wrong url and how you generate that link in your code?
  • For debugging I'd add logging (path + protocol). There's a copy and paste example docs.microsoft.com/en-us/aspnet/core/host-and-deploy/…
  • I have updated the question. Regarding logging; I don't see anything unusual about the headers that code snippet spits out.
  • Seems to work. How do I know where to put those lines? I checked the entire middleware documentation but it lacks good examples. Because order is important.
  • Think about what "middleware" means: It's just one function (middleware) calling the next function (middlware) in the order you added them with your UseXY() calls. Here the MVC middleware needs the PathBase property filled but there should be no other middleware that requires an empty PathBase - that's why I wrote "add before any middleware".
  • It's already there. docs.microsoft.com/en-us/azure/aks/…
  • Sounds like a Kubernetes bug
  • I don't think it's a bug. I think I just have to configure my app properly.