DEV Community

drorIvry
drorIvry

Posted on

Introducing Rego: The Lightweight Task Orchestrator for Kubernetes

rego logo

👋 Hey there! Today I want to introduce you to Rego - the blazingly fast API first task orchestrator that is designed to allow asynchronous workloads to be deployed over Kubernetes with minimal effort.
🔥 Rego is lightweight and super fast, making it an excellent choice for those who need a controlled way to run code on demand. Plus, it has an API to manage runs as well as run logs, so it's a very well-rounded tool.

Why We Created Rego

We created Rego because we were looking for a managed way to "go run this docker for me" and didn't like anything that we found. We had to have an API to manage the runs as well as run logs. Rego is the result of that effort.

Use Cases

Rego has several use cases, including:
🔌 Running async workloads that need to be managed by (or visible to) a UI 
🧪 Integrating non-production-grade code (like a data scientist's R code, for example) within your production environment in a contained way
 ️⏰ Using Rego to run stuff periodically with run history

Quick Start

Getting started with Rego is easy! Follow the steps below to get started with the CLI or the API.
Installing using k8s
Deploy Rego to your Kubernetes cluster by running the following command:

kubectl apply -f https://raw.githubusercontent.com/drorIvry/rego/main/deploy/deployment.yml
Enter fullscreen mode Exit fullscreen mode

P.S. don't forget to portforward
👀 there are more ways to deploy rego, check the docs

Using the CLI

The Rego CLI is the easiest way to start using Rego. Follow these steps to get started:
Install the Rego CLI by running the following command:

curl -L https://raw.githubusercontent.com/drorIvry/rego-cli/main/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

Test the connection by running the following command:

rego ping
Enter fullscreen mode Exit fullscreen mode

Deploy a Docker image by running the following command:

rego run -i hello-world
Enter fullscreen mode Exit fullscreen mode

For more complex deployments, use the following command as a template:

rego run -d "$(cat << EOF 
{
  "image": "hello-world",
  "name": "test",
  "namespace": "default",
  "execution_interval": 0,
  "metadata": {
    "ttlSecondsAfterFinished": 10,
    "completions": 10,
    "parallelism": 10
  }
}
EOF
)"
Enter fullscreen mode Exit fullscreen mode

Using the API

With Rego, you can use the API to create and run Kubernetes jobs with a managed API. 
 Create a new task by making a POST request to the following endpoint:

curl -X POST -d '{"image": "hello-world"}' localhost:4004/api/v1/task
Enter fullscreen mode Exit fullscreen mode

This will start a job on your Kubernetes cluster that runs the Docker image hello-world. The response will include the definition ID, which you can use to see the task's running status.

{
  "definition_id": "a36fbd9b-bf8a-4c59–94c1–9938b6707e8f",
  "message": "created"
}
Enter fullscreen mode Exit fullscreen mode

Check the task's running status by making a GET request to the following endpoint:

curl http://localhost:4004/api/v1/task/a36fbd9b-bf8a-4c59-94c1-9938b6707e8f/latest
Enter fullscreen mode Exit fullscreen mode

This will return the task's running status, including the status code and status message.

{
  "ID": 0,
  "CreatedAt": "2023–04–02T11:53:08.2008054+03:00",
  "UpdatedAt": "2023–04–02T11:53:16.2032147+03:00",
  "DeletedAt": null,
  "id": "7eb53d97–7380–4e0b-82a6-b38fbf9119d2",
  "task_definition_id": "a36fbd9b-bf8a-4c59–94c1–9938b6707e8f",
  "status_code": 500, // rego internal status code
  "status": "SUCCESS",
  "image": "hello-world",
  "name": "test",
  "namespace": "test",
  "metadata": {
    "ttlSecondsAfterFinished": 10,
    "completions": 10,
    "parallelism": 10
  }
}
Enter fullscreen mode Exit fullscreen mode

In conclusion, Rego is a powerful and flexible task orchestrator that can run your workloads with ease, while also providing a management API that can keep track of progress and run history. Whether you need to run async workloads that need to be managed, integrate non-production-grade code within your production environment in a contained way, or run stuff periodically with run history, Rego has got you covered.
And please ⭐star us on Github

Top comments (0)