Mumshad Mannambeth ( @mmumshad ) proposes, in his Udemy CKA course, to install Kubernetes with kubeadm on local machine. As more and more Mac machines are based on M1 CPUs chips, this Gist proposes a solution to get Vagrant working on Mac M1.
Problem statement: Virtualbox is not supported at the time on M1 chips, as a result, it is not possible to train on local machine. Alternative options for virtualization on Mac are vMWare Fusion or Parallels, or you have to run the workshop on some Cloud Provider (For example: Digital Ocean, Scaleway, Vultr or OVH)
Notice: Provided instructions may not be fully exhaustive, however all required elements should be there to manage to get it work on Mac M1 ( It works on my machine ... 😅 )
I tried with success an installation based on Vagrant + VMWare Fusion: There is a VMWare Fusion Tech Preview available that you can install as a replacement of VirtualBox. As Parallels now supports Mac M1 chips, and that an updated provider also supports Parallels on Mac M1, you should be able to get it done with Parallels (Pro or Business version is required).
After VMWare Fusion installation, you have to install Vagrant with brew ( brew install vagrant / At time v2.2.19 has a defect, therefore, you have to install Vagrant 2.2.18 ).
Then, you also have to install the Vagrant vmware provider:
vagrant plugin install vagrant-vmware-desktop
Next, you have to install Vagrant VMWare Utility following instructions on this page.
Finally, I have adapted Vagrantfile from Certified Kubernetes Administrator course as an example of a working configuration:
# -*- mode: ruby -*-
# vi:set ft=ruby sw=2 ts=2 sts=2:
# Define the number of master and worker nodes
# If this number is changed, remember to update setup-hosts.sh script with the new hosts IP details in /etc/hosts of each VM.
NUM_MASTER_NODE = 1
NUM_WORKER_NODE = 2
IP_NW = "192.168.56."
MASTER_IP_START = 1
NODE_IP_START = 2
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
# config.vm.box = "base"
config.vm.box = "spox/ubuntu-arm"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
config.vm.box_check_update = false
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Provision Master Nodes
(1..NUM_MASTER_NODE).each do |i|
config.vm.define "kubemaster" do |node|
# Name shown in the GUI
node.vm.provider "vmware_desktop" do |vb|
# vb.name = "kubemaster"
# vb.memory = 2048
# vb.cpus = 2
vb.vmx["displayName"] = "kubemaster"
vb.vmx["memsize"] = "2048"
vb.vmx["numvcpus"] = "2"
vb.vmx["ethernet0.pcislotnumber"] = "160"
end
node.vm.hostname = "kubemaster"
node.vm.network :private_network, ip: IP_NW + "#{MASTER_IP_START + i}"
node.vm.network "forwarded_port", guest: 22, host: "#{2710 + i}"
node.vm.provision "setup-hosts", :type => "shell", :path => "ubuntu/vagrant/setup-hosts.sh" do |s|
s.args = ["enp0s8"]
end
node.vm.provision "setup-dns", type: "shell", :path => "ubuntu/update-dns.sh"
end
end
# Provision Worker Nodes
(1..NUM_WORKER_NODE).each do |i|
config.vm.define "kubenode0#{i}" do |node|
node.vm.provider "vmware_desktop" do |vb|
vb.vmx["displayName"] = "kubenode0#{i}"
vb.vmx["memsize"] = "2048"
vb.vmx["numvcpus"] = "2"
# Fix
vb.vmx["ethernet0.pcislotnumber"] = "160"
end
node.vm.hostname = "kubenode0#{i}"
node.vm.network :private_network, ip: IP_NW + "#{NODE_IP_START + i}"
node.vm.network "forwarded_port", guest: 22, host: "#{2720 + i}"
node.vm.provision "setup-hosts", :type => "shell", :path => "ubuntu/vagrant/setup-hosts.sh" do |s|
s.args = ["enp0s8"]
end
node.vm.provision "setup-dns", type: "shell", :path => "ubuntu/update-dns.sh"
end
end
end
To start required VM for the hands on, you can run the command vagrant up
.
You will face some issues at running VMs. A great resource to fix any issue can be found checking this Gist.
Finally, you may have to run Vagran up
/ Vagran down
or Vagran destroy
a few times to overcome some blocking situation (with network interfaces among potential issues).
Thanks to @sbailliez and @fatso83 Gists and info sharing, that paved the way to the solution.
Great to see the research resulting in something substantial 😄