Kubetorch provides persistent storage through the Volume class, which abstracts Kubernetes PersistentVolumeClaims
while maintaining the flexibility to work with any storage backend your cluster supports.
Manages persistent storage for Kubetorch services and deployments.
- __init__(name: str, size: str, mount_path: str, storage_class: str | None = None, access_mode: str | None = None, namespace: str | None = None, core_v1: CoreV1Api | None = None)
Kubetorch Volume object, specifying persistent storage properties.
- Parameters:
name (str) β Name of the volume.
size (str) β Size of the volume.
mount_path (str) β Mount path for the volume.
storage_class (str, optional) β Storage class to use for the volume.
access_mode (str, optional) β Access mode for the volume.
namespace (str, optional) β Namespace for the volume.
Example:
import kubetorch as kt # Standard volume (ReadWriteOnce) kt.Volume(name="my-data", size="5Gi", mount_path="/data") # Shared volume (ReadWriteMany, requires JuiceFS or similar) kt.Volume( name="shared-data", size="10Gi", mount_path="/shared", storage_class="juicefs-sc-shared", access_mode="ReadWriteMany" ) # uv cache compute = kt.Compute( cpus=".01", env_vars={ "UV_CACHE_DIR": "/cache/uv_cache", "HF_HOME": "/cache/hf_cache", }, volumes=[kt.Volume(name="kt-global-cache", size="10Gi", mount_path="/cache")], )
Get the mount path for this volume
Get storage class - either specified or cluster default
Get existing volume by name
name (str) β Name of the volume/PVC
namespace (str, optional) β Kubernetes namespace
core_v1 (client.CoreV1Api, optional) β Kubernetes API client
mount_path (str, optional) β Override the mount path. If not provided, uses the annotation from the PVC
Volume instance loaded from existing PVC
Get configuration for this volume
Convert to Kubernetes volume spec for pod template
Create PVC if it doesnβt exist
Delete the PVC
Check if the PVC exists
Launch an interactive debug shell with this volume mounted.
This method creates a temporary Kubernetes pod that mounts the PersistentVolumeClaim (PVC) backing this Volume at the same path (self.mount_path) used by Kubetorch services.
image (str, optional) β Container image to use for the debug pod. Must include a shell (e.g., alpine:3.18, ubuntu:22.04, or a custom tools image). Defaults to alpine:latest.
Example:
import kubetorch as kt vol = kt.Volume.from_name("kt-global-cache") vol.ssh()