Cybersecurity for Everyone! Powered by NextGen AI!

Kubernetes Cluster Setup in Laptop Using VirtualBox

  • Attach NAT network to all three instances
  • Set the hostnames of VMs as following:

sudo hostnamectl set-hostname k8s-control for Master node

sudo hostnamectl set-hostname k8s-worker1 for Worker node 1

sudo hostnamectl set-hostname k8s-worker2 for Worker node 2

  • Edit /etc/hosts file to include IPs of all three nodes. For e.g. k8s-worker1 k8s-control  k8s-worker2
  • Run Following Commands in each of the nodes
cat << EOF | sudo tee /etc/modules-load.d/containerd.conf

sudo modprobe overlay
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1

sudo sysctl --system
  • Install and configure containerd on all nodes
sudo apt-get update && sudo apt-get install -y containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo systemctl restart containerd
  • Disable Swap on all three nodes
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
  • Install kubeadm, kubelet, and kubectl on all nodes
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s | sudo apt-key add -
cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb kubernetes-xenial main
sudo apt-get update
sudo apt-get install -y kubelet=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00
sudo apt-mark hold kubelet kubeadm kubectl
  • Initialize pod network, create cluster and setup Kubectl access – On the control plane (master) node only
sudo kubeadm init --pod-network-cidr --kubernetes-version 1.21.0
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
  • Install the Calico network add-on.
kubectl apply -f
  • Get the join command (this command is also printed during kubeadm init), You can copy that too.
kubeadm token create --print-join-command
  • Copy the join command from the control plane node. Run it on each worker node as root (i.e. with sudo ).
  • On the control plane (master) node, verify that all nodes in the cluster are ready. Note that it may take a few moments for all of the nodes to enter the READY state.
kubectl get nodes

CONGRATULATIONS!! You have setup the cluster successfully..

    Leave a Reply

    Harnessing Auto-GPT for Penetration Testing with OSINT Understanding Docker Through the LEGO Analogy: A Comprehensive Guide Embracing Zero Trust Architecture: The Future of Enterprise Security A Guide to Secure Online Banking and Financial Transactions 5 Best Practices for Secure Password Management