github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/csi_plugin.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: csi_plugin Stanza - Job Specification
     4  description: >-
     5    The "csi_plugin" stanza allows the task to specify it provides a
     6    Container Storage Interface plugin to the cluster.
     7  ---
     8  
     9  # `csi_plugin` Stanza
    10  
    11  <Placement groups={['job', 'group', 'task', 'csi_plugin']} />
    12  
    13  The "csi_plugin" stanza allows the task to specify it provides a
    14  Container Storage Interface plugin to the cluster. Nomad will
    15  automatically register the plugin so that it can be used by other jobs
    16  to claim [volumes][csi_volumes].
    17  
    18  ```hcl
    19  csi_plugin {
    20    id                      = "csi-hostpath"
    21    type                    = "monolith"
    22    mount_dir               = "/csi"
    23    stage_publish__base_dir = "/local/csi"
    24    health_timeout          = "30s"
    25  }
    26  ```
    27  
    28  ## `csi_plugin` Parameters
    29  
    30  - `id` `(string: <required>)` - This is the ID for the plugin. Some
    31    plugins will require both controller and node plugin types (see
    32    below); you need to use the same ID for both so that Nomad knows they
    33    belong to the same plugin.
    34  
    35  - `type` `(string: <required>)` - One of `node`, `controller`, or
    36    `monolith`. Each plugin supports one or more types. Each Nomad
    37    client node where you want to mount a volume will need a `node`
    38    plugin instance. Some plugins will also require one or more
    39    `controller` plugin instances to communicate with the storage
    40    provider's APIs. Some plugins can serve as both `controller` and
    41    `node` at the same time, and these are called `monolith`
    42    plugins. Refer to your CSI plugin's documentation.
    43  
    44  - `mount_dir` `(string: <optional>)` - The directory path inside the
    45    container where the plugin will expect a Unix domain socket for
    46    bidirectional communication with Nomad. This field is typically not
    47    required. Refer to your CSI plugin's documentation for details.
    48  
    49  - `stage_publish_base_dir` `(string: <optional>)` - The base directory 
    50    path inside the container where the plugin will be instructed to
    51    stage and publish volumes. This field is typically not required. 
    52    Refer to your CSI plugin's documentation for details.
    53  
    54  - `health_timeout` `(duration: <optional>)` - The duration that 
    55    the plugin supervisor will wait before restarting an unhealthy
    56    CSI plugin. Must be a duration value such as `30s` or `2m`.
    57    Defaults to `30s` if not set. 
    58  
    59  ~> **Note:** Plugins running as `node` or `monolith` require root
    60  privileges (or `CAP_SYS_ADMIN` on Linux) to mount volumes on the
    61  host. With the Docker task driver, you can use the `privileged = true`
    62  configuration, but no other default task drivers currently have this
    63  option.
    64  
    65  ## Recommendations for Deploying CSI Plugins
    66  
    67  CSI plugins run as Nomad tasks, but after mounting the volume are not in the
    68  data path for the volume. Tasks that mount volumes write and read directly to
    69  the volume via a bind-mount and there is no communication between the job and
    70  the CSI plugin. But when an allocation that mounts a volume stops, Nomad will
    71  need to communicate with the plugin on that allocation's node to unmount the
    72  volume. This has implications on how to deploy CSI plugins:
    73  
    74  * If you are stopping jobs on a node, you must stop tasks that claim
    75    volumes before stopping the `node` or `monolith` plugin for those
    76    volumes. If you use the `node drain` feature, plugin tasks will
    77    automatically be drained last.
    78  
    79  * Only the most recently-placed allocation for a given plugin ID and
    80    type (controller or node) will be used by any given client node. Run
    81    `node` plugins as system jobs and distribute `controller` plugins
    82    across client nodes using a constraint as shown below.
    83  
    84  * Some plugins will create volumes only in the same location as the
    85    plugin. For example, the AWS EBS plugin will create and mount
    86    volumes only within the same Availability Zone. You should configure
    87    your plugin task as recommended by the plugin's documentation to use
    88    the [`topology_request`] field in your volume specification.
    89  
    90  ## `csi_plugin` Examples
    91  
    92  ```hcl
    93  job "plugin-efs" {
    94    datacenters = ["dc1"]
    95  
    96    # you can run node plugins as service jobs as well, but running
    97    # as a system job ensures all nodes in the DC have a copy.
    98    type = "system"
    99  
   100    # only one plugin of a given type and ID should be deployed on
   101    # any given client node
   102    constraint {
   103      operator = "distinct_hosts"
   104      value = true
   105    }
   106  
   107    group "nodes" {
   108      task "plugin" {
   109        driver = "docker"
   110  
   111        config {
   112          image = "amazon/aws-efs-csi-driver:v.1.3.2"
   113  
   114          args = [
   115            "--endpoint=unix://csi/csi.sock",
   116            "--logtostderr",
   117            "--v=5",
   118          ]
   119  
   120          # all CSI node plugins will need to run as privileged tasks
   121          # so they can mount volumes to the host. controller plugins
   122          # do not need to be privileged.
   123          privileged = true
   124        }
   125  
   126        csi_plugin {
   127          id             = "aws-efs0"
   128          type           = "node"
   129          mount_dir      = "/csi"  # this path /csi matches the --endpoint
   130                              # argument for the container
   131          health_timeout = "30s"
   132        }
   133      }
   134    }
   135  }
   136  ```
   137  
   138  [csi]: https://github.com/container-storage-interface/spec
   139  [csi_volumes]: /docs/job-specification/volume
   140  [system]: /docs/schedulers#system
   141  [`topology_request`]: /docs/commands/volume/create#topology_request