The pods deployed to AKS gets terminated due to reschduling, low priority evictions as well as during scaled in. We can add a termination grase period and pre stop sleep time as shown below in Linux and Windows containers to allow, sufficient time to ingress services to get updated about terminating pods. However, Windows nanoserver does not support PowerShell. Therefore, we need to use a specific mechanism to pre stop hook for nanoserver images. For nanoserver images shutdown signal is correctly get sent to the dotnet app. So we can just setup a sllep time for pre stop hook as necessary.
Here is the solution for nanoserver Windows images.
Why ping 127.255.255 you can read here in comments that it is default Windows broadcast loop back address. The input to this is taken from answers here as well.
"cmd", "/c", "ping 127.255.255.255 -n 1 -w 300000 > nul"
Above long timeout of 5 minutes in pre stop hook is for ingress enebaled apps so that ingress service has enough time to remove traffic for terminating pod. but for backgroud jobs you may use a smaller timout such as 10 seconds as shown below.
"cmd", "/c", "ping 127.255.255.255 -n 1 -w 10000 > nul"
For other Windows images such as Windows server core, we can use bellow for where ingress requests need to be handled gracefully in terminating pods providing enough time to update ingress services..
"powershell.exe","-File","C:/app/exit_windows_container_gracefully.ps1","-waitBeforeShutDownSignal","300"
Refer the post "Gracefully Shut Down dotnet 8 IHostedService App - Deployed as a Windows Container in AKS - While Scale In or Pod Deallocations" for more setails on Windows server core and server images grceful shut down.
For Linux it can be simpler command like below. In Linux pods dotnet app container receive SIGTERM correctly. Therefore, no special mechanism required. Should use a longer sleep in pre stop hook such as 300 seconds for ingress services to get updated on terminating pods.
"sleep","300"
For Linux background services pod the timout can be set to a smaller value.
"sleep","10"
No comments:
Post a Comment