Skip to content

Commit

Permalink
reformat lxc guide (#5339)
Browse files Browse the repository at this point in the history
* reformat lxc guide

* reformat lxc guide
  • Loading branch information
Omar-Khawaja authored Feb 21, 2019
1 parent 2bc3172 commit cc328c7
Showing 1 changed file with 16 additions and 92 deletions.
108 changes: 16 additions & 92 deletions website/source/guides/external/lxc.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,30 @@ description: |-
## LXC

The `lxc` driver provides an interface for using LXC for running application
containers. You can download the external LXC driver
[here][lxc_driver_download]. This guide is compatible with Nomad 0.9 and above.
If you are using an older version of Nomad, see the [LXC][lxc-docs] driver
documentation.
containers. This guide 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][lxc_driver_download].

~> Note: This guide is compatible with Nomad 0.9 and above. If you are using an older version of Nomad, see the [LXC][lxc-docs] driver documentation.

## Reference Material

- Official [LXC][linux-containers] documentation
- Nomad [LXC][lxc-docs] external driver documentation
- Nomad LXC external driver [repo][lxc-driver-repo]

## Estimated Time to Complete

20 minutes

## Challenge

You need to deploy a workload using [Linux Containers][linux-containers-home].
Configure the client nodes that need to run this workload appropriately. You
will also need to install the `lxc-templates` package which will provide the
templates needed to start your containers.

## Solution

Install and configure the LXC external driver plugin. Verify the configuration
on the client node and deploy the application.

## Prerequisites
## Installation Instructions

To perform the tasks described in this guide, you need to have a Nomad
environment with Consul installed. You can use this
[repo](https://github.com/hashicorp/nomad/tree/master/terraform#provision-a-nomad-cluster-in-the-cloud)
to easily provision a sandbox environment. This guide will assume a cluster with
one server node and one client node.
### Step 1: Install the `lxc` and `lxc-templates` Packages

-> **Please Note:** This guide is for demo purposes and is only using a single
server node. In a production cluster, 3 or 5 server nodes are recommended.

## Steps

### Step 1: Verify Client Node Configuration

External drivers must be placed in the [plugin_dir][plugin_dir] directory which
defaults to [`data_dir`][data_dir]`/plugins`. Verify the `data_dir` directory on
the client node configuration. If you are using the environment provided by this
guide, the client configuration is located at `/etc/nomad.d/nomad.hcl`. The
configuration file will show you that the `data_dir` directory is
`/opt/nomad/data`. The relevant snippet of the configuration file is shown
below:

```shell
$ cat /etc/nomad.d/nomad.hcl
data_dir = "/opt/nomad/data"
bind_addr = "0.0.0.0"
...
```

### Step 2: Install the `lxc` and `lxc-templates` Packages

Before we generate a Nomad job file and deploy our workload, we will need to
install the `lxc` and `lxc-templates` packages which will provide the runtime
and templates we need to start our container. Run the following command:
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:

```shell
sudo apt install -y lxc lxc-templates
```

### Step 3: Download and Install the LXC Driver
### Step 2: Download and Install the LXC Driver

Make a directory called `plugins` in [data_dir][data_dir] (which is
`/opt/nomad/data` in our case) and download/place the [LXC
driver][lxc_driver_download] in it. The following sequences of commands
illustrate this process:
External drivers must be placed in the [plugin_dir][plugin_dir] directory which
defaults to [`data_dir`][data_dir]`/plugins`. Make a directory called `plugins` in [data_dir][data_dir] (which is `/opt/nomad/data` in the example below) and download/place the [LXC driver][lxc_driver_download] in it. The following sequence of commands illustrate this process:

```shell
$ sudo mkdir -p /opt/nomad/data/plugins
Expand All @@ -97,7 +48,7 @@ You can now delete the original zip file:
$ rm ./nomad-driver-lxc*.zip
```

### Step 4: Verify the LXC Driver Status
### Step 3: Verify the LXC 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.
Expand Down Expand Up @@ -136,37 +87,9 @@ Driver Status = docker,exec,java,lxc,mock_driver,raw_exec,rkt
...
```

### Step 5: Generate a Job File

Create a file named `lxc.nomad` and place the following contents in it:

```hcl
job "example-lxc" {
datacenters = ["dc1"]
type = "service"
group "example" {
task "example" {
driver = "lxc"
config {
log_level = "trace"
verbosity = "verbose"
template = "/usr/share/lxc/templates/lxc-busybox"
}
resources {
cpu = 500
memory = 256
}
}
}
}
```

### Step 6: Register the Nomad Job
### Step 4: Register the Nomad Job

Run the following command to register your Nomad job:
You can run this [LXC example job][lxc-job] to register a Nomad job that deploys an LXC workload.

```shell
$ nomad run lxc.nomad
Expand All @@ -178,9 +101,9 @@ $ nomad run lxc.nomad
==> Evaluation "d8be10f4" finished with status "complete"
```

### Step 7: Check the Status of the Job
### Step 5: Check the Status of the Job

You can run the following command to check the status of the jobs in your
Run the following command to check the status of the jobs in your
cluster:

```shell
Expand Down Expand Up @@ -212,7 +135,7 @@ ID Node ID Task Group Version Desired Status Created Modified
4248c82e 81c22a0c example 0 run running 6m58s ago 6m47s ago
```

## Next Steps
### More Configuration Options

The LXC driver is enabled by default in the client configuration. In order to
provide additional options to the LXC plugin, add [plugin
Expand All @@ -235,6 +158,7 @@ plugin "nomad-driver-lxc" {
[lxc_driver_download]: https://releases.hashicorp.com/nomad-driver-lxc
[lxc-driver-repo]: https://github.com/hashicorp/nomad-driver-lxc
[lxc-docs]: /docs/drivers/external/lxc.html
[lxc-job]: https://github.com/hashicorp/nomad-education-content/blob/master/lxc.nomad
[lxc_plugin_options]: /docs/drivers/external/lxc.html#plugin-options
[plugin_dir]: /docs/configuration/index.html#plugin_dir
[plugin_syntax]: /docs/configuration/plugin.html

0 comments on commit cc328c7

Please sign in to comment.