Hi,
I would like to do something similar to this, but I would like to use nomad for creating the subnet and the job.
As far as I understand the nomad docs I have to use CNI for this. I was able to come up with a config file:
{
"name": "mynet",
"cniVersion": "0.4.0",
"plugins": [
{
"type": "bridge",
"isDefaultGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"ranges": [
[
{
"subnet": "172.22.0.0/16"
}
]
]
}
}
]
}
I restart nomad agent, it parses the config file, so far so good.
The job file for pihole is the following:
job "pihole" {
datacenters = ["dc1"]
group "pihole" {
network {
mode = "cni/mynet"
port "http" {
static = 80
to = 80
}
port "DNS" {
static = 53
to = 53
}
}
task "pihole" {
driver = "docker"
env {
TZ = "Europe/Budapest"
VIRTUAL_HOST = "pi.hole"
PROXY_LOCATION = "pi.hole"
FTLCONF_LOCAL_IPV4 = "127.0.0.1"
WEBPASSWORD = "piholepass"
}
config {
image = "pihole/pihole:latest"
ports = ["http", "DNS"]
ipv4_address = "172.22.0.2"
volumes = [
"/home/voroskoi/.docker/pihole/etc:/etc/pihole",
"/home/voroskoi/.docker/pihole/dnsmasq.d:/etc/dnsmasq.d",
]
}
}
}
}
If I use set network.mode
to bridge
(and comment out ipv4_address
) it works fine. However with this job file the job starts up fine, but the container do not have access to the internet.
I find this in pihole log:
[âś—] DNS resolution is currently unavailable
I have checked ip addresses and firewall rules, CNI seems to take care of everything:
9: cni0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 72:e3:c6:d0:fd:06 brd ff:ff:ff:ff:ff:ff
inet 172.22.0.1/16 brd 172.22.255.255 scope global cni0
valid_lft forever preferred_lft forever
inet6 fe80::fc3a:eaff:fe94:19df/64 scope link
valid_lft forever preferred_lft forever
13: veth8b554574@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue master cni0 state UP
link/ether 72:e3:c6:d0:fd:06 brd ff:ff:ff:ff:ff:ff
inet6 fe80::70e3:c6ff:fed0:fd06/64 scope link
valid_lft forever preferred_lft forever
voroskoi ~ ❯ doas iptables -t nat --list-rules |grep -e 172.22 -e CNI-8cbcba57a0fe6959dd7aee6d
-N CNI-8cbcba57a0fe6959dd7aee6d
-A POSTROUTING -s 172.22.0.12/32 -m comment --comment "name: \"mynet\" id: \"34f2526f-5cc1-4714-8c6a-1efbfc606981\"" -j CNI-8cbcba57a0fe6959dd7aee6d
-A CNI-8cbcba57a0fe6959dd7aee6d -d 172.22.0.0/16 -m comment --comment "name: \"mynet\" id: \"34f2526f-5cc1-4714-8c6a-1efbfc606981\"" -j ACCEPT
-A CNI-8cbcba57a0fe6959dd7aee6d ! -d 224.0.0.0/4 -m comment --comment "name: \"mynet\" id: \"34f2526f-5cc1-4714-8c6a-1efbfc606981\"" -j MASQUERADE
The ipv4_address
line does not seem to work as the pihole ip is 172.22.0.12
, but that is an other problem.
What am I doing here wrong?