Skip to content

Instantly share code, notes, and snippets.

@noelbk
Created February 23, 2018 19:33
#! /bin/bash
set -eu -o pipefail
gcloud_dir="$(dirname "$0")"
. "$gcloud_dir"/algoalpha-dev-env
echo "Setting up development cluster for $USER_NAME"
# personal persistent disk
if gcloud compute disks describe $DISK_NAME >/dev/null 2>&1; then
echo "disk $DISK_NAME already exists, reusing it"
else
echo "Creating personal persistent disk: $DISK_NAME"
gcloud compute disks create $DISK_NAME --size=200GB
fi
# personal cluster
if gcloud beta container clusters describe $CLUSTER_NAME >/dev/null 2>&1; then
echo "cluster $CLUSTER_NAME already exists, reusing it"
else
echo "Creating personal cluster: $CLUSTER_NAME"
gcloud beta container clusters create $CLUSTER_NAME \
--machine-type=n1-highmem-4 \
--min-cpu-platform="Intel Sandy Bridge" \
--num-nodes=1 \
--enable-autoscaling \
--min-nodes=1 \
--max-nodes=4 \
--disk-size=50 \
--node-labels=algoalpha=control \
--scopes=cloud-platform,cloud-source-repos-ro
fi
echo "Getting kubectl credentials for new default cluster: $CLUSTER_NAME"
gcloud container clusters get-credentials $CLUSTER_NAME
kubectl apply -f - <<EOF
# NFS server for personal development disk
---
apiVersion: v1
kind: ReplicationController
metadata:
name: algoalpha-dev-nfs
spec:
replicas: 1
selector:
app: algoalpha-dev-nfs
template:
metadata:
labels:
app: algoalpha-dev-nfs
spec:
containers:
- name: algoalpha-dev-nfs
image: k8s.gcr.io/volume-nfs:0.8
command: [ "sh", "-c", "mkdir -p /exports/algoalpha && exec /usr/local/bin/run_nfs.sh /exports /" ]
ports:
- name: nfs
containerPort: 2049
- name: mountd
containerPort: 20048
- name: rpcbind
containerPort: 111
securityContext:
privileged: true
volumeMounts:
- mountPath: /exports
name: algoalpha-dev-disk
volumes:
- name: algoalpha-dev-disk
gcePersistentDisk:
pdName: $DISK_NAME
fsType: ext4
# service IP for algoalpha-dev-nfs
---
apiVersion: v1
kind: Service
metadata:
name: algoalpha-dev-nfs
spec:
ports:
- name: nfs
port: 2049
- name: mountd
port: 20048
- name: rpcbind
port: 111
selector:
app: algoalpha-dev-nfs
EOF
kubectl apply -f - <<EOF
# algoalpha development node:
# mounts $DISK_NAME on /algoalpha
---
apiVersion: v1
kind: ReplicationController
metadata:
name: algoalpha-dev
spec:
replicas: 1
selector:
app: algoalpha-dev
template:
metadata:
labels:
app: algoalpha-dev
spec:
nodeSelector:
algoalpha: control
containers:
- name: algoalpha
image: eu.gcr.io/deltascan-algo-dev/algoalpha
command: [ "bash", "-x", "/opt/algoalpha/algoalpha/gcloud/algoalpha-dev-server-entrypoint"]
volumeMounts:
- name: algoalpha-dev-disk
mountPath: /algoalpha
- name: algoalpha-data
mountPath: /algoalpha_data
securityContext:
privileged: true
volumes:
- name: algoalpha-dev-disk
nfs:
server: $(algoalpha-dev-nfs-ip)
path: /algoalpha
- name: algoalpha-data
gcePersistentDisk:
pdName: algoalpha-data
fsType: ext4
readOnly: true
EOF
algoalpha-dev-pod-wait
"$gcloud_dir"/algoalpha-dev-creds
algoalpha-dev-exec bash -c "echo 'export USER=$USER' >> ~/.bashrc"
cat <<EOF
Your personal cluster is running in $CLUSTER_NAME using your
persistent development disk $DISK_NAME. Here are some handy commands:
Start port forwarding and ssh into your development pod:
. gcloud/algoalpha-dev-env
kubectl port-forward \$(algoalpha-dev-pod) 2222:22 &
ssh-keygen -f ~/.ssh/known_hosts -R [localhost]:2222
/algoalpha/algoalpha on the dev node is a git repo that is shared by
all minions. Your git creds are copied there, so you can commit from
the dev node directly:
ssh -p 2222 root@localhost
cd /algoalpha/algoalpha
# check out your local repo locally
git remote add $USER git@github.com:$USER/algoalpha.git
git fetch $USER
git checkout -b $USER/master
edit files
git add/commit/push
When you're ready to run on a horde of minions, first test it on the
dev node:
octave --eval polydeltaEvaluateFull
Then unleash the horde!
gcloud/algoalpha-dev-minions
When you're done, delete the whole cluster and minions. Your development disk
will be preserved and used for next time
gcloud/algoalpha-dev-delete
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment