containerd Task Driver
Name: containerd-driver
Homepage: https://github.com/Roblox/nomad-driver-containerd
containerd (containerd.io
) is a lightweight container
daemon for running and managing container lifecycle. Docker daemon also uses
containerd.
nomad-driver-containerd
enables Nomad clients to launch containers directly
using containerd, without Docker. The Docker daemon is therefore not required on
the host system.
See the project's homepage for more details.
Client Requirements
The containerd task driver is not built into Nomad. It must be
downloaded
onto the client host in the configured plugin
directory.
Linux (Ubuntu >=16.04) with
containerd
(>=1.3) installed.containerd-driver
binary in Nomad's plugin_dir.
Capabilities
The containerd-driver
implements the following capabilities.
Feature | Implementation |
---|---|
send signals | true |
exec | true |
filesystem isolation | image |
network isolation | host, group, task, none |
volume mounting | true |
For sending signals, one can use nomad alloc signal
command.
For exec'ing into the container, one can use nomad alloc exec
command.
Task Configuration
Since Docker also relies on containerd for managing container lifecycle, the
example job created by nomad init -short
can easily be adapted
to use containerd-driver
instead:
The containerd task driver supports the following parameters:
image
- (Required) OCI image (Docker is also OCI compatible) for your container.
command
- (Optional) Command to override command defined in the image.
args
- (Optional) Arguments to the command.
cwd
- (Optional) Specify the current working directory (cwd) for your container process. If the directory does not exist, one will be created for you.privileged
- (Optional)true
orfalse
(default) Run container in privileged mode. Your container will have all Linux capabilities when running in privileged mode.
host_dns
- (Optional)true
(default) orfalse
By default, a container launched usingcontainerd-driver
will use host/etc/resolv.conf
. This is similar to Docker's behavior. However, if you don't want to use host DNS, you can turn off this flag by settinghost_dns=false
.seccomp
- (Optional) Enable default seccomp profile. List of allowed syscalls.seccomp_profile
- (Optional) Path to custom seccomp profile.seccomp
must be set totrue
in order to useseccomp_profile
.The default
docker
seccomp profile found in the Moby repository can be downloaded, and modified (by removing/adding syscalls) to create a custom seccomp profile. The custom seccomp profile can then be saved under/opt/seccomp/seccomp.json
on the Nomad client nodes.
readonly_rootfs
- (Optional)true
orfalse
(default) Container root filesystem will be read-only.
host_network
- (Optional)true
orfalse
(default) Enable host network. This is equivalent to--net=host
in docker.
cap_add
- (Optional) Add individual capabilities.
cap_drop
- (Optional) Drop individual capabilities.
devices
- (Optional) A list of devices to be exposed to the container.
mounts
- (Optional) A list of mounts to be mounted in the container. Volume, bind and tmpfs type mounts are supported. fstab stylemount options
are supported.type
- (Optional) Supported values arevolume
,bind
ortmpfs
. Default:volume
.target
- (Required) Target path in the container.source
- (Optional) Source path on the host.options
- (Optional) fstab stylemount options
. NOTE: For bind mounts, at leastrbind
andro
are required.
Networking
nomad-driver-containerd
supports host and bridge networks.
NOTE: host
and bridge
are mutually exclusive options, and only one of
them should be used at a time.
Host network can be enabled by setting
host_network
totrue
in task config of the job spec (see host_network under Task Configuration).Bridge network can be enabled by setting the
network
stanza in the task group section of the job spec.
You need to install CNI plugins on Nomad client nodes under /opt/cni/bin
before you can use bridge
networks.
Instructions for installing CNI plugins.
Also, ensure your Linux operating system distribution has been configured to allow container traffic through the bridge network to be routed via iptables. These tunables can be set as follows:
To preserve these settings on startup of a Nomad client node, add a file
including the following to /etc/sysctl.d/
or remove the file your Linux
distribution puts in that directory.
Port Forwarding
Nomad supports both static
and dynamic
port mapping.
- Static ports
Static port mapping can be added in the network
stanza.
Here, host
port 8889
is mapped to container
port 8889
.
NOTE: static ports are usually not recommended, except for
system
or specialized jobs like load balancers.
- Dynamic ports
Dynamic port mapping is also enabled in the network
stanza.
Here, nomad will allocate a dynamic port on the host
and that port
will be mapped to 8080
in the container.
You can read more about configuring networking under the network
stanza documentation.
Service discovery
Nomad schedules workloads of various types across a cluster of generic hosts. Because of this, placement is not known in advance and you will need to use service discovery to connect tasks to other services deployed across your cluster. Nomad integrates with Consul to provide service discovery and monitoring.
A service
block can be added to your job spec, to enable service discovery.
The service stanza instructs Nomad to register a service with Consul.
Plugin Options
enabled
- (Optional) Thecontainerd
driver may be disabled on hosts by setting this option tofalse
(defaults totrue
).containerd_runtime
- (Required) Runtime forcontainerd
e.g.io.containerd.runc.v1
orio.containerd.runc.v2
stats_interval
- (Optional) This value defines how frequently you want to sendTaskStats
to nomad client. (defaults to1 second
).
An example of using these plugin options with the new plugin syntax is shown below:
Please note the plugin name should match whatever name you have specified for the external driver in the plugin_dir directory.