Minikube quick and easy setup

Ian Muge
5 min readMay 27, 2020

Minikube. Image courtesy of linuxx.info

Background

Recently I had to do a number of tasks developing,debugging and testing simple Kubernetes manifests; I couldn’t keep launching and destroying full k8s clusters on the cloud and my laptop is a bit older so I can’t really run minikube reliably locally. My solution: I would create an ephemeral VM, install minikube, deploy and test all I needed and destroy the VM. This was especially useful when I was doing technical assessments during interviews.

Prerequisites

I used GCP for this test but given it is a bash file, it is not restricted to any provider. The script is customised and tested on RHEL, Centos and Ubuntu. It is highly advisable to have a virtual machine with at least 4GB memory and 2 vCPU; on GCP the n1-standard-2 machine would serve pretty well. Other than those there are no other strict prerequisites.

It would also be nice to allocate it enough local storage; for basic tests, approximately 50GB would be adequate . You can take advantage of the free tier cloud credits.

Setup

As mentioned, this is all a bash script, so you just have to copy it to your server and run it. Where it requires root access the script escalates privileges just for that particular command and continues running as the current user. The user should have sudo “NOLOGIN” access though, as is the case for the default users on AWS (ec2-user/ubuntu) and GCP. This setup simply explains what is happening within the script.

[a]: Instructs the script to output each command it is executing by changing runtime parameters , this helps when debugging and to understand what is happening.

[b]: Gets what Linux distribution is running in this case: ubuntu, centos or rhel

set -x #[a]
VERSION=$( awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | tr -d '"') #[b]

[c]: It runs conditional scripts based on the distro we are currently on.

[d]: It removes previous base docker packages that might have been installed by default

[e]: It installs the dependencies for the docker-ce packages

[f]: It sets up the gpg-key, adds the docker repository to the system and installs docker-ce (community edition)

N.B: It does a similar set up for the RHEL and Centos setup just that it uses yum instead of apt.

if [ $VERSION == "ubuntu" ] #[c]
then
# remove old versions [d]
sudo apt-get remove docker docker-engine docker.io containerd runc
# setup base [e]
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# echo "Install Docker" [f]
curl -fsSL <https://download.docker.com/linux/ubuntu/gpg> | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] <https://download.docker.com/linux/ubuntu> $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
fi

[g]: It adds the current user to the newly created docker group. This allows the current user to execute docker commands without privilege escalation. It should however be noted that this takes effect the next time the current user logs in to the account.

[h]: Start the docker service

[i]: Confirm all is working as expected by checking the docker information. We temporarily execute the command as a different group id using the sg command.

# add current user to the docker group [g]
sudo usermod -aG docker "$(id -gn)"
# echo "Start docker service" [h]
sudo systemctl start docker
# echo "Confirm service" [i]
sg docker -c "docker info"

[j]: Ensure the binary installation folder is available

[k]: Download and install docker-compose

[l]: Download and install minikube

[m]: Download and install kubectl. Confirm it is available by querying the client version.

# echo "Additional Setup" [j]
sudo mkdir -p /usr/local/bin/
# echo "Install Docker compose" [k]
curl -Lo docker-compose <https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$>(uname -s)-$(uname -m) && chmod +x docker-compose
sudo install docker-compose /usr/local/bin/
# echo "Install minikube" [l]
curl -Lo minikube <https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64> && chmod +x minikube
sudo install minikube /usr/local/bin/
# Install kubectl [m]
curl -Lo kubectl <https://storage.googleapis.com/kubernetes-release/release/`curl> -s <https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl> && chmod +x ./kubectl
sudo install kubectl /usr/local/bin/
kubectl version --client

[n]: Starts minikube using the docker driver. This will fetch and setup the required minikube images on the local docker instance

[o]: Enables the ingress addon. This allows the use of the ingress resource within the manifests. Other addons like localstorage are installed by default.

[p]: Confirms the status of the minikube components

[q]: Exposes the local docker environment. This allows the use of images available or built on the local docker engine, this means minikube doesn’t have to fetch all the images remotely.

[r]: Removes the downloaded copies of minikube, kubectl and docker-compose. Resets the runtime parameters and exits

# echo "Start minikube" 
sg docker -c "minikube start --driver=docker" #[n]
sg docker -c "minikube addons enable ingress" #[o]
sg docker -c "minikube status" #[p]
eval $(sg docker -c 'minikube -p minikube docker-env') #[q]
# Clean up [r]
rm -f docker-compose minikube kubectl
set +x
exit

Caveats

Firewall access: If you are to expose some of the services publicly, for testing for example, you will need to permit firewall access. That is based on the protocol and ports to be accessed. This will be determined by the service ports you shall be working with.

Local storage provider: Minikube by default sets up the local storage provider. This means your VM needs to have enough storage or adequate attached storage to function as expected, especially as test data grows.

Conclusion

This provides a quick, easy installation and setup for minikube on a cloud VM for testing and practise purposes. Alternatives for this would be microk8s, or k3s all of which serve pretty well too. This should save you some time so you can go about the bulk of your work on the code, manifests and thinking about the general architecture.

TL;DR

This is a quick and easy guide for a baseline minikube setup on a cloud VM. It works on RHEL, centos and ubuntu. To quickly get up and running: download the gist on your cloud VM and run the script as shown below.

curl -Lo install_minikube.sh '<https://gist.githubusercontent.com/ianmuge/388471b7d1867dcc9e425ffa5217c077/raw/install_minikube.sh>'
bash install_minikube.sh

References

[1] https://gist.github.com/ianmuge/388471b7d1867dcc9e425ffa5217c077

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Ian Muge
Ian Muge

Written by Ian Muge

If I have to do it more than twice, I am automating it. #StayLazy

No responses yet

Write a response