Skip to content

Interactive Pods & Long-Idle Guidelines

Interactive pods enable live development, notebook prototyping, and terminal access to GPU hardware.

Because GPU scheduling requires specifying resource limits (nvidia.com/gpu), you can launch an interactive session using either a declarative YAML manifest (recommended) or a one-liner with --overrides.

Section titled “Option A: Using a YAML Manifest (Recommended)”

Save the following as dev-session.yaml:

apiVersion: v1
kind: Pod
metadata:
name: dev-session
namespace: <your-namespace>
spec:
restartPolicy: Never
containers:
- name: dev-container
image: pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime
stdin: true
tty: true
command: ["/bin/bash"]
resources:
limits:
nvidia.com/gpu: "1"
cpu: "8"
memory: "32Gi"

Apply and attach to the session:

Terminal window
# Launch the pod
kubectl apply -f dev-session.yaml
# Attach to the running shell
kubectl attach -it dev-session -n <your-namespace>
# Or exec an independent interactive bash shell
kubectl exec -it dev-session -n <your-namespace> -- /bin/bash

Option B: One-Liner with kubectl run and --overrides

Section titled “Option B: One-Liner with kubectl run and --overrides”

Since kubectl run does not have a native --limits flag, pass container resource limits using --overrides:

Terminal window
kubectl run dev-session \
--namespace <your-namespace> \
--image=pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime \
--restart=Never \
--rm -it \
--overrides='{
"spec": {
"containers": [{
"name": "dev-session",
"image": "pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime",
"stdin": true,
"tty": true,
"resources": {
"limits": {
"nvidia.com/gpu": "1",
"cpu": "8",
"memory": "32Gi"
}
}
}]
}
}' -- /bin/bash

Option C: Quick CPU-Only Interactive Shell

Section titled “Option C: Quick CPU-Only Interactive Shell”

For lightweight debugging or scripting that doesn’t require GPUs:

Terminal window
kubectl run dev-session \
--namespace <your-namespace> \
--image=ubuntu:22.04 \
--restart=Never \
--rm -it -- /bin/bash

  1. Clean up when done: Do not leave idle GPU pods running overnight without computations. When finished, exit and delete the pod:
    Terminal window
    kubectl delete pod dev-session -n <your-namespace>
  2. Mount Persistent Storage: Always mount a CephFS PVC so your notebooks, code edits, and conda environments persist across pod restarts.
  3. Port Forwarding for Web UIs: If your pod runs TensorBoard, Streamlit, or JupyterLab on port 8888:
    Terminal window
    kubectl port-forward dev-session 8888:8888 -n <your-namespace>
    Open http://localhost:8888 on your local laptop to access the interactive web interface securely via encrypted SSH/tunnel.