github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/website/source/guides/operating-a-job/external/lxc.html.md (about)

     1  ---
     2  layout: "guides"
     3  page_title: "LXC"
     4  sidebar_current: "guides-operating-a-job-external-lxc"
     5  description: |-
     6    Guide for using LXC external task driver plugin.
     7  ---
     8  
     9  ## LXC
    10  
    11  The `lxc` driver provides an interface for using LXC for running application
    12  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].
    13  
    14  ~> 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.
    15  
    16  ## Reference Material
    17  
    18  - Official [LXC][linux-containers] documentation
    19  - Nomad [LXC][lxc-docs] external driver documentation
    20  - Nomad LXC external driver [repo][lxc-driver-repo]
    21  
    22  ## Installation Instructions
    23  
    24  ### Step 1: Install the `lxc` and `lxc-templates` Packages
    25  
    26  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:
    27  
    28  ```shell
    29  sudo apt install -y lxc lxc-templates
    30  ```
    31  
    32  ### Step 2: Download and Install the LXC Driver
    33  
    34  External drivers must be placed in the [plugin_dir][plugin_dir] directory which
    35  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:
    36  
    37  ```shell
    38  $ sudo mkdir -p /opt/nomad/data/plugins
    39  $ curl -O https://releases.hashicorp.com/nomad-driver-lxc/0.1.0-rc2/nomad-driver-lxc_0.1.0-rc2_linux_amd64.zip
    40  $ unzip nomad-driver-lxc_0.1.0-rc2_linux_amd64.zip
    41  Archive:  nomad-driver-lxc_0.1.0-rc2_linux_amd64.zip
    42    inflating: nomad-driver-lxc
    43  $ sudo mv nomad-driver-lxc /opt/nomad/data/plugins
    44  ```
    45  You can now delete the original zip file:
    46  
    47  ```shell
    48  $ rm ./nomad-driver-lxc*.zip
    49  ```
    50  
    51  ### Step 3: Verify the LXC Driver Status
    52  
    53  After completing the previous steps, you do not need to explicitly enable the
    54  LXC driver in the client configuration, as it is enabled by default.
    55  
    56  Restart the Nomad client service:
    57  
    58  ```shell
    59  $ sudo systemctl restart nomad
    60  ```
    61  
    62  After a few seconds, run the `nomad node status` command to verify the client
    63  node is ready:
    64  
    65  ```shell
    66  $ nomad node status
    67  ID        DC   Name             Class   Drain  Eligibility  Status
    68  81c22a0c  dc1  ip-172-31-5-174  <none>  false  eligible     ready
    69  ```
    70  
    71  You can now run the `nomad node status` command against the specific node ID to
    72  see which drivers are initialized on the client. In our case, the client node ID
    73  is `81c22a0c` (your client node ID will be different). You should see `lxc`
    74  appear in the `Driver Status` section as shown below:
    75  
    76  ```shell
    77  $ nomad node status 81c22a0c
    78  ID            = 81c22a0c
    79  Name          = ip-172-31-5-174
    80  Class         = <none>
    81  DC            = dc1
    82  Drain         = false
    83  Eligibility   = eligible
    84  Status        = ready
    85  Uptime        = 2h13m30s
    86  Driver Status = docker,exec,java,lxc,mock_driver,raw_exec,rkt
    87  ...
    88  ```
    89  
    90  ### Step 4: Register the Nomad Job
    91  
    92  You can run this [LXC example job][lxc-job] to register a Nomad job that deploys an LXC workload.
    93  
    94  ```shell
    95  $ nomad run lxc.nomad
    96  ==> Monitoring evaluation "d8be10f4"
    97      Evaluation triggered by job "example-lxc"
    98      Allocation "4248c82e" created: node "81c22a0c", group "example"
    99      Allocation "4248c82e" status changed: "pending" -> "running" (Tasks are running)
   100      Evaluation status changed: "pending" -> "complete"
   101  ==> Evaluation "d8be10f4" finished with status "complete"
   102  ```
   103  
   104  ### Step 5: Check the Status of the Job
   105  
   106  Run the following command to check the status of the jobs in your
   107  cluster:
   108  
   109  ```shell
   110  $ nomad status
   111  ID           Type     Priority  Status   Submit Date
   112  example-lxc  service  50        running  2019-01-28T22:05:36Z
   113  ```
   114  As shown above, our job is successfully running. You can see detailed
   115  information about our specific job with the following command:
   116  
   117  ```shell
   118  $ nomad status example-lxc
   119  ID            = example-lxc
   120  Name          = example-lxc
   121  Submit Date   = 2019-01-28T22:05:36Z
   122  Type          = service
   123  Priority      = 50
   124  Datacenters   = dc1
   125  Status        = running
   126  Periodic      = false
   127  Parameterized = false
   128  
   129  Summary
   130  Task Group  Queued  Starting  Running  Failed  Complete  Lost
   131  example     0       0         1        0       0         0
   132  
   133  Allocations
   134  ID        Node ID   Task Group  Version  Desired  Status   Created    Modified
   135  4248c82e  81c22a0c  example     0        run      running  6m58s ago  6m47s ago
   136  ```
   137  
   138  ### More Configuration Options
   139  
   140  The LXC driver is enabled by default in the client configuration. In order to
   141  provide additional options to the LXC plugin, add [plugin
   142  options][lxc_plugin_options] `volumes_enabled` and `lxc_path` for the `lxc`
   143  driver in the client's configuration file like in the following example:
   144  
   145  ```hcl
   146  plugin "nomad-driver-lxc" {
   147    config {
   148      enabled = true
   149      volumes_enabled = true
   150      lxc_path = "/var/lib/lxc"
   151    }
   152  }
   153  ```
   154  
   155  [data_dir]: /docs/configuration/index.html#data_dir
   156  [linux-containers]: https://linuxcontainers.org/lxc/introduction/
   157  [linux-containers-home]: https://linuxcontainers.org
   158  [lxc_driver_download]: https://releases.hashicorp.com/nomad-driver-lxc
   159  [lxc-driver-repo]: https://github.com/hashicorp/nomad-driver-lxc
   160  [lxc-docs]: /docs/drivers/external/lxc.html
   161  [lxc-job]: https://github.com/hashicorp/nomad-education-content/blob/master/lxc.nomad
   162  [lxc_plugin_options]: /docs/drivers/external/lxc.html#plugin-options
   163  [plugin_dir]: /docs/configuration/index.html#plugin_dir
   164  [plugin_syntax]: /docs/configuration/plugin.html