Quantcast
Channel: Chaminda's DevOps Journey with MSFT
Viewing all articles
Browse latest Browse all 340

Linux AKS Scaled Jobs Handle Graceful Termination for dotnet App using IHostedService

$
0
0

 We have discussed "Windows AKS Scaled Jobs Handle Graceful Termination for dotnet App using IHostedService When Preemption" previously. However,  for Linux scaled jobs we have to handle the graceful termination, using a bash script intead of a PowerShell script.

We can create a script with bash as shown below.


Copyable code is below.

#!/bin/bashwaitBeforeShutDownSignal=$1;
sleep $waitBeforeShutDownSignal;

dotnet_pid=$(pgrep dotnet);

if[ -n "$dotnet_pid"]; then    while kill -0 "$dotnet_pid" 2>/dev/null; dosleep 1;
    donefi

Copy the file to base image in the dockerfile and enable execution for the script.


Then we can use it in scaled job deployment manifest to setup the pre stop hook as shown below..

terminationGracePeriodSeconds: 15000
containers:
  - name: ${aks_app_name}$
    lifecycle:
      preStop:
        exec:
          command: ["/bin/sh","-c","/app/wait_linux_container_gracefully.sh10"]

This will ensure the preemtion request will not terminate the Linux scaled job, until the termination grace period is over, or the job execution completed. If the termination grace period is setup sufficiently, the job execution to the completion can be guranteed.


Viewing all articles
Browse latest Browse all 340

Trending Articles