How to run Nomad cluster on the Grid using Terraform

Nomad: Simple and Flexible Workload Orchestration

In the dynamic world of cloud computing, managing and orchestrating workloads across diverse environments can be a daunting task. Nomad emerges as a powerful solution, simplifying and streamlining the deployment, scheduling, and management of applications.

Nomad’s elegance lies in its lightweight architecture and ease of use. It operates as a single binary, minimizing resource consumption and complexity. Its intuitive user interface and straightforward configuration make it accessible to a wide range of users, from novices to experienced DevOps.

Nomad’s versatility extends beyond its user-friendliness. It seamlessly handles a wide array of workloads, including legacy applications, microservices, and batch jobs. Its adaptability extends to diverse environments, effortlessly orchestrating workloads across on-premises infrastructure and public clouds. It’s more of kubernetes for humans :slight_smile:

terraform {
  required_providers {
    grid = {
      source = "threefoldtech/grid"
    }
  }
}

resource "grid_network" "net1" {
  name        = "nomadnet"
  nodes       = [14]
  ip_range    = "10.1.0.0/16"
}
resource "grid_deployment" "d1" {
  name         = "nomad"
  node         = 14
  network_name = grid_network.net1.name
  vms {
    name       = "server1"
    flist      = "https://hub.grid.tf/aelawady.3bot/abdulrahmanelawady-nomad-server-latest.flist"
    cpu        = 2
    memory     = 1024
    entrypoint = "/sbin/zinit init"
    ip         = "10.1.2.2"
    env_vars = {
      SSH_KEY = file("~/.ssh/id_rsa.pub")
    }
    planetary = true
  }
  vms {
    name       = "server2"
    flist      = "https://hub.grid.tf/aelawady.3bot/abdulrahmanelawady-nomad-server-latest.flist"
    cpu        = 2
    memory     = 1024
    entrypoint = "/sbin/zinit init"
    env_vars = {
      SSH_KEY = file("~/.ssh/id_rsa.pub")
      FIRST_SERVER_IP = "10.1.2.2"
    }
    planetary = true
  }
  vms {
    name       = "server3"
    flist      = "https://hub.grid.tf/aelawady.3bot/abdulrahmanelawady-nomad-server-latest.flist"
    cpu        = 2
    memory     = 1024
    entrypoint = "/sbin/zinit init"
    env_vars = {
      SSH_KEY = file("~/.ssh/id_rsa.pub")
      FIRST_SERVER_IP = "10.1.2.2"
    }
    planetary = true
  }
  vms {
    name       = "client1"
    flist      = "https://hub.grid.tf/aelawady.3bot/abdulrahmanelawady-nomad-client-latest.flist"
    cpu        = 2
    memory     = 1024
    entrypoint = "/sbin/zinit init"
    env_vars = {
      SSH_KEY = file("~/.ssh/id_rsa.pub")
      FIRST_SERVER_IP = "10.1.2.2"
    }
    planetary = true
  }
  vms {
    name       = "client2"
    flist      = "https://hub.grid.tf/aelawady.3bot/abdulrahmanelawady-nomad-client-latest.flist"
    cpu        = 2
    memory     = 1024
    entrypoint = "/sbin/zinit init"
    env_vars = {
      SSH_KEY = file("~/.ssh/id_rsa.pub")
      FIRST_SERVER_IP = "10.1.2.2"
    }
    planetary = true
  }
}

output "server1_ip" {
  value = grid_deployment.d1.vms[0].ygg_ip
}
output "server2_ip" {
  value = grid_deployment.d1.vms[1].ygg_ip
}
output "server3_ip" {
  value = grid_deployment.d1.vms[2].ygg_ip
}
output "client1_ip" {
  value = grid_deployment.d1.vms[3].ygg_ip
}
output "client2_ip" {
  value = grid_deployment.d1.vms[4].ygg_ip
}

Congrats, you have now a cluster of 3 server nodes and 2 client nodes to deploy your workloads on :slight_smile:

If you’re wondering how the image is built, you can check this pull request

You can now use the cluster to deploy your workloads, check deploying a redis workload on the cluster

2 Likes