Score:1

Running a job automatically after deployment in a kubernetes cluster

ng flag

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

c4f4t0r avatar
nl flag
You could create a helm chart and use a helm hook to create the job after the deployment
au flag
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?
Wytrzymały Wiktor avatar
it flag
Hello @AlessandroAstarita. Any updates?
Rajesh Dutta avatar
br flag
@Alessandro Astarita in you case I would recommend to use helm chart as this will keep things in orchestration way.
Score:0
tr flag

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.

moonkotte avatar
in flag
Hello @AlessandroAstarita! Does this [answer](https://serverfault.com/help/someone-answers) your question?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.