Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Last active November 12, 2024 04:47
Show Gist options
  • Save pythoninthegrass/af1adb98fc8c368a41d73a1f29a76d18 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/af1adb98fc8c368a41d73a1f29a76d18 to your computer and use it in GitHub Desktop.
Spin up a kind cluster with jupyterhub
#!/usr/bin/env bash
set -e
# Clean up function
cleanup() {
echo "Cleaning up existing cluster..."
kind delete cluster
}
# Delete existing cluster if it exists
if kind get clusters | grep -q "kind"; then
cleanup
fi
# Store kind cluster configuration in a variable with port mapping
kind_config=$(cat << EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30080
hostPort: 30080
protocol: TCP
- role: worker
- role: worker
EOF
)
# Create the cluster using the variable
echo "Creating kind cluster..."
echo "$kind_config" | kind create cluster --config=-
# Add JupyterHub helm repository
echo "Adding JupyterHub helm repository..."
helm repo add jupyterhub https://hub.jupyter.org/helm-chart/ 2>/dev/null || true
helm repo update
# Store JupyterHub config in a variable with proper spacing
jhub_config=$(cat << EOF
proxy:
service:
type: NodePort
nodePorts:
http: 30080
hub:
config:
Authenticator:
admin_users:
- admin
DummyAuthenticator:
password: password
db:
pvc:
storageClassName: standard
singleuser:
storage:
dynamic:
storageClass: standard
EOF
)
# Create namespace (idempotent)
echo "Creating namespace..."
kubectl create namespace jhub 2>/dev/null || true
# Remove existing helm release if it exists
if helm list -n jhub | grep -q "jhub"; then
echo "Removing existing JupyterHub installation..."
helm uninstall jhub -n jhub
fi
# Install JupyterHub using the variable
echo "Installing JupyterHub..."
echo "$jhub_config" | helm install jhub jupyterhub/jupyterhub \
--namespace jhub \
--version=4.0.0 \
--values - \
--timeout 5m
# Wait for pods to be ready
echo "Waiting for pods to be ready..."
kubectl wait --for=condition=ready pod -l app=jupyterhub --namespace jhub --timeout=300s
# Get NodePort
echo "Getting NodePort service information..."
kubectl get svc proxy-public -n jhub
echo "JupyterHub should be accessible at http://localhost:30080"
echo "Default login credentials:"
echo "Username: admin"
echo "Password: password"
@pythoninthegrass
Copy link
Author

git clone https://gist.github.com/af1adb98fc8c368a41d73a1f29a76d18.git kind_jupyterhub
cd kind_jupyterhub
./deploy.sh
open http://localhost:30080
kind delete cluster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment