Working with Kubernetes on your Computer (Minikube)
Hey everybody! In this post, I’d like to talk about Container-centric infrastructure with Kubernetes. This is Part 4 of a series of posts on using installing and using Kubernetes.
If you missed Part 3 where I give you Install Kubernetes on your Computer (Minikube), make sure to check that out.
Open a Terminal window or command prompt, navigate to a location on your computer where you want the code to land and clone the code from GitHub.
git clone https://github.com/makotogo/developerWorks
Now run the application in Node.
Open a browser and point it to
http://localhost:8080 to see the message.
And there it is. Now that you have an application, it’s time to containerize it.
Containerize the application
Here’s how you use Docker to do that. Take a look at the Dockerfile:
COPY k8sdemo.js .
CMD node k8sdemo.js
Use this Docker definition to containerize the application. But before we can do that we need to start minikube, and I’ll show you why in a minute.
Execute the minikube start command:
The first time Minikube runs, it has to download the ISO image to run inside of VirtualBox, and may take a minute or two depending on the speed of your internet connection. Once the image has been downloaded, minikube will start.
Minikube runs inside VirtualBox in its own VM. We need to make sure that Docker uses the internal Docker registry on Minikube’s VM by executing this command:
eval $(minikube docker-env)
Otherwise Docker will use the local registry on your machine, which is not accessible from the VM where minikube is running.
Now, from the Terminal window, execute the docker build command:
docker build -t k8sdemo:v1 .
This will create the image with a name of
k8sdemo and a tag of
v1, and store it in the Docker registry on the minikube host VM. When deploying the image to Minikube, you’ll reference that tag explicitly.
From the Terminal window execute the kubectl run command:
kubectl run k8sdemo --image=k8sdemo:v1 --port=8080
And now the application is up and running in its own Pod.
In this post I showed you how to work with Kubernetes on your computer. You containerized a simple application, then deployed it to your local Kubernetes cluster.
In Part 5, I’ll show you how to manage an application running in a Kubernetes cluster using kubectl and the Kubernetes Web UI Dashboard.
Want to know more?
If you want to learn more about Kubernetes, check out this post at IBM developerWorks: What is Kubernetes?
Be sure to check out the other posts in this series:
Check out this video at IBM developerWorks TV, where I show you everything I covered in Parts 1-5 of this series:
Introduction to Kubernetes:
Thanks for reading!