Container Orchestration with Kubernetes, Part 4

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.

The Application

So now you’re finally ready to start using Kubernetes. The first step in deploying a containerized application is, well, the application. I’ve put together some demo JavaScript code that you’ll run as a Node.js application.

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

Navigate to the kubernetes directory and take a look at the JavaScript code. This toy application doesn’t do anything serious, just outputs a message to the console. But it’s enough for our purposes here.

Now run the application in Node.

node k8sdemo.js

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:

FROM node:6.11.4
EXPOSE 8080
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:

minikube start

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.

Conclusion

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!

–jsp

One thought on “Container Orchestration with Kubernetes, Part 4

  1. Pingback: Container Orchestration with Kubernetes, Part 5 – j steven perry, The Blog

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.