There are many options to provision a local Kubernetes cluster on your laptop. The most popular ones are minikube, kind, K3s and MicroK8s. These options provide a simple and fast way to get Kubernetes running on your laptop by abstracting the complexities within the Kubernetes control plane.
Kubeadm is a tool that facilitates provisioning Kubernetes clusters on virtual machines. It can provision a multi-node Kubernetes cluster for development or production purposes. It can provision clusters on your local laptop, on-premise cloud or public cloud. A cluster provisioned by kubeadm is a great way for Kubernetes administrators to have a playground to work with. It is also useful for people pursuing the CKA and CKS certifications to practice tasks like cluster upgrade and troubleshooting.
VirtualBox is by far the most popular tool to spin up virtual machines (VMs) on a personal laptop. VirtualBox supports virtualization for x86 and AMD64 CPU architectures.
In 2020, Apple introduced the M series of MacBooks which use the Apple Silicon chip, based on ARM64 CPU architecture. VirtualBox does not have good support for machines based on ARM64 (a developer preview version exists, which cannot be relied on). As the M series MacBooks have gained popularity, it is important to look for an alternative virtualization tool that is tested and certified for ARM64. Enter Multipass by Canonical, a simple virtualization tool that is fully compatible with ARM64 based machines.
This article is a step-by-step walkthrough on how to install a Kubernetes cluster on a MacBook (M series) laptop using the kubeadm tool. It is a simplification of the steps in the official Kubernetes documentation.
A MacBook laptop (M series) with minimum 16 GB RAM (recommended).
Multipass by Canonical should be installed as per the instructions for macOS. After installation, verify that you are able to launch a sample Ubuntu instance. Cleanup the instance after verification.
Your account on your MacBook must have admin privileges and be able to use sudo.
The macaddress field should contain the exact MAC address chosen in the multipass launch command.
The addresses field should contain the static IP address that will be allocated to this VM. The static IP address should be in the same subnet as the original IP address of the instance.
The original IP address allocated to the VM can be found by the multipass info kubemaster command as shown below:
multipass info kubemaster | grep IPv4
You should see an output similar to:
IPv4: 192.168.73.7
In this example, the original IP address of the instance is 192.168.73.7. So the static IP address can be chosen as 192.168.73.101
You should see an output displaying both the original IP address and the static IP address:
IPv4: 192.168.73.7 192.168.73.101
Let's test the network connectivity using the ping command:
Example:
Original IP of the instance: 192.168.73.7
Static IP of the instance: 192.168.73.101
IP of the host laptop: 192.168.0.2
All the commands below should return a successful output:
# Ping from local to the original IP address of kubemasterping 192.168.73.7# Ping from local to the static IP address of kubemasterping 192.168.73.101# Ping from kubemaster to localmultipass exec -n kubemaster -- ping 192.168.0.2
Provisioning the first worker node (kubeworker01) #
Launch thekubeworker01 instance with a manual network
Test using ping similar to the steps followed for kubemaster.
Additionally, test that ping from kubemaster to kubeworker01 and vice versa is working.
# Ping from local to the original IP address of kubeworker01ping 192.168.73.8# Ping from local to the static IP address of kubeworker01ping 192.168.73.102# Ping from kubeworker01 to localmultipass exec -n kubeworker01 -- ping 192.168.0.2# Ping from kubeworker01 to kubemastermultipass exec -n kubeworker01 -- ping 192.168.73.101# Ping from kubemaster to kubeworker01multipass exec -n kubemaster -- ping 192.168.73.102
Provisioning the second worker node (kubeworker02) #
Launch thekubeworker02 instance with a manual network
Test using ping similar to the steps followed for kubemaster.
Additionally, test that all 3 VMs are able to ping each other successfully through their static IPs.
# Ping from local to the original IP address of kubeworker02ping 192.168.73.9# Ping from local to the static IP address of kubeworker02ping 192.168.73.103# Ping from kubeworker02 to localmultipass exec -n kubeworker02 -- ping 192.168.0.2# Ping from kubeworker02 to kubemastermultipass exec -n kubeworker02 -- ping 192.168.73.101# Ping from kubeworker02 to kubeworker01multipass exec -n kubeworker02 -- ping 192.168.73.102# Ping from kubemaster to kubeworker02multipass exec -n kubemaster -- ping 192.168.73.103# Ping from kubeworker01 to kubeworker02multipass exec -n kubeworker01 -- ping 192.168.73.103
Forwarding IPv4 and letting iptables see bridged traffic #
Execute the below set of commands onkubemaster, kubeworker01 and kubeworker02
cat <<EOF | sudo tee /etc/modules-load.d/k8s.confoverlaybr_netfilterEOFsudo modprobe overlaysudo modprobe br_netfilter# sysctl params required by setup, params persist across rebootscat <<EOF | sudo tee /etc/sysctl.d/k8s.confnet.bridge.bridge-nf-call-iptables = 1net.bridge.bridge-nf-call-ip6tables = 1net.ipv4.ip_forward = 1EOF# Apply sysctl params without rebootsudo sysctl --system# Verify that the br_netfilter, overlay modules are loaded by running the following commands:lsmod | grep br_netfilterlsmod | grep overlay#Verify that the net.bridge.bridge-nf-call-iptables, net.bridge.bridge-nf-call-ip6tables, and net.ipv4.ip_forward system variables are set to 1 in your sysctl config by running the following command:sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables net.ipv4.ip_forward
Verify that the net.bridge.bridge-nf-call-iptables, net.bridge.bridge-nf-call-ip6tables, and net.ipv4.ip_forward system variables are set to 1 in your sysctl config.
You must deploy a Container Network Interface (CNI) based Pod network add-on so that your Pods can communicate with each other. Cluster DNS (CoreDNS) will not start up before a network is installed.
A list of all compatible Pod network add-ons can be found here.
Validate that the Kubernetes setup is working correctly by deploying a nginx pod on the cluster.
Execute the below command onkubemaster
kubectl run test-nginx --image=nginx
kubectl get pod test-nginx
NAME READY STATUS RESTARTS AGEtest-nginx 1/1 Running 0 47s
Once the pod is in a Ready state, then it's time to say Congratulations! You've just built a fully functioning 3 node Kubernetes cluster on a M series MacBook.
Multipass offers an easy and effective way to take a backup of the controlplane and worker nodes. Using this backup, a corrupt Kubernetes cluster can be restored to a previous working state.
With a background in computer science and nearly two decades of experience in the industry, Aditya is enthusiastic about solving complex problems and staying up-to-date with the latest technologies.
He has achieved the CKAD, CKA, CKS certifications in Kubernetes along with the AWS CLF-C02 and SAA-C03 certifications.
He loves to share his knowledge through blogs, articles, videos and courses.
He thrives on challenges and enjoys exploring new opportunities in the world of microservices and cloud-native technologies, with a particular emphasis on Kubernetes.
Aditya is a member of the Kubernetes GitHub organization and actively contributes to the documentation for Kubernetes.