hi there. is there a way to make sub directories of a hosted volume accessible to jobs without needing to define new host_volumes in a client stanza each time, and restarting the nomad agent on a node?
Let’s imagine I have a nomad client, with this stanza in /etc/nomad/nomad.hcl
:
client {
host_volume "persistent_data" {
path = "/mnt/some-directory-for-nomad"
read_only = false
}
}
And later on I have defined a job where I want to access this persistent_data
volume, like so:
# make the volume available above accessible
volume "persistent_data_available_to_task" {
type = "host"
read_only = false
source = "persistent_data"
}
# make the directory /mnt/some-directory-for-nomad accessible to the job,
# mounted as /var/lib/rabbitmq for a job to write to and persist data
volume_mount {
volume = "persistent_data_available_to_task"
destination = "/var/lib/rabbitmq"
read_only = false
}
This is fine, but when I find scenarios where a a new job needs some persistence on the host, but I don’t want to allow the other job to access the data, I need to define a new host_volume:
client {
host_volume "persistent_data" {
path = "/mnt/some-directory-for-nomad"
read_only = false
}
host_volume "another_persistent_data" {
path = "/mnt/a-different-directory-for-nomad"
read_only = false
}
}
And then, to be able to access this new host_volume
in a different job I need to do this:
# make the volume available above accessible
volume "persistent_data_available_to_another_job" {
type = "host"
read_only = false
source = "another_persistent_data"
}
# make the this second directory accessible to this job now
volume_mount {
volume = "persistent_data_available_to_another_job"
destination = "/var/lib/some-other-programme"
read_only = false
}
I can do this, but it’s a pain, because I need to update the nomad client information then restart it each time to make the volume available.
Can I just make a subdirectory of a host volume accessible instead?
What I want to do is this - I want to define a persistent directory that the nomad client can make available to jobs, and that jobs can access between allocations. So in /etc/nomad.hcl
I might have this:
client {
host_volume "persistent_data" {
path = "/mnt/some-directory-for-nomad"
read_only = false
}
}
And then in each of the jobs, I’d have something like this:
# make the volume available above accessible just to job_one
volume "persistent_data_available_to_just_one_job" {
type = "host"
read_only = false
source = "persistent_data"
# this isn't in the volume API, but I wish it was
path = "some-sub-directory-for-first-job"
}
then in another job, I’d be able to do something like this:
# make the volume available above, accessible just to the second job
volume "persistent_data_available_to_just_second_job" {
type = "host"
read_only = false
source = "persistent_data"
# again, wishful thinking
path = "some-sub-directory-for-second-job"
}
volume_mount {
volume = "persistent_data_available_to_just_second_job"
destination = "/var/lib/rabbitmq"
read_only = false
}
Is something like this supported?
I see some extra config options for the client config pertaining to docker, like setting docker.volumes.enabled
, but this isn’t something I’m familiar with yet - so apologies if this is already supported: