I am using a IHostedService to register my pods inside the k8s cluster. It all runs fine but when I need to update or scale my deployments I get zombie pods hanging around in Consul.
My IHostedService implements the StopAsync as follows:
public async Task StopAsync(CancellationToken cancellationToken)
{
_cts.Cancel();
_logger.LogInformation("De-registering from Consul");
try
{
await _consulClient.Agent.ServiceDeregister(_registrationId, cancellationToken);
}
catch (Exception ex)
{
_logger.LogError(ex, $"De-registration failed");
}
}
I also tried injecting in IHostApplicationLifetime and registering an ApplicationStopping but it's the same deal - these functions never get called unless I physically press ctrl +c which obviously isn't happening inside k8s
How is everyone deregistering their pods?
I'm using netcore 3.1