Kubernetes Cluster Using the Vagrant File
Kubernetes using the Vagrant File
What is a Vagrant File?
A vagrant file is the declarative configuration file that describes all your software requirements, packages, operating system configuration, users, and more.
As we know Vagrant file is the declarative means just instructions in the files which are performed for the aimed task
In the installation of K8S we need
We need some tools like
Vagrant installation on the system I’m using the Windows os here in this Vagrant is available for Linux and Mac OS vagrant Download it and install it on your os
another program oracle VirtualBox which is free and Opensource & a Code Editor i use the VS code
The Vagrant file is Declarative we are installing the Ubuntu Nodes (3) Cluster Username and Password is here kubeadmin\kubeadmin
Vagrant file must be saved as simple as “vagrantfile”
Vagrant File
# -*- mode: ruby -*-
# vi: set ft=ruby :
ENV['VAGRANT_NO_PARALLEL'] = 'yes'
Vagrant.configure(2) do |config|
config.vm.provision "shell", path: "bootstrap.sh"
NodeCount = 3 #<----Number of nodes
(1..NodeCount).each do |i|
config.vm.define "node#{i}" do |node|
node.vm.box = "generic/ubuntu2004"
node.vm.hostname = "node#{i}.example.com"
node.vm.network "private_network", ip: "172.16.16.10#{i}"
node.vm.provider "virtualbox" do |v|
v.name = "node#{i}"
v.memory = 2048
v.cpus = 2
end
end
end
end
Bootstrap file is used to make Pre configurations for all the Three Nodes
Bootstrap.sh
#!/bin/bash
# Enable ssh password authentication
echo "Enable ssh password authentication"
sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed -i 's/.*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl reload sshd
# Set Root password
echo "Set root password"
echo -e "kubeadmin\nkubeadmin" | passwd root >/dev/null 2>&1
# Update bashrc file
echo "export TERM=xterm" >> /etc/bashrc