繁体   English   中英

ASP.NET Core 2.0在Kubernetes中启动Kestrel时出错

[英]ASP.NET Core 2.0 Error starting Kestrel in Kubernetes

创建了一个新的ASP.NET Core 2.0项目,它在本地运行良好。 然后在本地运行Docker容器后它也可以正常工作。 但是当我尝试在Kubernetes pod中使用Docker镜像时,它会运行几分钟然后给我这个:

    Unhandled Exception: System.InvalidOperationException: A path base can 
    only be configured using IApplicationBuilder.UsePathBase().
    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.
    <BindAddressAsync>d__7.MoveNext()

这是我的Program.cs

public class Program
{
    public static void Main(string[] args)
    {
         BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
         WebHost.CreateDefaultBuilder(args)
             .UseStartup<Startup>()
             .Build();
}

Startup.cs

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true,
                ReactHotModuleReplacement = true
            });
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

            routes.MapSpaFallbackRoute(
                name: "spa-fallback",
                defaults: new { controller = "Home", action = "Index" });
        });
    }
}

当发生此错误时,我们使用FROM microsoft/aspnetcore-build:1.1基本映像作为构建和运行时。 当我们遇到错误时,我们只是尝试升级到FROM microsoft/aspnetcore-build:2.0 我不确定这个图像的具体问题是什么,但Kubernetes不喜欢它。

稍后,我们将dockerfile切换为多级; 使用FROM microsoft/aspnetcore-build:1.1并使用FROM microsoft/dotnet:1.1-runtime ,当我们将其升级到相应的2.0版本时,我们没有再遇到此错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM