Polymer+Node+K8s = All Kinds of Awesome

Building and deploying a modern, scalable PWA (Part 1)

In this series of posts, we’re going to be looking at a collection of technologies and techniques that can be deployed to create Progressive Web Application, containerise it, and serve it from a Kubernetes cluster. This allows us to provide a great experience to our users, whilst having a simple to maintain, and highly scalable back end for our DevOps team to look after.

We’re going to be creating a number of moving parts, but they’re all quite small and simple to organise, so lets start by taking a look at the collection of technologies employed in this stack.


Polymer

Polymer is a front-end project created by a team at Google. It’s main aim is to simplify the creation of Web Components, which is where it’s most commonly deployed. It can, however, be used to great effect to create single-page applications and PWA’s, so whilst it’s often overlooked in favour of larger, better known frameworks like Angular, React and Vue.js, it could be a great choice for your next project and is well worth spending some time getting to know. You can learn more about the Polymer Project at https://www.polymer-project.org/

Node

Node is the platform that took JavaScript from being just a front-end technology to being a solid choice for the back-end of system too. It allows the creation of highly efficient and responsive services which can be run almost anywhere. It’s also extremely easy to containerise Node services using Docker, which combined with the non-typed nature of JavaScript makes it a good choice when working in a micro-services style architecture. In our stack we’ll be using Node and several open source Node packages to create a lightweight, efficient service to serve up our PWA. You can find out more about Node, find the official distributions and read all of the documentation at https://nodejs.org/en/.

Docker

Docker, probably the most popular containerisation technology today, has been around for a number of years. However, the rise in popularity of Continuous Delivery/Deployment, the DevOps culture etc. has seen widespread adoption of containerisation and an explosion of interest in Docker. Using Docker we can both package up our own software into simple to run containers, and also leverage the wide array of containers available for running other software, such as database engines, web servers etc. In this series we’ll be specifically using Docker to host our web server, and using a clever Docker pattern along the way to ensure we have the most optimised containers we can get. Given the popularity of Docker in modern architectures, there’s a wealth of information available; you can find the official site at https://www.docker.com/, and checkout official container images for a variety of software on the Docker Hub at https://hub.docker.com/.

Kubernetes

Once the use of containers for running software became w widely used pattern, it became obvious that some way of wrangling complex systems composed of sometimes hundred or thousands of containers was needed; they became to big and intricate to be managed manually.

This lead to a number of projects for container orchestrators, including Apache Masos and Swarm amongst others. In 2014 Google open-sourced their Borg orchestrator as the first release of Kubernetes, and in the ensuing years this has become probably the pre-eminent orchestrator in production use. We’ll be building a Kubernetes cluster in GCP, the Google Cloud Platform, to run our containers in. We’ll take a look at how it monitors the health of services, scales services, and how we can get internet traffic in and out of the cluster to serve public websites. You can find out a lot more about what Kubernetes can do on the official site, at https://kubernetes.io/.


Tooling

Obviously we’re going to need to get the right tooling in place to build all of this. Actually not much is needed, it’s all open source so freely available (with the exception of a GCP account, but you get $300 of credit with a new account so that’s all good), and simple to install. Here’s what you’ll need:

Node and NPM — start by installing the latest LTS version from the NodeJS website.

The Polymer-CLI — The Polymer team produce a handy command line toolkit for creating and working with Polymer projects, which can be globally installed using NPM.

Docker — or the Docker Toolkit if you’re running on Windows. Docker is designed to run on, and produce Linux containers. It can be installed natively on Linux systems, on Windows the Docker Toolkit automatically spins up a Linux VM with everything you need to run Docker.

A good code editor — Personal choice is key here, I’m a fan of VS Code, but Atom, Sublime or Notepad++ will do the job. Anything that can edit text files!

MiniKube — Optional. A good choice for running a small, single node K8s cluster on your dev box, for testing before moving into the cloud.

There’s nothing to trick in installing any of these, and there’s plenty of guides and blogs out there, so I won’t reinvent the wheel here.


In part two of this series we’ll be we’ll be creating a basic PWA, looking at how it works and building a Node based server to serve up the content; stay tuned!

Like what you read? Give John Clarke a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.