Cuber: deploy your apps on Kubernetes easily (Heroku alternative)
Tags: kubernetes, devops, tooling, docker
Published: 2022-02-21 18:18:36

Cuber is an automation tool that makes it easy to publish your applications on Kubernetes. Cuber is a gem written in Ruby, but you can deploy apps in any language and framework.

**TL;DR** Define a `Cuberfile`, run `cuber deploy` and you will have your application running on Kubernetes (which is much cheaper than Heroku).

{% embed https://github.com/cuber-cloud/cuber-gem %}

## Why Cuber?

There are already many platforms and tools to publish and run your applications in the cloud:

- Heroku is simple, but you get lock-in and high costs when you scale.
- Capistrano works very well, but when you scale on multiple machines you need to manage each of them (and can become a pain when you start having 10+ servers).
- Dokku and other projects are great projects, but they don't have horizontal scalability (you are constrained on a single server).
- Managing servers and infrastructure directly (e.g. use droplets directly on DigitalOcean) is complex and time consuming and it doesn't scale well to tens or hundreds of servers.
- Jenkins, Argo CD, Helm, kustomize and other devops tools for Kubernetes require deep knowledge of Kubernetes and they basically add complexity over complexity.

... And that's why, after using many of the above solutions, I built Cuber. 

Cuber has the **simplicity** of a PaaS, like Heroku, while you get the cost of bare infrastructure (i.e. by using Kubernetes, instead of Heroku, you get a **80% cost reduction!**).

Also, **you don't have provider lock-in**, since you can easily move to any Kubernetes provider (e.g. DigitalOcean, Vultr, Google Cloud, AWS, or any other).

## How it works

You just need to create a **Cuberfile** for your application (it is somewhat similar to a Procfile for Heroku or a Capfile for Capistrano).

A Cuberfile is made only of a few lines of code.

Here's an example for a Rails application:

```ruby
app 'myapp'
repo '.'
buildpacks 'heroku/buildpacks:20'
image 'username/myapp'
kubeconfig 'kubeconfig.yml'
proc :web, 'bundle exec puma', scale: 3
env 'RAILS_ENV', 'production'
env 'RAILS_LOG_TO_STDOUT', 'enabled'
env 'RAILS_SERVE_STATIC_FILES', 'enabled'
env 'RAILS_MASTER_KEY', File.read('config/credentials/production.key').strip, secret: true
```

As you can see we define:

- the **name of our application**
- the **Git repo** (i.e. the location of the Git repo, where to get the source code)
- how to build the application (i.e. in the above example we use automatic builds with **Heroku Buildpacks**, but we can also provide a Dockerfile if we prefer)
- where the store the Docker image of our application (i.e. the **Docker repository**)
- the **Kubernetes cluster** (i.e. where to deploy our application)
- the process to run (i.e. in this case we define the **web server process**, but we can also add background workers and other custom processes)
- the **environment variables** and **secrets** that we want to make available to our running application.

This is only a basic example, but you can also add more configurations (e.g. database migrations, ssl, etc.)

After defining your Cuberfile, you can deploy your application to Kubernetes with a single command:

```
$ cuber deploy
```

This command will run a CI/CD pipeline:

1. Checkout the code from the Git repository
2. Build the app using Buildpacks or Docker
3. Publish the Docker image in the Docker registry
4. Run your app on Kubernetes

Finally you can see the status of your running application:

```
$ cuber info
```

## There's even more

Using Cuber, it's not only simple to deploy an application, but it's simple to maintain it over time.

When you need to change a configuration, simply edit the `Cuberfile` and then type `cuber deploy` again.

You can also run maintenance task directly on your cluster:

```
$ cuber run [yourcommand]
```

For example with a Rails application you can run:

```
$ cuber run rails db:migrate
$ cuber restart
```

Or you can run interactive shells, for example:

```
$ cuber run bash
$ cuber run rails console
```

You can even see your application logs with a simple command:

```
$ cuber logs
```

## Built for production

Cuber is a new project, but it uses the best practices and it is a solid tool meant for production.

Before creating it I have scaled [Pushpad](https://pushpad.xyz) to thousands of requests per second and I have written the [Kubernetes & Rails Definitive Guide](https://kubernetes-rails.com).

Give it a try ;)