3.1K
Many thanks to @towe75 and Pascom for contributing this plugin to Nomad!
This project has a go.mod definition. So you can clone it to whatever directory you want. It is not necessary to setup a go path at all. Ensure that you use go 1.13 or newer.
$ git clone [email protected]:hashicorp/nomad-driver-podman
cd nomad-driver-podman
./build.sh
podman installedYou need a varlink enabled podman binary and a system socket activation unit, see https://podman.io/blogs/2019/01/16/podman-varlink.html.
nomad agent, nomad-driver-podman and podman will reside on the same host, so you do not have to worry about the ssh aspects of podman varlink.
Ensure that nomad can find the plugin, see plugin_dir
volumes stanza:
plugin "nomad-driver-podman" {
config {
volumes {
enabled = true
selinuxlabel = "z"
}
}
}
gc stanza:
plugin "nomad-driver-podman" {
config {
gc {
container = false
}
}
}
plugin "nomad-driver-podman" {
config {
recover_stopped = false
}
}
"unix://run/podman/io.podman" when running as root or a cgroup V1 system, and "unix://run/user/<USER_ID>/podman/io.podman" for rootless cgroup V2 systemsplugin "nomad-driver-podman" {
config {
socket_path = "unix://run/podman/io.podman"
}
}
config {
image = "docker://redis"
}
config {
entrypoint = "/entrypoint.sh"
}
config {
command = "some-command"
}
config {
args = [
"arg1",
"arg2",
]
}
config {
working_dir = "/data"
}
config {
volumes = [
"/some/host/data:/container/data"
]
}
config {
tmpfs = [
"/var"
]
}
hostname - (Optional) The hostname to assign to the container. When launching more than one of a task (using count) with this option set, every container the task starts will have the same hostname.
Forwarding and Exposing Ports - (Optional) See Docker Driver Configuration for details.
init - Run an init inside the container that forwards signals and reaps processes.
config {
init = true
}
config {
init = true
init_path = /usr/libexec/podman/catatonit
}
user = nobody
config {
}
After setting memory reservation, when the system detects memory contention or low memory, containers are forced to restrict their consumption to their reservation. So you should always set the value below --memory, otherwise the hard limit will take precedence. By default, memory reservation will be the same as memory limit.
config {
memory_reservation = "100m"
}
Unit can be b (bytes), k (kilobytes), m (megabytes), or g (gigabytes). If you don't specify a unit, b is used. Set LIMIT to -1 to enable unlimited swap.
config {
memory_swap = "180m"
}
config {
memory_swappiness = 60
}
bridge: (default for rootful) create a network stack on the default bridgenone: no networkingcontainer:id: reuse another container's network stackhost: use the Podman host network stack. Note: the host mode gives the
container full access to local system services such as D-bus and is therefore
considered insecureslirp4netns: use slirp4netns to create a user network stack. This is the
default for rootless containers. Podman currently does not support it for root
containers issue.config {
network_mode = "bridge"
}
job "redis" {
datacenters = ["dc1"]
type = "service"
group "redis" {
task "redis" {
driver = "podman"
config {
image = "docker://redis"
port_map {
redis = 6379
}
}
resources {
cpu = 500
memory = 256
network {
mbits = 20
port "redis" {}
}
}
}
}
}
nomad run redis.nomad
==> Monitoring evaluation "9fc25b88"
Evaluation triggered by job "redis"
Allocation "60fdc69b" created: node "f6bccd6d", group "redis"
Evaluation status changed: "pending" -> "complete"
==> Evaluation "9fc25b88" finished with status "complete"
podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d2d700cbce6 docker.io/library/redis:latest docker-entrypoint... 16 seconds ago Up 16 seconds ago redis-60fdc69b-65cb-8ece-8554-df49321b3462
edit /etc/default/grub to enable cgroups v2
GRUB_CMDLINE_LINUX_DEFAULT="quiet cgroup_enable=memory swapaccount=1 systemd.unified_cgroup_hierarchy=1"
sudo update-grub
ensure that podman varlink is running
$ systemctl --user status io.podman
● io.podman.service - Podman Remote API Service
Loaded: loaded (/usr/lib/systemd/user/io.podman.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2020-07-01 16:01:41 EDT; 7s ago
TriggeredBy: ● io.podman.socket
Docs: man:podman-varlink(1)
Main PID: 25091 (podman)
Tasks: 29 (limit: 18808)
Memory: 17.5M
CPU: 184ms
CGroup: /user.slice/user-1000.slice/[email protected]/io.podman.service
├─25091 /usr/bin/podman varlink unix:/run/user/1000/podman/io.podman --timeout=60000 --cgroup-manager=systemd
├─25121 /usr/bin/podman varlink unix:/run/user/1000/podman/io.podman --timeout=60000 --cgroup-manager=systemd
└─25125 /usr/bin/podman
ensure that you have a recent version of crun
crun -V
crun version 0.13.227-d38b
commit: d38b8c28fc50a14978a27fa6afc69a55bfdd2c11
spec: 1.0.0
+SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +YAJL
nomad job run example.nomad
job "example" {
datacenters = ["dc1"]
type = "service"
group "cache" {
count = 1
restart {
attempts = 2
interval = "30m"
delay = "15s"
mode = "fail"
}
task "redis" {
driver = "podman"
config {
image = "redis"
port_map {
db = 6379
}
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
network {
# mbits = 10
port "db" {}
}
}
}
}
}
verify podman ps
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2423ae3efa21 docker.io/library/redis:latest redis-server 7 seconds ago Up 6 seconds ago 127.0.0.1:21510->6379/tcp, 127.0.0.1:21510->6379/udp redis-b640480f-4b93-65fd-7bba-c15722886395
Content type
Image
Digest
Size
13.9 MB
Last updated
over 5 years ago
docker pull hashicorp/nomad-driver-podmanPulls:
181
Last week