Skip to content

Instantly share code, notes, and snippets.

@mcwienczek
Created May 21, 2017 09:12
Show Gist options
  • Save mcwienczek/af81401aa9af3ce68c26203170a9fb30 to your computer and use it in GitHub Desktop.
Save mcwienczek/af81401aa9af3ce68c26203170a9fb30 to your computer and use it in GitHub Desktop.
Setup a CoreOS cluster with fleet and etcd on Google Compute Engine.

Setup a CoreOS cluster on GCE

Setup a CoreOS cluster with fleet and etcd on Google Compute Engine.

  • Install gcutil and authorize it
  • Make sure your Google Cloud project has billing information
  • bash coreos-cluster-for-gce.sh {your project name}

Check the source of the script to see what actually happens.

The script uses https://discovery.etcd.io for cluster discovery.

#!/bin/bash
#pass the Google Compute Engine Project as parameter
ETCD_DISCOVERY_URL=$(curl https://discovery.etcd.io/new)
gcutil --project=$1 \
addimage \
--description="CoreOS 247.0.0" \
coreos-production-v247-0-0 \
gs://storage.core-os.net/coreos/amd64-generic/247.0.0/coreos_production_gce.tar.gz
for NODE in node1 node2 node3
do
gcutil --project=$1 \
addinstance $NODE \
--image=coreos-production-v247-0-0 \
--persistent_boot_disk \
--zone=europe-west1-a \
--machine_type=f1-micro \
--metadata=startup-script:"#!/bin/sh
ETCD_DISCOVERY_URL=$ETCD_DISCOVERY_URL
HOSTNAME=\$(curl http://metadata/0.1/meta-data/hostname)
IPADDR=\$(ifconfig eth0| grep 'inet ' | cut -dt -f2 | awk '{ print \$1}')
sudo systemctl start fleet
etcd -name \$HOSTNAME -peer-addr \$IPADDR:7001 -addr \$IPADDR:4001 -discovery \$ETCD_DISCOVERY_URL
"
gcutil --project=$1 ssh --ssh_user=core $NODE "curl http://metadata/0.1/meta-data/attributes/startup-script | bash"
done
echo ""
echo "The etcd discovery url is: $ETCD_DISCOVERY_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment