This topic mainly describes how to manage sandboxes across their lifecycle in VCI Agent Sandbox, such as creating, suspending, restoring, deleting, and modifying sandboxes.
You can use VCI resources to create a sandbox.
tip
- A sandbox is a Sandbox Custom Resource.
- VCI containers use Kata Containers to achieve strong isolation.
- To define a deletion/retention policy for a sandbox snapshot by using SandboxSnapShotClass , create a related custom resource in advance. The following YAML file serves as an example. For details, see Data persistence.
- An image required to run the sandbox has been created. Make sure that the nodes in the cluster where the sandbox is located can pull the image. You can also upload the image to CR. For details, see Pushing and pulling images by using Docker.
- When you create a sandbox by using an existing snapshot, you can obtain the snapshot ID by using one of the following two methods:
- Use the snapshot ID automatically created by VCI during the shutdown of an existing sandbox.
- Use the Snapshot-type Custom Resource created by the user.
Creating sandboxes for the first time
If you create a sandbox in VCI Agent Sandbox for the first time, use the following sample code.
If the status.phase of the CRD changes to Running, it indicates that the sandbox has been created. The sample code snippet is as follows:
Create a sandbox by using an existing snapshot
When you create a sandbox by using an existing snapshot in VCI Agent Sandbox, add the annotation vci.volcengine.com/snapshot-id based on the sample code displayed in the Creating sandboxes for the first time section. The complete sample code is as follows.
Automatically create snapshots
To suspend a sandbox, set its replicas to 0. By default, when the sandbox is suspended, VCI Agent Sandbox will automatically generate a snapshot. The sample code snippet is as follows:
If the status.phase of the CRD changes to Paused, it indicates that the sandbox has been suspended. The sample code snippet is as follows:
If you do not want a snapshot to be automatically created when the sandbox is suspended, you can disable this feature by configuring the annotation agent.sandbox.io/auto-create-snapshot: "false".
If the status.phase of the CRD changes to Paused, it indicates that the sandbox has been suspended and no snapshots will be automatically generated. The sample code snippet is as follows:
To restore a sandbox, set its replicas to 1. The snapshot generated from the previous shutdown will be used for restoring the sandbox. The sample code snippet is as follows:
If the status.phase of the Custom Resource changes to Running, it indicates that the sandbox has been restored.
Update through recreation
When updating the CPU, memory, or GPU configuration of the sandbox, you need to first suspend the sandbox and then update the resources within the podTemplate. After the configuration is complete, resume the sandbox. This process will destroy the original Pod and then recreate a Pod to update the sandbox configuration.
- Suspend the sandbox by setting replicas to 0. The sandbox is suspended if status.phase is Paused.
- Update the resources field in podTemplate.
- Restore the sandbox by setting replicas to 1. The Custom Resource is restored if status.phase is Running.
You can perform an in-place update on a sandbox image without rebuilding the Pod. It means that you can update the sandbox image on the existing Pod without destroying the Pod. This shortens the time required for configuration changes.
- Configure the annotation vci.volcengine.com/persistent-container: "true" in the sandbox YAML file.
- Subsequent updates to the image configured in podTemplate can be performed directly via YAML, and the VCI Agent Sandbox will update the container image in place.
- After the update is complete, if the status.phase of the custom resource is Running and the container image has switched to the target version, the in-place update of the sandbox is complete.
If you no longer need a sandbox, you can directly delete the corresponding Sandbox resource. When you delete the sandbox, its corresponding VCI Pod, Snapshot, Custom Resource, and PVC resources will be automatically deleted.
The data retention policy of a data volume is determined by the retention policy of the StorageClass.
- Retain: After the PVC is released, the PV remains Released and is not automatically deleted or reclaimed.
- Delete: After the PVC is released, the PV and its underlying storage resources are automatically deleted.
To delete the sandbox at a scheduled time, you can specify shutdownTime. The sample code is as follows.