Skip to content

Instantly share code, notes, and snippets.

@Subv
Last active May 31, 2018 14:21
Show Gist options
  • Save Subv/e2ce843221b15ea4050e827316aa70ef to your computer and use it in GitHub Desktop.
Save Subv/e2ce843221b15ea4050e827316aa70ef to your computer and use it in GitHub Desktop.
Kubernetes Master node installer script.
#!/bin/bash
# First, install Docker.
echo "Adding Docker APT repository"
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
sudo apt-get update
echo "Installing Docker from the official repository"
sudo apt-get install -y docker-ce
# Next, install Kubelet, Kubeadm and Kubernetes-cni
echo "Adding Kubernetes repositories"
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
echo "Installing kubelet, kubeadm and kubernetes-cni"
sudo apt-get install -y kubelet kubeadm kubernetes-cni
# Disable the swap partition, note that this is not permanent.
# For a permanent solution, comment out the swap line in /etc/fstab
echo "Disabling swap partition. THIS IS NOT PERMANENT."
echo "Swap will have to be disabled each time the system is restarted."
echo "For a permanent solution, comment out the swap line in /etc/fstab"
sudo swapoff -a
# Create the kubernetes cluster
echo "Creating kubernetes cluster on network 10.244.0.0/16"
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
echo "Copying kubernetes configuration file to user folder"
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
echo "Installing network administration interface (Canal)"
kubectl apply -f https://raw.githubusercontent.com/projectcalico/canal/master/k8s-install/1.7/rbac.yaml
kubectl apply -f https://raw.githubusercontent.com/projectcalico/canal/master/k8s-install/1.7/canal.yaml
echo "Allowing master node to run tasks"
kubectl taint nodes --all node-role.kubernetes.io/master-
echo "Installing control interface dependencies"
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential
# We have a dependency on libpng-dev for one of the control interface's dependencies
sudo apt-get install -y libpng-dev
sudo npm install -g bower
# MongoDB is required for the control interface to work
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org
echo "Starting MongoDB"
sudo service mongod start
echo "Installing deployment control interface"
mkdir -p $HOME/kubernetes-control
cd $HOME/kubernetes-control
git clone https://github.com/Subv/kubernetes-cluster-control.git .
npm install
echo "Installing nginx"
sudo apt-get install -y nginx
# Remove the default configuration.
sudo rm /etc/nginx/sites-enabled/default
# Create a folder to store each new subdomain created by the management application
sudo mkdir -p /etc/nginx/sites-available/kubecluster-domains
sudo rm -f /etc/nginx/sites-enabled/kubecluster.conf
sudo cp kubecluster.conf /etc/nginx/sites-enabled/kubecluster.conf
# We don't have to modify the /etc/hosts file because we use http://lvh.me, it's a nice domain that redirects to 127.0.0.1
sudo nginx -s reload
echo "OK - The current system is now a Kubernetes master node."
server {
listen 80 default_server;
server_name lvh.me;
location / {
proxy_pass http://127.0.0.1:3000/;
}
}
# Include the config file for all subdomains of the application
include /etc/nginx/sites-available/kubecluster-domains/*.conf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment