Nomad and Podman


Nomad Podman

mkdir -p /opt/nomad/plugins, download podman driver nomad-driver-podman_0.3.0_linux_amd64.zip and copy to /opt/nomad/plugins

Temporary: Running the below commands to start Podman service with a set duration. # podman system service -t 0 & or # podman system service -t 5000 &

Permanent

This is needed for the API Service,# yum install podman-remote and # cat /usr/lib/systemd/system/podman.socket

Commands to enable the daemon

# systemctl daemon-reload # systemctl enable --now podman.socket

make sure sock file exists,# ls -lt /run/podman/podman.sock

If you don’t see it then run # touch /run/podman/podman.sock

Nomad start (for non prod we use dev mode)

nomad agent -dev -bind 0.0.0.0 -log-level INFO -plugin-dir=/opt/nomad/plugins

Nomad Web UI

To access UI from web browser, http://ipaddress:4646

Nomad and Docker driver(out of the box support)

Consul on the host


job "consul" {
  datacenters = ["dc1"]
  group "consul" {
    count = 1
    task "consul" {
      driver = "raw_exec"
            
      config {
        command = "consul"
        args    = ["agent", "-dev"]
      }
      artifact {
        source = "https://releases.hashicorp.com/consul/1.9.0/consul_1.9.0_linux_amd64.zip"
      }
    }
  }
}

==================================

Create a job for Fabio and name it fabio.nomad

job "fabionew" {
  datacenters = ["dc1"]
  type = "system"

  group "fabio" {
    network {
      port "lb" {
        static = 9999
      }
      port "ui" {
        static = 9998
      }
    }
    task "fabio" {
      driver = "docker"
      config {
        image = "fabiolb/fabio"
        network_mode = "host"
        ports = ["lb","ui"]
      }

      resources {
        cpu    = 200
        memory = 128
      }
    }
  }
}

Setting type to system ensures that Fabio is run on all clients. Note that the network_mode option is set to host so that Fabio can communicate with Consul on the client nodes.

Create a job for Apache and name it webserver.nomad

job "webserver" {
  datacenters = ["dc1"]
  type = "service"

  group "webserver" {
    count = 4
    network {
	  
      port "http" {
        to = 80
      }
    }

    service {
      name = "apache-webserver"
      tags = ["urlprefix-/"]
      port = "http"
      check {
        name     = "alive"
        type     = "http"
        path     = "/"
        interval = "20s"
        timeout  = "20s"
      }
    }

    restart {
      attempts = 2
      interval = "30m"
      delay = "15s"
      mode = "fail"
    }

    task "apache" {
      driver = "docker"
      config {
        image = "httpd:latest"
        ports = ["http"]
      }
    }
  }
}

--------------------
job "http-echo-dynamic-service" {
  datacenters = ["dc1"]
  group "echo" {
    count = 3
    task "server" {
      driver = "podman"
      config {
        image = "httpd:alpine"
       }
	  }
     network {
          port "http" {
		        to     = 80 
          }
        }

      service {
        name = "http-echo"
        port = "http"
        tags = [
          "urlprefix-/http-echo"
        ]
        check {
          type     = "http"
          path     = "/"
          interval = "2s"
          timeout  = "2s"
        }
      }
    }
}