Setup nomad cluster with Vagrant
Rizqy Nugroho
Time to read
~ 3 minutes
Published
Dec 24, 23
Introduction:
Nomad, an open-source cluster manager and scheduler by HashiCorp, simplifies the deployment and management of applications at scale. Setting up a Nomad cluster in development mode is an excellent way to explore its features and functionality in a controlled environment. In this guide, we'll walk through the steps to help you establish a Nomad cluster on your local machine for development purposes.
Before we begin, ensure you have the following prerequisites installed on your machine:
Download and install Vagrant from the official website: Vagrant Downloads.
Install a virtualization provider like VirtualBox: VirtualBox Downloads.
Create a new directory for your Nomad cluster and navigate to it. Create a file named Vagrantfile
with the following content:
Vagrant.configure("2") do |config|
(1..3).each do |i|
config.vm.define "nomad-node-#{i}" do |node|
node.vm.box = "ubuntu/bionic64"
node.vm.network "private_network", type: "dhcp"
node.vm.provider "virtualbox" do |vb|
vb.memory = "512"
end
end
end
end
This configuration sets up a simple cluster with three nodes.
In the terminal, navigate to the directory containing the Vagrantfile
and run:
vagrant up
This command will create and start the virtual machines based on the configuration.
SSH into each virtual machine and install Nomad. Run the following commands for each node:
vagrant ssh nomad-node-1
sudo apt-get update
sudo apt-get install -y nomad
Repeat these commands for nomad-node-2
and nomad-node-3
.
Create a Nomad configuration file on each node. For example, create a file named nomad.hcl
with the following content:
data_dir = "/var/lib/nomad"
server {
enabled = true
bootstrap_expect = 3
}
client {
enabled = true
}
On nomad-node-1
, run:
sudo nomad agent -config=nomad.hcl
On nomad-node-2
and nomad-node-3
, run:
sudo nomad agent -config=nomad.hcl -server -join=<IP_ADDRESS_OF_NOMAD_NODE_1>
Replace <IP_ADDRESS_OF_NOMAD_NODE_1>
with the actual IP address of nomad-node-1
.
Check the status of the Nomad cluster by running the following command on any of the nodes:
nomad server members
You should see information about the three Nomad servers.
Congratulations! You've successfully set up a Nomad cluster in development mode. This guide provides a basic foundation for understanding Nomad's cluster architecture and how it manages tasks across multiple nodes. Feel free to explore more advanced configurations and Nomad features to enhance your understanding of this powerful orchestration tool.