0

I'm starting to do some tests with nomad and I could use a bit on help on the easiest way to add networking to a group task. Basically my questions are:

Which is the easiest way to add internal networking between tasks? and Shouldn't the tasks on the same group have default access to each other? Or there is something I'm doing wrong?

I have this configuration:

job "job" {
    datacenters = [ "dc1" ]
    type = "service"
    group "group" {
      count = 1
        task "db" {
            kill_timeout = "120s"
            driver = "docker"
            config {
                image = "dbimage"
                port_map {
                  db = 3306
                }
            }
            env {
                MYSQL_DATABASE = "db"
                MYSQL_ROOT_PASSWORD = "pass"
            }
            
            service {
                name = "db"
                port = "db"
            }
            resources {
                memory = 256
                network {
                    mode = "host"
                    port "db" {}
                }
            }
        }
        task "app1" {
            driver = "docker"
            kill_timeout = "120s"
            config {
                image = "app1"
                port_map {
                  app1 = 5000
                }
            }
            service {
                name = "app1"
                port = "app1"
            }
            resources {
                memory = 128
                network {
                    mode = "host"
                    port "app1" {}
                }
            }
        }
        task "app2" {
            driver = "docker"
            kill_timeout = "120s"
            config {
                image = "app2:image"
                port_map {
                  app2 = 4000
                }
            }
            env {
                .....
            }
            service {
                name = "app2"
                port = "app2"
            }
            resources {
                memory = 256
                network {
                    mode = "host"
                    port "app2" {}
                }
            }
        }
    }
}

and I would like that my app1 and app2 could talk internally to each other and to the db. I have read about the the nomad ADDRESS variables that are passed to each container and I tried to reach connectivity but I get connection refused. Is the only way to accomplish this behaviour with connect ? Or there is a simpler way? Appreciate the help :)

Gustavo Yance
  • 101
  • 2
  • 12
  • Have you seen [this post](https://stackoverflow.com/questions/63601913/nomad-and-port-mapping/65458554#65458554), specifically TLDR; section?) – Ilya Kisil Jan 18 '21 at 12:49

1 Answers1

1

You can use NOMAD_ADDR_task_port variable for connect to another task in job group.

For example, use $NOMAD_ADDR_db_db environment variable in app1 and app2 tasks to get ip:port pair of db task.

For more info, look https://www.nomadproject.io/docs/runtime/environment

SAS
  • 23
  • 6