Installing Kubernetes on Ubuntu in Virtual Box

Goal: Install Kubernetes (microk8s) on Ubuntu on VirtualBox (Windows host) and get access to it from a laptop.

The host machine is Windows 10 x64 with IP:
VirtualBox 6.1

Guest OS is Ubuntu 20.04 LTS
Laptop OS MacOS Catalina

Install VirtualBox

Create a virtual machine with such minimum parameters: CPU – 1 min, RAM from 3Gb, HDD from 15Gb.

choose x64 version. If you see only 32bit check is the hardware virtualization is enabled in the BIOS:
– For Intel x64: VT-x (Intel Virtualization Technology) and VT-d are both enabled
– For AMD x64: AMD SVM (Secure Virtual Machine) is enabled
chose VMDK, better stability.

Download Ubuntu 20.04 x64

Choose downloaded ISO as a CD
tap “Start”

Installation is regular but you need to remember your password and chose to install K8s & Docker.

creation of credentials and server’s name
installing SSH
installing K8s & Docker

After installation completed tap “Reboot”. If it seems that the system hangs just push “Enter” several times.

Log in to the kubmaster virtual machine and check the IP.

$ sudo ip addr

Install DNS and Dashboard.
# microk8s.enable dns dashboard
Then you can use the following command to see if your services are running yet:

# microk8s.kubectl get all --all-namespaces

Let’s make port forward for K8s dashboard, SSH and kubectl.

Login via ssh to the server from laptop.

$ ssh val@

to be possible connect to cluster via host Windows machine we need to add an IP of the host to microk8s config.

$ sudo -s
# cp /snap/microk8s/current/certs/csr.conf.template /var/snap/microk8s/current/certs/csr.conf.template
look to the /snap/microk8s/current/certs/csr.conf and check the amount of the IP (will need it in the next step)
# vim /var/snap/microk8s/current/certs/csr.conf.template and add a similar line likeIP.7 =
you should add IP.x bigger than in csr.conf. If in csr.conf the last one was IP.4 then in csr.conf.template host IP should go by key IP.5.
After that stop/start k8s:
# microk8s.stop
# microk8s.start
Reload certificates:
# microk8s.refresh-certs -i

To run dashboard forwarding in the background:

# microk8s kubectl port-forward --address -n kube-system service/kubernetes-dashboard 443:443 &

To log in to the dashboard token is needed. Here are commands to get it:
# token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
# echo $token

if not working here is another way:
# microk8s kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)

and search here for kubernetes-dashboard-token

Via browser in laptop go to (use token to log in).

In the kubmaster server run such command to get the configuration of the cluster:
# microk8s.kubectl config view --raw

server IP should be changed to

and paste it to ~/.kube/config in laptop.

run $ kubectl get all --all-namespaces to check access

Kubernetes up and running. Goal is reached.

One thought on “Installing Kubernetes on Ubuntu in Virtual Box”

  1. In MicroK8s container data are kept under /var/snap/microk8s/common/var/lib/containerd and /var/snap/microk8s/common/run/. If you do a df -h you should see that the filesystem holding those paths (probably the root filesystem) is running low on disk space. If you want to use other volumes with free disk space you have to configure MicroK8s accordingly. Edit /var/snap/microk8s/current/args/containerd and point the –root and –state to the volume you want to use. Here is an example with the /mnt:

    –config ${SNAP_DATA}/args/containerd.toml
    –root /mnt/var/lib/containerd
    –state /mnt/run/containerd
    –address ${SNAP_COMMON}/run/containerd.sock

    After that you must restart MicroK8s for this configuration to take effect. Execute: microk8s.stop, microk8s.start.
    But the simplest answer is to specify host path directly in your PV yaml spec – perfect for single node microk8s.

Leave a comment