gtctl

gtctl, g-t-control, is a command-line tool for managing the GreptimeDB clusters. gtctl is the All-in-One binary that integrates with multiple operations of GreptimeDB clusters.

Installation

One-line Installation

Download the binary using the following command:

bash

  1. curl -fsSL https://raw.githubusercontent.com/greptimeteam/gtctl/develop/hack/install.sh | sh

After downloading, the gtctl will be in the current directory.

You also can install gtctl from the AWS-CN S3 bucket:

bash

  1. curl -fsSL https://downloads.greptime.cn/releases/scripts/gtctl/install.sh | sh -s -- -s aws

Homebrew

On macOS, gtctl is available via Homebrew:

bash

  1. brew tap greptimeteam/greptime
  2. brew install gtctl

From Source

If you already have the Go installed, you can run the make command under this project to build gtctl:

bash

  1. make gtctl

After building, the gtctl will be generated in ./bin/. If you want to install gtctl, you can run the install command:

bash

  1. # The built gtctl will be installed in /usr/local/bin.
  2. make install
  3. # The built gtctl will be installed in your customed path.
  4. make install INSTALL_DIR=<your-path>

Enable gtctl Autocompletion (Optional)

The gtctl supports autocompletion of several different shells.

Bash

The gtctl completion script for Bash can be generated with the command gtctl completion bash. Sourcing the completion script in your shell enables gtctl autocompletion.

bash

  1. echo 'source <(gtctl completion bash)' >> ~/.bashrc

Zsh

The gtctl completion script for Zsh can be generated with the command gtctl completion zsh. Sourcing the completion script in your shell enables gtctl autocompletion.

bash

  1. mkdir -p $ZSH/completions && gtctl completion zsh > $ZSH/completions/_gtctl

Fish

The gtctl completion script for Fish can be generated with the command gtctl completion fish. Sourcing the completion script in your shell enables gtctl autocompletion.

bash

  1. gtctl completion fish | source

Quick Start

The fastest way to experience the GreptimeDB cluster is to use the playground:

bash

  1. gtctl playground

The playground will deploy the minimal GreptimeDB cluster on your environment in bare-metal mode.

Deployments

The gtctl supports two deployment mode: Kubernetes and Bare-Metal.

Kubernetes

Prerequisites

  • Kubernetes 1.18 or higher version is required.

    You can use the kind to create your own Kubernetes cluster:

    bash

    1. kind create cluster

Create

Create your own GreptimeDB cluster and etcd cluster:

bash

  1. gtctl cluster create mycluster -n default

If you want to use artifacts(charts and images) that are stored in the CN region, you can enable --use-greptime-cn-artifacts:

bash

  1. gtctl cluster create mycluster -n default --use-greptime-cn-artifacts

After creating, the whole GreptimeDB cluster will start in the default namespace:

bash

  1. # Get the cluster.
  2. gtctl cluster get mycluster -n default
  3. # List all clusters.
  4. gtctl cluster list

All the values used for cluster, etcd and operator which provided in charts are configurable, you can use --set to configure them. The gtctl also surface some commonly used configurations, you can use gtctl cluster create --help to browse them.

bash

  1. # Configure cluster datanode replicas to 5
  2. gtctl cluster create mycluster --set cluster.datanode.replicas=5
  3. # Two same ways to configure etcd storage size to 15Gi
  4. gtctl cluster create mycluster --set etcd.storage.volumeSize=15Gi
  5. gtctl cluster create mycluster --etcd-storage-size 15Gi

Dry Run

gtctl provides --dry-run option in cluster creation. If a user executes the command with --dry-run, gtctl will output the manifests content without applying them:

bash

  1. gtctl cluster create mycluster -n default --dry-run

Connect

You can use the kubectl port-forward command to forward frontend requests:

bash

  1. kubectl port-forward svc/mycluster-frontend 4002:4002 > connections.out &

Use gtctl connect command or your mysql client to connect to your cluster:

bash

  1. gtctl cluster connect mycluster -p mysql
  2. mysql -h 127.0.0.1 -P 4002

Scale (Experimental)

You can use the following commands to scale (or down-scale) your cluster:

bash

  1. # Scale datanode to 3 replicas.
  2. gtctl cluster scale <your-cluster> -n <your-cluster-namespace> -c datanode --replicas 3
  3. # Scale frontend to 5 replicas.
  4. gtctl cluster scale <your-cluster> -n <your-cluster-namespace> -c frontend --replicas 5

Delete

If you want to delete the cluster, you can:

bash

  1. # Delete the cluster.
  2. gtctl cluster delete mycluster -n default
  3. # Delete the cluster, including etcd cluster.
  4. gtctl cluster delete mycluster -n default --tear-down-etcd

Bare-Metal

Create

You can deploy the GreptimeDB cluster on a bare-metal environment by the following simple command:

bash

  1. gtctl cluster create mycluster --bare-metal

It will create all the necessary meta information on ${HOME}/.gtctl.

If you want to do more configurations, you can use the yaml format config file:

bash

  1. gtctl cluster create mycluster --bare-metal --config <your-config-file>

You can refer to the example config cluster.yaml and cluster-with-local-artifacts.yaml provided in examples/bare-metal.

Delete

Since the cluster in bare-metal mode runs in the foreground, any SIGINT and SIGTERM will delete the cluster. For example, the cluster will be deleted after pressing Ctrl+C on keyboard.

The deletion will also delete the meta information of one cluster which located in ${HOME}/.gtctl. The logs of cluster will remain if --retain-logs is enabled (enabled by default).

Development

There are many useful tools provided through Makefile, you can simply run make help to get more information:

  • Compile the project

    bash

    1. make

    Then the gtctl will be generated in ./bin/.

  • Run the unit test

    bash

    1. make test
  • Run the e2e test

    bash

    1. make e2e