Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 17 additions & 27 deletions docs/examples/kubernetes-pvc-volume-mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The script creates a sandbox, writes a marker file under `/mnt/data`, kills it,

## Pool mode: pre-mount a shared PVC

Pool pods are created before a sandbox is allocated, so storage shared by a pool must be part of the Pool pod template. Create the PVC first, then mount it in every warm pod through `Pool.spec.template`:
Pool pods are created before a sandbox is allocated, so storage shared by a pool must be part of the Pool pod template. Create the PVC in the lifecycle server's configured Kubernetes sandbox namespace. This example uses `opensandbox`.

```yaml
apiVersion: v1
Expand All @@ -123,34 +123,24 @@ spec:
resources:
requests:
storage: 100Gi
---
apiVersion: sandbox.opensandbox.io/v1alpha1
kind: Pool
metadata:
name: shared-workspace-pool
namespace: opensandbox
spec:
template:
spec:
containers:
- name: sandbox-container
image: python:3.11
command: ["sleep", "3600"]
volumeMounts:
- name: shared-workspace
mountPath: /workspace
volumes:
- name: shared-workspace
persistentVolumeClaim:
claimName: shared-workspace-pvc
capacitySpec:
bufferMax: 10
bufferMin: 2
poolMax: 20
poolMin: 5
```

Apply the Pool manifest to the cluster before allocating sandboxes from it. Sandboxes then select the preconfigured Pool with `extensions.poolRef` and do not pass a per-sandbox `volumes` list.
Start from the [Kubernetes Pool sample](https://github.com/opensandbox-group/OpenSandbox/blob/main/kubernetes/config/samples/sandbox_v1alpha1_pool.yaml), which sets up the task executor and execd used by SDK-created sandboxes. Set the Pool's `metadata.name` to `shared-workspace-pool` and its namespace to the PVC's namespace. Append the following entry to `spec.template.spec.volumes`.

```yaml
- name: shared-workspace
persistentVolumeClaim:
claimName: shared-workspace-pvc
```

Append the following entry to `volumeMounts` on the sample's `sandbox` container.

```yaml
- name: shared-workspace
mountPath: /mnt/data
```

Apply the PVC and updated Pool before creating sandboxes. Set `extensions.poolRef` to `shared-workspace-pool` and omit per-sandbox `volumes`. You can also [select the Pool from an SDK client pool](/guides/client-pool#use-a-kubernetes-pool-as-the-backend).

::: warning Static pool storage only
The PVC must already exist, and its access mode and storage backend must allow all scheduled warm pods to mount it. OpenSandbox does not create, mutate, or delete PVCs referenced by a Pool template. A sandbox creation request cannot add `volumes` while also using `extensions.poolRef`, because the selected warm pod already exists.
Expand Down
19 changes: 19 additions & 0 deletions docs/guides/client-pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ The warmup path — the leader-only replenish flow above — is worth zooming in

![Warmup reconcile sequence](../public/images/client-pool-warmup-sequence.svg)

### Use a Kubernetes Pool as the backend

With the Kubernetes BatchSandbox provider, an SDK client pool can create sandboxes from a pre-warmed Kubernetes `Pool`. Create the Kubernetes Pool in the lifecycle server's configured sandbox namespace, then set `extensions.poolRef` in the SDK pool's creation spec. The SDK's `pool_name` selects its own state-store namespace. It can differ from the Kubernetes Pool name.

Use this creation spec with either `SandboxPoolSync` or `SandboxPoolAsync`.

```python
from opensandbox import PoolCreationSpec

creation_spec = PoolCreationSpec(
image="sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/code-interpreter:v1.1.0",
extensions={"poolRef": "shared-workspace-pool"},
)
```

Both background warmup and `DIRECT_CREATE` fallback use this selection. Python's creation spec requires `image`, and the Kubernetes Pool template determines the actual Pod image.

For shared storage, [pre-mount an existing PVC in the Kubernetes Pool template](/examples/kubernetes-pvc-volume-mount#pool-mode-pre-mount-a-shared-pvc) and leave `volumes` unset in the creation spec. The lifecycle server rejects a nonempty `volumes` list together with `poolRef`. To choose a volume per sandbox, pass `volumes` in an on-demand create request and omit `poolRef`.

### Lifecycle model

During graceful operation, each pool instance moves through `NOT_STARTED → STARTING → RUNNING → DRAINING → STOPPED`. A failed start or non-graceful shutdown can transition directly to `STOPPED`. If awaiting Python's `SandboxPoolAsync.start()` is cancelled, it waits for startup-owned resource cleanup, even if the caller cancels repeatedly during cleanup. Successful cleanup returns the pool to `STOPPED` before propagating `CancelledError`, so the same instance can then be started again. If cleanup itself fails after a further caller cancellation, `CancelledError` takes precedence and retains the cleanup error as its cause. Without a further cancellation, the cleanup error propagates normally. In either case the lifecycle state is `STOPPED`, allowing another `start()` attempt instead of silently returning in `STARTING`. Resource cleanup may still be incomplete when closing fails. Health is tracked separately as `HEALTHY | DEGRADED | DRAINING | STOPPED`; after `degraded_threshold` consecutive warmup or reconcile failures the pool enters `DEGRADED`. Go applies exponential replenish backoff while degraded. Its periodic reconciliation still observes namespace retirement, reaps idle entries, and shrinks excess capacity during backoff; only new warmup creation is delayed. Python, JavaScript, and Kotlin continue attempting reconciliation at their nominal one-second cadence: `warmup_create_qps` is their pressure control, and `snapshot().backoff_active` / `snapshot().backoffActive` is retained only for compatibility and is always `false`. Callers do not need to observe these states directly — `snapshot()` exposes them for diagnostics.
Expand Down
Loading