LXC task driver plugin
The lxc
driver provides an interface for using LXC for running application
containers. This tutorial walks through the steps involved in configuring a Nomad
client agent to be able to run LXC jobs. You can download the external LXC
driver here.
Note
This tutorial is compatible with Nomad 0.9 and above. If you are using an older version of Nomad, refer to the LXC driver documentation.
Install the LXC task driver plug-in dependencies
Before deploying an LXC workload, you will need to install the lxc
and
lxc-templates
packages which will provide the runtime and templates to start
your container. Run the following command:
$ sudo apt install -y lxc lxc-templates
Download and install the LXC task driver plug-in
External drivers must be placed in the plugin_dir directory which
defaults to data_dir
/plugins
.
Make a directory called plugins
in data_dir (which is /opt/nomad/data
in the example below)
$ sudo mkdir -p /opt/nomad/data/plugins
Download LXC driver.
$ curl -O https://releases.hashicorp.com/nomad-driver-lxc/0.1.0-rc2/nomad-driver-lxc_0.1.0-rc2_linux_amd64.zip
Unzip the binary.
$ unzip nomad-driver-lxc_0.1.0-rc2_linux_amd64.zipArchive: nomad-driver-lxc_0.1.0-rc2_linux_amd64.zip inflating: nomad-driver-lxc
Move the LXC driver into your new plugins
directory.
$ sudo mv nomad-driver-lxc /opt/nomad/data/plugins
You can now delete the original zip file:
$ rm ./nomad-driver-lxc*.zip
Verify the LXC task driver status
After completing the previous steps, you do not need to explicitly enable the LXC driver in the client configuration, as it is enabled by default.
Restart the Nomad client service:
$ sudo systemctl restart nomad
After a few seconds, run the nomad node status
command to verify the client
node is ready:
$ nomad node statusID DC Name Class Drain Eligibility Status81c22a0c dc1 ip-172-31-5-174 <none> false eligible ready
You can now run the nomad node status
command against the specific node ID to
enumerate the drivers initialized on the client. In the example case, the client
node ID is 81c22a0c
—your client node ID will be different. When configured
properly, the "Driver Status" line should include "lxc" in the list as shown
below:
$ nomad node status 81c22a0cID = 81c22a0cName = ip-172-31-5-174Class = <none>DC = dc1Drain = falseEligibility = eligibleStatus = readyUptime = 2h13m30sDriver Status = docker,exec,java,lxc,mock_driver,raw_exec,rkt...
Register the Nomad job
You can run this LXC example job to register a Nomad job that deploys an LXC workload.
$ nomad run lxc.nomad==> Monitoring evaluation "d8be10f4" Evaluation triggered by job "example-lxc" Allocation "4248c82e" created: node "81c22a0c", group "example" Allocation "4248c82e" status changed: "pending" -> "running" (Tasks are running) Evaluation status changed: "pending" -> "complete"==> Evaluation "d8be10f4" finished with status "complete"
Check the status of the job
Run the following command to check the status of the jobs in your cluster:
$ nomad statusID Type Priority Status Submit Dateexample-lxc service 50 running 2019-01-28T22:05:36Z
The output above shows the job running successfully. You can obtain detailed information about the specific job with the following command:
$ nomad status example-lxcID = example-lxcName = example-lxcSubmit Date = 2019-01-28T22:05:36ZType = servicePriority = 50Datacenters = dc1Status = runningPeriodic = falseParameterized = false SummaryTask Group Queued Starting Running Failed Complete Lostexample 0 0 1 0 0 0 AllocationsID Node ID Task Group Version Desired Status Created Modified4248c82e 81c22a0c example 0 run running 6m58s ago 6m47s ago
Explore additional plug-in options
The LXC driver is enabled by default in the client configuration. In order to
provide additional options to the LXC plugin, add plugin
options volumes_enabled
and lxc_path
for the lxc
driver in the client's configuration file like in the following example:
plugin "nomad-driver-lxc" { config { enabled = true volumes_enabled = true lxc_path = "/var/lib/lxc" }}
Next steps
At this point, your clusters will be configured to run LXC jobs on this client. Continue performing this step on all cluster nodes that you would like to be able to run LXC jobs. You will use this same process to enable LXC in your production clusters, allowing you to run even more types of workload in Nomad.