.NET 6升级至.NET 8后AKS中启动探针失败问题求助
.NET 8升级后AKS中服务启动失败:健康检查连接拒绝
近期将服务从.NET 6升级至.NET 8后,在Azure Kubernetes集群(AKS)中完全无法运行。所有服务因AKS健康检查无法连接容器而失败,导致AKS反复重启容器。
报错信息
Startup probe failed: Get "http://x.x.x.x:80/health/startup": dial tcp x.x.x.x:80: connect: connection refused
排查过程
最初怀疑是.NET 8容器化应用默认端口从80改为8080的破坏性变更,按文档设置了环境变量ASPNETCORE_URLS、ASPNETCORE_HTTP_PORTS、ASPNETCORE_HTTPS_PORTS指定端口。但升级前已在容器环境变量及appsettings.json中配置了ASPNETCORE_URLS,理论上应用应继续使用原端口,且已在Dockerfile中添加这些环境变量,问题仍未解决。
尝试增加启动探针超时时间也无效:
startupProbe: httpGet: path: /health/startup port: http timeoutSeconds: 30
关键注意事项
- 未修改该应用的deployment.yaml、service.yaml或ingress.yaml文件,此前这些配置在端口80上运行正常。
- 将应用降级回.NET 6后无需其他变更即可正常运行。
Dockerfile内容
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 ENV ASPNETCORE_URLS=http://+:80 ENV ASPNETCORE_HTTP_PORTS=80 ENV ASPNETCORE_HTTPS_PORTS=443 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["nuget.config", "."] COPY ["NID.Support.API/NID.Support.API.csproj", "NID.Support.API/"] RUN dotnet restore "NID.Support.API/NID.Support.API.csproj" COPY . . WORKDIR "/src/NID.Support.API" RUN dotnet build "NID.Support.API.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "NID.Support.API.csproj" -c Release -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "NID.Support.API.dll"]
补充信息与日志
观察到Kestrel服务似乎在应用关闭后才尝试启动,原因不明。
kubectl日志
[15:34:51 DBG] Registered model binder providers, in the following order: ["Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ServicesModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.HeaderModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.FloatingPointTypeModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.EnumTypeModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.DateTimeModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.SimpleTypeModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.TryParseModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.CancellationTokenModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ByteArrayModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.FormFileModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.FormCollectionModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.KeyValuePairModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.DictionaryModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ArrayModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.CollectionModelBinderProvider", "Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexObjectModelBinderProvider"] [15:34:53 DBG] Hosting starting [15:34:53 WRN] Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed. For more information go to https://aka.ms/aspnet/dataprotectionwarning [15:34:53 INF] User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest. [15:34:53 DBG] Repository contains no viable default key. Caller should generate a key with immediate activation. [15:34:53 DBG] Policy resolution states that a new key should be added to the key ring. [15:34:53 INF] Creating key {xxxx} with creation date 2024-06-12 15:34:53Z, activation date 2024-06-12 15:34:53Z, and expiration date 2024-09-10 15:34:53Z. [15:34:53 DBG] Descriptor deserializer type for key {xxxx} is 'Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. [15:34:53 DBG] No key escrow sink found. Not writing key {xxxx} to escrow. [15:34:53 WRN] No XML encryptor configured. Key {xxxx} may be persisted to storage in unencrypted form. [15:34:53 INF] Writing data to file '/root/.aspnet/DataProtection-Keys/key-xxxx.xml'. [15:34:53 DBG] Key cache expiration token triggered by 'CreateNewKey' operation. [15:34:53 DBG] Reading data from file '/root/.aspnet/DataProtection-Keys/key-xxxx.xml'. [15:34:53 DBG] Found key {xxxx}. [15:34:53 DBG] Considering key {xxxx} with expiration date 2024-09-10 15:34:53Z as default key. [15:34:53 DBG] Using managed symmetric algorithm 'System.Security.Cryptography.Aes'. [15:34:53 DBG] Using managed keyed hash algorithm 'System.Security.Cryptography.HMACSHA256'. [15:34:53 DBG] Using key {xxxx} as the default key. [15:34:53 DBG] Key ring with default key {xxxx} was loaded during application startup. [15:36:05 INF] Application is shutting down... [15:36:05 WRN] Overriding HTTP_PORTS '80' and HTTPS_PORTS '443'. Binding to values defined by URLS instead 'http://*:80;'. [15:36:06 DBG] Middleware configuration started with options: {AllowedHosts = *, AllowEmptyHosts = True, IncludeFailureMessage = True} [15:36:06 DBG] Wildcard detected, all requests with hosts will be allowed. [15:36:06 ERR] Hosting failed to start System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken) at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__14_1(IHostedService service, CancellationToken token) at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation) System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken) at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__14_1(IHostedService service, CancellationToken token) at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation) at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) at Program.<Main>$(String[] args) in /src/NID.Support.API/Program.cs:line 182
内容的提问来源于stack exchange,提问作者Juan P. Garces
相关产品推荐
相关产品推荐

