0

I'm learning k8s hpa autoscale and have one confusion。

if there are some codes run in pod like this:

# do something1
time.sleep(15)
# do something2

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?

og f91
  • 37
  • 5

1 Answers1

4

There as a few options as to how can you control what should happen when your service goes down. Typically, K8S will send a soft termination to the container's main process, which the process can use to handle gracefully(intercept interrupt signals). Although, K8S will only wait for terminationGracePeriod time defined in the PodSpec.

You can also use a lifecycle hook called preStop and handle the service termination process externally.

Some information is here in this StackOverflow answer: Is there a way to downscale pods only when message is processed (the pod finished its task) with the HorizontalPodAutoscaler in Kubernetes?

Read the Kubernetes documentation about the pod termination process with respect to service management and pod lifecycle. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination

To answer your question, it will depend on terminationGracePeriod on whether or not something2 will execute.

Shubham Singh
  • 946
  • 6
  • 12