0

I have a cronjob being deployed to two different clusters. Each cluster is a different region. Having these jobs running on two different clusters is to help insure the cronjob will run if one of the regions goes down.

I want the two deployments to be able to check if the deployment on the other cluster is running. If it is, the cronjob should not run. I do have concurrencyPolicy set to false, but that only matters for the cluster the cronjob is running on.

Is this something that is even possible?

Here is a basic idea of my Helm chart

apiVersion: batch/v1
kind: CronJob
metadata:
  name: 
  namespace: 
  labels:
    app.kubernetes.io/component: cronjob
    app.kubernetes.io/instance: 
    app.kubernetes.io/managed-by: helm
    app.kubernetes.io/name: 
    app.kubernetes.io/part-of: 
spec:
  schedule:
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 0
  successfulJobsHistoryLimit: 0
  jobTemplate:
    spec:
      activeDeadlineSeconds: 240
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
          labels:
            app.kubernetes.io/component: cronjob
            app.kubernetes.io/instance:
            app.kubernetes.io/managed-by: helm
            app.kubernetes.io/name: 
            app.kubernetes.io/part-of: 
        spec:
          imagePullSecrets:
            - name: 
          serviceAccountName: 
          restartPolicy: OnFailure
          containers:
            - name: 
              image:
              command: ["dumb-init", "node", "./main.js"]
              imagePullPolicy: IfNotPresent
              resources:
                requests:
                  cpu: "256m"
                  memory: "1G"
              env:
                - name:
                  value:
              envFrom:
          affinity:
            nodeAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
                - weight: 1
                  preference:
                    matchExpressions:
                      - key: Criticality
                        operator: In
                        values:
                          - Important
4
  • There is nothing built into kubernetes that will provide you with this sort of cross-cluster coordination. There may be some third-party packages that can help, or you can provide your own api endpoint that can be used to check the state of this job (or a related deployment) on the remote cluster.
    – larsks
    Commented Jul 9 at 19:35
  • Maybe create a pipeline that runs on a schedule and uses kubectl commands to 1) check the cluster status and 2) enable/disable the CRON job? Commented Jul 9 at 19:57
  • @larsks I kinda assumed that was true Commented Jul 10 at 3:23
  • @RuiJarimba Looking into a path forward on this Commented Jul 10 at 3:23

0

Browse other questions tagged or ask your own question.