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
- Create three virtual machines (VMs) in VirtualBox:
- Machine 1:
master
- Machine 2:
node1
- Machine 3:
node2
- 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
- Update and install essential packages:
sudo apt-get update
sudo apt-get install -y curl vim openssh-server net-tools iptables arptables ebtables
- Configure hostname:
sudo vim /etc/hostname
Set the hostname to master
, node1
, or node2
accordingly.
- Configure hosts file:
sudo vim /etc/hosts
Add the following entry:
127.0.0.1 <hostname>
- Check SSH service:
sudo service ssh status
- 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
- Disable swap:
sudo swapoff -a
sudo vim /etc/fstab
Comment out the swap line.
- Install Docker:
sudo apt-get install -y docker.io
- 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
- Initialize Kubernetes on the master node:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.100.100.2
- 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
- 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
- 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>
- Run the join command on
node1
andnode2
:
sudo kubeadm join 192.100.100.2:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Verification
- 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.