Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created January 6, 2020 23:26
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 ruanbekker/1e0f5ab424b055b45f6b2a1e6d38a7df to your computer and use it in GitHub Desktop.
Save ruanbekker/1e0f5ab424b055b45f6b2a1e6d38a7df to your computer and use it in GitHub Desktop.
Provision a VM with Multipass

Install Multipass on Mac

$ brew cask install multipass

Create a SSH Key

$ sh-keygen -b 2048 -f ~/.ssh/multipass -t rsa -q -N ""

Create a Cloud-Init Config

cloud-init.yaml:

#cloud-config
ssh_authorized_keys:
  - ssh-rsa AAA..the-output-of-multipass.pub.. user@host

runcmd:
- apt update && apt upgrade -y

Multipass General Usage

Find a image:

$ multipass find
16.04 (or: x, xenial)
18.04 (or: b, bionic, default, lts)

Launch a VM with bionic and passing the cloud-init:

$ multipass launch bionic --name k3s-master --cloud-init=./cloud-init.yaml

View the VM's info:

$ multipass info k3s-master
Name:           k3s-master
State:          RUNNING
IPv4:           192.168.64.3
Release:        Ubuntu 18.04.3 LTS
Image hash:     6afb97af96b6 (Ubuntu 18.04 LTS)
Load:           0.37 0.62 0.33
Disk usage:     1.4G out of 4.7G
Memory usage:   144.2M out of 986.0M

SSH to the VM:

$ ssh -i ~/.ssh/multipass multipass@$(multipass info k3s-master | grep 'IPv4' | awk '{print $2}')

Exec to the VM:

$ multipass exec k3s-master -- /bin/bash

Delete the VM:

$ multipass delete k3s-master
$ multipass purge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment