How to run Podman with Hashicorp Nomad on Ubuntu 20.04 LTS

Requirements

  • You already have a Nomad cluster running (or in dev mode)
  • Docker isn’t installed, or at least disabled (otherwise it will mess with iptables and your containers will probably not be reachable)

Install Podman on Nomad client nodes

For the official documentation, refer here.

. /etc/os-releaseecho "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.listcurl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key" | sudo apt-key add -sudo apt-get update && \
sudo apt-get -y upgrade && \
sudo apt-get -y install podman

Create a systemd service for Podman

Here the goal is to use the Podman API as a socket. Find more details here.
In this service example, we run Podman as root but you can run it (should?) with a non-root user, just make sure the socket file will be in a writable path for the podman user.

sudo bash -c ' cat << EOF > /etc/systemd/system/podman.service
[Unit]
Description=Podman API service
[Service]
User=root
WorkingDirectory=/var/run/
ExecStart=podman system service --timeout 0 unix:///var/run/podman.sock
Restart=no
[Install]
WantedBy=multi-user.target
EOF'

Then reload systemd and start Podman service

sudo systemctl daemon-reload
sudo service podman start
# You may want to check the status of the service ;)
sudo service podman status

Download and install Podman plugin for Nomad on client nodes

Make sure you download the correct version for your distribution and your processor architecture. Find all Podman plugin versions here.
Note that the folder to your Nomad plugins may differ from this example.

wget https://releases.hashicorp.com/nomad-driver-podman/0.3.0/nomad-driver-podman_0.3.0_linux_amd64.zipunzip nomad-driver-podman_0.3.0_linux_amd64.zipmv nomad-driver-podman /var/nomad/plugins/

Enable Podman plugin in Nomad clients

In the Nomad client nodes configuration file add. Don’t forget to reload the Nomad clients after the modification.

plugin "nomad-driver-podman" {
config {
socket_path = "unix:///var/run/podman.sock"
}
}

That’s it! Now you can enjoy Podman with Nomad :) Let’s try it with a simple job.

Create a job that uses the Podman plugin

For this example, we will launch a very basic job that will run a Redis instance in your Nomad cluster.

Note that in the driver section we now use “podman”.

sudo bash -c 'cat << EOF > redis.nomad
job "redis" {
datacenters = ["dc1"]
group "cache" {
network {
port "redis" { to = "6379" }
}
task "redis" {
driver = "podman"
config {
image = "redis:6.2"
ports = ["redis"]
}
resources {
cpu = 500
memory = 256
}
}
}
}
EOF'

Run your job

nomad job run redis.nomad

Check the status of your job

nomad job status redis

You should see your job running.

ID            = redis
Name = redis
Submit Date = 2022-02-23T20:35:49Z
Type = service
Priority = 50
Datacenters = dc1
Namespace = default
Status = running
Periodic = false
Parameterized = false
Summary
Task Group Queued Starting Running Failed Complete Lost
cache 0 0 1 0 0 0
Latest Deployment
ID = 8fd2238e
Status = successful
Description = Deployment completed successfully
Deployed
Task Group Desired Placed Healthy Unhealthy Progress Deadline
cache 1 1 1 0 2022-02-23T20:45:59Z
Allocations
ID Node ID Task Group Version Desired Status Created Modified
af38cd69 9779b14d cache 1 run running 7m21s ago 6m28s ago

Hope this quick start with Podman and Hashicorp Nomad helped you ✌️

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store