DEV Community

Cover image for Deploy a JavaScript, Node.js, and Express Website to Kubernetes in 5 Minutes with Jetpack.io
Rob Richardson
Rob Richardson

Posted on • Originally published at jetpack.io

Deploy a JavaScript, Node.js, and Express Website to Kubernetes in 5 Minutes with Jetpack.io

Deploying to Kubernetes is Hard

Maybe you can relate: We've finished coding a website, and we're ready to deploy. We know we want to deploy to Kubernetes, to take advantage of it's industrial-scale hosting, automatic load-balancing, fault tolerance, scaling, and more.

But deploying to Kubernetes is hard. Now we have to trek into the land of containers, pods, services, ingress, and yaml. Ugh. "I just finished the website. I don't want to read a book just to make it work." Kubernetes has too many options and concepts: Pods, Deployments, ReplicaSets, Services, ConfigMaps. Oh my! And the Kubernetes yaml file is really confusing and specific. I really wish it was easier to deploy a website to Kubernetes.

Why Jetpack.io

Jetpack.io is a zero-DevOps solution for deploying to Kubernetes. Jetpack.io takes your code, packages it up in a container, and publishes it to Kubernetes. Jetpack.io also creates a public URL so the site can be routable from the internet, and can stream application logs back to your terminal. All of the toil of Kubernetes melts away, and we can focus on our application.
In this tutorial, we'll build an Express website in JavaScript, configure it for Jetpack.io, and deploy it to Kubernetes – all in 5 minutes.

Building an Express.js app with Node.js

In this example we'll quickly scaffold an Express website. You could swap out these steps with use an existing Node web site, or scaffold a site using other frameworks or tools.

  1. Open a terminal in an empty directory.

  2. Generate an Express website:

npx express-generator --view hbs
Enter fullscreen mode Exit fullscreen mode

Now we have a regular Node.js website. Feel free to customize this site to meet your needs.

Configure the App for Containers

Jetpack.io assumes your web server is running on port 8080 from inside a Docker container. In this section we'll build a Dockerfile to run the web site on port 8080.

  1. Create a new file in the folder named Dockerfile and add this content:
FROM node:alpine
WORKDIR /app
COPY . .
RUN npm install
ENV PORT=8080
EXPOSE 8080
CMD ["npm", "start"]
Enter fullscreen mode Exit fullscreen mode

Note: this is a bare-bones Dockerfile. Depending on your app's dependencies, you may need to add more.

Initialize the project with Jetpack.io

Jetpack.io needs some initial configuration to understand the Node.js web server. We need only do this once per website.

  1. To install the Jetpack CLI, open a terminal and run
curl https://get.jetpack.io -fsSL | bash
Enter fullscreen mode Exit fullscreen mode

Jetpack CLI works on Linux, macOS, and on Windows via WSL2.

  1. Login to Jetpack CLI:
jetpack auth login
Enter fullscreen mode Exit fullscreen mode

Logging into Jetpack allows you to deploy to the Jetpack.io Kubernetes cluster. You can also run on your own cluster in your Azure, AWS, GCP, or private cloud account.

  1. Initialize the project for Jetpack:
jetpack init
Enter fullscreen mode Exit fullscreen mode

This wizard interviews you and configures the Jetpack deployment strategy to match your application.

  1. Answer that Yes, this is a web server. This tells Jetpack that we want to accept inbound traffic.

If we were building a scheduled cron job or a function that drained a queue, we could answer no.

  1. Finish the wizard, and Jetpack CLI automatically generates an appropriate jetconfig.yaml file. You should commit this to source control.

Deploy to Kubernetes using Jetpack.io

Now that the project is configured for Jetpack, deploying is really easy.

  1. Open a terminal in the directory with the Dockerfile and jetconfig.yaml file.

  2. Deploy to Kubernetes:

jetpack dev
Enter fullscreen mode Exit fullscreen mode

Now Jetpack makes the deployment really simple. Automatically it will:

  • Build the Docker image
  • Push the image to a private registry
  • Schedule the necessary Kubernetes resources
  • Create a publicly routable URL to test the website
  • Setup port-forwarding from your local machine
  • Stream application logs back to the terminal
  1. Test the website:

In the console output will be the publicly routable URL. Click this URL to view the web page.

Jetpack also sets up port-forwarding, so you can also browse to http://localhost:8080/ to view the page.

Well that was easy

It's easy to deploy a Node.js and Express.js app built with JavaScript to Kubernetes with Jetpack.io. In this tutorial we scaffolded a website, configured it for Jetpack.io, and used Jetpack.io to deploy to Kubernetes. Jetpack.io is a great zero-DevOps solution for deploying to Kubernetes. Visit https://jetpack.io/docs/ to learn more and to start deploying your content to Kubernetes with ease.

Top comments (0)