Skip to content

Instantly share code, notes, and snippets.

@nrb
Last active September 20, 2018 18:30
Show Gist options
  • Save nrb/a47dbc56a69d27e196c847901bba7127 to your computer and use it in GitHub Desktop.
Save nrb/a47dbc56a69d27e196c847901bba7127 to your computer and use it in GitHub Desktop.
A helper scrip to spin up GKE clusters
#!/usr/bin/env sh
# This script lives in ~/bin
# It mostly automates the instructions found on https://heptio.github.io/ark/v0.9.0/gcp-config, except that creating the bucket and service account has already been done.
# Source the variables since they're private information
# Defines $PROJECT, $CREDS_FILE, $SERVICE_ACCOUNT_EMAIL, and $BUCKET.
source ~/bin/gke-vars.sh
# Spin up a GKE cluster and get the credentials for kubeconfig
gcloud container clusters create cluster-1 --cluster-version=1.10.7 --disk-size=30 --enable-autorepair --preemptible --no-enable-cloud-logging --no-enable-cloud-monitoring && gcloud container clusters get-credentials cluster-1 --zone us-east4-b --project $PROJECT
# Create a new credentials file if one isn't found.
if [[ ! -f $CREDS_FILE ]]; then
gcloud iam service-accounts keys create $CREDS_FILE --iam-account $SERVICE_ACCOUNT_EMAIL
fi
kubectl apply -f examples/common/00-prereqs.yaml
kubectl create secret generic cloud-credentials --namespace $NAMESPACE --from-file cloud=$CREDS_FILE
# TODO: update with BackupStorageLocation
cat examples/gcp/00-ark-config.yaml | sed "s/<YOUR_BUCKET>/$BUCKET/" | kubectl apply -f -
# Only apply the deployment file if -d switch is provided. Otherwise, we'll run Ark locally.
if [[ "$1" == "-d" ]]; then
kubectl apply -f examples/gcp/10-deployment.yaml
kubectl apply -f examples/gcp/20-restic-daemonset.yaml
fi
cat examples/nginx-app/with-pv.yaml | sed "s/<YOUR_STORAGE_CLASS_NAME>/standard/" | kubectl apply -f -
# When done, I delete the cluster with:
# gcloud container clusters delete cluster-1 --async
# --async can be left off if you want to wait for the cluster to teardown.
# TODO: Script to gather all snapshots and delete them, since those can add up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment