Skip to content

cuongdo/cockroachdb-terraform-gce

Repository files navigation

WARNING Use this only for development or testing. This is currently partly functional due to GCE network load balancing configuration. Also, this does not yet support the creation of secure clusters.

Deploy cockroach cluster on Google Cloud Engine using Terraform

This directory contains the Terraform configuration files needed to launch a Cockroach cluster on GCE (Google Compute Engine).

Terraform stores the state of the cloud resources locally (in a file called terraform.tfstate), so this is meant to be used by a single user. For multi-user cooperation, please see Terraform's documentation on remote state.

One-time setup steps

  1. Have a Google Cloud Platform account
  2. Download terraform, version 0.6.7 or greater, unzip, and add to your PATH.
  3. Create and download GCE credentials.
  4. Set your credentials in environment variables:
$ export GOOGLE_CREDENTIALS="contents of json credentials file"
$ export GOOGLE_PROJECT="my-google-project"
5. Save your GCE key as `~/.ssh/google_compute_engine`, or adjust the `key_name` variable.

Variables

Some configuration can be performed by using the --var command line parameter to override the variables in variables.tf.

The following variables are likely to change based on your account or setup:

  • gce_zone: availability zone for instances
  • gce_region: region for forwarding rules and target pools
  • key_name: base name of the Google Cloud SSH key

The following variables can be modified if necessary:

  • sql_port: the port for the backends and load balancer
  • machine_type: type of machine to run instances on
  • gce_image: OS image for your GCE instances
  • action: default action. Defaults to start. Override is specified in initialization step

Create a cockroach cluster with 3 nodes

$ terraform apply --var=num_instances=3


Outputs:

  instances = 104.196.43.55,104.196.19.237,104.196.107.237

To see the actions that will be performed by terraform, use plan instead of apply.

The cluster is now running with three nodes and is reachable through the any of the instances.

Using the cluster

Connect to the cluster

Use one of the instances in the terraform output to issue SQL queries to your new cluster:

$ cockroach sql --url postgresql://[email protected]:26257/?sslmode=disable
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
[email protected]:26257> show databases;
+----------+
| Database |
+----------+
| system   |
+----------+

View the admin UI

To view the admin web UI, visit any of the instances on the http_port (default 8080).

SSH into individual instances

The names of the GCE instances are shown as a comma-separated list in the terraform output. Use the gcloud tool, included with the Google Cloud SDK, to SSH into one of the machines:

$ ssh -i ~/.ssh/google_compute_engine [email protected]

ubuntu@cockroach-1:~$ ps -Af|grep cockroach
ubuntu    1500     1  0 15:16 ?        00:00:01 ./cockroach start --log-dir=cockroach-data/logs --logtostderr=false --insecure --host=10.240.0.12 --port=26257 --http-port=8080

ubuntu@cockroach-1:~$ ls logs
$ ls cockroach-data/logs
cockroach.cockroach-1.ubuntu.log.INFO.2016-04-06T15_16_45Z.1500     cockroach.INFO    cockroach.STDOUT
cockroach.cockroach-1.ubuntu.log.WARNING.2016-04-06T15_16_45Z.1500  cockroach.STDERR  cockroach.WARNING

Note the ubuntu user in the above command-line.

Destroy the cluster

$ terraform destroy

The destroy command requires confirmation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published