This document lists all the steps to take in order to create a MicroK8s environment using Multipass on Ubuntu distro.
- Create a fresh Ubuntu VM (using the latest LTS) with Multipass:
# install multipass
user@hostname:~$ sudo snap install multipass
# Run a VM named "rinj-vm"
user@hostname:~$ multipass launch ubuntu --name rinj-vm --mem 4G --disk 20G
# List all running VMs, an instance called "rinj-vm" should be visible
user@hostname:~$ multipass list
# Visualize info about the new VM
user@hostname:~$ multipass info rinj-vm
# Run a shell into the VM
user@hostname:~$ multipass shell rinj-vm
- Let's do some updates and install MicroK8s:
# Updates
ubuntu@rinj-vm:~$ sudo apt update && sudo apt upgrade -y
# Install MicroK8s
ubuntu@rinj-vm:~$ sudo snap install microk8s --classic --channel=latest/stable
# Start MicroK8s
ubuntu@rinj-vm:~$ sudo microk8s start # This command could take some time to complete, just wait
# Add the user ubuntu to the 'microk8s' group
ubuntu@rinj-vm:~$ sudo usermod -a -G microk8s ubuntu
ubuntu@rinj-vm:~$ sudo chown -f -R ubuntu ~/.kube
# Exit from the VM
ubuntu@rinj-vm:~$ exit
# Restart the VM
user@hostname:~$ multipass restart rinj-vm
- Enable the MicroK8s dashboard, so we can access it from our host's browser just for making sure that all is working as expected:
# Re-run a shell into the VM
user@hostname:~$ multipass shell rinj-vm
# Enable dns and dashboard
ubuntu@rinj-vm:~$ microk8s enable dns dashboard
# Port-forward dashboard
ubuntu@rinj-vm:~$ microk8s kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443 --address 0.0.0.0
Into another terminal run these commands:
# <DASHBOARD_ADDRESS>
user@hostname:~$ echo "https://$(multipass list | grep rinj-vm | awk '{print $3}'):10443"
# <DASHBOARD_TOKEN>
user@hostname:~$ multipass exec rinj-vm -- microk8s kubectl create token default
Now you should be able to see the kubernetes dashboard navigating, in your browser, to <DASHBOARD_ADDRESS>. Choose the access via token and paste the <DASHBOARD_TOKEN>.
- Create a shared folder, mounting local_test_folder from host to the VM
user@hostname:~$ multipass mount ./test rinj-vm:~/vm_test_folder