<p>I'm learning k8s hpa autoscale and have one confusion。</p>
<p>if there are some codes run in pod like this:</p>
<pre class="lang-py prettyprint-override"><code># do something1
time.sleep(15)
# do something2
</code></pre>
<p>when execution come to time.sleep(15) and at this time the hpa scale down, will this pod be removed and something2 will not execute？</p>

og f91
<p>There as a few options as to how can you control what should happen when your service goes down. Typically, K8S will send a <code>soft termination</code> to the container's main process, which the process can use to handle gracefully(intercept interrupt signals).
Although, K8S will only wait for <code>terminationGracePeriod</code> time defined in the PodSpec.</p>
<p>You can also use a lifecycle hook called <code>preStop</code> and handle the service termination process externally.</p>
<p>Some information is here in this StackOverflow answer: <a href="https://stackoverflow.com/questions/56552175/is-there-a-way-to-downscale-pods-only-when-message-is-processed-the-pod-finishe">Is there a way to downscale pods only when message is processed (the pod finished its task) with the HorizontalPodAutoscaler in Kubernetes?</a></p>
<p>Read the Kubernetes documentation about the pod termination process with respect to service management and pod lifecycle.
<a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination</a></p>
<p>To answer your question,  it will depend on <code>terminationGracePeriod</code> on whether or not <code>something2</code> will execute.</p>
