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.
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.
- Have a Google Cloud Platform account
- Download terraform, version 0.6.7 or greater, unzip, and add to your
PATH
. - Create and download GCE credentials.
- 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.
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 instancesgce_region
: region for forwarding rules and target poolskey_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 balancermachine_type
: type of machine to run instances ongce_image
: OS image for your GCE instancesaction
: default action. Defaults tostart
. Override is specified in initialization step
$ 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
.
Use one of the instances
in the terraform output to issue SQL queries
to your new cluster:
$ cockroach sql --url postgresql://root@104.196.43.55:26257/?sslmode=disable
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
root@104.196.43.55:26257> show databases;
+----------+
| Database |
+----------+
| system |
+----------+
To view the admin web UI, visit any of the instances
on the http_port
(default 8080).
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 ubuntu@104.196.43.55
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.
$ terraform destroy
The destroy
command requires confirmation.