To simplify the YAML configuration for storage mounting and runtime injection in Agent Sandbox, you can configure the spec.runtimes field in a Sandbox resource. This automatically injects CSI storage mount and AgentRuntime configurations, streamlining the deployment process.
Prerequisites
You have set up the Agent Sandbox environment. For more information, see Create an Agent Sandbox.
In the Add-ons section of your cluster, verify that the
ack-agent-sandbox-controllercomponent is version v0.5.10 or later.The component installer creates a ConfigMap object named
sandbox-injection-configin thesandbox-systemnamespace with default configurations. For custom settings or modifications, contact Alibaba Cloud technical support to validate the configuration before making changes.
Overview
When you configure dynamic storage mounts in an Agent Sandbox, the YAML configuration is typically complex because you must manually configure CSI and sidecar containers. With the Sidecar automatic injection feature, you only need to define the application container and declare the spec.runtimes field in the SandboxSet or Sandbox resource. The system then automatically injects the required CSI and AgentRuntime Sidecar configurations into each new Sandbox. The following two injection types are currently supported:
csi: Injects theinit containerandVolumeconfigurations for mounting storage by using CSI, enabling the mounting of shared storage such as NAS and OSS.agent-runtime: Injects the AgentRuntime init container (an environment management tool such as envd) and adds corresponding environment variables and lifecycle hooks to the application container.
Automatic sidecar injection affects only new Sandbox instances. To use theCommandandFilesystemAPIs, you must injectagent-runtime.
Configure sidecar injection
Declare the runtime type to be injected in the spec.runtimes field of a SandboxSet or Sandbox resource. The following examples show the configurations for both types of resources.
Example: SandboxSet resource
apiVersion: agents.kruise.io/v1alpha1
kind: SandboxSet
metadata:
name: code-interpreter-inject-test
namespace: default
spec:
runtimes:
- name: csi # Enables CSI mounting capabilities. The corresponding sidecar is injected into new Sandbox instances.
- name: agent-runtime # Injects environment management tools like envd.
replicas: 4
template:
metadata:
labels:
alibabacloud.com/acs: "true"
spec:
automountServiceAccountToken: false
containers:
- image: registry-cn-zhangjiakou-vpc.ack.aliyuncs.com/acs/code-interpreter:v1.6 # Replace with your cluster's region ID.
imagePullPolicy: IfNotPresent
name: sandbox
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: "1"
memory: 1Gi
terminationGracePeriodSeconds: 30Example: Sandbox resource
apiVersion: agents.kruise.io/v1alpha1
kind: Sandbox
metadata:
name: code-interpreter-inject-test-xxx
namespace: default
spec:
runtimes:
- name: csi # Provides CSI mounting capabilities.
- name: agent-runtime # Injects environment management tools like envd.
...Injection configuration
The following code shows the default injection configurations provided in v0.5.9 and later, which you typically do not need to modify. The system automatically replaces the <region-id> placeholder in image addresses with the region ID of your cluster (for example, cn-zhangjiakou).
The data structure for each configuration item contains the following fields:
Field | Description |
| The injection configuration for the main container includes items such as environment variables ( |
| A list of sidecar containers used to inject CSI plugin containers or AgentRuntime init containers. The format is an array of |
| A list of volumes to be injected at the Pod level, formatted as an array of |