2

Does anyone know how to launch a job automatically after a deployment with kubernetes?

I tried using postStart script but the task is executed on every replica of the deployment. I want to execute it only once time after deployment is completed.

The job is about clearing remote cache, updating translations, etc...

Thank you

Alex

  • 2
    You could create a helm chart and use a helm hook to create the job after the deployment – c4f4t0r Dec 15 '21 at 10:35
  • A deployment will create a replicaset which will attempt to set up the required number of Pods and may or may not succeed in doing this. Are you wanting to trigger the job immediately after the deployment request is sent to the Kubernetes API. Or, are you wanting to wait until all Pods are ready? Or perhaps, just when the first available Pod is ready? – harunahi Dec 15 '21 at 11:02
  • Hello @AlessandroAstarita. Any updates? – Wytrzymały Wiktor Dec 22 '21 at 11:23
  • @Alessandro Astarita in you case I would recommend to use helm chart as this will keep things in orchestration way. – Rajesh Dutta Dec 24 '21 at 14:57

1 Answers1

1

This is a community wiki answer posted for better visibility. Feel free to expand it.

Based on the comments provided, the best solution for creating a job after deployment is to use Chart Hooks from Helm.

Helm provides a hook mechanism to allow chart developers to intervene at certain points in a release's life cycle. For example, you can use hooks to:

  • Load a ConfigMap or Secret during install before any other charts are loaded.

  • Execute a Job to back up a database before installing a new chart, and then execute a second job after the upgrade in order to restore data.

  • Run a Job before deleting a release to gracefully take a service out of rotation before removing it.

  • Hello @AlessandroAstarita! Does this [answer](https://serverfault.com/help/someone-answers) your question? – moonkotte Dec 30 '21 at 12:36