Using Kubernetes for Local Development — Minikube
Disclaimer
This content is part of / inspired by one of our online courses/training. We are offering up to 80% OFF on these materials, during the Black Friday 2019.
You can receive your discount here.

If your ops team is using Docker and Kubernetes, it is recommended to adopt the same or similar technologies in development. This will reduce the number of incompatibility and portability problems and makes everyone consider the application contains a common responsibility of both Dev and Ops teams.

This blog post introduces the usage of Kubernetes in development mode and it is inspired by a screencast that you can find in Painless Docker Course.

Minikube is a tool that makes developers’ life easy by allowing them to use and run a Kubernetes cluster in a local machine.
In this blog post, for the examples that I tested, I am using Linux Mint 18, but it doesn’t change anything apart from the installation part.
cat /etc/lsb-release DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=18.1
DISTRIB_CODENAME=serena
DISTRIB_DESCRIPTION=”Linux Mint 18.1 Serena”

Prerequisites
In order to work with Minikube, we should have Kubectl and Minikube installed + some virtualization drivers.
- For OS X, install xhyve driver, VirtualBox, or VMware Fusion, then Kubectl and Minikube
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectlwebserver-2022867364-r5zzlchmod +x ./kubectlsudo mv ./kubectl /usr/local/bin/kubectlcurl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.21.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- For Windows, install VirtualBox or Hyper-V then Kubectl and Minikube
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.7.0/bin/windows/amd64/kubectl.exeAdd the binary to your PATH (This article explains how to modify the PATH)
Download the minikube-windows-amd64.exe file, rename it to minikube.exe and add it to your path.
Find the last release here.
- For Linux, install VirtualBox or KVM then Kubectl and Minikube
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectlchmod +x ./kubectlsudo mv ./kubectl /usr/local/bin/kubectlcurl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.21.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Using Minikube
Let’s start by creating an image from this Dockerfile:
FROM busybox
ADD index.html /www/index.html
EXPOSE 8000
CMD httpd -p 8000 -h /www; tail -f /dev/nullAdd something you’d like to see in the index.html page.
Build the image:
docker build -t eon01/hello-world-web-server .Let’s run the container to test it:
docker run -d --name webserver -p 8000:8000 eon01/hello-world-web-serverThis is the output of docker ps:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2ad8d688d812 eon01/hello-world-web-server "/bin/sh -c 'httpd..." 3 seconds ago Up 2 seconds 0.0.0.0:8000->8000/tcp webserver
Let’s commit the image and upload it to the public Docker Hub. You can use your own private registry:
docker commit webserver
docker push eon01/hello-world-web-serverRemove the container since we will use it with Minikube
docker rm -f webserverTime to start Minikube:
minikube startCheck the status:
minikube statusWe are running a single node:
kubectl get nodeRun the webserver:
kubectl run webserver --image=eon01/hello-world-web-server --port=8000A webserver should have it’s port exposed:
kubectl expose deployment webserver --type=NodePortIn order to get the service url type:
minikube service webserver --urlWe can see the content of the web page using :
curl $(minikube service webserver --url)To show a summary of the running cluster run:
kubectl cluster-infoFor more details:
kubectl cluster-info dumpWe can also list the pods using:
kubectl get podsAnd to access to the dashboard use:
minikube dashboardIf you would like to access the frontend of the web application type:
kubectl proxyIf we want to execute a command inside the container, get the pod id using:
kubetctl get podsThen use it like :
kubectl exec webserver-2022867364-0v1p9 -it -- /bin/shTo finish, delete all deployments:
kubectl delete deployments --allDelete all pods:
kubectl delete pods --allAnd stop Minikube
minikube stopI hope you enjoyed this introduction.
Connect Deeper
If you resonated with this article, you can find more interesting content in Painless Docker Course.
You can also follow my free course, 10 Great Tips To Learn Docker.
We, Eralabs, will be happy to help you with your Docker and Cloud Computing projects, contact us and we will be happy to hear about your projects.
Please subscribe to DevOpsLinks (An Online Community Of Thousands Of IT Experts & DevOps Enthusiast From All Over The World) and if you are interested in getting only news and tutorials about Kubernetes, you can join Kaptain (A #Kubernetes Community Hub, Hand Curated Newsletter, Team Chat, Training & More).
You may be also interested in joining our newsletter Shipped, a newsletter focused on containers, orchestration and serverless technologies.
You can find me on Twitter, Clarity or my website and you can also check my books: SaltStack For DevOps.
Don’t forget to join my last project Jobs For DevOps !
If you liked this post, please recommend it and share it with your followers.
Join our community Slack and read our weekly Faun topics ⬇

