CoreOS cluster on a Mac via Vagrant

Fancy playing with CoreOS and on a Mac? It is possible

# Clone CoreOS's Vagrant repository from https://github.com/coreos/coreos-vagrant
git clone git@github.com:coreos/coreos-vagrant.git 
cd coreos-vagrant
 
# Clear out any pre-existing cluster
vagrant destroy -f
 
# Ensure the latest vagrant images are being used
vagrant box update
 
# Ensure we start 3 instances
cp config.rb.sample config.rb
sed -i '' "s/#\$num_instances=.*/\$num_instances=3/" config.rb
 
# Use alpha because the Stable fleet doesn't include Global=true
sed -i '' "s/#\$update_channel=.*/\$update_channel='alpha'/" config.rb
 
# Show the changes if necessary
#diff config.rb.sample config.rb
 
 
# Create a new etcd discovery token for this cluster
# *** Each time the cluster is fully destroyed, you need to generate a new token ***
curl https://discovery.etcd.io/new > discovery.token
cp user-data.sample user-data
sed -i '' -e "s,#discovery: https://discovery.etcd.io/<token>,discovery: $(sed 's:/:\\/:g' discovery.token)," user-data
 
# Show the changes if necessary
#diff user-data.sample user-data
 
# Ensure the SSH key is added
eval "ssh-agent"
echo $SSH_AUTH_SOCK
ssh-add ~/.vagrant.d/insecure_private_key
 
# Start the cluster
vagrant up

# Clear out any pre-existing cluster
vagrant destroy -f

# Ensure the latest vagrant images are being used
vagrant box update

# Ensure we start 3 instances
cp config.rb.sample config.rb
sed -i ” "s/#\$num_instances=.*/\$num_instances=3/" config.rb

# Use alpha because the Stable fleet doesn’t include Global=true
sed -i ” "s/#\$update_channel=.*/\$update_channel=’alpha’/" config.rb

# Show the changes if necessary
#diff config.rb.sample config.rb

# Create a new etcd discovery token for this cluster
# *** Each time the cluster is fully destroyed, you need to generate a new token ***
curl https://discovery.etcd.io/new > discovery.token
cp user-data.sample user-data
sed -i ” -e "s,#discovery: https://discovery.etcd.io/<token>,discovery: $(sed ‘s:/:\\/:g’ discovery.token)," user-data

# Show the changes if necessary
#diff user-data.sample user-data

# Ensure the SSH key is added
eval "ssh-agent"
echo $SSH_AUTH_SOCK
ssh-add ~/.vagrant.d/insecure_private_key

# Start the cluster
vagrant up

Now you can SSH to the cluster and check it all works.

# SSH to node 1
vagrant ssh core-01 -- -A
 
# Show the machines in your cluster
fleetctl list-machines
 
# Test etcd - create and retrieve a key on this host
etcdctl mk "/andrewgorton.uk/$(hostname)" "$(ifconfig enp0s8| grep 'inet' | grep -v 'inet6' | tr -s ' ' | cut -d ' ' -f 3)"
etcdctl get "/andrewgorton.uk/$(hostname)"
 
# Test etcd works across the cluster - set a key on this host
etcdctl set first-etcd-key "Hello World"
 
# Test etcd works across the cluster - get the same key from a different host
fleetctl ssh  $(fleetctl list-machines -l | tail -n +2 | awk '{ print $1 }' | grep -v "$(cat /etc/machine-id)" | head -1 ) etcdctl get first-etcd-key
 
# Check Docker runs on this host
docker run hello-world

# Show the machines in your cluster
fleetctl list-machines

# Test etcd – create and retrieve a key on this host
etcdctl mk "/andrewgorton.uk/$(hostname)" "$(ifconfig enp0s8| grep ‘inet’ | grep -v ‘inet6’ | tr -s ‘ ‘ | cut -d ‘ ‘ -f 3)"
etcdctl get "/andrewgorton.uk/$(hostname)"

# Test etcd works across the cluster – set a key on this host
etcdctl set first-etcd-key "Hello World"

# Test etcd works across the cluster – get the same key from a different host
fleetctl ssh $(fleetctl list-machines -l | tail -n +2 | awk ‘{ print $1 }’ | grep -v "$(cat /etc/machine-id)" | head -1 ) etcdctl get first-etcd-key

# Check Docker runs on this host
docker run hello-world

Simple!

This is my personal blog - all views are my own.

Tagged with: , , , , ,