【问题标题】:dotnet core app api do not keep running on kubernetesdotnet core app api 不在 kubernetes 上继续运行
【发布时间】:2019-02-11 23:58:32
【问题描述】:

我正在将一个 dotnet 核心应用程序设置到 kubernetes 集群中,并且出现错误“无法启动 kestrel”。

Dockerfile 在本地机器上运行正常。

at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
Unhandled Exception: System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found.
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found.
Unable to start Kestrel.

我的码头文件:

[...build step]
FROM microsoft/dotnet:2.1-aspnetcore-runtime
COPY --from=build-env /app/out ./app
ENV PORT=5000
ENV ASPNETCORE_URLS=http://+:${PORT}
WORKDIR /app
EXPOSE $PORT
ENTRYPOINT [ "dotnet", "Gateway.dll" ]

我希望应用程序成功启动,但我收到此错误“无法启动 kestrel”。

[更新]

我已经从应用程序中删除了 https 端口并在没有 https 的情况下再次尝试,但现在应用程序只是启动和停止而没有任何错误或警告。容器日志如下:

使用 dotnet run 在本地运行或构建映像并从容器运行,一切正常。应用程序刚刚关闭到 Kubernetes。

我正在使用 dotnet core 2.2

[更新]

我生成了一个证书,在项目中添加,在红隼中设置,我得到了相同的结果。使用 docker imagem 的本地主机可以工作,但在 Kubernetes(谷歌云)中,它只是在启动后立即关闭。

本地主机:

$ docker run --rm -it -p 5000:5000/tcp -p 5001:5001/tcp juooo:latest
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {f7808ac5-0a0d-47d0-86cb-c605c2db84a3} may be persisted to storage in unencrypted form.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'https://+:5001, http://+:5000'. Binding to endpoints defined in UseKestrel() instead.
Hosting environment: Production
Content root path: /app
Now listening on: https://0.0.0.0:5001
Application started. Press Ctrl+C to shut down.

【问题讨论】:

  • 在我的 kubernetes 集群上,我们在负载均衡器上终止 ssl,因此我们不必在代码中处理 https。
  • 能否使用kubectl describe添加Kubernetes部署yaml和事件日志

标签: kubernetes google-cloud-platform dockerfile


【解决方案1】:

我发现了一个带有 kubernetes 错误的事件日志,指出 kubernetes 无法命中 (:5000/)。所以我尝试创建一个针对 root 应用程序的控制器(因为它是一个 api,所以没有像 web 应用程序那样的 root)并且它起作用了。

【讨论】:

  • 我应该说我在 pod event 中找到了这个信息到 kubernetes 中。
【解决方案2】:

问题似乎是在创建 docker 映像时未正确配置 SSL 证书。在开发机器上,它将使用开发人员证书,但在其他机器上它应该存储在某个地方。检查this

【讨论】:

  • 我尝试删除 https 设置,但应用程序仍未运行
【解决方案3】:

我很确定您需要打开防火墙规则才能在 80 以外的任何端口上运行,例如:

gcloud compute firewall-rules create test-node-port --allow tcp:5000

取自 kubernetes 操作指南,位于此处:https://cloud.google.com/kubernetes-engine/docs/how-to/exposing-apps

【讨论】:

    猜你喜欢
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    • 2017-09-15
    • 2022-11-15
    相关资源
    最近更新 更多