This topic describes how to use the PV mounting capability in the VCI Agent Sandbox scenario to implement dynamic mounting of PVs for Sandbox in warm pool instances. This meets the diverse storage requirements of different businesses and tenants.
The dynamic mounting mode does not require predefined PVs in the template. SandboxClaim specifies the container mount directory (mountPath) when claiming the sandbox instance and supports adding new PVs and volumeMount. VCI injects the CSI mounting add-on in the form of Hidercar (shadow container) to ensure security. This applies to the scenarios where the mount directory can only be determined when the sandbox instance is running, or where an existing annotation contains mountPath and low-cost migration is required. Currently, only TOS-type PVs are supported.
The dynamic mounting capability is enabled and configured by adding annotations to SandboxTemplate and SandboxClaim. The following table describes the core annotation.
When using the dynamic mounting capability, please note the following restrictions.
- The VCI Agent Sandbox component, agent-sandbox, has been installed in the VCI business cluster to support CRDs such as SandboxTemplate, SandboxWarmPool, and SandboxClaim. For detailed operations, see Installation guide.
- A TOS storage bucket (Bucket) has been created. For details, see Creating buckets.
- The kubectl tool has already been installed locally, and the target cluster has been connected by using kubectl. For detailed description, see Connecting to clusters using kubectl.
Step 1: Create a SandboxTemplate
- Create a SandboxTemplate and declare vke.volcengine.com/csi-sidecar-inject: "true" in the annotations of podTemplate to enable dynamic mounting mode. The example SandboxTemplate YAML file dynamic-mount-template.yaml is shown below.
- Execute the following command to create the SandboxTemplate.
Step 2: Create a SandboxWarmPool
The warm pool will warm up a batch of Sandboxes in the Running state based on the template, so that claim requests directly hit the warmed instances. The Hidercar and Init containers required for dynamic mounting are also injected at this stage.
- Create SandboxWarmPool. The example YAML file dynamic-mount-warmpool.yaml is shown below.
- Run the following command to create the SandboxWarmPool.
Access TOS credentials through Secret management.
- Create a YAML file for the Secret. The example file vke-tos-secret.yaml is as follows.
tip
You can use the echo -n "${ak}" | base64 command to base64-encode your AK, SK, and other data, and replace all ****** in the code below with your own actual values. For more information on base64 encoding, see FAQ. - Run the following command to create the Secret.
Prepare the target PV for dynamic mounting. Currently, the dynamic mounting mode only supports TOS storage.
- Create a YAML file for the PV. The example YAML file pv-tos-shared.yaml is shown below.
- Run the following command to create the PV.
This topic provides the following two ways to create a sandbox.
Claim through SandboxClaim
Create through E2B SDK
By creating a SandboxClaim and specifying mountPath, initiate a claim for the Sandbox and explicitly declare the dynamic mounting configuration. If the annotation contains the mountPath field, the dynamic mounting mode is applied. The controller executes the CSI mounting through the Hidercar channel and mounts the subdirectory of the specified PV to any absolute path inside the container.
- Create SandboxClaim. The example YAML file dynamic-mount-claim.yaml is shown below.
- Execute the following command to create SandboxClaim.
Based on the created SandboxTemplate, use the E2B protocol to create a Sandbox. The dynamic mounting annotation can be passed in the metadata of the sandbox. The example code is as follows. For more E2B SDK-related parameter descriptions and development guides, see E2B SDK development guide. tip
The template parameter in the E2B SDK needs to be configured with the ID of the created SandboxTemplate. The value of the ID varies depending on how the SandboxTemplate is created:
- When creating a SandboxTemplate through Kubernetes API (YAML): The template ID is <metadata.namespace value>--<metadata.name value>, for example, default--dynamic-mount-template.
- When creating a SandboxTemplate through the VCI E2B SDK: The template ID is the actual returned template_id parameter value.
Confirm that the PV has been mounted to the specified container directory as expected and can be read from and written to normally.
- Confirm that /mnt/data is an independent mount point.
- The expected result is as follows. In the "Mounted on" column, it is /mnt/data, and the Filesystem is "TOS mount", indicating that TOS has been mounted to the target directory.
- Confirm that the subdirectory content can be read.
- The expected result is as follows. It lists the files and directories under the tenant-a subdirectory in the TOS bucket.