Skip to content

Instantly share code, notes, and snippets.

@spareslant
Created December 26, 2020 23:31
Show Gist options
  • Save spareslant/d9f17c5c3bde9b8ba820914481fdf9f1 to your computer and use it in GitHub Desktop.
Save spareslant/d9f17c5c3bde9b8ba820914481fdf9f1 to your computer and use it in GitHub Desktop.
k8s multinode cluster Vagrantfile file
all_hosts = [
{
vagrant_hostname: "master",
full_hostname: "amachine.virtual.machine",
vmbox: "fedora/31-cloud-base",
vmbox_version: "31.20191023.0",
ip: "10.0.0.10",
memory: 2048,
cpus: 1
},
{
vagrant_hostname: "worker1",
full_hostname: "another.virtual.machine",
vmbox: "fedora/31-cloud-base",
vmbox_version: "31.20191023.0",
ip: "10.0.0.12",
memory: 2048,
cpus: 1
},
]
# individual machine names must be mentioned is below command line in
# order to bring machines. (due to autostart: false)
# vagrant up amachine anotherMachine
Vagrant.configure("2") do |config|
#config.vm.box = "fedora/31-cloud-base"
#config.vm.box_version = "31.20191023.0"
all_hosts.each do |host|
config.vm.define host[:vagrant_hostname], autostart: false do |this_host|
this_host.vm.network :private_network, ip: host[:ip]
this_host.vm.hostname = host[:full_hostname]
this_host.vm.box = host[:vmbox]
this_host.vm.box_version = host[:vmbox_version]
this_host.vm.provider "virtualbox" do |m|
m.memory = host[:memory]
m.cpus = host[:cpus]
end
end
end
# config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.provision :shell, privileged: true, inline: $install_docker
config.vm.provision :shell, privileged: true, inline: $install_k8s
end
$install_docker = <<-DOCKER
echo "=====================Installing Docker ========================="
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io
dnf -y install grubby
grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
systemctl start docker
systemctl enable docker
DOCKER
$install_k8s = <<-K8S
echo "=====================Installing K8S ========================="
update-alternatives --set iptables /usr/sbin/iptables-legacy
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
# Set SELinux in permissive mode (effectively disabling it)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet
K8S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment