<p>I am running an airflow cluster on EKS on AWS. I have setup some scaling config for worker setup. If CPU/Mem &gt; 70% then airflow spins up new worker pod. However I am facing an issue when these worker pods are scaling down. When worker pods start scaling down, two things happen:</p>
<ol>
<li>If no tasks is running on a worker pod, it terminates within 40sec.</li>
<li>If any task is running on a worker pod, it terminates in about 8min, and after one more minute, I find the task failing on UI.</li>
</ol>
<p>I have setup below two properties in helm chart for worker pod termiantion.</p>
<pre><code>celery:
    ## if celery worker Pods are gracefully terminated
    ## - consider defining a `workers.podDisruptionBudget` to prevent there not being
    ##   enough available workers during graceful termination waiting periods
    ##
    ## graceful termination process:
    ##  1. prevent worker accepting new tasks
    ##  2. wait AT MOST `workers.celery.gracefullTerminationPeriod` for tasks to finish
    ##  3. send SIGTERM to worker
    ##  4. wait AT MOST `workers.terminationPeriod` for kill to finish
    ##  5. send SIGKILL to worker
    ##
    gracefullTermination: true

    ## how many seconds to wait for tasks to finish before SIGTERM of the celery worker
    ##
    gracefullTerminationPeriod: 180

  ## how many seconds to wait after SIGTERM before SIGKILL of the celery worker
  ## - [WARNING] tasks that are still running during SIGKILL will be orphaned, this is important
  ##   to understand with KubernetesPodOperator(), as Pods may continue running
  ##
  terminationPeriod: 120
</code></pre>
<p>I can see that worker pod should shutdown after 5 mins or irrespective task running or not. So I am not sure why I see total of 8 min for worker pod termination. And my main issue is there any way I can setup config so that worker pod only terminates when task running on it finishes execution. Since tasks in my dags can run anywhere between few minutes to few hours so I don't want to put a large value for <strong>gracefullTerminationPeriod</strong>. I Would appreciate any solution around this.</p>
<p>Some more info: Generally the long running task is a python operator which runs either a presto sql query or Databricks job via Prestohook or DatabricksOperator respectively. And I don't want these to recivie SIGTERM before they complete their execution on worker pod scaling down.</p>

bha159
<p>This is not possible due to limitations from K8 end. More details are available <a href="https://github.com/kubernetes/kubernetes/issues/107598" rel="nofollow noreferrer">here</a>. However by using a large value of &quot;gracefulTerminationPeriod&quot; works, although this is not what I intended to do but it works better than I originally thought. When large value of gracefulTerminationPeriod is set, workers doesn't wait around for gracefulTerminationPeriod time to terminate. If a worker pod is marked for termination it terminates as soon as tasks running on it reaches zero.</p>
<p>Until K8 accept proposed changes and new community helm chart is released, I think this is the best solution without incurring costs of keeping worker up.</p>
