|
# -*- mode: ruby -*- |
|
# vi: set ft=ruby : |
|
|
|
# This script to install Kubernetes will get executed after we have provisioned the box |
|
$script = <<-SCRIPT |
|
# Install kubernetes |
|
apt-get update && apt-get install -y apt-transport-https |
|
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - |
|
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list |
|
deb http://apt.kubernetes.io/ kubernetes-xenial main |
|
EOF |
|
apt-get update |
|
apt-get install -y kubelet kubeadm kubectl |
|
# kubelet requires swap off |
|
swapoff -a |
|
# keep swap off after reboot |
|
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab |
|
# Get the IP address that VirtualBox has given this VM |
|
IPADDR=`ip -4 address show dev eth1 | grep inet | awk '{print $2}' | cut -f1 -d/` |
|
echo This VM has IP address $IPADDR |
|
# Writing the IP address to a file in the shared folder |
|
echo $IPADDR > /vagrant/ip-address.txt |
|
# Set up Kubernetes |
|
NODENAME=$(hostname -s) |
|
kubeadm init --apiserver-cert-extra-sans=$IPADDR --node-name $NODENAME |
|
# Set up admin creds for the vagrant user |
|
echo Copying credentials to /home/vagrant... |
|
sudo --user=vagrant mkdir -p /home/vagrant/.kube |
|
cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config |
|
chown $(id -u vagrant):$(id -g vagrant) /home/vagrant/.kube/config |
|
SCRIPT |
|
|
|
Vagrant.configure("2") do |config| |
|
config.vm.define :k8s1 do |k8s1| |
|
k8s1.vm.provider "virtualbox" do |v| |
|
v.memory = 16384 |
|
v.cpus = 2 |
|
end |
|
# Specify your hostname if you like |
|
# k8s1.vm.hostname = "k8s1" |
|
k8s1.vm.box = "bento/ubuntu-20.04" |
|
k8s1.vm.provision "shell", inline: "swapoff -a" |
|
k8s1.vm.network "private_network", type: "dhcp" |
|
# k8s1.vm.network "forwarded_port", guest: 10102, host: 10102, autocorrect: true |
|
k8s1.vm.provision "docker" |
|
# Specify the shared folder mounted from the host if you like |
|
# By default you get "." synced as "/vagrant" |
|
# k8s1.vm.synced_folder ".", "/folder" |
|
k8s1.vm.provision "shell", inline: $script |
|
end |
|
|
|
config.vm.define :k8s2 do |k8s2| |
|
k8s2.vm.provider "virtualbox" do |v| |
|
v.memory = 16384 |
|
v.cpus = 2 |
|
end |
|
# Specify your hostname if you like |
|
# k8s2.vm.hostname = "k8s2" |
|
k8s2.vm.box = "bento/ubuntu-20.04" |
|
k8s2.vm.provision "shell", inline: "swapoff -a" |
|
k8s2.vm.network "private_network", type: "dhcp" |
|
# k8s2.vm.network "forwarded_port", guest: 10102, host: 10102, autocorrect: true |
|
k8s2.vm.provision "docker" |
|
# Specify the shared folder mounted from the host if you like |
|
# By default you get "." synced as "/vagrant" |
|
# k8s2.vm.synced_folder ".", "/folder" |
|
k8s2.vm.provision "shell", inline: $script |
|
end |
|
|
|
end |