<p>We are having a Kubernetes service whose pods take some time to warm up with first requests. Basically first incoming requests will read some cached values from Redis and these requests might take a bit longer to process. When these newly created pods become ready and receive full traffic, they might become not very responsive for up to 30 seconds, before everything is correctly loaded from Redis and cached.</p>

<p>I know, we should definitely restructure the application to prevent this, unfortunately that is not feasible in a near future (we are working on it). </p>

<p>It would be great if it was possible to reduce the weight of the newly created pods, so they would receive 1/10 of the traffic in the beggining with the weight increasing as the time would pass. This would be also great for newly deployed versions of our application to see if it behaves correctly.</p>

<p>Until the application can be restructured to do this "priming" internally...</p>

<p>For when running on Kubernetes, look into <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/" rel="nofollow noreferrer">Container Lifecycle Hooks</a> and specifically into the <code>PostStart</code> hook. Documentation <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#lifecycle-v1-core" rel="nofollow noreferrer">here</a> and example <a href="https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/" rel="nofollow noreferrer">here</a>.</p>

<p>It seems that the behavior of "...The Container's status is not set to RUNNING until the postStart handler completes" is what can help you.</p>

<p>There's are few gotchas like "... there is no guarantee that the hook will execute before the container ENTRYPOINT" because "...The postStart handler runs asynchronously relative to the Container’s code", and "...No parameters are passed to the handler". </p>

<p>Perhaps a custom script can simulate that first request with some retry logic to wait for the application to be started?</p>
