Introducing Rego: The Lightweight Task Orchestrator for Kubernetes
Tags: kubernetes, go, serverless, programming
Published: 2023-04-19 12:38:48


![rego logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzbudrt5cv6l77vztasj.png)

👋 Hey there! Today I want to introduce you to [Rego](https://drorivry.github.io/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:
```sh
kubectl apply -f https://raw.githubusercontent.com/drorIvry/rego/main/deploy/deployment.yml
```

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:
```sh
curl -L https://raw.githubusercontent.com/drorIvry/rego-cli/main/install.sh | sh
```

Test the connection by running the following command:
```sh
rego ping
```

Deploy a Docker image by running the following command:
```sh
rego run -i hello-world
```

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

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

### 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:

```sh
curl -X POST -d '{"image": "hello-world"}' localhost:4004/api/v1/task
```

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.

```sh
{
  "definition_id": "a36fbd9b-bf8a-4c59–94c1–9938b6707e8f",
  "message": "created"
}
```

Check the task's running status by making a GET request to the following endpoint:
```sh
curl http://localhost:4004/api/v1/task/a36fbd9b-bf8a-4c59-94c1-9938b6707e8f/latest
```

This will return the task's running status, including the status code and status message.
```js
{
  "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
  }
}
```

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](https://github.com/drorivry/rego)