Skip to content

Instantly share code, notes, and snippets.

@nmagee
Created April 21, 2025 20:44
Show Gist options
  • Save nmagee/fa8a5efa4988f2b7a9e564dbb20e559c to your computer and use it in GitHub Desktop.
Save nmagee/fa8a5efa4988f2b7a9e564dbb20e559c to your computer and use it in GitHub Desktop.
Lab 9 - Kubernetes Cron Jobs

Kubernetes Cron Jobs

To process multiple jobs at scale in an organized and manageable way, organizations might choose from a variety of tools.

One powerful tool to run and scheduled jobs is Kubernetes, an open source platform first created by Google. Kubernetes (or K8S) orchestrates dozens or even hundreds (or thousands) of containerized jobs using a "declared state" model - which is to say that developers describe the state of their application and the cluster makes it happen.

In this lab you will create and submit a CronJob to run in the UVA Kubernetes cluster.

Instructions

  1. Create a fork of this repository: https://github.com/uvasds-systems/uvasds-services/
  2. Clone your new fork to your local laptop, or open it in a GitHub Codespace.
  3. cd into uvasds-services/templates/ds2002 and find the nem2p.yaml file.
  4. Copy that file, renaming it with your username. Be sure to keep the .yaml suffix.
  5. Edit that new file. Replace all instances of nem2p with your computing ID.
  6. (Refer to the example below) Replace the values between the quotes on line 7 so that it runs every 30 minutes: 0-59/30 * * * *
  7. Most importantly, line 14 should point to the container you created for Lab 8. Your GitHub Actions workflow should build that container and push it to the GHCR, where K8S can pull it.
  8. Once you have made these edits, ADD, COMMIT, and PUSH your changes to your fork.
  9. From the home page of your fork in GitHub, click on the "Contribute" button and submit a Pull Request to the parent repository. From there the instructor will review and approve your submission.
  10. That's it! We will see your deployment on the backend, which will be graded automatically.
apiVersion: batch/v1
kind: CronJob
metadata:
name: nem2p-job
namespace: uvasds-services
spec:
schedule: "0-59/15 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: nem2p-job-container
image: ghcr.io/uvasds-systems/docker-iss:latest
imagePullPolicy: Always
envFrom:
- secretRef:
name: ds2002-mongo
resources:
limits:
cpu: "0.25"
memory: 512Mi
requests:
cpu: "0.1"
memory: 256Mi
restartPolicy: Never
ttlSecondsAfterFinished: 86400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment