How to run minikube on 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.
- 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
- 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
- Now we should be able to start mimikube by running the following command.
sudo minikube start
Minikube should now be running in your vm.
- 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.
- 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
- 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.
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
Get the URL of the exposed Service to view the Service details:
minikube service hello-minikube --url
Open the url in a browser and you should see the following
- 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
Delete the hello-minikube Deployment:
kubectl delete deployment hello-minikube
Stop the local Minikube cluster:
Delete the local Minikube cluster:
To start your minikube cluster again just run
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.
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.
Most probable your minikube is running as a container on docker.
Try running it bare metal : minikube config set vm-driver none
I tested your solution and it works.
The difference in my implementation is that I have to runs all the commands like root so
kubectl create deployment hello-minikube –image=k8s.gcr.io/echoserver:1.10
for me become:
sudo kubectl create deployment hello-minikube –image=k8s.gcr.io/echoserver:1.10
and so on.
It is normal?
Mostly worked well. I installed from a clean Ubuntu install – so also had to install gcc make perl dksm;
#sudo apt-get install build-essential gcc make perl dkms
And install docker;
#sudo apt install docker.io
#sudo systemctl start docker
#sudo systemctl enable docker