Reputation: 405
I started two Nomad jobs, one for PostgreSQL and another on for pgAdmin on the Nomad dev on my MacOS. The jobspecs are these:
## postgres.nomad
job "postgres" {
datacenters = ["dc1"]
type = "service"
group "postgres" {
count = 1
task "postgres" {
driver = "docker"
config {
image = "postgres"
network_mode = "host"
port_map {
db = 5432
}
}
env {
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="postgres"
}
logs {
max_files = 5
max_file_size = 15
}
resources {
cpu = 1000
memory = 1024
network {
mbits = 10
port "db" {
static = 5432
}
}
}
service {
name = "postgres"
tags = ["postgres for vault"]
port = "db"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
}
update {
max_parallel = 1
min_healthy_time = "5s"
healthy_deadline = "5m"
auto_revert = false
canary = 0
}
}
## pgadmin.nomad
job "pgadmin4" {
datacenters = ["dc1"]
type = "service"
group "pgadmin4" {
count = 1
task "pgadmin4" {
driver = "docker"
config {
image = "dpage/pgadmin4"
network_mode = "host"
port_map {
db = 8080
}
volumes = [
"local/servers.json:/servers.json",
"local/servers.passfile:/root/.pgpass"
]
}
template {
perms = "600"
change_mode = "noop"
destination = "local/servers.passfile"
data = <<EOH
postgres.service.consul:5432:postgres:postgres:postgres
EOH
}
template {
change_mode = "noop"
destination = "local/servers.json"
data = <<EOH
{
"Servers": {
"1": {
"Name": "Local Server",
"Group": "Server Group 1",
"Port": "5432",
"Username": "root",
"PassFile": "/root/.pgpass",
"Host": "postgres.service.consul",
"SSLMode": "disable",
"MaintenanceDB": "postgres"
}
}
}
EOH
}
env {
PGADMIN_DEFAULT_EMAIL="[email protected]"
PGADMIN_DEFAULT_PASSWORD="yoursecurepassword"
PGADMIN_LISTEN_PORT="5050"
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION="False"
PGADMIN_SERVER_JSON_FILE="/servers.json"
}
logs {
max_files = 5
max_file_size = 15
}
resources {
cpu = 1000
memory = 1024
network {
mbits = 10
port "ui" {
static = 5050
}
}
}
service {
name = "pgadmin"
tags = [ "urlprefix-/pgadmin strip=/pgadmin"]
port = "ui"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
}
update {
max_parallel = 1
min_healthy_time = "5s"
healthy_deadline = "3m"
auto_revert = false
canary = 0
}
}
All of the jobs have been deployed successfully and has their status as running.
As seen in the jobspecs, pgadmin should be running in localhost:5050 but whenever I try to reach this address in the browser I get the "Can't connect to the server" error. Is there any configuration missing?
Upvotes: 1
Views: 1470
Reputation: 974
job -> group -> network
, see herenetwork_mode = "host"
if you just want to expose a single port.here's avaliable config
job "postgres" {
datacenters = ["dc1"]
type = "service"
group "postgres" {
count = 1
task "postgres" {
driver = "docker"
config {
image = "postgres"
ports = ["db"]
}
env {
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="postgres"
}
logs {
max_files = 5
max_file_size = 15
}
resources {
cpu = 1000
memory = 1024
}
service {
name = "postgres"
tags = ["postgres for vault"]
port = "db"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
network {
mbits = 10
port "db" {
static = 5432
}
}
}
update {
max_parallel = 1
min_healthy_time = "5s"
healthy_deadline = "5m"
auto_revert = false
canary = 0
}
}
job "pgadmin4" {
datacenters = ["dc1"]
type = "service"
group "pgadmin4" {
count = 1
task "pgadmin4" {
driver = "docker"
config {
image = "dpage/pgadmin4"
ports = ["ui"]
volumes = [
"local/servers.json:/servers.json",
"local/servers.passfile:/root/.pgpass"
]
}
template {
perms = "600"
change_mode = "noop"
destination = "local/servers.passfile"
data = <<EOH
postgres.service.consul:5432:postgres:postgres:postgres
EOH
}
template {
change_mode = "noop"
destination = "local/servers.json"
data = <<EOH
{
"Servers": {
"1": {
"Name": "Local Server",
"Group": "Server Group 1",
"Port": "5432",
"Username": "root",
"PassFile": "/root/.pgpass",
"Host": "postgres.service.consul",
"SSLMode": "disable",
"MaintenanceDB": "postgres"
}
}
}
EOH
}
env {
PGADMIN_DEFAULT_EMAIL="[email protected]"
PGADMIN_DEFAULT_PASSWORD="yoursecurepassword"
PGADMIN_LISTEN_PORT="5050"
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION="False"
PGADMIN_SERVER_JSON_FILE="/servers.json"
}
logs {
max_files = 5
max_file_size = 15
}
resources {
cpu = 1000
memory = 1024
}
service {
name = "pgadmin"
tags = [ "urlprefix-/pgadmin strip=/pgadmin"]
port = "ui"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
network {
mbits = 10
port "ui" {
static = 5050
}
}
}
update {
max_parallel = 1
min_healthy_time = "5s"
healthy_deadline = "3m"
auto_revert = false
canary = 0
}
}
Upvotes: 0