Ankit Panigrahy
Ankit Panigrahy

Reputation: 11

How to trigger a kubernetes/openshift job restart when ever a specific pod in the cluster will restart?

For example, I have a pod running a server in it and I have a job in my cluster that is doing some yaml patching on the server deployment.

Is there a way we can set up some kind of trigger or anything that will rerun the job when ever the respective deployment change happens?

Upvotes: 0

Views: 1214

Answers (1)

Vasilii Angapov
Vasilii Angapov

Reputation: 9042

You can add your job spec into the deployment as initContainer like that:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      initContainers:
      - name: init
        image: centos:7
        command:
        - "bin/bash"
        - "-c"
        - "do something useful"
      containers:
      - name: nginx
        image: nginx

In this case every time you rollout the deployment, job defined in initContainers will run.

Upvotes: 1

Related Questions