How to run minikube in a virtualbox vm

Minikube is a tool that makes it easy to run Kubernetes locally. With minikube you can run a single node kubernetes cluster on your workstation. If you are looking to try out kubernetes or need a kubernetes sand box environment minikube can be very handy.

This post will show you how to get minikube up and running within an Ubuntu 1804 VM running on virtualbox.

Before you start you will need to have virtualbox installed and a VM up and running. Checkout the virtualbox website here for instructions on how to get started with virtualbox.

 

Steps

  1. First you will need to download and install minikube. Run the following command.
    curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_1.7.2-0_amd64.deb \
    && sudo dpkg -i minikube_1.7.2-0_amd64.deb

    How to run minikube on a virtualbox vm-image001

  2. Once minikube is installed we will need to do some configuration. In this scenario we are going to run minikube within a VM so we will need to use the None (bare-metal) driver. The none driver requires minikube to be run as root, until #3760 can be addressed. To make none the default driver run the following command
    sudo minikube config set vm-driver none

    How to run minikube on a virtualbox vm-image003

  3. Now we should be able to start mimikube by running the following command.
    sudo minikube start

    How to run minikube on a virtualbox vm-image005

    Minikube should now be running in your vm.

  4. Next you will need to install kubectl the Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. To install kubectl run the following commands
    sudo apt-get update && sudo apt-get install -y apt-transport-https
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
    sudo apt-get update
    sudo apt-get install -y kubectl

    You should now be ready to run kubectl commands against your minikube cluster.

  5. We can test our minikube install by creating a Kubernetes Deployment using an existing image named echoserver, which is a simple HTTP server and expose it on port 8080 using --port.
    To do this run the following command

    kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10

    How to run minikube on a virtualbox vm-image007

  6. To access the hello-minikube Deployment, expose it as a Service:
    kubectl expose deployment hello-minikube --type=NodePort --port=8080The option --type=NodePort specifies the type of the Service.

    How to run minikube on a virtualbox vm-image009

    The hello-minikube Pod is now launched but you have to wait until the Pod is up before accessing it via the exposed Service. Check if the Pod is up and running:

    kubectl get pod

    How to run minikube on a virtualbox vm-image011

    Get the URL of the exposed Service to view the Service details:

    minikube service hello-minikube --url

    How to run minikube on a virtualbox vm-image013

    Open the url in a browser and you should see the following

    How to run minikube on a virtualbox vm-image015

  7. If you no longer want the Service and cluster to run, you can delete them. Delete the hello-minikube Service:
    kubectl delete services hello-minikube

    How to run minikube on a virtualbox vm-image017

    Delete the hello-minikube Deployment:

    kubectl delete deployment hello-minikube

    How to run minikube on a virtualbox vm-image019

    Stop the local Minikube cluster:

    minikube stop

    How to run minikube on a virtualbox vm-image021

    Delete the local Minikube cluster:

    minikube delete

    How to run minikube on a virtualbox vm-image023

    To start your minikube cluster again just run

    Minikube start
    
    

Thats it. You now should be able to spin up and down a single node kubernetes cluster within a virtualbox vm.
Leave a comment below to let me know if this worked for you or not.

1 Comment

  1. Markus on August 10, 2020 at 7:39 pm

    Do you have some port forwarding logic set for this? I am able to hit the server with curl and it gives the expected output, however I am not able to open the url on the host machine browser.

Leave a Comment