An open API service indexing awesome lists of open source software.

https://github.com/imubit/k8s-job-scheduler

Python package for managing and scheduling Jobs in Kubernetes
https://github.com/imubit/k8s-job-scheduler

Last synced: 7 months ago
JSON representation

Python package for managing and scheduling Jobs in Kubernetes

Awesome Lists containing this project

README

        

[![Project generated with PyScaffold](https://img.shields.io/badge/-PyScaffold-005CA0?logo=pyscaffold)](https://pyscaffold.org/)
[![Coveralls](https://img.shields.io/coveralls/github/imubit/k8s-job-scheduler/main.svg)](https://coveralls.io/r/imubit/k8s-job-scheduler)
[![PyPI-Server](https://img.shields.io/pypi/v/k8s-job-scheduler.svg)](https://pypi.org/project/k8s-job-scheduler/)

# k8s-job-scheduler

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.

## Installation

```python
pip install k8s-job-scheduler
```

## Getting Started

```commandline
from 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.

## Other Prerequisites

### Executing Python functions withing Kubernetes containers

* Docker images should include Python interpreter and all the dependencies required to execute the function.
* `dill` package is used to send the execution function and it's arguments when Docker container is created. `dill` is dynamically installed on job container execution start when job is created with `create_instant_python_job`. You can use `pip_packages` argument to add extra Python packages to be installed, or remove `dill` if you use docker image with preinstalled `dill`.