This guide outlines how to deploy Nomad and Consul on Google Cloud Platform (GCP) using Packer to build custom images based on HashiCorp's Reference Architecture.
Before you begin, ensure you have the following tools installed:
Authenticate your GCP account and configure the project you want to use:
# Authenticate your GCP account
gcloud auth login
gcloud auth application-default login
# Set your Google Cloud project ID
gcloud config set project <PROJECT_ID>
Replace <PROJECT_ID>
with your GCP project ID.
Copy your Nomad and Consul license files (nomad.hclic
and consul.hclic
) to the root of your working directory:
cp ~/Downloads/nomad.hclic .
cp ~/Downloads/consul.hclic .
Ensure both license files are present before building your images.
Use the provided script to configure necessary variables for the Packer build:
sh packer/set-vars.sh
The script will prompt you for your GCP project ID, region, and other details. By default, it uses London (europe-west2) as the region. Modify this if needed during execution.
Once variables are set, you can use Packer to build the Nomad server and client images. To update the version of Nomad or Consul, modify the NOMAD_VERSION
and CONSUL_VERSION
in the provision-nomad.sh & provision-consul.sh scripts.
You can run both builds simultaneously using ./build-packer.sh
, or manually with the following commands:
# Initialize Packer
packer init packer/gcp-almalinux-nomad-server.pkr.hcl
packer init packer/gcp-almalinux-nomad-client.pkr.hcl
packer init packer/gcp-almalinux-consul-server.pkr.hcl
packer init packer/gcp-almalinux-nginx.pkr.hcl
# Build the Nomad server image
packer build -var-file=variables.pkrvars.hcl packer/gcp-almalinux-nomad-server.pkr.hcl
# Build the Nomad client image
packer build -var-file=variables.pkrvars.hcl packer/gcp-almalinux-nomad-client.pkr.hcl
# Build the Consul server image
packer build -var-file=variables.pkrvars.hcl packer/gcp-almalinux-consul-server.pkr.hcl
# Build the nginx server image
packer build -var-file=variables.pkrvars.hcl packer/gcp-almalinux-nginx.pkr.hcl
You can now use Terraform to provision a Nomad cluster. This example creates a 3-node Nomad server cluster with an additional Nomad client node. The terraform.tfvars
file is generated from the original variables.pkrvars.hcl
used during the Packer build.
# Create tfvars from pkrvars and provision the cluster
sed '/image_family.*/d' variables.pkrvars.hcl > tf/terraform.tfvars
cd tf
terraform init
terraform apply
The firewall rule will open TCP ports 4646 and 8500, allowing you to access Nomad on port 4646 and Consul on port 8500 on the relevent the servers. You can access these services via a web browser using the external IP addresses of your servers.
Integration with Kubernetes is currently a work in progress. Stay tuned for updates on how to incorporate Nomad into your Kubernetes environment.