Skip to main content

Infrastructure Options

· 5 min read
Max Kaido
Architect

Both Terraform + Nomad and Ansible + Dokku are excellent choices, each offering unique benefits. Let’s break them down and guide you through implementation for either approach:

Option 1: Terraform + Nomad

This combination gives you infrastructure as code with workload orchestration in a declarative and scalable manner.

Key Features:

  • Terraform:
    • Manage cloud and local servers declaratively.
    • Easily scale infrastructure by editing configurations.
  • Nomad:
    • Orchestrate workloads (containerized and non-containerized).
    • Lightweight and simpler than Kubernetes.

How It Works:

  1. Terraform provisions your infrastructure (cloud servers, local machines).
  2. Nomad deploys and manages services and applications on the provisioned nodes.

Implementation Plan:

  1. Install Terraform:

    • Install Terraform on your control node.
      sudo apt update && sudo apt install -y terraform
  2. Define Infrastructure:

    • Create a Terraform configuration (main.tf) for your cloud and local servers.

    • Example:

      provider "aws" {
      region = "us-east-1"
      }

      resource "aws_instance" "nomad_servers" {
      ami = "ami-12345678"
      instance_type = "t3.medium"
      count = 3
      tags = {
      Name = "nomad-server"
      }
      }
  3. Deploy Infrastructure:

    • Initialize and apply the configuration:
      terraform init
      terraform apply
  4. Install Nomad:

    • On each server, install Nomad:
      curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
      sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
      sudo apt update && sudo apt install nomad -y
  5. Configure Nomad:

    • Set up Nomad server on one node:

      sudo nano /etc/nomad.d/server.hcl

      Example config:

      server {
      enabled = true
      bootstrap_expect = 3
      }
    • Set up Nomad clients on other nodes.

  6. Deploy Services:

    • Write a Nomad job file (service.nomad):

      job "example" {
      group "web" {
      task "nginx" {
      driver = "docker"

      config {
      image = "nginx:latest"
      }
      }
      }
      }
    • Run the job:

      nomad run service.nomad
  7. Monitor Nomad:

    • Use Nomad’s built-in UI (http://<server-ip>:4646) or integrate it with Grafana for metrics.

Option 2: Ansible + Dokku

This approach focuses on configuration management with lightweight application hosting.

Key Features:

  • Ansible:
    • Automate server setup and software deployment.
  • Dokku:
    • Easily deploy and manage containerized applications.

How It Works:

  1. Ansible sets up servers and installs Dokku.
  2. Dokku acts as a lightweight PaaS for your applications.

Implementation Plan:

  1. Install Ansible:

    • On your control node:
      sudo apt update && sudo apt install ansible -y
  2. Configure Inventory:

    • Create an inventory file (/etc/ansible/hosts):
      [all]
      server1 ansible_host=192.168.1.101 ansible_user=debuser
      server2 ansible_host=192.168.1.102 ansible_user=debuser
  3. Write Playbook to Set Up Dokku:

    • Create a playbook (dokku_setup.yml):

      ---
      - hosts: all
      become: true
      tasks:
      - name: Install Dokku
      shell: |
      wget https://raw.githubusercontent.com/dokku/dokku/v0.30.0/bootstrap.sh
      sudo DOKKU_TAG=v0.30.0 bash bootstrap.sh

      - name: Set up Dokku
      shell: |
      sudo dokku plugin:install-dependencies
      sudo dokku domains:enable
  4. Deploy Dokku:

    • Run the playbook:
      ansible-playbook dokku_setup.yml
  5. Deploy Applications with Dokku:

    • On your local machine:
      git remote add dokku dokku@<server-ip>:myapp
      git push dokku main
  6. Monitor Dokku:

    • Use Dokku’s built-in tools for service health or integrate with Prometheus/Grafana.

Comparison

FeatureTerraform + NomadAnsible + Dokku
Ease of SetupModerateEasy
Infrastructure ControlHigh (provision and orchestrate)Low (manual provisioning)
Service DeploymentHighly scalable (containers, binaries, VMs)Containerized apps only
ObservabilityBuilt-in + GrafanaDokku tools + Grafana
ScalabilityHighModerate
Best Use CaseDynamic infrastructure + complex servicesLightweight container hosting

Recommendation

  • Choose Terraform + Nomad if:

    • You need dynamic infrastructure provisioning and scalable workload orchestration.
    • You want a fully declarative approach.
    • You’re planning to manage a mix of containers and non-containerized apps.
  • Choose Ansible + Dokku if:

    • You want a simple, quick setup.
    • You’re primarily deploying web applications or microservices.
    • You value familiarity and ease of use.

Let me know which one you prefer, and I’ll provide further guidance for a detailed setup!

Setting up a new laptop for integration into your infrastructure would involve different workflows for Terraform + Nomad and Ansible + Dokku. Here’s a detailed breakdown:


Case 1: Terraform + Nomad

In this setup, the new laptop becomes part of the infrastructure provisioned and managed by Terraform. Nomad will orchestrate its workloads.


Step 1: Prepare the Laptop for Terraform Management

  1. Install Required Tools:

    • Install SSH:
      sudo apt update && sudo apt install openssh-server -y
      sudo systemctl enable ssh
      sudo systemctl start ssh
    • Generate SSH keys for Terraform access:
      ssh-keygen -t rsa -b 4096 -C "laptop@infra"
  2. Add the Laptop to Terraform Inventory:

    • Update your Terraform configuration to include the laptop:

      resource "null_resource" "laptop" {
      connection {
      type = "ssh"
      user = "debuser"
      host = "192.168.1.101"
      private_key = file("~/.ssh/id_rsa")
      }

      provisioner "remote-exec" {
      inline = [
      "sudo apt update",
      "sudo apt install -y nomad",
      ]
      }
      }
  3. Provision the Laptop:

    • Apply the updated Terraform configuration:
      terraform apply

Step 2: Integrate the Laptop with Nomad

  1. Install Nomad:

    • Terraform provisions Nomad during setup, but you can manually verify:
      sudo apt install nomad -y
  2. Configure Nomad as a Client:

    • Create a client configuration file:
      sudo nano /etc/nomad.d/client.hcl
      Example content:
      client {
      enabled = true
      servers = ["192.168.1.200"] # IP of Nomad server
      }
  3. Start the Nomad Agent:

    sudo systemctl enable nomad
    sudo systemctl start nomad
  4. Test Nomad Integration:

    • Run a simple job to verify:
      nomad job run example.nomad

Step 3: Monitor and Deploy Services

  • Monitor the laptop through the Nomad UI (http://<server-ip>:4646).
  • Deploy workloads via Nomad job specifications.

Case 2: Ansible + Dokku

With this setup, the new laptop becomes part of your Ansible inventory and uses Dokku for service management.


Step 1: Prepare the Laptop for Ansible Management

  1. Install Required Tools:

    • Install SSH and allow passwordless login:
      sudo apt update && sudo apt install openssh-server -y
      sudo systemctl enable ssh
      sudo systemctl start ssh
      ssh-keygen -t rsa
    • Copy your Ansible control node’s SSH key:
      ssh-copy-id debuser@192.168.1.101
  2. Add the Laptop to Ansible Inventory:

    • Update /etc/ansible/hosts:
      [laptops]
      laptop1 ansible_host=192.168.1.101 ansible_user=debuser

Step 2: Configure the Laptop via Ansible

  1. Create an Ansible Playbook:

    • Example playbook for Dokku installation:

      ---
      - hosts: laptops
      become: true
      tasks:
      - name: Update the system
      apt:
      update_cache: yes

      - name: Install Dokku
      shell: |
      wget https://raw.githubusercontent.com/dokku/dokku/v0.30.0/bootstrap.sh
      sudo DOKKU_TAG=v0.30.0 bash bootstrap.sh

      - name: Configure Dokku
      shell: |
      sudo dokku domains:enable
      sudo dokku apps:create laptop-app
  2. Run the Playbook:

    ansible-playbook dokku_setup.yml

Step 3: Deploy Services with Dokku

  1. Create a Git Remote:
    • On your local machine:
      git remote add dokku dokku@192.168.1.101:laptop-app
  2. Push Code:
    git push dokku main
  3. Test the Service:
    • Access the app via the Dokku-provided domain (e.g., http://<laptop-ip>).

Comparison of Laptop Setup

FeatureTerraform + NomadAnsible + Dokku
Ease of SetupModerate (requires Terraform config updates)Easy (uses Ansible inventory and playbooks)
ScalabilityHigh (automates provisioning and orchestration)Moderate (limited to individual services)
Service DeploymentSupports diverse workloadsPrimarily containerized apps
ObservabilityIntegrated via NomadIntegrated via Dokku and Prometheus
Best Use CaseDynamic orchestrationSimple, quick app deployment

Recommendation

  • Choose Terraform + Nomad if:

    • You want the laptop to be part of a dynamic infrastructure with scalable workload orchestration.
    • You need to run non-containerized workloads or use mixed workloads.
  • Choose Ansible + Dokku if:

    • The laptop will primarily host containerized applications.
    • You value simplicity and prefer to manage services with Git-based workflows.

Let me know if you’d like detailed commands or configurations for either setup!