Cloud Native / Cloud Services

Deploy a MEAN Web App with Google Kubernetes Engine, Portworx

1 Mar 2019 9:12am, by

In one of my previous articles, I introduced Portworx as the container-native storage platform. In this tutorial, we will deploy and manage a Node.js web application and a MongoDB database in Google Kubernetes Engine. To achieve high availability for MongoDB, we will use a Portworx storage cluster deployed on GKE.

Launching a GKE Cluster

Let’s launch a three node GKE cluster based on Ubuntu OS with an SSD-based disk of 50GB attached to each node. Replace the PROJECT with your own GCP project id.

The below command updates kubeconfig with the credentials and endpoint of the cluster.

Let’s add the current user to role cluster-admin

Verify that the cluster is up and running.

Installing Portworx Storage Cluster

Portworx is installed as a DaemonSet on each node of GKE. We can install it by generating the YAML spec through an online tool. Visit the Portworx documentation page to get started.

Get the version of Kubernetes with the following command. The installation tool needs to know the exact version of the distribution.

Portworx relies on etcd to store the metadata and cluster state. For this demo, we will use the built-in etcd cluster.

Under the Storage tab, choose GKE and populate the information for the spec. We are choosing an SSD disk with 20GB as dedicated block storage for Portworx. Since we have three nodes, we will get aggregate storage of 60GB.

Choose defaults for the Network tab and click Next.

In the last tab, choose Google Kubernetes Engine and click Finish.

We are ready to install Portworx based on the generated specification. You can either download the spec or copy it.

Switch to the terminal and run the command copied from the spec generator. It will take a few minutes for Portworx cluster to get installed.

Verify the cluster by checking the Portworx Pods running in kube-system namespace. All the Pods should be running.

Deploying MongoDB

We will create a StorageClass for Portworx with a replication factor of 3. This ensures that the data is redundantly available on multiple nodes.

With the StorageClass in place, we will create a Persistent Volume Control (PVC) that will be used by MongoDB Pod.

The storage backend for MongoDB Pod is now ready.

Let’s go ahead and create the MongoDB Pod.

To make the database Pod accessible to the web application, we will expose it through a ClusterIP-based Service.

The database backend is now ready. It’s time to deploy the web application.

Deploying Node.js Web Application

The web application is a simple todo task list that persists changes to MongoDB. Create the Deployment for the web app with replicas.

Finally, we will expose the web application through a load balancer.

Check the Service created for the web app to get the IP address of the load balancer.

Accessing the web app shows the below UI.

In the next part of this series, I will show you how to perform failover of MongoDB database running within GKE.

Portworx is a sponsor of The New Stack.

Feature image via Pixabay.

A newsletter digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.