如何配置ASP.net Core来使用kubernetes NGINX入口



我有一个问题与ASP。netcore和kubernetes入口。我有2个微服务前端和后端和前端,我可以看到网站,但所有的wwwroot内容不可用。

如果我去测试。当我把鼠标悬停在CSS文件上时,它说它正在查看test.local/CSS/style.css,而不是test.local/web/CSS/style.css。当我手动转到test.local/web/CSS/style.css时,CSS文件在那里。

ingressrule:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test
namespace: test
spec:
ingressClassName: nginx
rules:
- host: "test.local"
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api
port:
number: 80
- path: /webui
pathType: Prefix
backend:
service:
name: webui
port:
number: 80

startup.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace rmn.WebUI
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UsePathBase("/webui");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
}
}

我也试过用不同的重写注解。

试试这样

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cafe-ingress
annotations:
kubernetes.io/ingress.class: "nsx"
ncp/use-regex: "True"
#/tea/cup will be rewritten to /cup before sending request to endpoint
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: cafe.example.com
http:
paths:
- path: /tea/(.*)
backend:
serviceName: tea-svc
servicePort: 80
- path: /coffee/(.*)
backend:
serviceName: coffee-svc
servicePort: 80

相关内容

  • 没有找到相关文章

最新更新