Friday, August 13, 2021

Kubernetes Cluster - Using Vagrant


Installing Kubernetes Cluster (1 Master and 2 Worker Nodes) using Vagrant

 (Kubeadm installation)

Pod Network:- Calico
Container Runtime: containerd

  • Step 1:- Download Virtual Box and install it on your OS
  • Step 2:- Download Vagrant and Install it (It needs to ask for restart).
  • Step 3:- Download Git and Install it.
  • Step 4:- Clone the git repo using the command
    git clone
  • Step 5:- Once Step 4 is executed successfully then you will get one folder k8s in the current directory
  • Under k8s there is one more folder K8s-Vagrant
  •  Change directory K8s-Vagrant/ on the command terminal
  • Step 6:- Install some vagrant plugins by running the below command
    vagrant plugin install vagrant-vbguest
  • Step 7:- Run the below command to create Kubernetes Cluster (It will take around 10-15 mins)
    vagrant up
  • If you get any error in Step 7 then you can run the command for each node seprately like
        vagrant up kmaster
        vagrant up kworker1
        vagrant up kworker2
  • Step 8:- Connect to the Master server
    vagrant ssh kmaster
  1.   mkdir -p $HOME/.kube
  2.   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  3.   sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Run the below command to check all nodes are in cluster and in ready state
       kubectl get nodes
    Note:- If it shows only master node or it shows the master and worker nodes but worker nodes are not in the ready state then run below command on the master node to print the token.
          cat /
Copy the join command and run it on worker1 and worker2
  • Step 9:- Verify the cluster is in ready state
    kubectl get nodes


Unknown said...

hi raman
how to go into the worker node
if i do ssh kworker1 it is asking password and we dont have password

KubectlgetName said...

Please run these command if you want run cluster from local machine

mkdir -p $HOME/.kube
cp configs/config $HOME/.kube

Please confirm Raman sir ?

KubectlgetName said...

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

Krunal said...

root@ubuntu2004:/home/vagrant# kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?
root@ubuntu2004:/home/vagrant# mkdir -p $HOME/.kube
root@ubuntu2004:/home/vagrant# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

cp: cannot stat '/etc/kubernetes/admin.conf': No such file or directory

Got above error while copying admin.conf file , kubernetes folder is not available in Master.
Kindly help here .

Post a Comment