Skip to content

Instantly share code, notes, and snippets.

@akinsella
Last active June 8, 2023 11:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akinsella/ab51ec72dd954d93221df9928a00c642 to your computer and use it in GitHub Desktop.
Save akinsella/ab51ec72dd954d93221df9928a00c642 to your computer and use it in GitHub Desktop.
Proposed solution to run Vagrant successfully on Mac M1

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.

@fatso83
Copy link

fatso83 commented Mar 30, 2022

Great to see the research resulting in something substantial 😄

@EZ4BRUCE
Copy link

hi bro, i got a problem says : kubemaster: Device "enp0s8" does not exist. do you know how to fix it?
btw the vagrant version on me is v2.3.3

@fatso83
Copy link

fatso83 commented Dec 1, 2022

Yo, brother from another mother. I do not know how to fix that, sorry. That requires more info and more time that I do not have. Try some dedicated forum or Gitter for Vagrant 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment