Example Cron Job YAML Files

This example shows how to deploy the Data Export image to Kubernetes as a cron job.

In these examples, the image must connect to the existing shared storage PersistentVolume for a MATRIXX Engine. The job creates a new PersistentVolume where Data Export writes the output. For more information about shared storage, see the discussion about shared storage configuration in MATRIXX Configuration.

Cron Job with Sideloader

The following example cron job runs Data Export on the Engine 1 (Sub Domain 1) checkpoints. An optional data-export ConfigMap can hold files that must be copied to /opt/mtx/conf. A Sideloader holds files copied to /opt/mtx/conf.

apiVersion: batch/v1
kind: Job
metadata:
  name: data-export-s1e1
spec:
  ttlSecondsAfterFinished: 86400
  template:
    spec:
      imagePullSecrets:
        - name: matrixx-docker-registry-creds
      automountServiceAccountToken: false
      restartPolicy: OnFailure
 
      volumes:
          # An optional ConfigMap that will be synched to /opt/mtx/conf
        - name: data-export-configmap
          configMap:
            name: data-export
            optional: true
          # Share Sideloader directory
        - name: sideloader-sync-dir
          emptyDir: {}
          # The Engine's Shared Storage PV
        - name: data-export-input
          persistentVolumeClaim:
            claimName: shared-storage-s1e1
          # The PV where the output will be written to
        - name: data-export-output
          persistentVolumeClaim:
            claimName: data-export-output
 
      initContainers:
          # Sideloader that will unpack from the '{{ $sideloadImage.name }}' image
          - name: "sideloader"
            image: localhost:32000/custom-data-export-sideloader:latest
            imagePullPolicy: Always
            env:
              # Comma separated list of directories that will be unpacked to /sync
              - name: MTX_SYNC_TARGET_DIRS
                value: "/opt/mtx"
            volumeMounts:
              - mountPath: /sync
                name: sideloader-sync-dir
            # Sideloader used to unpack the contents of a ConfigMap
          - name: "configmap-sideloader"
            image: localhost/matrixx-sideloader:5212
            imagePullPolicy: Always
            volumeMounts:
                # Mount the contents of the ConfigMap under /opt/mtx/conf where they will be unpacked to /sync/conf automatically
              - mountPath: /opt/mtx/conf
                name: data-export-configmap
              - mountPath: /sync
                name: sideloader-sync-dir
 
      containers:
        - name: data-export
          image: localhost:32000/data-export:5212
          imagePullPolicy: Always
          env:
 
              # Output Directory
            - name: MTX_OUTPUT_DIRECTORY
              value: /opt/mtx/data/export/export-s1e1
 
              # Output Directory Postfix Expression
            - name: MTX_OUTPUT_DIRECTORY_POSTFIX_EXP
              value: echo "/$(date +"%Y%m%d-%H%M%S")"
 
              # MATRIXX Schema Version
            - name: MTX_VERSION
              value: "5212"
               
              # Export Config File Name
            - name: MTX_EXPORT_CONFIG_FILE
              value: /opt/mtx/conf/subscriber_export.yaml
 
          args:
            - --no-colors
            # Uncomment to allow additional script output
            # - --verbose
             
          volumeMounts:
              # Shared Sideloader Sync Directory
            - mountPath: /sync
              name: sideloader-sync-dir
              # Input Directory Mount
            - name: data-export-input
              mountPath: /shared
              # Output Directory Mount
            - name: data-export-output
              mountPath: /opt/mtx/data/export

For more information, see the discussion about configuration sources in MATRIXX Configuration.

Cron Job without a Sideloader

In the following example cron job, the data-export ConfigMap is mounted to /sync/conf and its contents are synched to /opt/mtx/conf at start up.

apiVersion: batch/v1
kind: Job
metadata:
  name: data-export-s1e1
spec:
  ttlSecondsAfterFinished: 86400
  template:
    spec:
      imagePullSecrets:
        - name: matrixx-docker-registry-creds
      automountServiceAccountToken: false
      restartPolicy: OnFailure
 
      volumes:
          # An optional ConfigMap that will be synched to /opt/mtx/conf
        - name: data-export-configmap
          configMap:
            name: data-export
            optional: true
          # The Engine's Shared Storage PV
        - name: data-export-input
          persistentVolumeClaim:
            claimName: shared-storage-s1e1
          # The PV where the output will be written to
        - name: data-export-output
          persistentVolumeClaim:
            claimName: data-export-output
 
      containers:
        - name: data-export
          image: localhost:32000/data-export:5212
          imagePullPolicy: Always
          env:
 
              # Output Directory
            - name: MTX_OUTPUT_DIRECTORY
              value: /opt/mtx/data/export/export-s1e1
 
              # Output Directory Postfix Expression
            - name: MTX_OUTPUT_DIRECTORY_POSTFIX_EXP
              value: echo "/$(date +"%Y%m%d-%H%M%S")"
 
              # MATRIXX Schema Version
            - name: MTX_VERSION
              value: "5212"
 
              # Export Config File Name
            - name: MTX_EXPORT_CONFIG_FILE
              value: /opt/mtx/conf/subscriber_export.yaml
 
          args:
            - --no-colors
            # Uncomment to allow additional script output
            # - --verbose
 
          volumeMounts:
              # Shared Sideloader Sync Directory
            - mountPath: /sync/conf
              name: data-export-configmap
              # Input Directory Mount
            - name: data-export-input
              mountPath: /shared
              # Output Directory Mount
            - name: data-export-output
              mountPath: /opt/mtx/data/export