Skip to content

Commit 70a5a8f

Browse files
Docs: Add guides section (#140)
* add guides * move all guides to examples * minor fixes * remove reference to platform
1 parent e26ddb2 commit 70a5a8f

File tree

13 files changed

+752
-0
lines changed

13 files changed

+752
-0
lines changed

examples/jupyterlab/README.md

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
# JupyterLab on Agent-Sandbox
2+
3+
## Prerequisites
4+
5+
**You must have agent-sandbox already installed on your cluster.** Follow the installation guide:
6+
7+
**[Agent-Sandbox Installation Guide](../../INSTALL.md)**
8+
9+
Make sure the agent-sandbox controller is running before proceeding:
10+
11+
```bash
12+
kubectl get pods -n agent-sandbox-system
13+
# Should show agent-sandbox-controller-0 in Running state
14+
```
15+
16+
## Project Structure
17+
18+
```
19+
.
20+
├── README.md # This file
21+
├── ../../INSTALL.md # Agent-sandbox installation guide
22+
├── jupyterlab.yaml # Modular deployment (Secret + Sandbox only)
23+
├── jupyterlab-full.yaml # All-in-one deployment (+ ConfigMap with file contents)
24+
└── files/
25+
├── download_models.py # Script to download HuggingFace models
26+
├── requirements.txt # Python dependencies
27+
└── welcome.ipynb # Sample notebook
28+
```
29+
30+
## Installation Methods
31+
32+
Choose one of two deployment methods:
33+
34+
### Method A: All-in-One Deployment
35+
36+
Use `jupyterlab-full.yaml` which contains everything in a single file.
37+
38+
**Steps:**
39+
40+
1. **Edit the HuggingFace token:**
41+
42+
```bash
43+
# Open jupyterlab-full.yaml and replace HF_TOKEN with your actual token
44+
vi jupyterlab-full.yaml
45+
```
46+
47+
Or use sed:
48+
49+
```bash
50+
export HF_TOKEN="your_actual_HF_token_here"
51+
sed -i "s/HF_TOKEN/$HF_TOKEN/g" jupyterlab-full.yaml
52+
```
53+
54+
2. **Deploy everything:**
55+
56+
```bash
57+
kubectl apply -f jupyterlab-full.yaml
58+
```
59+
60+
3. **Skip to "Verify Installation" section below.**
61+
62+
63+
### Method B: Modular Deployment
64+
65+
Use `jupyterlab.yaml` + create ConfigMap from files. This keeps YAML clean.
66+
67+
**Steps:**
68+
69+
1. **Create the ConfigMap from files:**
70+
71+
```bash
72+
kubectl create configmap jupyter-init-files \
73+
--from-file=files/download_models.py \
74+
--from-file=files/requirements.txt \
75+
--from-file=files/welcome.ipynb \
76+
--namespace=default
77+
```
78+
79+
Verify the ConfigMap was created:
80+
81+
```bash
82+
kubectl get configmap jupyter-init-files -o yaml
83+
```
84+
85+
2. **Edit the HuggingFace token:**
86+
87+
```bash
88+
# Open jupyterlab.yaml and replace HF_TOKEN with your actual token
89+
vi jupyterlab.yaml
90+
```
91+
92+
Or use sed:
93+
94+
```bash
95+
export HF_TOKEN="your_actual_HF_token_here"
96+
sed -i "s/HF_TOKEN/$HF_TOKEN/g" jupyterlab.yaml
97+
```
98+
99+
3. **Deploy the Sandbox:**
100+
101+
```bash
102+
kubectl apply -f jupyterlab.yaml
103+
```
104+
105+
---
106+
107+
## Verify Installation
108+
109+
### 1. Monitor Initialization
110+
111+
The init container will download packages and models on first run (~5-10 minutes):
112+
113+
```bash
114+
# Watch pod creation
115+
kubectl get pods -l sandbox=jupyterlab -w
116+
117+
# Check init container logs
118+
kubectl logs -f jupyterlab-sandbox -c setup-environment
119+
120+
# You should see:
121+
# "Installing Python dependencies to persistent storage..."
122+
# "Downloading models to persistent storage..."
123+
# "Initialization complete!"
124+
```
125+
126+
### 2. Check Main Container
127+
128+
Once init completes, verify JupyterLab started:
129+
130+
```bash
131+
# Check main container logs
132+
kubectl logs -f jupyterlab-sandbox -c jupyterlab
133+
134+
# Look for: "Jupyter Server ... is running at http://0.0.0.0:8888"
135+
```
136+
137+
### 3. Verify Pod is Running
138+
139+
```bash
140+
kubectl get sandbox jupyterlab-sandbox
141+
kubectl get pod jupyterlab-sandbox
142+
143+
# Both should show Running status
144+
```
145+
146+
## Access JupyterLab
147+
148+
### Port Forward to Local Machine
149+
150+
```bash
151+
kubectl port-forward --address 0.0.0.0 pod/jupyterlab-sandbox 8888:8888
152+
```
153+
154+
**Access in browser:**
155+
- Local: http://localhost:8888
156+
157+
**Navigate to the welcome notebook:**
158+
- Open http://localhost:8888/lab/tree/work/welcome.ipynb
159+
- Or click `welcome.ipynb` in the JupyterLab file browser
160+
161+
**No password required** (authentication disabled for sandbox use).
162+
163+
## What Gets Deployed
164+
165+
### Resources
166+
167+
1. **Secret** (`jupyter-hf-token`): Stores your HuggingFace token
168+
2. **ConfigMap** (`jupyter-init-files`): Contains Python scripts and notebooks
169+
3. **Sandbox** (`jupyterlab-sandbox`): Creates the JupyterLab environment with:
170+
- Init container: Downloads models and installs dependencies
171+
- Main container: Runs JupyterLab server
172+
- PVC: 20Gi persistent storage
173+
174+
## Customization
175+
176+
### Add More Python Packages
177+
178+
Edit `files/requirements.txt`:
179+
180+
```
181+
transformers>=4.51.0
182+
torch
183+
huggingface_hub
184+
ipywidgets
185+
pandas>=2.0.0 # Add your packages
186+
scikit-learn
187+
matplotlib
188+
```
189+
190+
Then recreate the ConfigMap and force re-initialization:
191+
192+
```bash
193+
# Method A (all-in-one): Edit jupyterlab-full.yaml and reapply
194+
kubectl apply -f jupyterlab-full.yaml
195+
196+
# Method B (modular): Recreate ConfigMap
197+
kubectl delete configmap jupyter-init-files
198+
kubectl create configmap jupyter-init-files \
199+
--from-file=files/download_models.py \
200+
--from-file=files/requirements.txt \
201+
--from-file=files/welcome.ipynb
202+
203+
# Force re-init for both methods
204+
kubectl exec jupyterlab-sandbox -- rm /home/jovyan/.initialized
205+
kubectl delete pod jupyterlab-sandbox
206+
```
207+
208+
### Add More Models
209+
210+
Edit `files/download_models.py`:
211+
212+
```python
213+
model_names = [
214+
"Qwen/Qwen3-Embedding-0.6B",
215+
"meta-llama/Llama-3.2-1B-Instruct", # Add more
216+
]
217+
```
218+
219+
Then recreate ConfigMap and force re-init (same steps as above).
220+
221+
### Add More Notebooks
222+
223+
Add `.ipynb` files to the `files/` directory, then:
224+
225+
```bash
226+
# Recreate ConfigMap with all files
227+
kubectl delete configmap jupyter-init-files
228+
kubectl create configmap jupyter-init-files \
229+
--from-file=files/ \
230+
--namespace=default
231+
232+
# Update init script to copy all notebooks
233+
# Edit jupyterlab.yaml or jupyterlab-full.yaml:
234+
# Change: cp /config/welcome.ipynb /home/jovyan/work/welcome.ipynb
235+
# To: cp /config/*.ipynb /home/jovyan/work/
236+
237+
# Reapply and restart
238+
kubectl apply -f jupyterlab.yaml
239+
kubectl delete pod jupyterlab-sandbox
240+
```
241+
242+
### Change Storage Size
243+
244+
Modify `volumeClaimTemplates` in the Sandbox spec:
245+
246+
```yaml
247+
volumeClaimTemplates:
248+
- metadata:
249+
name: workspace
250+
spec:
251+
resources:
252+
requests:
253+
storage: 50Gi # Increase for large datasets
254+
```
255+
256+
**Note:** You must delete the existing Sandbox and PVC to change storage size:
257+
258+
```bash
259+
kubectl delete sandbox jupyterlab-sandbox
260+
kubectl delete pvc jupyterlab-sandbox-workspace
261+
kubectl apply -f jupyterlab.yaml
262+
```
263+
264+
## Troubleshooting
265+
266+
### Init Container Fails
267+
268+
**Check init logs:**
269+
270+
```bash
271+
kubectl logs jupyterlab-sandbox -c setup-environment
272+
```
273+
274+
**Common issues:**
275+
276+
1. **Invalid HuggingFace token** - 401 Unauthorized errors
277+
- Solution: Verify your token at https://huggingface.co/settings/tokens
278+
- Update the secret: `kubectl delete secret jupyter-hf-token && kubectl create secret ...`
279+
280+
2. **Out of disk space** - Ephemeral storage exceeded
281+
- This shouldn't happen with current config (everything uses PVC)
282+
- Check PVC is mounted: `kubectl describe pod jupyterlab-sandbox | grep Volumes`
283+
284+
3. **Model download timeout** - Network issues or large model
285+
- Check init logs for specific error
286+
- Try with a smaller model first
287+
288+
### JupyterLab Not Starting
289+
290+
**Check main container logs:**
291+
292+
```bash
293+
kubectl logs jupyterlab-sandbox -c jupyterlab
294+
```
295+
296+
**Common issues:**
297+
298+
1. **Port already in use** - Unlikely in fresh pod
299+
- Verify with: `kubectl exec jupyterlab-sandbox -- netstat -tuln | grep 8888`
300+
301+
2. **Python packages not found** - Init failed or was skipped
302+
- Check if packages exist: `kubectl exec jupyterlab-sandbox -- ls /home/jovyan/.local/lib/python3.12/site-packages`
303+
- Force re-init: `kubectl exec jupyterlab-sandbox -- rm /home/jovyan/.initialized && kubectl delete pod jupyterlab-sandbox`
304+
305+
## Cleanup
306+
307+
### Delete Everything
308+
309+
```bash
310+
# Delete Sandbox (also deletes pod and PVC)
311+
kubectl delete sandbox jupyterlab-sandbox
312+
313+
# Delete ConfigMap and Secret
314+
kubectl delete configmap jupyter-init-files
315+
kubectl delete secret jupyter-hf-token
316+
```
317+
318+
### Keep Data, Remove Deployment
319+
320+
```bash
321+
# Delete just the Sandbox (keeps PVC)
322+
kubectl delete sandbox jupyterlab-sandbox --cascade=orphan
323+
324+
# PVC remains - you can reattach it later
325+
kubectl get pvc jupyterlab-sandbox-workspace
326+
```
327+
328+
## Additional Resources
329+
330+
- [Agent-Sandbox GitHub](https://github.com/kubernetes-sigs/agent-sandbox)
331+
- [JupyterLab Documentation](https://jupyterlab.readthedocs.io/)
332+
- [HuggingFace Tokens](https://huggingface.co/settings/tokens)
333+
- [Kubernetes Sandboxes](https://kubernetes.io/docs/concepts/workloads/pods/sandboxes/)

0 commit comments

Comments
 (0)