Minikube runs a Kubernetes cluster with a single node inside a virtual machine on the personal computer. Therefore, there is a need to have virtualization on a personal machine with a KVM or VirtualBox hypervisor. The tutorial below is done on a Fedora and KVM system.
Also, before installing Minikube, we need to install kubectl, one of the most used kubernetes tools.
Installing kubectl
Kubectl is the command-line Kubernetes utility that lets us launch or manage applications in a k8s cluster. With kubectl we can inspect cluster resources or create, delete, or update components.
Install kubectl in CentOS, Red Hat, Fedora
First, we need to add the repo for Kubernetes:
$ sudo vi /etc/yum.repos.d/kubernetes.repo
Inside the file we add:
[Kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
$ sudo dnf upgrade && sudo dnf install kubectl -y
Installing kubectl in Debian, Ubuntu, and derivatives
The following lines will be run:
$ 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 –
$ sudo touch /etc/apt/sources.list.d/kubernetes.list
$ echo “deb http://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
Install Minikube
We will install the latest minikube version – 1.1.0 at the time of writing this tutorial.
In Linux, run the following command:
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Start Minikube
Now we can launch our first single-node K8s cluster managed by Minikube. If we work with VirtualBox, we do not have to do anything special – Minikube starts by default using the VirtualBox driver:
$ minikube start
If we chose the KVM hypervisor as a virtualization, we need to install the corresponding driver (assuming we have already configured QEMU and KVM):
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 && chmod +x docker-machine-driver-kvm2 && sudo mv docker-machine-driver-kvm2 /usr/local/bin /
To start Minikube with KVM, run the command:
$ minikube start –vm-driver kvm2
For the next cluster launches, the minikube start command is sufficient without the kvm driver indication.
That’s all! If you open Virtual Machine Manager or VirtualBox, you will see the new virtual machine created.
We can start viewing the cluster, launching apps, and so on. Below are some examples that will help you get started.
View K8s cluster nodes
$ kubectl get nodes
$ kubectl get nodes -owide
Installing the first deployment
$ kubectl run hello-minikube –image=k8s.gcr.io/echoserver:1.10 –port=8080
Create a NodePort service for this first deployment
$ kubectl expose deployment hello-minikube –type=NodePort
View pods
$ kubectl get pods
$ kubectl get pods -owide
View the pod description
$ kubectl describe under hello-minikube-7c77b68cff-n7lg4
We can use the curl command on the hello-minikube
$ curl $(minicube service hello-minikube –url)
View services
$ kubectl get svc
Viewing namespace
$ kubectl get ns
View cluster IP and cluster information
$ minikube ip
$ kubectl cluster-info
Stop the K8s Cluster:
$ minikube stop
Resources consumed by Minikube
When prevoiusly set, Minikube starts with 2 core and 2 GB of RAM. If you want to allocate more resources to your k8s cluster, run the start command with the –memory and –cpus flags (if you already started a minikube cluster, it must be deleted before allocating more processors and a larger amount of memory):
$ minikube delete
$ minikube start –memories 4096 –cpus 4