Skip to content

Commit 11b3a27

Browse files
author
mgoddard
committed
Adding a script to deploy this on a GKE cluster, plus YAML files for (a) data loading and (b) running the app
1 parent d0929f2 commit 11b3a27

File tree

4 files changed

+103
-22
lines changed

4 files changed

+103
-22
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM python:3.8-slim-buster
22
WORKDIR /app
33
COPY . /app
4-
RUN apt-get update && apt-get --yes --no-install-recommends install python3-dev build-essential cmake && rm -rf /var/lib/apt/lists/*
4+
RUN apt-get update && apt-get --yes --no-install-recommends install python3-dev build-essential cmake curl && rm -rf /var/lib/apt/lists/*
55
RUN pip3 install --no-cache-dir -r requirements.txt && rm -rf ~/.cache/pip
66
EXPOSE 18080
77
ENTRYPOINT [ "python", "./map_app.py" ]

crdb-geo-tourist.yaml

+46-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
11
apiVersion: v1
2-
kind: Pod
2+
kind: Service
3+
metadata:
4+
name: crdb-geo-tourist-lb
5+
spec:
6+
selector:
7+
app: crdb-geo-tourist
8+
ports:
9+
- protocol: "TCP"
10+
port: 80
11+
targetPort: 18080
12+
type: LoadBalancer
13+
14+
---
15+
apiVersion: apps/v1
16+
kind: Deployment
317
metadata:
418
name: crdb-geo-tourist
519
spec:
6-
containers:
7-
- name: crdb-geo
8-
image: mgoddard/crdb-geo-tourist:1.0
9-
imagePullPolicy: Always
10-
env:
11-
- name: PGHOST
12-
value: ""
13-
- name: PGPORT
14-
value: "26257"
15-
- name: PGDATABASE
16-
value: "defaultdb"
17-
- name: PGUSER
18-
value: "root"
19-
- name: PGPASSWORD
20-
value: ""
21-
- name: MAPBOX_TOKEN
22-
value: "INSERT YOUR MAPBOX TOKEN VALUE HERE"
23-
- name: USE_GEOHASH
24-
value: "False"
25-
restartPolicy: Always
20+
selector:
21+
matchLabels:
22+
app: crdb-geo-tourist
23+
replicas: 2
24+
template:
25+
metadata:
26+
labels:
27+
app: crdb-geo-tourist
28+
spec:
29+
containers:
30+
- name: crdb-geo-tourist
31+
image: mgoddard/crdb-geo-tourist:1.0
32+
imagePullPolicy: Always
33+
ports:
34+
- containerPort: 18080
35+
restartPolicy: Always
36+
env:
37+
- name: PGHOST
38+
value: "cockroachdb-public"
39+
- name: PGPORT
40+
value: "26257"
41+
- name: PGDATABASE
42+
value: "defaultdb"
43+
- name: PGUSER
44+
value: "root"
45+
- name: PGPASSWORD
46+
value: ""
47+
- name: MAPBOX_TOKEN
48+
value: "INSERT YOUR MAPBOX TOKEN VALUE HERE"
49+
- name: USE_GEOHASH
50+
value: "False"
2651

data-loader.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: crdb-geo-loader
5+
spec:
6+
containers:
7+
- name: crdb-geo-loader
8+
image: mgoddard/crdb-geo-tourist:1.0
9+
imagePullPolicy: Always
10+
env:
11+
- name: PGHOST
12+
value: "cockroachdb-public"
13+
- name: PGPORT
14+
value: "26257"
15+
- name: PGDATABASE
16+
value: "defaultdb"
17+
- name: PGUSER
18+
value: "root"
19+
- name: PGPASSWORD
20+
value: ""
21+
- name: DATA_URL
22+
value: "https://storage.googleapis.com/crl-goddard-gis/osm_1m_eu.txt.gz"
23+
command: ["/bin/bash", "-c"]
24+
args: ["curl -s -k ${DATA_URL} | gunzip - | ./load_osm_stdin.py"]
25+
restartPolicy: Never
26+

deploy_k8s.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# 2 vCPU, 8 GB RAM, $0.075462/hour
4+
MACHINETYPE="e2-standard-2"
5+
NAME="${USER}-geo-tourist"
6+
ZONE="us-east4-b"
7+
8+
# Create the GKE K8s cluster
9+
gcloud container clusters create $NAME --zone=$ZONE --machine-type=$MACHINETYPE --num-nodes=4
10+
11+
ACCOUNT=$( gcloud info | perl -ne 'print "$1\n" if /^Account: \[([^@]+@[^\]]+)\]$/' )
12+
13+
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=$ACCOUNT
14+
15+
# Create the CockroachDB cluster
16+
YAML="https://raw.githubusercontent.com/cockroachdb/cockroach/master/cloud/kubernetes/cockroachdb-statefulset.yaml"
17+
kubectl apply -f $YAML
18+
19+
# Initialize DB / cluster
20+
YAML="https://raw.githubusercontent.com/cockroachdb/cockroach/master/cloud/kubernetes/cluster-init.yaml"
21+
kubectl apply -f $YAML
22+
23+
# Create table, index, and load data
24+
YAML="./data-loader.yaml"
25+
kubectl apply -f $YAML
26+
27+
# Start the Web UI
28+
YAML="./crdb-geo-tourist.yaml"
29+
kubectl apply -f $YAML
30+

0 commit comments

Comments
 (0)