N_NODES=2
ENV["LC_ALL"] = "en_US.UTF-8"
ID = "#{rand(01..99)}"
$script = <<-SCRIPT
apt update
# Disable swap
#/etc/fstab /etc/fstab-BKP
#swapoff -a
#sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# Install Docker
sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get -y install docker-ce=18.06.2~ce~3-0~ubuntu
# Install kubeadm
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
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 kubelet=1.13.12-00 kubeadm=1.13.12-00 kubectl=1.13.12-00
sudo apt-mark hold kubelet kubeadm kubectl
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.provision "shell", inline: $script
#config.ssh.private_key_path = '~/.ssh/id_rsa'
#config.ssh.password = "123456"
config.vm.network "public_network", type: "dhcp", bridge: "wlp2s0"
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--cpus", 2]
end
(1..N_NODES).each do |i|
config.vm.define "node#{i}" do |subconfig|
subconfig.vm.hostname = "node#{i}"
#subconfig.vm.network :private_network, ip: "10.0.2.#{10 + i}"
#subconfig.vm.network "forwarded_port", guest: 22, host: "#{2220 + i}", host_ip: "127.0.0.1", auto_correct: true
#subconfig.vm.network "forwarded_port", guest: 22, host: "#{2230 + i}", host_ip: "192.168.0.102", auto_correct: true
end
end
end
# Get all IPs
EXTRA=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | paste -s -d ",")
kubeadm init \
--service-cidr=10.10.0.0/24 \
--pod-network-cidr=10.20.0.0/24 \
--apiserver-advertise-address=PUT.YOUR.VM.IP.HERE \
--apiserver-cert-extra-sans="$EXTRA"
# Deploy CNI
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')&env.IPALLOC_RANGE=10.20.0.0/24"
Create Kubelet extra args.
KUBELET_EXTRA_ARGS=--node-ip=PUT.YOUR.NODE.IP.HERE
Run the join command using your master node IP.
After deploying Weave, your worker node might be "NotReady" and the docker container k8s_weave_weave-net might log the error above.
ip route add 10.96.0.1/32 dev eth1 src 192.168.0.126
Where 192.168.0.126 is the IP of your Node.