Skip to content

Instantly share code, notes, and snippets.

@vyta
Last active February 5, 2020 23:35
Show Gist options
  • Save vyta/de4d09393efebc2b70afe211641e4515 to your computer and use it in GitHub Desktop.
Save vyta/de4d09393efebc2b70afe211641e4515 to your computer and use it in GitHub Desktop.
Script to install docker and create kind cluster
#!/bin/bash
# The MIT License (MIT)
#
# Copyright (c) 2015 Microsoft Azure
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
while getopts c:e: option; do
case "${option}" in
c) CONFIG=${OPTARG};;
e) EXPOSE=${OPTARG};;
esac
done
echo "Installing Docker prereqs..."
apt-get update -y && apt-get upgrade -y
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
echo "Installing Docker..."
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io jq
if [ $? == 0 ];
then
echo "Docker install complete"
else
echo "Docker install failed."
exit 1
fi
echo "Installing kubectl..."
curl -s -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
mv ./kubectl /bin/kubectl
echo "Getting kind..."
curl -s -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(uname)-amd64
chmod +x ./kind
mv ./kind /bin/kind
kindConfig=${CONFIG:-'https://gist.githubusercontent.com/vyta/970caa97401fdc6fb8fdd3b3da6778e9/raw/bd213c9c8036f01cddea2bc256e93462a95dda9f/1-worker.yaml'}
curl -s -Lo ./kind-config $kindConfig
if [[ $EXPOSE -eq "true" ]];
then
kindConfig='https://gist.githubusercontent.com/vyta/bdc99acec88abdea7d91204622752b70/raw/f1e3612667fb1c82b84430252c38d75688e084fe/2-worker-public.yaml'
curl -Lo ./kind-config $kindConfig
PUBLIC_IP=$(curl -s -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2019-08-15" | jq -r '.network.interface[0].ipv4.ipAddress[0].publicIpAddress')
sed -i -e 's PUBLIC_IP '${PUBLIC_IP}' g' ./kind-config
fi
echo "Using config at $kindConfig"
kind create cluster --name kind-cluster --config ./kind-config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment