apiVersion: batch/v1
# check your API version, 
# CronJobs are available on batch/v1 since v1.21
# previous versions have to use v1beta1 api
# apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: rolling-update-cronjob
  namespace: r-updated
spec:
  schedule: "*/1 * * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 2
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: kubectl-rollingupdate
            image: d3fk/kubectl:latest
            # Set env var to be used by the command args
            env:
            - name: RUPDATE_TRIGGER
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            # We need to patch the targeted deployment annotation with a different value to trigger the rolling update
            # i.e: current date and time, pod name that triggered this update (the env var set in this example) ...
            args: ["patch", "deployment/test-deployment", "-p", "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"rolling-update-trigger\":\"$(RUPDATE_TRIGGER)\"}}}}}"]
            volumeMounts:
            - name: kubeconfig
              mountPath: /.kube
              subPath: .kube

          volumes:
          - name: kubeconfig
            configMap:
              name: kubeconfig

          restartPolicy: Never
