Minikube Overview
Minikube is a tool which allows you to run a single node Kubernetes cluster on a local machine or a VM. Minikube is easy to get setup and running, requiring only a few minutes as opposed to the complex install process and hardware required for a full-blown Kubernetes environment. Minikube can also be spun up and down in a faster manner, making it ideal for local debugging and testing for your infrastructure-as-code; however, it is not intended for Production use.
This step-by-step guide outlines the installation of Minikube using VirtualBox as the underlying hypervisor and Docker as the container runtime.
Pre-Requisites
List of requirements and versions used for this install guide.
Memory – 4GB (Default – 1GB)
CPU – 1 Core (Default)
OS – CentOS 7
Privileges – Root
VirtualBox – v6.0.4
Minikube – v0.34.1
Kubectl – v1.13
VirtualBox Installation
1.) In order to install VirtualBox, virtualization support must be enabled in the BIOS of the target system (your laptop, a VM, or even a target CentOS 7 server). Verify virtualization is enabled.
[ `egrep -c 'vmx|svm' /proc/cpuinfo` -eq 0 ] && { echo "Virtualization is not supported by the CPU, exiting.."; exit 1; }
2.) Disable selinux & stop firewall as needed.
setenforce 0
perl -pi -e 's/SELINUX\=enforcing/SELINUX\=disabled/g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
3.) Install dependency packages required for VirtualBox.
/usr/bin/yum -y install binutils qt gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms bash-completion
4.) Download the VirtualBox yum repository definition and install and setup VirtualBox 6.0. Add the local root user to the vboxusers
group to run the VirtualBox.
/usr/bin/wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo -O /etc/yum.repos.d/virtualbox.repo
/usr/bin/yum -y install VirtualBox-6.0
/usr/lib/virtualbox/vboxdrv.sh setup
usermod -a -G vboxusers root
5.) Next, download the 64 bit Minikube executable for Linux from the Google minikube file repository.
/usr/bin/curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
cp -p minikube /usr/local/bin && rm -f minikube
6.) Create the Kubernetes yum repository definition, install kubectl (Kubernetes CLI), and use kubectl to add auto-completion to your bash profile.
cat < /etc/yum.repos.d/kubernetes.repo
[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
EOF
/usr/bin/yum -y install kubectl
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
7.) Start Minikube by invoking the Minikube executable, passing in --memory
and --cpus
arguments to set the memory and compute power of the Minikube VM as needed. We recommend setting memory to 4096 (4GB) and cpu to 2 cores. Set the no_proxy variable to allow the kubectl utility to connect directly to the IP of the Minikube VM. Using the Minikube executable, enable the Kubernetes dashboard to provide a UI for interacting with the encapsulated Kubernetes control plane and run a proxy on port 8001 to allow you to access the Kubernetes dashboard using your web browser. The --disable-filter=true
argument allows all requests to access the dashboard without any filtering enabled.
minikube start --memory=4096 --cpus=2
export no_proxy=$no_proxy,$(minikube ip)
nohup kubectl proxy --address='0.0.0.0' --port=8001 --disable-filter=true &
sleep 30
minikube addons enable dashboard
nohup minikube dashboard &
minikube addons open dashboard
8.) Your Minikube-based Kubernetes instance is now running and accessible via the kubectl utility and the dashboard ui! You can access the Kubernetes dashboard using the following URL:
http://LINUX_IP:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
9.) When you are done working with your Minikube instance, execute the commands below to cleanup Kubernetes and stop and delete Minikube.
/bin/kubectl delete deploy,svc --all
/usr/local/bin/minikube stop
/usr/local/bin/minikube delete
10.) A quick cheat sheet of helpful Minikube commands:
# set & get current context of cluster
kubectl config use-context minikube
kubectl config current-context
# fetch all the kubernetes objects for a namespace
kubectl get all -n kube-system
# display cluster details
kubectl cluster-info
# set custom memory and cpu
minikube config set memory 4096
minikube config set cpus 2
# fetch cluster ip
minikube ip
# ssh to the minikube vm
minikube ssh
# display addons list and status
minikube addons list
# exposes service to vm & retrieves url
minikube service elasticsearch
minikube service elasticsearch --url
Summary
This guide gives you a quick set of steps that you can use to spin up a local Minikube instance for experimenting with Kubernetes and container orchestration. Minikube can be used to explore and understand the internals of Kubernetes and Docker Containers with a simple setup process and quick turnaround.
If you have questions on how you can best leverage our experience, would like further examples and/or need help with your Cloud-based environment, please engage us via comments on this blog post, or reach out to us.