Horizontal Pod Autoscaling (HPA) with an initContainer that requires a Job Horizontal Pod Autoscaling (HPA) with an initContainer that requires a Job kubernetes kubernetes

Horizontal Pod Autoscaling (HPA) with an initContainer that requires a Job


There is, unfortunately, no simple Kubernetes feature to resolve your issue.

I recommend extending your deployment tooling/scripts to separate the migration job and your deployment. During the deploy process, you first execute the migration job and then deploy your deployment. Without the job attached, the HPA can nicely scale your pods.

There is a multitude of ways to achieve this:

  • Have a bash, etc. script first to execute the job, wait and then update your deployment
  • Leverage more complex deployment tooling like Helm, which allows you to add a 'pre-install hook' to your job to execute them when you deploy your application