<p>Running in Kubernetes I have a Deployment with autoscaling based on <a href="https://keda.sh/" rel="nofollow noreferrer">Keda</a>.</p>
<p>This Deployment runs long running tasks of several hours and moving to jobs is currently not an option.</p>
<p>Is there any way in Kubernetes to lock a node and/or pod while the long task is running to prevent them from terminating due to down scaling during the long tasks are running?</p>
<p>The only option I currently am aware of it using a long <code>terminationGracePeriodSeconds</code> and making sure the pod exists once the task ends.</p>

<p>You can use a <a href="https://kubernetes.io/docs/tasks/run-application/configure-pdb/" rel="nofollow noreferrer">podDisruptionBudget</a> to achieve that. It will make sure a certain number of pods should always remain online and nodes containing these pods cannot be deleted as long as they don't have a replacement online.</p>
