Skip to content

Instantly share code, notes, and snippets.

@nirbhabbarat
Created July 20, 2020 13:35
Show Gist options
  • Save nirbhabbarat/2bf028399610c1b24209eed169dd08e6 to your computer and use it in GitHub Desktop.
Save nirbhabbarat/2bf028399610c1b24209eed169dd08e6 to your computer and use it in GitHub Desktop.
Vagrant file to install 1 master and 1 node in local (node will not join) as its for dev env for CKAD learning. Check kubeadm_init.log for join command in master.
Vagrant.configure("2") do |config|
config.vm.provision :shell, privileged: true, inline: $install_common_tools
config.vm.define :master do |master|
master.vm.provider :virtualbox do |vb|
vb.name = "master"
vb.memory = 4048
vb.cpus = 2
end
master.vm.box = "ubuntu/bionic64"
#master.disksize.size = "25GB"
master.vm.hostname = "master"
master.vm.network :private_network, ip: "10.0.0.10"
master.vm.provision :shell, privileged: false, inline: $kube_install
end
%w{node1}.each_with_index do |name, i|
config.vm.define name do |node|
node.vm.provider "virtualbox" do |vb|
vb.name = "node#{i + 1}"
vb.memory = 4048
vb.cpus = 2
end
node.vm.box = "ubuntu/bionic64"
#node.disksize.size = "25GB"
node.vm.hostname = name
node.vm.network :private_network, ip: "10.0.0.#{i + 11}"
end
end
end
$kube_install = <<-SCRIPT
sudo kubeadm init --apiserver-advertise-address=10.0.0.10 --pod-network-cidr=10.244.0.0/16 >> kubeadm_init.log
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
SCRIPT
$install_common_tools = <<-SCRIPT
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 \
$(lsb_release -cs) \
stable"
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y docker-ce kubelet kubeadm kubectl
echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
echo "1" > /proc/sys/net/ipv4/ip_forward
mkdir -p $HOME/.kube
sudo systemctl enable docker
sudo systemctl start docker
SCRIPT
@nirbhabbarat
Copy link
Author

nirbhabbarat commented Jul 20, 2020

DevOps quick guide

When preparing for CKAD/CKA you tend to create cluster multiple times and delete as well. This helps do the bare minimal setup of k8s master and node to begin practicing.

Start VMs

vagrant up

SSH VMs

vagrant ssh master
vagrant ssh node1

Add node1 to the local cluster

vagrant ssh master
tail kubeadm_init.log # this will give you Kubernetes join command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment