How to set up a Nomad cluster on the Google Cloud using Terraform
- These scripts require Terraform 0.6.3 or greater
- Follow the instructions on https://www.terraform.io/intro/getting-started/install.html to set up Terraform on your machine.
- Visit https://console.developers.google.com
- Navigate to APIs & Auth -> Credentials -> Service Account -> Generate new JSON key
- The file will be downloaded to your machine
- Visit https://cloud.google.com/sdk/
- Install the SDK, login and authenticate with your Google Account.
- Back in the Developer Console, go to Compute - Compute Engine - Metadata and click the SSH Keys tab. Add your public SSH key there.
- Use the path to the private key and the username in the next step as
gce_ssh_user
andgce_ssh_private_key_file
Copy thevariables.tf.example
file to varables.tf
and adjust to your situation
Create the plan and save it to a file.
terraform plan -out my.plan
Once you are satisfied with the plan, apply it.
terraform apply my.plan
Log in to every node. There is a default server.hcl there, copied from the resources dir, that you can use to start the node. Start the agent, specifying the address of eth0 to bind to.
sudo nomad agent -config server.hcl -bind=10.11.12.4
Execute this on every node, the agent needs to be running on all of them.
From one of the nodes, connect to the others.
nomad server-join -address http://$OTHER_SERVER:4646 $MYADDRESS
You should see the node joining in the logs. Repeat this step for all nodes in the cluster.
To be able to reach the agent, export the NOMAD_ADDR variable.
export NOMAD_ADDR="http://nomad1:4646"
When you're done, clean up the cluster with
terraform destroy
- Automate starting of nomad daemon
- Discover other nodes
- Automating joining of other nodes