Set up a Nomad cluster on Azure
This tutorial will guide you through deploying a Nomad cluster with access control lists (ACLs) enabled on Azure. Consider checking out the cluster setup overview first as it covers the contents of the code repository used in this tutorial.
Prerequisites
For this tutorial, you need:
- Packer 1.9.4 or later
- Terraform 1.2.0 or later
- Nomad 1.7.7 or later
- An Azure account configured for use with Terraform
- az CLI 2.60.0 or later
Note
This tutorial creates Azure resources that may not qualify as part of the Azure free tier. Be sure to follow the Cleanup process at the end of this tutorial so you don't incur any additional unnecessary charges.
Clone the code repository
The cluster setup code repository contains configuration files for creating a Nomad cluster on Azure. It uses Consul for the initial setup of the Nomad servers and clients and enables ACLs for both Consul and Nomad.
Clone the code repository.
Navigate to the cloned repository folder.
Navigate to the azure
folder.
Create the Nomad cluster
There are two main steps to creating the cluster: building a virtual machine image with Packer and provisioning the cluster infrastructure with Terraform. Both Packer and Terraform require that you configure variables before you run commands. The variables.hcl.example
file contains the configuration you need for this tutorial.
Update the variables file for Packer
Rename variables.hcl.example
to variables.hcl
and open it in your text editor.
Update the location
variable with your preferred Azure datacenter location. In this example, the location is eastus
. The remaining variables are for Terraform, and you update them after building the VM image.
Create an Azure resource group
Packer needs an existing resource group in order to build the VM image. Initialize Terraform to download required plugins and set up the workspace.
Next, run Terraform in target mode so that it only deploys the resource group for Packer to use. Enter yes
to confirm the run.
Build the VM image
Now that there is an existing resource group, Packer is ready to build the VM image. First, initialize Packer to download the required plugins.
Tip
packer init
returns no output when it finishes successfully.
Then, build the image and provide the variables file with the -var-file
flag.
Tip
Packer will print out a Warning: Undefined variable
message notifying you that some variables were set in variables.hcl
but not used, this is only a warning. The build will still complete sucessfully.
Packer outputs the specific VM image name once it finishes building the image. In this example, the value is hashistack.20221202190723
.
Update the variables file for Terraform
Open variables.hcl
in your text editor and update the image_name
variable with the value output from the Packer build contained in ManagedImageName
. In this example, the value is hashistack.20221202190723
.
The remaining variables in variables.hcl
are optional.
- Â
allowlist_ip
is a CIDR range specifying which IP addresses are allowed to access the Consul and Nomad UIs on ports8500
and4646
as well as SSH on port22
. The default value of0.0.0.0/0
allows traffic from everywhere. - Â
name
is a prefix for naming the Azure resources. - Â
server_instance_type
andclient_instance_type
are the virtual machine instance types for the cluster server and client nodes, respectively. - Â
server_count
andclient_count
are the number of nodes to create for the servers and clients, respectively.
Deploy the Nomad cluster
Run the Terraform deployment and provide the variables file with the -var-file
flag. Respond yes
to the prompt to confirm the operation. The provisioning takes several minutes. The Consul and Nomad web interfaces are available upon completion.
Verify the services are in a healthy state. Navigate to the Consul UI in your web browser with the URL in the Terraform output.
Click on the Log in button and use the bootstrap token secret consul_bootstrap_token_secret
from the Terraform output to log in.
Click on the Nodes page from the sidebar navigation. There are six healthy nodes, including three Consul servers and three Consul clients created with Terraform.
Set up access to Nomad
Run the post-setup.sh
script.
Note
It may take some time for the setup scripts to complete and for the Nomad user token to become available in the Consul KV store. If the post-setup.sh
script doesn't work the first time, wait a couple of minutes and try again.
Apply the export
commands from the output.
Finally, verify connectivity to the cluster with nomad node status
Navigate to the Nomad UI in your web browser with the URL in the post-setup.sh
script output. Click on Sign In in the top right corner and log in with the bootstrap token saved in the NOMAD_TOKEN
environment variable. Set the Secret ID to the token's value and click Sign in with secret.
Click on the Clients page from the sidebar navigation and feel free to explore the UI.
Cleanup
Destroy infrastructure
Use terraform destroy
to remove the provisioned infrastructure, along with the VM image built by Packer. Respond yes
to the prompt to confirm removal.
Delete the VM image
Your Azure account still has the virtual machine image, which you may be charged for. Delete the image by running the az image delete
command. In this example, the VM image name is hashistack.20221202190723
.
Next steps
In this tutorial you created a Nomad cluster on Azure with Consul and ACLs enabled. From here, you may want to:
- Run a job with a Nomad spec file or with Nomad Pack
- Test out native service discovery in Nomad
For more information, check out the following resources.
- Learn more about managing your Nomad cluster
- Read more about the ACL stanza and using ACLs