'ASP.NET Core 6 running in k8s shutting down
OK I´m new to ASP.NET Core 6 and k8s. So far all apps I was hosting (java, js, python) didn't have any issue.
Deployment service and ingress were created successfully but I was having error in pod:
{"EventId":3,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware","Message":"Failed to determine the https port for redirect.","State":{"Message":"Failed to determine the https port for redirect.
I have always managed certificates at ingress level and so far with no issues. I'm always using Nginx also as IC.
After some research I end up with following post:
How to make sure my .NET Core service running in EKS can find the https port?
So basically I decided to remove the C# code the https redirection I saw in developers code and rebuild image app.UseHttpsRedirection();
. This way I can managed security ssl as I said, from ingress level. (Here is the commented line)
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
//app.UseHttpsRedirection();
So now I tested new Docker image locally and it works.
But inside kubernetes I'm getting:
There are no redirects errors but I'm just getting "application is shutting down now".
Any idea what this can be related to?
Ingres secret with certificates were created successfully and ingres is using that secret for tls.
here describe pod.
Solution 1:[1]
I am not sure about your configuration, but I had the similar "application is shutting down now" issue and found out that I missed .AddHealthChecks() and .UseHealthChecks("/health") in Startup.cs file. Your reason can be different, but maybe this will give you a hint :)
Solution 2:[2]
ok So Application was running but giving 404, so k8s interpreted that as unhealthy. So I added the health check in the liveness and readiness probe like: path: /healthy and that way it started to give the 200 code and container started to run normally.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dina Sergienko |
Solution 2 | Chanafot |