book-of-kubernetes / examples

Examples for The Book of Kubernetes
MIT License
166 stars 76 forks source link

Set up for M1 Mac #8

Closed chasewilson closed 2 years ago

chasewilson commented 2 years ago

VirtualBox doesn't work well for M1 Macs and set up instructions don't seem to be geared for Mac? Any guidance for this set up?

Thanks in advance!

AlanHohn commented 2 years ago

Hi @chasewilson,

Thanks for the question. There are a couple possible options:

Use AWS

You can use the AWS configuration to run VMs there. Ansible will work well from a Mac, so your Mac can be the control machine and you can pretty much just follow the AWS instructions as-is.

If you want to isolate the environment you use for this, you can start by installing pyenv from Homebrew. Note that none of the Ansible automation embeds any AWS credential information, so the easiest thing is to use aws configure from the AWS CLI to provide your credentials.

Use an ARM version of Ubuntu

I don't have an ARM-based Mac so I can't test this one, but according to this article you can install Multipass using Homebrew and then use that to kick off an ARM-based Ubuntu VM image.

The Vagrant configuration is really only doing a couple things:

  1. Instantiating one or more Ubuntu virtual machines (currently Focal 20.04 machines) with the right CPU, memory, network, and port forwarding;
  2. Running an Ansible playbook against those machines for whatever automation is needed to set up for that chapter.

It would be a bit of a faff, but it should be possible to use multipass to generate whatever virtual machines are needed for each chapter. You can run Ansible on the Mac with this configuration as well. This page describes how to either grab the SSH keys that multipass uses, or inject a public key, so Ansible can use key-based authentication to the Ubuntu virtual machines. You would probably want to create an Ansible inventory file that tells Ansible what machines are available and how to connect to them; you could then run Ansible directly using the playbook.yaml file.

There are a couple things to note here:

  1. The automation is designed to start over at the beginning of each chapter, but once you have your Kubernetes cluster going in Part II, it should be possible to just reuse the same set of VMs as long as you clean up resources that were created. Of course, if in doubt, you can always use multipass to delete and re-create.
  2. The network configurations are a little specific, especially for the Kubernetes clusters. Multipass on MacOS doesn't seem to have support for adding an additional private network, so you may need to update the places in the automation where it references IP addresses on the 192.168.65 to match the machines you end up creating. I probably wasn't as careful as I should have been in making this easy.

If you go this route, and want to collaborate on improvements to the automation so it works better in this kind of scenario, please reach out with your findings.