feat: add floating IP to pihole

This commit is contained in:
vincent 2022-11-27 11:09:50 +01:00
parent 2c770c0163
commit 1e42376ed4

View File

@ -7,20 +7,18 @@ job "pihole" {
} }
type = "service" type = "service"
constraint { constraint {
attribute = "${attr.unique.hostname}" attribute = "${attr.cpu.arch}"
value = "oscar" value = "amd64"
} }
group "pi-hole" { group "pi-hole" {
network { network {
mode = "host"
port "dns" { port "dns" {
static = 53 static = 53
} }
port "http" { port "http" {
static = 8090
to = 80
} }
} }
service { service {
name = "pihole-gui" name = "pihole-gui"
tags = ["pihole", "admin", tags = ["pihole", "admin",
@ -37,12 +35,37 @@ job "pihole" {
} }
task "server" { task "server" {
driver = "docker" driver = "docker"
service {
name = "dns"
port = "dns"
check {
name = "service: dns tcp check"
type = "tcp"
interval = "10s"
timeout = "2s"
success_before_passing = "3"
failures_before_critical = "3"
}
check {
name = "service: dns dig check"
type = "script"
command = "/usr/bin/dig"
args = ["+short", "@127.0.0.1"]
interval = "10s"
timeout = "2s"
check_restart {
limit = 3
grace = "60s"
}
}
}
config { config {
image = "pihole/pihole:latest" image = "pihole/pihole:latest"
ports = [ network_mode = "host"
"dns",
"http",
]
volumes = [ volumes = [
"local/dnsmasq.d/02-localresolver.conf:/etc/dnsmasq.d/02-localresolver.conf", "local/dnsmasq.d/02-localresolver.conf:/etc/dnsmasq.d/02-localresolver.conf",
"/mnt/diskstation/nomad/pihole:/etc/pihole" "/mnt/diskstation/nomad/pihole:/etc/pihole"
@ -57,10 +80,13 @@ job "pihole" {
TZ = "Europe/Paris" TZ = "Europe/Paris"
DNS1 = "1.1.1.1" DNS1 = "1.1.1.1"
DNS2 = "80.67.169.40" DNS2 = "80.67.169.40"
WEB_PORT = "${NOMAD_PORT_http}"
} }
template { template {
data = <<EOH data = <<EOH
INTERFACE = {{ sockaddr "GetPrivateInterfaces | include \"network\" \"192.168.1.0/24\" | attr \"name\"" }}
WEBPASSWORD="{{with secret "secrets/data/nomad/pihole"}}{{.Data.data.WEBPASSWORD}}{{end}}" WEBPASSWORD="{{with secret "secrets/data/nomad/pihole"}}{{.Data.data.WEBPASSWORD}}{{end}}"
EOH EOH
destination = "local/file.env" destination = "local/file.env"
@ -81,8 +107,46 @@ local-ttl=2
} }
resources { resources {
memory = 200 memory = 100
} }
} }
task "keepalived" {
driver = "docker"
lifecycle {
hook = "poststart"
sidecar = true
}
env {
KEEPALIVED_ROUTER_ID = "53"
KEEPALIVED_STATE = "MASTER"
KEEPALIVED_VIRTUAL_IPS = "192.168.1.4"
}
template{
destination = "local/env.yaml"
change_mode = "restart"
env= true
data = <<EOH
KEEPALIVED_INTERFACE= {{ sockaddr "GetPrivateInterfaces | include \"network\" \"192.168.1.0/24\" | attr \"name\"" }}
EOH
}
config {
image = "osixia/keepalived:2.0.20"
network_mode = "host"
cap_add = [
"NET_ADMIN",
"NET_BROADCAST",
"NET_RAW"
]
}
resources {
cpu = 20
memory = 20
}
}
} }
} }