首页 > 解决方案 > 当 Docker compose 为 Dotnet 核心项目工作时,Kubernetes 因 SSL 错误而失败

问题描述

我是 Kubernetes 的新手,我正在本地开发中尝试其中的一些。在我在这里给出我的问题陈述之前是我的环境和我的项目的状态。

  1. 我有启用 WSL2 的 Windows 10 和通过 VS Code 运行的 Ubuntu。
  2. 我已经在 VS Code 中启用了所需的插件(如 Kubernetes、Docker 等)
  3. 我安装了启用了 WSL2 + Ubuntu + Kubernetes 的 Docker 桌面。
  4. 我通过 Docker 从本地系统 + ubuntu 获得了 ASP.Net Core 5 工作版本
  5. 我有 dockerfile + docker compose 文件,并且我已经对它们进行了测试,无论是否使用 SSL 端口,并且这些都可以使用 SSL,也可以不使用 SSL。(为此我修改了程序以接受非 SSL 请求)。

来到 docker 文件——它需要像 5000(对于非 SSL)和 5001(对于 SSL)这样暴露的端口进入 docker compose 文件——它需要像5000:805000:443

-- 它还具有用于 URL 的环境变量,例如

ASPNETCORE_URLS=https://+5001;http://+5000

-- 它还具有证书路径的环境变量,例如

ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx

-- 它还有证书密码的环境变量,比如

ASPNETCORE_Kestrel__Certificates__Default__Password=SECRETPASSWORD

现在,当我说它docker compose up --build构建项目并启动容器时。我可以通过 https://localhost:5001 和 http://localhost:5000 访问该站点

现在,来到 kubernets——我已经使用 kompose 工具来生成 kubernetes 特定的 yaml 文件——我没有对此进行任何更改。我运行了命令kompose convert -f docker-compose.yaml -o ./.k8 ——最后,我运行了kubectl apply -f .k8

它启动容器但立即失败。我检查了日志,它显示以下内容:

crit: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to start Kestrel.
      Interop+Crypto+OpenSslCryptographicException: error:2006D080:BIO routines:BIO_new_file:no such file
         at Interop.Crypto.CheckValidOpenSslHandle(SafeHandle handle)
         at Internal.Cryptography.Pal.OpenSslX509CertificateReader.FromFile(String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
         at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
         at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Certificates.CertificateConfigLoader.LoadCertificate(CertificateConfig certInfo, String endpointName)
         at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert()
         at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
         at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
         at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
         at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
Unhandled exception. Interop+Crypto+OpenSslCryptographicException: error:2006D080:BIO routines:BIO_new_file:no such file

标签: sslkubernetesdocker-composekompose

解决方案


在“It has required mapping like 5000:80and 5000:443”中,实际上应该是5001:443(因为端口5001用于映射到https 443端口)。

基于此错误消息

“nterop+Crypto+OpenSslCryptographicException:错误:2006D080:BIO 例程:BIO_new_file:没有这样的文件”,

证书文件似乎不存在于以下位置:/https/aspnetapp.pfx

使用以下 Docker 命令运行映像:

docker run -it --entrypoint sh <image name>

您将在不运行入口点的情况下访问容器cd /https/,请检查证书是否位于此文件夹中,如果不是,这可能是问题所在。


推荐阅读