github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/drivers/external/containerd.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: 'Drivers: nomad-driver-containerd'
     4  sidebar_title: containerd
     5  description: >-
     6    The containerd driver is used
     7    for launching containers using containerd.
     8  ---
     9  
    10  # containerd Task Driver
    11  
    12  Name: `containerd-driver`
    13  
    14  Homepage: https://github.com/Roblox/nomad-driver-containerd
    15  
    16  containerd ([`containerd.io`](https://containerd.io)) is a lightweight container
    17  daemon for running and managing container lifecycle. Docker daemon also uses
    18  containerd.
    19  
    20  ```hcl
    21  dockerd (docker daemon) --> containerd --> containerd-shim --> runc
    22  ```
    23  
    24  `nomad-driver-containerd` enables Nomad clients to launch containers directly
    25  using containerd, without Docker. The Docker daemon is therefore not required on
    26  the host system.
    27  
    28  See the [project's homepage](https://github.com/Roblox/nomad-driver-containerd)
    29  for more details.
    30  
    31  ## Client Requirements
    32  
    33  The containerd task driver is not built into Nomad. It must be
    34  [`downloaded`][releases] onto the client host in the configured plugin
    35  directory.
    36  
    37  - Linux (Ubuntu >=16.04) with [`containerd`](https://containerd.io/downloads/) (>=1.3) installed.
    38  
    39  - [`containerd-driver`][releases] binary in Nomad's [plugin_dir][].
    40  
    41  ## Capabilities
    42  
    43  The `containerd-driver` implements the following [capabilities](/docs/internals/plugins/task-drivers#capabilities-capabilities-error).
    44  
    45  | Feature              | Implementation          |
    46  | -------------------- | ----------------------- |
    47  | send signals         | true                    |
    48  | exec                 | true                    |
    49  | filesystem isolation | image                   |
    50  | network isolation    | host, group, task, none |
    51  | volume mounting      | true                    |
    52  
    53  For sending signals, one can use `nomad alloc signal` command.<br/>
    54  For exec'ing into the container, one can use `nomad alloc exec` command.
    55  
    56  ## Task Configuration
    57  
    58  Since Docker also relies on containerd for managing container lifecycle, the
    59  example job created by [`nomad init -short`][nomad-init] can easily be adapted
    60  to use `containerd-driver` instead:
    61  
    62  ```hcl
    63  job "redis" {
    64    datacenters = ["dc1"]
    65  
    66    group "redis-group" {
    67      task "redis-task" {
    68        driver = "containerd-driver"
    69  
    70        config {
    71          image = "docker.io/library/redis:alpine"
    72        }
    73  
    74        resources {
    75          cpu    = 500
    76          memory = 256
    77        }
    78      }
    79    }
    80  }
    81  ```
    82  
    83  The containerd task driver supports the following parameters:
    84  
    85  - `image` - (Required) OCI image (Docker is also OCI compatible) for your
    86    container.
    87  
    88  ```hcl
    89  config {
    90    image = "docker.io/library/redis:alpine"
    91  }
    92  ```
    93  
    94  - `command` - (Optional) Command to override command defined in the image.
    95  
    96  ```hcl
    97  config {
    98    command = "some-command"
    99  }
   100  ```
   101  
   102  - `args` - (Optional) Arguments to the command.
   103  
   104  ```hcl
   105  config {
   106    args = [
   107      "arg1",
   108      "arg2",
   109    ]
   110  }
   111  ```
   112  
   113  - `cwd` - (Optional) Specify the current working directory (cwd) for your container process.
   114    If the directory does not exist, one will be created for you.
   115  
   116  - `privileged` - (Optional) `true` or `false` (default) Run container in
   117    privileged mode. Your container will have all Linux capabilities when running
   118    in privileged mode.
   119  
   120  ```hcl
   121  config {
   122    privileged = true
   123  }
   124  ```
   125  
   126  - `host_dns` - (Optional) `true` (default) or `false` By default, a container
   127    launched using `containerd-driver` will use host `/etc/resolv.conf`. This is
   128    similar to [Docker's behavior]. However, if you don't want to use
   129    host DNS, you can turn off this flag by setting `host_dns=false`.
   130  
   131  - `seccomp` - (Optional) Enable default seccomp profile. List of [allowed syscalls].
   132  
   133  - `seccomp_profile` - (Optional) Path to custom seccomp profile.
   134    `seccomp` must be set to `true` in order to use `seccomp_profile`.
   135  
   136    The default `docker` seccomp profile found in the [Moby repository]
   137    can be downloaded, and modified (by removing/adding syscalls) to create a custom seccomp profile.
   138    The custom seccomp profile can then be saved under `/opt/seccomp/seccomp.json` on the Nomad client nodes.
   139  
   140  ```hcl
   141  config {
   142    seccomp         = true
   143    seccomp_profile = "/opt/seccomp/seccomp.json"
   144  }
   145  ```
   146  
   147  - `readonly_rootfs` - (Optional) `true` or `false` (default) Container root
   148    filesystem will be read-only.
   149  
   150  ```hcl
   151  config {
   152    readonly_rootfs = true
   153  }
   154  ```
   155  
   156  - `host_network` ((#host_network)) - (Optional) `true` or `false` (default)
   157    Enable host network. This is equivalent to `--net=host` in docker.
   158  
   159  ```hcl
   160  config {
   161    host_network = true
   162  }
   163  ```
   164  
   165  - `cap_add` - (Optional) Add individual capabilities.
   166  
   167  ```hcl
   168  config {
   169    cap_add = [
   170      "CAP_SYS_ADMIN",
   171      "CAP_CHOWN",
   172      "CAP_SYS_CHROOT"
   173    ]
   174  }
   175  ```
   176  
   177  - `cap_drop` - (Optional) Drop individual capabilities.
   178  
   179  ```hcl
   180  config {
   181    cap_drop = [
   182      "CAP_SYS_ADMIN",
   183      "CAP_CHOWN",
   184      "CAP_SYS_CHROOT"
   185    ]
   186  }
   187  ```
   188  
   189  - `devices` - (Optional) A list of devices to be exposed to the container.
   190  
   191  ```hcl
   192  config {
   193    devices = [
   194      "/dev/loop0",
   195      "/dev/loop1"
   196    ]
   197  }
   198  ```
   199  
   200  - `mounts` - (Optional) A list of mounts to be mounted in the container. Volume,
   201    bind and tmpfs type mounts are supported. fstab style [`mount options`][] are
   202    supported.
   203  
   204    - `type` - (Optional) Supported values are `volume`, `bind` or `tmpfs`.
   205      **Default:** `volume`.
   206  
   207    - `target` - (Required) Target path in the container.
   208  
   209    - `source` - (Optional) Source path on the host.
   210  
   211    - `options` - (Optional) fstab style [`mount options`][]. **NOTE:** For bind
   212      mounts, at least `rbind` and `ro` are required.
   213  
   214  ```hcl
   215  config {
   216    mounts = [
   217      {
   218        type = "bind"
   219        target = "/tmp/t1"
   220        source = "/tmp/s1"
   221        options = ["rbind", "ro"]
   222      }
   223    ]
   224  }
   225  ```
   226  
   227  ## Networking
   228  
   229  `nomad-driver-containerd` supports **host** and **bridge** networks.
   230  
   231  **NOTE:** `host` and `bridge` are mutually exclusive options, and only one of
   232  them should be used at a time.
   233  
   234  1. **Host** network can be enabled by setting `host_network` to `true` in task
   235     config of the job spec (see [host_network][host-network] under Task
   236     Configuration).
   237  
   238  2. **Bridge** network can be enabled by setting the `network` stanza in the task
   239     group section of the job spec.
   240  
   241  ```hcl
   242  network {
   243    mode = "bridge"
   244  }
   245  ```
   246  
   247  You need to install CNI plugins on Nomad client nodes under `/opt/cni/bin`
   248  before you can use `bridge` networks.
   249  
   250  **Instructions for installing CNI plugins.**
   251  
   252  ```hcl
   253   $ curl -L -o cni-plugins.tgz "https://github.com/containernetworking/plugins/releases/download/v0.9.0/cni-plugins-linux-$( [ $(uname -m) = aarch64 ] && echo arm64 || echo amd64)"-v0.9.0.tgz
   254   $ sudo mkdir -p /opt/cni/bin
   255   $ sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz
   256  ```
   257  
   258  Also, ensure your Linux operating system distribution has been configured
   259  to allow container traffic through the bridge network to be routed via iptables.
   260  These tunables can be set as follows:
   261  
   262  ```hcl
   263   $ echo 1 > /proc/sys/net/bridge/bridge-nf-call-arptables
   264   $ echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
   265   $ echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
   266  ```
   267  
   268  To preserve these settings on startup of a Nomad client node, add a file
   269  including the following to `/etc/sysctl.d/` or remove the file your Linux
   270  distribution puts in that directory.
   271  
   272  ```hcl
   273   net.bridge.bridge-nf-call-arptables = 1
   274   net.bridge.bridge-nf-call-ip6tables = 1
   275   net.bridge.bridge-nf-call-iptables = 1
   276  ```
   277  
   278  ## Port Forwarding
   279  
   280  Nomad supports both `static` and `dynamic` port mapping.
   281  
   282  1. **Static ports**
   283  
   284  Static port mapping can be added in the `network` stanza.
   285  
   286  ```hcl
   287  network {
   288    mode = "bridge"
   289    port "lb" {
   290      static = 8889
   291      to     = 8889
   292    }
   293  }
   294  ```
   295  Here, `host` port `8889` is mapped to `container` port `8889`.<br/>
   296  **NOTE:** static ports are usually not recommended, except for
   297  `system` or specialized jobs like load balancers.
   298  
   299  2. **Dynamic ports**
   300  
   301  Dynamic port mapping is also enabled in the `network` stanza.
   302  
   303  ```hcl
   304  network {
   305    mode = "bridge"
   306    port "http" {
   307      to = 8080
   308    }
   309  }
   310  ```
   311  Here, nomad will allocate a dynamic port on the `host` and that port
   312  will be mapped to `8080` in the container.
   313  
   314  You can read more about configuring networking under the [`network`] stanza documentation.
   315  
   316  ## Service discovery
   317  
   318  Nomad schedules workloads of various types across a cluster of generic hosts.
   319  Because of this, placement is not known in advance and you will need to use
   320  service discovery to connect tasks to other services deployed across your cluster.
   321  Nomad integrates with Consul to provide service discovery and monitoring.
   322  
   323  A [`service`] block can be added to your job spec, to enable service discovery.
   324  
   325  The service stanza instructs Nomad to register a service with Consul.
   326  
   327  ## Plugin Options ((#plugin_options))
   328  
   329  - `enabled` - (Optional) The `containerd` driver may be disabled on hosts by
   330    setting this option to `false` (defaults to `true`).
   331  
   332  - `containerd_runtime` - (Required) Runtime for `containerd` e.g.
   333    `io.containerd.runc.v1` or `io.containerd.runc.v2`
   334  
   335  - `stats_interval` - (Optional) This value defines how frequently you want to
   336    send `TaskStats` to nomad client. (defaults to `1 second`).
   337  
   338  An example of using these plugin options with the new [plugin syntax][plugin] is
   339  shown below:
   340  
   341  ```hcl
   342  plugin "containerd-driver" {
   343    config {
   344      enabled = true
   345      containerd_runtime = "io.containerd.runc.v2"
   346      stats_interval = "5s"
   347    }
   348  }
   349  ```
   350  
   351  Please note the plugin name should match whatever name you have specified for
   352  the external driver in the [plugin_dir][plugin_dir] directory.
   353  
   354  [nomad-driver-containerd]: https://github.com/Roblox/nomad-driver-containerd
   355  [nomad-init]: /docs/commands/job/init
   356  [plugin]: /docs/configuration/plugin
   357  [plugin_dir]: /docs/configuration#plugin_dir
   358  [plugin-options]: #plugin_options
   359  [host-network]: #host_network
   360  [`mount options`]: https://github.com/containerd/containerd/blob/9561d9389d3dd87ff6030bf1da4e705bbc024130/mount/mount_linux.go#L198-L222
   361  [Moby repository]: https://github.com/moby/moby/blob/master/profiles/seccomp/default.json
   362  [Docker's behavior]: https://docs.docker.com/config/containers/container-networking/#dns-services
   363  [allowed syscalls]: https://github.com/containerd/containerd/blob/master/contrib/seccomp/seccomp_default.go#L51-L390
   364  [`network`]: /docs/job-specification/network
   365  [`service`]: /docs/job-specification/service
   366  [releases]: https://github.com/Roblox/nomad-driver-containerd/releases/