Skip to content

Setup Nomad

Matthias Vandermaesen edited this page Aug 18, 2022 · 9 revisions

Installing nomad / consul:

Installation on Fedora 36.

$ sudo dnf install -y dnf-plugins-core
$ sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
$ sudo dnf -y install nomad

See: https://learn.hashicorp.com/tutorials/nomad/get-started-install?in=nomad/get-started

Startup nomad / consul:

In two separate terminal sessions:

$ sudo nomad agent -dev -bind 0.0.0.0 -log-level INFO -config /etc/nomad.d/nomad.hcl
$ consul agent -dev

Production deployment: https://learn.hashicorp.com/tutorials/nomad/production-deployment-guide-vm-with-consul

Configure DNS forwarding for Consul Service discovery

See: https://learn.hashicorp.com/tutorials/consul/dns-forwarding

Configuration for using nomad (single node) on your laptop

In /etc/nomad/nomad.hcl:

# Full configuration options can be found at https://www.nomadproject.io/docs/configuration

data_dir  = "/opt/nomad/data"
bind_addr = "0.0.0.0"

server {
  # license_path is required as of Nomad v1.1.1+
  #license_path = "/etc/nomad.d/nomad.hcl"
  enabled          = true
  bootstrap_expect = 1
}

client {
  enabled = true
  servers = ["127.0.0.1"]

  host_volume "imagor" {
    path      = "/path/to/imagor/data
    read_only = false
  }

  host_volume "biblio_backend" {
    path      = "/path/to/bibliobackend/data"
    read_only = false
  }
}

You need a data_dir which stores artefacts when running Nomad so: sudo mkdir -p /opt/nomad/data.

Starting Biblio backend with Nomad

Get the code of the biblio-backend.nomad file. This is a job definition which will need to spin up a container in Nomad:

Running the job in Nomad:

$ nomad job run biblio-backend.nomad

Wait until the job finishes. You'll have an allocation which represent 3 running docker containers on your machine, managed by Nomad.

Checking the logs of an allocation / docker. The ID of the allocation can be found by running nomad job status biblio-backend

$ nomad alloc logs -stderr <alloc-id>

You can dynamically make a change to the nomad file and then plan and run the job again to perform an update. Nomad does all the work of managing the containers for you:

$ nomad job plan biblio-backend.nomad
# copy the run command with the -check parameter from the output
$ nomad job run -check <priority> biblio-backend.nomad

Installing CNI tools to be able to use the "bridge" network mode:

https://discuss.hashicorp.com/t/failed-to-find-plugin-bridge-in-path/3095

$ curl -L -o cni-plugins.tgz https://github.com/containernetworking/plugins/releases/download/v0.8.1/cni-plugins-linux-amd64-v0.8.1.tgz
$ sudo mkdir -p /opt/cni/bin
$ sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz

Working with postgres as a seperate service on your host (not managed by nomad)

edit postgresql.conf:

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)

edit pg_hba.conf

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             0.0.0.0/0               md5
host    all             all             127.0.0.1/32            md5
host    all             all             localhost               md5

Working with elasticsearch as a seperate service on your host (not managed by nomad)

edit /etc/elasticsearch/elasticsearch.yml

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
# network.host: 127.0.0.1
network.bind_host: 0.0.0.0
network.publish_host: 127.0.0.1

References:

NOMAD

https://storiesfromtheherd.com/nomad-tips-and-tricks-766878dfebf4
https://storiesfromtheherd.com/just-in-time-nomad-80f57cd403ca
https://adri-v.medium.com/just-in-time-nomad-running-traefik-on-hashiqube-7d6dfd8ef9d8
https://mykidong.medium.com/install-nomad-cluster-d9a40d2206f5 # cluster
https://community.hetzner.com/tutorials/install-nomad-consul-cluster # cluster
https://mrkaran.dev/posts/home-server-nomad/
https://mrkaran.dev/posts/nomad-networking-explained/ # networking in nomad
https://faun.pub/just-in-time-nomad-running-temporal-on-nomad-5fee139f37ea # temporal @ nomad
https://atodorov.me/2021/07/09/logging-on-nomad-and-log-aggregation-with-loki/ # logging @ nomad
https://danielabaron.me/blog/nomad-tips-and-tricks/ # tips 'n tricks
https://github.com/hashicorp/nomad-guides
https://learn.hashicorp.com/tutorials/nomad/stateful-workloads-host-volumes?in=nomad/stateful-workloads # mounting volumes
https://www.nomadproject.io/docs/job-specification/volume

CONSUL

https://learn.hashicorp.com/tutorials/consul/get-started-service-discovery?in=consul/getting-started

Clone this wiki locally