Issue when running mongodb with Nomad

Hi, all!
I’m trying to launch MongoDB with Nomad job. Nomad works with Consul. But, when I do it, I receive an error:

### mongodb 1 unplaced

* Constraint `missing compatible host volumes` filtered 1 node
* Constraint `${node.unique.name} = wl01-mongodb-prod-02` filtered 14 nodes

Here is my nomad job:

job "mongodb-prod" {

  datacenters = ["sms"]
  type = "service"
  namespace = "SMS-PROD"

  constraint {
    attribute = "${node.unique.name}"
    #operator  = "regexp"
    value     = "wl01-mongodb-prod-02"
  }

  group "mongodb" {
    network {
      port  "mdb" {
        static = 27017
      }
      dns {
        servers = ["172.17.0.1", "172.21.10.10", "172.21.11.10"]
      }
    }
    
    restart {
     attempts = 3
     delay    = "30s"
     interval = "3m"
     mode     = "fail"
    }
    volume "MDB-PROD" {
      type      = "host"
      read_only = false
      source    = "MDB-PROD"
    }

    task "mongodb-prod" {
      driver = "docker"

      volume_mount {
        volume      = "MDB-PROD"
        destination = "/DATA/MDB-PROD"
        read_only   = false
      }

      config {
        image = "mongo:latest"
        ports = ["mdb"]

       volumes = [
        "local/mongod.conf:/etc/mongod.conf"
       ]

       command = "mongod"
       args = ["-f","/etc/mongod.conf"]

       network_mode = "host"
     }

artifact {
        source        = "http://127.0.0.1:8500/v1/kv/MONGODB/SMS-PROD/mongod.conf?raw"
        destination   = "local/"
}
template {
        source        = "local/mongod.conf"
        destination   = "local/mongod.conf"
}

     resources {
       cpu    = 1000
       memory = 1024
     }

     service {
       name = "mongodb-prod"
       tags = ["SMS","mongodb","MGMT","prod"]
       port = "mdb"

     }

   }
 }
}

What am I doing wrong?

Hi @Dagora77!

From those that run output looks like there are 2 constraints your job needs to have satisfied before it can be placed.

  1. There needs to be a node with name wl01-mongodb-prod-02
  2. That node needs a MDB-PROD host volume

Can you check that you actually have a node that meets those requirements?

For starters you can use nomad node status to make sure you have a node of that exact name, and then nomad node status -verbose <id> to inspect that node and see you have the correct volume mount defined on it.

Hello, @seth.hoenig .

  1. Yeah, I have node with name wl01-mongodb-prod-02
  2. But there are no host volumes with the name MDB-PROD.

Could you tell me, please, how can I create appropriate host volume?

You’ll want to declare a host_volume in your Nomad Client configuration

1 Like

Thank you! I found an example of how to do it :slightly_smiling_face: