DevOps Tools

Comprehensive Guide to Setting Up a Kubernetes Cluster with kubeadm on VirtualBox for Windows 10 Pro

In this guide, we will set up a Kubernetes cluster using VirtualBox on a Windows 10 Pro system. The cluster will consist of one master node and two worker nodes, all running Ubuntu 18.04. This setup will allow IT professionals to gain hands-on experience with Kubernetes and kubeadm.

Prerequisites

  • Windows 10 Pro
  • VirtualBox installed (with Extension Pack)
  • Ubuntu 18.04 ISO

VirtualBox Configuration

Create Virtual Machines

  1. Create three virtual machines (VMs) in VirtualBox:
  • Machine 1: master
  • Machine 2: node1
  • Machine 3: node2
  1. Configure each VM:
  • Memory: At least 2GB
  • CPU: At least 2 CPUs
  • Network:
    • Adapter 1: Bridged Adapter
    • Adapter 2: Host-Only Adapter (create a Host-Only Network if one doesn’t exist)

VM Network Configuration

Each VM must have a unique MAC address, hostname, and static IP address on the Host-Only network.

  • master:
  • Hostname: master
  • IP Address: 192.100.100.2
  • node1:
  • Hostname: node1
  • IP Address: 192.100.100.3
  • node2:
  • Hostname: node2
  • IP Address: 192.100.100.4

Ubuntu Configuration

Common Steps for All Nodes

  1. Update and install essential packages:
   sudo apt-get update
   sudo apt-get install -y curl vim openssh-server net-tools iptables arptables ebtables
  1. Configure hostname:
   sudo vim /etc/hostname

Set the hostname to master, node1, or node2 accordingly.

  1. Configure hosts file:
   sudo vim /etc/hosts

Add the following entry:

   127.0.0.1 <hostname>
  1. Check SSH service:
   sudo service ssh status
  1. Configure network interfaces:
   ifconfig enp0s8 <node-specific-ip>
   vim /etc/network/interfaces

Add/update:

   auto enp0s8
   iface enp0s8 inet static
       address <node-specific-ip>
       netmask 255.255.255.0
  1. Disable swap:
   sudo swapoff -a
   sudo vim /etc/fstab

Comment out the swap line.

  1. Install Docker:
   sudo apt-get install -y docker.io
  1. Install Kubernetes components:
   sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
   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 kubeadm kubectl
   sudo apt-mark hold kubelet kubeadm kubectl

Master Node Configuration

  1. Initialize Kubernetes on the master node:
   sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.100.100.2
  1. Set up kubectl for the regular user:
   mkdir -p $HOME/.kube
   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
   sudo chown $(id -u):$(id -g) $HOME/.kube/config
  1. Install a pod network add-on (Flannel):
   kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Worker Node Configuration

Join Nodes to the Cluster

  1. Get the join command from the master node:
   kubeadm token create --print-join-command

This command outputs something like:

   kubeadm join 192.100.100.2:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
  1. Run the join command on node1 and node2:
   sudo kubeadm join 192.100.100.2:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>

Verification

  1. Check the status of nodes from the master node:
   kubectl get nodes

This command should list all three nodes (master, node1, and node2) as Ready.

Conclusion

By following these steps, you have set up a basic Kubernetes cluster using VirtualBox on a Windows 10 Pro system with one master node and two worker nodes. This setup is ideal for learning and experimenting with Kubernetes in a controlled environment.

Ali Imran
Over the past 20+ years, I have been working as a software engineer, architect, and programmer, creating, designing, and programming various applications. My main focus has always been to achieve business goals and transform business ideas into digital reality. I have successfully solved numerous business problems and increased productivity for small businesses as well as enterprise corporations through the solutions that I created. My strong technical background and ability to work effectively in team environments make me a valuable asset to any organization.
https://ITsAli.com

Leave a Reply