1 =========================
2 Block Devices and Nomad
3 =========================
5 Like Kubernetes, Nomad can use Ceph Block Device. This is made possible by
6 `ceph-csi`_, which allows you to dynamically provision RBD images or import
9 Every version of Nomad is compatible with `ceph-csi`_, but the reference
10 version of Nomad that was used to generate the procedures and guidance in this
11 document is Nomad v1.1.2, the latest version available at the time of the
12 writing of the document.
14 To use Ceph Block Devices with Nomad, you must install
15 and configure ``ceph-csi`` within your Nomad environment. The following
16 diagram shows the Nomad/Ceph technology stack.
19 +-------------------------+-------------------------+
20 | Container | ceph--csi |
24 +----------+--------------+-------------------------+
29 +---------------------------------------------------+
32 +--------+------------------------------------------+
35 +---------------+ +----------------+
38 +------------------------+ +------------------------+
40 | Kernel Modules | +------------------------+
42 +------------------------+-+------------------------+
44 +------------------------+-+------------------------+
46 +------------------------+ +------------------------+
49 Nomad has many possible task drivers, but this example uses only a Docker container.
52 ``ceph-csi`` uses the RBD kernel modules by default, which may not support
53 all Ceph `CRUSH tunables`_ or `RBD image features`_.
58 By default, Ceph block devices use the ``rbd`` pool. Ensure that your Ceph
59 cluster is running, then create a pool for Nomad persistent storage:
63 ceph osd pool create nomad
65 See `Create a Pool`_ for details on specifying the number of placement groups
66 for your pools. See `Placement Groups`_ for details on the number of placement
67 groups you should set for your pools.
69 A newly created pool must be initialized prior to use. Use the ``rbd`` tool
70 to initialize the pool:
79 Ceph Client Authentication Setup
80 --------------------------------
82 Create a new user for Nomad and `ceph-csi`. Execute the following command and
83 record the generated key:
85 .. code-block:: console
87 $ ceph auth get-or-create client.nomad mon 'profile rbd' osd 'profile rbd pool=nomad' mgr 'profile rbd pool=nomad'
89 key = AQAlh9Rgg2vrDxAARy25T7KHabs6iskSHpAEAQ==
95 Configuring Nomad to Allow Containers to Use Privileged Mode
96 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98 By default, Nomad doesn't allow containers to use privileged mode. We must
99 configure Nomad so that it allows containers to use privileged mode. Edit the
100 Nomad configuration file by adding the following configuration block to
101 `/etc/nomad.d/nomad.hcl`::
105 allow_privileged = true
109 Loading the rbd module
110 ~~~~~~~~~~~~~~~~~~~~~~
112 Nomad must have the `rbd` module loaded. Run the following command to confirm that the `rbd` module is loaded:
114 .. code-block:: console
120 If the `rbd` module is not loaded, load it:
133 sudo systemctl restart nomad
136 Create ceph-csi controller and plugin nodes
137 ===========================================
139 The `ceph-csi`_ plugin requires two components:
141 - **Controller plugin**: communicates with the provider's API.
142 - **Node plugin**: executes tasks on the client.
145 We'll set the ceph-csi's version in those files. See `ceph-csi release`_
146 for information about ceph-csi's compatibility with other versions.
148 Configure controller plugin
149 ---------------------------
151 The controller plugin requires the Ceph monitor addresses of the Ceph
152 cluster. Collect both (1) the Ceph cluster unique `fsid` and (2) the monitor
155 .. code-block:: console
159 fsid b9127830-b0cc-4e34-aa47-9d1a2e9949a8
161 0: [v2:192.168.1.1:3300/0,v1:192.168.1.1:6789/0] mon.a
162 1: [v2:192.168.1.2:3300/0,v1:192.168.1.2:6789/0] mon.b
163 2: [v2:192.168.1.3:3300/0,v1:192.168.1.3:6789/0] mon.c
165 Generate a ``ceph-csi-plugin-controller.nomad`` file similar to the example
166 below. Substitute the `fsid` for "clusterID", and the monitor addresses for
169 job "ceph-csi-plugin-controller" {
170 datacenters = ["dc1"]
175 task "ceph-controller" {
179 "clusterID": "b9127830-b0cc-4e34-aa47-9d1a2e9949a8",
187 destination = "local/config.json"
188 change_mode = "restart"
192 image = "quay.io/cephcsi/cephcsi:v3.3.1"
194 "./local/config.json:/etc/ceph-csi-config/config.json"
199 target = "/tmp/csi/keys"
202 size = 1000000 # size in bytes
208 "--controllerserver=true",
209 "--drivername=rbd.csi.ceph.com",
210 "--endpoint=unix://csi/csi.sock",
211 "--nodeid=${node.unique.name}",
212 "--instanceid=${node.unique.name}-controller",
214 "--logtostderr=true",
216 "--metricsport=$${NOMAD_PORT_metrics}"
224 name = "ceph-csi-controller"
226 tags = [ "prometheus" ]
237 Configure plugin node
238 ---------------------
240 Generate a ``ceph-csi-plugin-nodes.nomad`` file similar to the example below.
241 Substitute the `fsid` for "clusterID" and the monitor addresses for
244 job "ceph-csi-plugin-nodes" {
245 datacenters = ["dc1"]
256 "clusterID": "b9127830-b0cc-4e34-aa47-9d1a2e9949a8",
264 destination = "local/config.json"
265 change_mode = "restart"
268 image = "quay.io/cephcsi/cephcsi:v3.3.1"
270 "./local/config.json:/etc/ceph-csi-config/config.json"
275 target = "/tmp/csi/keys"
278 size = 1000000 # size in bytes
284 "--drivername=rbd.csi.ceph.com",
286 "--endpoint=unix://csi/csi.sock",
287 "--nodeid=${node.unique.name}",
288 "--instanceid=${node.unique.name}-nodes",
290 "--logtostderr=true",
292 "--metricsport=$${NOMAD_PORT_metrics}"
301 name = "ceph-csi-nodes"
303 tags = [ "prometheus" ]
314 Start plugin controller and node
315 --------------------------------
317 To start the plugin controller and the Nomad node, run the following commands:
321 nomad job run ceph-csi-plugin-controller.nomad
322 nomad job run ceph-csi-plugin-nodes.nomad
324 The `ceph-csi`_ image will be downloaded.
326 Check the plugin status after a few minutes:
328 .. code-block:: console
330 $ nomad plugin status ceph-csi
332 Provider = rbd.csi.ceph.com
334 Controllers Healthy = 1
335 Controllers Expected = 1
340 ID Node ID Task Group Version Desired Status Created Modified
341 23b4db0c a61ef171 nodes 4 run running 3h26m ago 3h25m ago
342 fee74115 a61ef171 controller 6 run running 3h26m ago 3h25m ago
344 Using Ceph Block Devices
345 ========================
350 ``ceph-csi`` requires the cephx credentials for communicating with the Ceph
351 cluster. Generate a ``ceph-volume.hcl`` file similar to the example below,
352 using the newly created nomad user id and cephx key::
357 plugin_id = "ceph-csi"
358 capacity_max = "200G"
359 capacity_min = "100G"
362 access_mode = "single-node-writer"
363 attachment_mode = "file-system"
368 userKey = "AQAlh9Rgg2vrDxAARy25T7KHabs6iskSHpAEAQ=="
372 clusterID = "b9127830-b0cc-4e34-aa47-9d1a2e9949a8"
374 imageFeatures = "layering"
377 After the ``ceph-volume.hcl`` file has been generated, create the volume:
381 nomad volume create ceph-volume.hcl
383 Use rbd image with a container
384 ------------------------------
386 As an exercise in using an rbd image with a container, modify the Hashicorp
387 `nomad stateful`_ example.
389 Generate a ``mysql.nomad`` file similar to the example below::
392 datacenters = ["dc1"]
394 group "mysql-server" {
396 volume "ceph-mysql" {
398 attachment_mode = "file-system"
399 access_mode = "single-node-writer"
401 source = "ceph-mysql"
414 task "mysql-server" {
417 volume = "ceph-mysql"
422 MYSQL_ROOT_PASSWORD = "password"
425 image = "hashicorp/mysql-portworx-demo:latest"
426 args = ["--datadir", "/srv/mysql"]
434 name = "mysql-server"
450 nomad job run mysql.nomad
452 Check the status of the job:
454 .. code-block:: console
456 $ nomad job status mysql-server
461 ID Node ID Task Group Version Desired Status Created Modified
462 38070da7 9ad01c63 mysql-server 0 run running 6s ago 3s ago
464 To check that data are persistent, modify the database, purge the job, then
465 create it using the same file. The same RBD image will be used (re-used,
468 .. _ceph-csi: https://github.com/ceph/ceph-csi/
469 .. _csi: https://www.nomadproject.io/docs/internals/plugins/csi
470 .. _Create a Pool: ../../rados/operations/pools#createpool
471 .. _Placement Groups: ../../rados/operations/placement-groups
472 .. _CRUSH tunables: ../../rados/operations/crush-map/#tunables
473 .. _RBD image features: ../rbd-config-ref/#image-features
474 .. _nomad stateful: https://learn.hashicorp.com/tutorials/nomad/stateful-workloads-csi-volumes?in=nomad/stateful-workloads#create-the-job-file
475 .. _ceph-csi release: https://github.com/ceph/ceph-csi#ceph-csi-container-images-and-release-compatibility