Kubernetes cron job needs one command to finish first?

1/17/2019

I have a Kubernetes cron job that creates a zip file which takes about 1 hour. After it's completion I want to upload this zip file to an AWS s3 bucket.

How do I tell the cron job to only do the s3 command after the zip is created?

Should the s3 command be within the same cron job?

Currently my YAML looks like this:

kind: CronJob
metadata:
  name: create-zip-upload
spec:
  schedule: "27 5 * * *" # everyday at 05:27 AM
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: mycontainer
            image: 123456789.my.region.amazonaws.com/mycompany/myproject/rest:latest
        args:
        - /usr/bin/python3
        - -m
        - scripts.createzip
-- William Ross
kubernetes

1 Answer

1/17/2019

Kubernetes doesn't have a concept of a relationship between resources. There isn't an official or clean way to have something occurring in one resource cause an effect on another resource.

Because of this, the best solution is to just put the s3 cmd into the same cronjob.

There's two ways to do this:

  1. Add the s3 cmd logic to your existing container.
  2. Create a new container in the same cronjob that watches for the file and then runs the s3 cmd.
-- Swiss
Source: StackOverflow