How to create host directories? #1571
-
Scenario I want to create and setup a directory in the underlying host, but it should be available before my pods/tasks/containers start so they can use and share the directory |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Other cloud-based Linux distributions provide mechanisms to create host directories in early stages of the init process (like cloud-init or ignition in CoreOS-like distributions), and Bottlerocket is not the exception. Users can create a one-off bootstrap container that sets up the host directory with the tools they are already familiar with. Here is an example of how to do so. Given a bootstrap container called setup-host-directory with the following configuration: [settings.bootstrap-containers.setup-host-directory]
source="<SOURCE>"
mode="once"
user-data="ypXjg47igKLhtKXigKLKlOODjiDvuLUg4pS74pSB4pS7Cg==" Where FROM alpine
ADD setup-host-directory /
RUN chmod +x setup-host-directory/
ENTRYPOINT ["sh", "setup-host-directory"] And #! /usr/bin/env sh
# We'll read some data to be written out from given user-data.
USER_DATA_DIR=/.bottlerocket/bootstrap-containers/current
# This is the in-container view of where the host's `/var` can be accessed.
HOST_VAR_DIR=/.bottlerocket/rootfs/var
# The directory that'll be created by this bootstrap container
MY_HOST_DIR=$HOST_VAR_DIR/lib/my_directory
# Create it!
mkdir -p $MY_HOST_DIR
# Write the user-data to our new path:
cat $USER_DATA_DIR/user-data > $MY_HOST_DIR/bear.txt
# The bootstrap container can set the permissions which are seen by the host:
chmod -R o+r $MY_HOST_DIR
chown -R 1000:1000 $MY_HOST_DIR You should see a new directory under |
Beta Was this translation helpful? Give feedback.
Other cloud-based Linux distributions provide mechanisms to create host directories in early stages of the init process (like cloud-init or ignition in CoreOS-like distributions), and Bottlerocket is not the exception. Users can create a one-off bootstrap container that sets up the host directory with the tools they are already familiar with. Here is an example of how to do so.
Given a bootstrap container called setup-host-directory with the following configuration:
Where
<SOURCE>
, is the URL of an image with the following definition: