Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Basic Datasette in Kubernetes#
This recipe for deploying the official datasetteproject/datasette container in Kubernetes just worked for me. It uses an interesting (possibly nasty?) trick to install plugins and download a SQLite database file on container startup, without needing to bake a brand new container image.
I’m running 2 replicas, to experiment with the cluster.
1apiVersion: apps/v12kind: Deployment3metadata:4 name: datasette-deployment5spec:6 replicas: 27 selector:8 matchLabels:9 app: datasette10 template:11 metadata:12 labels:13 app: datasette14 spec:15 containers:16 - name: datasette17 image: datasetteproject/datasette18 command:19 - sh20 - -c21 args:22 - |-23 # Install some plugins24 pip install \25 datasette-debug-asgi \26 datasette-cluster-map \27 datasette-psutil28 # Download a DB (using Python because curl/wget are not available)29 python -c 'import urllib.request; urllib.request.urlretrieve("https://global-power-plants.datasettes.com/global-power-plants.db", "/home/global-power-plants.db")'30 # Start Datasette, on 0.0.0.0 to allow external traffic31 datasette -h 0.0.0.0 /home/global-power-plants.db32 ports:33 - containerPort: 800134 protocol: TCPThe devious trick here is to use command and args to specify a multi-line shell script to run on startup, which installs some plugins with pip install, then downloads a database file using urllib.request.urlretrieve() in Python (because wget and curl are not included in the official image), then starts Datasette against that downloaded file.