Last active
November 12, 2024 04:47
-
-
Save pythoninthegrass/af1adb98fc8c368a41d73a1f29a76d18 to your computer and use it in GitHub Desktop.
Spin up a kind cluster with jupyterhub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git clone https://gist.github.com/af1adb98fc8c368a41d73a1f29a76d18.git kind_jupyterhub cd kind_jupyterhub ./deploy.sh open http://localhost:30080 kind delete cluster