Volumes

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.

Volume Class

class kubetorch.Volume(name: str, size: str, storage_class: str | None = None, mount_path: str | None = None, access_mode: str | None = None, namespace: str | None = None, core_v1: CoreV1Api | None = None)

Manages persistent storage for Kubetorch services and deployments.

__init__(name: str, size: str, storage_class: str | None = None, mount_path: 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.

  • storage_class (str, optional) – Storage class to use for the volume.

  • mount_path (str, optional) – Mount path for the volume.

  • access_mode (str, optional) – Access mode for the volume.

  • namespace (str, optional) – Namespace for the volume.

Example:

import kubetorch as kt kt.Volume(name="my-data", size="5Gi"), # Standard volume (ReadWriteOnce) # Shared volume (ReadWriteMany, requires JuiceFS or similar) kt.Volume(name="shared-data", size="10Gi", storage_class="juicefs-sc-shared", access_mode="ReadWriteMany") # uv cache compute = kt.Compute( cpus=".01", env_vars={ "UV_CACHE_DIR": "/ktfs/kt-global-cache/uv_cache", "HF_HOME": "/ktfs/kt-global-cache/hf_cache", }, volumes=[kt.Volume("kt-global-cache", size="10Gi")], )
property storage_class: str

Get storage class - either specified or cluster default

classmethod from_name(name: str, create_if_missing: bool = False, namespace: str | None = None, core_v1: CoreV1Api | None = None) Volume

Get existing volume or optionally create it

config() Dict[str, str]

Get configuration for this volume

pod_template_spec() dict

Convert to Kubernetes volume spec for pod template

create() V1PersistentVolumeClaim

Create PVC if it doesn’t exist

delete() None

Delete the PVC

exists() bool

Check if the PVC exists

ssh(image: str = 'alpine:latest')

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.

Parameters:

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()