Google Cloud Platform

Prerequisites

  • Download and install terraform.

  • Verify by the terraform command, it should print a help message that looks similar to that shown below.

  1. $ terraform
  1. Usage: terraform [--version] [--help] <command> [args]
  2. ...
  3. Common commands:
  4. apply Builds or changes infrastructure
  5. console Interactive console for Terraform interpolations
  6. destroy Destroy Terraform-managed infrastructure
  7. env Workspace management
  8. fmt Rewrites config files to canonical format

1. Create a terraform config file

  • First create a terraform file with provider details
  1. provider "google"
  2. {
  3. # Provide your Creadentilals
  4. credentials = "${file("yugabyte-pcf-bc8114281026.json")}"
  5. # The name of your GCP project
  6. project = "<Your-GCP-Project-Name>"
  7. }

NOTE: :- You can get credentials file by following steps given here

  • Now add the yugabyte terraform module to your file
  1. module "yugabyte-db-cluster" {
  2. source = "github.com/Yugabyte/terraform-gcp-yugabyte.git"
  3. # The name of the cluster to be created.
  4. cluster_name = "test-cluster"
  5. # key pair.
  6. ssh_private_key = "SSH_PRIVATE_KEY_HERE"
  7. ssh_public_key = "SSH_PUBLIC_KEY_HERE"
  8. ssh_user = "SSH_USER_NAME_HERE"
  9. # The region name where the nodes should be spawned.
  10. region_name = "YOUR_VPC_REGION"
  11. # Replication factor.
  12. replication_factor = "3"
  13. # The number of nodes in the cluster, this cannot be lower than the replication factor.
  14. node_count = "3"
  15. }

2. Create a cluster

Init terraform first if you have not already done so.

  1. $ terraform init

To check what changes are going to happen in environment run the following

  1. $ terraform plan

Now run the following to create the instances and bring up the cluster.

  1. $ terraform apply

Once the cluster is created, you can go to the URL http://<node ip or dns name>:7000 to view the UI. You can find the node’s ip or dns by running the following:

  1. $ terraform state show google_compute_instance.yugabyte_node[0]

You can access the cluster UI by going to any of the following URLs.

You can check the state of the nodes at any point by running the following command.

  1. $ terraform show

3. Verify resources created

The following resources are created by this module:

  • module.terraform-gcp-yugabyte.google_compute_instance.yugabyte_node The GCP VM instances.

For cluster named test-cluster, the instances will be named yugabyte-test-cluster-n1, yugabyte-test-cluster-n2, yugabyte-test-cluster-n3.

  • module.terraform-gcp-yugabyte.google_compute_firewall.Yugabyte-Firewall The firwall rule that allows the various clients to access the YugabyteDB cluster.

For cluster named test-cluster, this firewall rule will be named default-yugabyte-test-cluster-firewall with the ports 7000, 9000, 9042 and 6379 open to all.

  • module.terraform-gcp-yugabyte.google_compute_firewall.Yugabyte-Intra-Firewall The firewall rule that allows communication internal to the cluster.

For cluster named test-cluster, this firewall rule will be named default-yugabyte-test-cluster-intra-firewall with the ports 7100, 9100 open to all other vm instances in the same network.

  • module.terraform-gcp-yugabyte.null_resource.create_yugabyte_universe A local script that configures the newly created instances to form a new YugabyteDB universe.

4. Destroy the cluster (optional)

To destroy what we just created, you can run the following command.

  1. $ terraform destroy

Prerequisites

  • Download and Install gcloud command line tool.
  • Clone git repo from here

Deploying using Cloud Shell

Google Cloud Platform - 图1

  • Change current directory to cloned git repo directory
  • Use gcloud command to create deployment-manager deployment
  1. $ gcloud deployment-manager deployments create <your-deployment-name> --config=yugabyte-deployment.yaml
  • Wait for 5-10 minutes after the creation of all resources is complete by the above command.

  • Once the deployment creation is complete, you can describe it as shown below.

  1. $ gcloud deployment-manager deployments describe <your-deployment-name>

In the output, you will get the YugabyteDB admin URL, JDBC URL, YSQL, YCQL and YEDIS connection string. You can use YugabyteDB admin URL to access admin portal.

Refer the GKE deployment instructions in the Kubernetes section.