A package for managing Kubernetes jobs and cron jobs from Python. It allows running CLI scripts and Python functions within native Kubernetes job engine.
No need to package separate Docker images with functions to be executed - the package can remotely "inject" the Python function using dill into publicly available Docker images.
pip install k8s-job-schedulerfrom k8s_job_scheduler import JobManager
def add(a, b):
return a + b
manager = JobManager(docker_image="python:3.11.1-slim-bullseye")
job = manager.create_instant_python_job(add, 1, 2)
This example will create a Kubernetes job and run the function add with arguments 1 and 2 inside Python Docker container.
- Docker images should include Python interpreter and all the dependencies required to execute the function.
dillpackage is used to send the execution function and it's arguments when Docker container is created.dillis dynamically installed on job container execution start when job is created withcreate_instant_python_job. You can usepip_packagesargument to add extra Python packages to be installed, or removedillif you use docker image with preinstalleddill.