In the previous post I listed the steps on setting up a Kubernetes Cluster system. In this session, I will run through on how to create an image, build it, and use the same image to create our pods. I will also show how automated build works in Docker Hub.
Create a Docker Hub account if you haven’t done so. We would also need a repository for your codes. I am using Github to store my codes.
Create new Github repo
In your Github account, create a new repository and upload your codes. Our Node.js application will just output some text as an http response.
We will also need a Docker file. A Docker file contains instructions on how to create our image. Here’s the structure of my Github repo.
Basically our Dockerfile contains the following steps. First is, I declared that I will be using the alpine image and install nodejs package on it. We will also copy index.js to the /src directory of the image and set it to listen to web port 8080 and start the Node.js application.
Configure Source Provider
Login to your Docker Hub account (http://cloud.docker.com) and go to Cloud Settings section.
Under the Source Provider, configure GitHub provider using your Github details.
Now that our Source provider is configured, we can now start to create a new Docker Hub repository.
In the Build Settings section, select the Source Provider and the repo
Click Create & Build to start building our docker image.
You can see from the Timeline section the steps it is doing to build our image. You can click the specific step to view more details.
Once our image is built, you can see under the General Section that we now have a new docker image (latest)
We can now use this image to create our pods. In my repo, I created a yml file that I’ll use to create a pod in our Kubernetes Cluster. Issue the following command to create our pod.
After a couple of minutes, we can see that a pod has been created.
Using the pod IP address, we can curl port 8080 to test our image.
As you can see from the above, we got an http response from our pod from our Node.js application.
Let’s try to update our code in Github. Update index.js adding in a version 2 in the response string.
Once you commit the changes, you will see in Docker hub that an Automatic Build will be triggered to update our docker image.
We could have created a deployment to simulate Blue-Green deployment/Update our pods but for simplicity, we will focus on just creating pods manually. Delete the current running pod. Re-running the steps to create a pod by passing in the same yml file, we should be able to see the updated Node.js application.
Still new to this technology, I hope this post provided some understanding on the basics of Containers/image/Kubernetes. There’s so much more to learn and explore on this Container Technology. Connect with me on LinkedIn as I would like to know how others implement CI/CD process and what framework/methodology or tools they follow.