Launching Out

What do you want in life is a question many are unwilling to answer. Some give vague answers such as ‘money’, ‘fame’, and ‘happiness.’ but these are only...

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Dockerizing and Deploying a NodeJs App

Today we are going to write a simple NodeJs app, dockerize and deploy it to Google cloud using Kubernetes. The main objective of this article is to give an insight of deploying a NodeJs app to Google cloud. Therefore, no Javascript experience is required. I’ll assume you have never worked with JS. The code base is going to be very basic. Let’s do this!

Section A: Node App

Section B: Dockerizing The App

Now, let’s build the image. Run docker build -t nodeapp . Don’t forget to include the period. You can tag your image with any name. Mine I have tagged it, nodeapp as shown in the command.

Sample of my build logs.

Run docker run -p 3000:3000 nodeapp . On your browser, go to localhost:3000. You should be able view your application! Your app is now dockerized! To view your image, run docker images . This will display images with their details. To run your app in the background(detached mode), run docker run -d -p 3000:3000 nodeapp . Run docker ps to view your container, docker stop <CONTAINER ID> to stop the container.

Section C: Deploying to Google cloud

We want now to make our application public.

Pushing The Docker Image

Push your image by running this command:

gcloud docker -- push <HOSTNAME>/<YOUR-PROJECT-ID/<IMAGE-NAME> , for example, gcloud docker -- push us.gcr.io/nodeapp-123456/nodeapp .

Note: Ensure kubectl has the right credentials by running
gcloud auth application-default login
.

Awyeah! Let us now deploy our app. Run the following command:

Make your app public by using this command:

Check the status of your deployment. If all is good, the status on your pod should be, Running .

How will you access your remote app? How will you share a link to allow other people access your app? Don’t worry. Run kubectl get services . Use the EXTERNAL-IP to access the app. Don’t forget include the port. For example, 30.123.119.166:3000 . You should now access your app via the address.

It has been a long journey, right? Let me say congratulations for building, dockerizing and deploying an app. Even though it was a very simple app. I believe you’ve learned something.

Note: I have not covered a lot of stuff here. Please use gcloud, docker and kubernetes docs to learn more.

Credits:
- Google Cloud Platform docs
- Docker docs

Your comments are highly welcomed!

Add a comment

Related posts:

Interesting Patterns In The Mainstream Adoption Of Technology

Mainstream society has been making steady progress thanks to the adoption of technology. As the scientific discoveries and technological achievements continue to increase, society at large continues…

Farewell to Buddy the Internet Dog

Many of my long time students said something like this over on Facebook: ​ ​“ We grew up with Buddy!” ​ “We got our training from you and Buddy!”​ ​ Thanks… ​ 17 years. ​ Buddy thanks for a damn good…

More Songs About Buildings And Food.

Regardless of genre or era, music has a few throughlines and themes that seem to appear everywhere. It can be hard to pick my favorite of anything, let alone music, and let alone music discussions…