YugabyteDB Managed CLI: provisioning a free DB from the command line
Tags: yugabytedb, free, managed, service
Published: 2023-03-04 22:20:36

In the previous post about YugabyteDB managed, I have created a free YugabyteDB in the cloud using the REST API. If you want a simpler way here is the same with `ybm`, the YugabyteDB Managed CLI.

## Install YBM CLI

I'm running this on my laptop on Windows. I get the latest version from https://github.com/yugabyte/ybm-cli/releases :

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hp6onvi3iubkm1gl9hw.png)

I have downloaded `ybm_0.1.3_windows_amd64.zip` and unzipped to get `ybm.exe` in the current directory (have it in the PATH)

I have set the API KEY and API host as an environment variable, see the [previous post](https://dev.to/yugabyte/yugabytedb-managed-api-provisioning-a-free-db-from-command-line-47k6) on how to get them (TL;DR: create an account in cloud.yugabyte.com and create an API key):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hj12ytt86szclgnktw32.png)

I can now use `ybm` to list the clusters and allow lists:

```sh
C:\Users\franck> ybm cluster list

No clusters found

C:\Users\franck> ybm network-allow-list list

Name               Description               Allow List                          Clusters
home                                         217.42.42.42/32
```

## Creation of Sandbox (Free tier)

I have no cluster yet, let's create a free one:

```sh
ybm cluster create ^
    --credentials=username=admin,password=Password-5up3r53cr3t ^
    --cloud-type=AWS ^
    --cluster-type=SYNCHRONOUS ^
    --node-config=num-cores=2,disk-size-gb=10 ^
    --region-info=region=eu-west-1,num-nodes=1 ^
    --cluster-tier=Sandbox ^
    --fault-tolerance=NONE ^
    --database-version=Preview ^
    --wait ^
    --cluster-name=my-free-yugabytedb

```

I used `--wait` to see the creation steps:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/krr5q2nst0bufds1264o.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gtpurkb9ysrk3hdgj3zb.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xddzebj2fmvpe760n9n2.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5s8tqjj0uczyi4w6csx.png)

I assign the IP Allow List to access it from home:
```sh
ybm cluster network allow-list assign ^
    --network-allow-list=home ^
    --cluster-name=my-free-yugabytedb

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3oakbgocfirzuvdu1fl1.png)

I get the cluster ID with 
```sh
ybm cluster describe ^
    --cluster-name=my-free-yugabytedb

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqozgoow306d3wiij8nb.png)

The host of the load balancer is `region.cluster_id.YBM_HOST` and I can connect with:
```sh
psql postgresql://admin:Password-5up3r53cr3t@eu-west-1.37a18be6-67fb-47e3-ab07-b85ab0020d56.cloud.yugabyte.com:5433/yugabyte?sslmode=require
```

## Single-Region (Fault Tolerance: AZ Level)

Here is how I create a Single-Region in Dedicated (Paid or Trial) over 3 regions in Tokyo:
```sh
ybm cluster create ^
    --credentials=username=admin,password=Password-5up3r53cr3t ^
    --cloud-type=AWS ^
    --cluster-type=SYNCHRONOUS ^
    --node-config=num-cores=4,disk-size-gb=200 ^
    --region-info=region=ap-northeast-1,num-nodes=3 ^
    --cluster-tier=Dedicated ^
    --fault-tolerance=ZONE ^
    --database-version=Preview ^
    --wait ^
    --cluster-name=my-single-region

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q06zxhd3vd1iwey5zjby.png)

## Multi-Region (Fault Tolerance: Region Level)

Here is the list of available regions in AWS:
```sh
ybm region list --cloud-provider AWS

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2t2sh3498btjst2alrnn.png)

For multi-region we need VPC peering:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qg82amvfbfc6uxeifhqa.png)

I create a GEO-PARTITIONNED with 3 `--region-info`:
```sh
ybm cluster create ^
    --credentials=username=admin,password=Password-5up3r53cr3t ^
    --cloud-type=AWS ^
    --cluster-type=GEO_PARTITIONED ^
    --node-config=num-cores=4,disk-size-gb=200 ^
    --region-info=region=ap-south-1,num-nodes=3,vpc=vpc-ap-south-1 ^
    --region-info=region=ap-southeast-1,num-nodes=3,vpc=vpc-ap-southeast-1 ^
    --region-info=region=ap-southeast-2,num-nodes=3,vpc=ap-southeast-2 ^
    --cluster-tier=Dedicated ^
    --fault-tolerance=REGION ^
    --database-version=Preview ^
    --wait ^
    --cluster-name=my-multi-region

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q06zxhd3vd1iwey5zjby.png)

## Any Platform

YBM CLI is available for all platforms.  The first argument of `ybm` is the object and the second argument is the verb. Check `ybm completion` to setup auto-completion. This is the first version, it will evolve, all that is available in the GUI is available in the CLI.