Minikube, kubernetes & Docker: deploy and run containerized Nodejs apps using minikube, on MacOS.
In the previous post we already played with git, nodejs and docker. We successfully create containerized git-ed nodejs with docker. Now, with nodejs image-ready we will try to deploy our containerized apps into kubernetes using minikube. Minikube is a mini version of kubernetes which enable us to play kubernetes on our local PC. Unlike kubernetes, minikube only run single node in cluster. single node is more than enough to try kubernetes in local anyway. Oh and I almost forgot, this tutorial entirely done in MacOS environment.
Pre-Requisite
- docker
- minikube
- containerized nodejs apps
if you dont have minikube please follow this post. Mr. Brian Mathew explain clearly step by step how to install minikube on Mac.
Let’s Kubernet-ing
I assume you had done installed minikube on you local Mac. This is the pre-condition of my docker images
as we can see on the picture above, I have “rizkyaddon/hellome:v1” image. This image contain simple nodejs apps. The Dockerfile to build this image is like below
FROM node:9-slim
WORKDIR /app
COPY . /app
RUN npm install express
EXPOSE 3000CMD [“node”, “app.js”]
Ok, now the image ready and what we do next is to deploy the image to kubernetes using this command
kubectl run hellome — image=rizkyaddon/hellome:v1 — port=3000
some command need to be explain right?.
- “run hellome” is to tell kubernetes that the name of deployment will be hellome, it can be anything but i choose to name it hellome.
- “ — image:rizkyaddon/hellome:v1” is to tell kubernetes which docker image to be deployed.
- “ — port=3000” tell kubernetes which port that the container exposing. our nodejs apps run and exposed on port 3000. therefore, to make the pods and service run we have to tell kubernetes to target the listening port of the apps.
after we execute the command above we will get message from kubernetes
we can chekc the status of our deployment using command
kubectl get deployments
the “AVAILABLE” column with value 1, indicate that our deployment is successfull. furthermore, we can check the deploymet status via browser using command:
minikube dashboard
marks the vocab deployments, pods, replica sets in the next post I will detailing the explaination. So, now our containerized nodejs apps have been deployed to kubernetes. The next step is to Create a Service
By default, the Pod is only accessible by its internal IP address within the Kubernetes cluster. To make the hellome Container accessible from outside the Kubernetes virtual network, you have to expose the Pod as a Kubernetes Service.
From your development machine, you can expose the Pod to the public internet using the kubectl expose command:
kubectl expose deployment hellome — type=”LoadBalancer”
The --type="LoadBalance"
flag indicates that you want to expose your service outside of the cluster. This is for us on cloud providers that support load balancers, they use an external IP address that is provisioned to access the service. check the service you just exposed using command
kubectl get services
and finally we can accessed our newly created nodejs service using command
minikube service hellome
command above redirect us to our default browser and show the default page of our service, running on kubernetes.
And its done we successfully deploy our containterized apps on kubernetes on the IP address of 192.168.99.102 and port 30051. feel free to comment and ask anything about this post. Sayonara, see you on the next post. :)