About
This is a very simple 3 tier application written on nodejs, i,e.
———-————-———–
frontend <–> backend api <–> database
———-————-———–
Info
A live working url is hosted at: https://thisthing.works
Everything is pushed to gitlab as:
repo | url | Remarks |
---|---|---|
api | https://gitlab.com/node-3tier-application/api | backend api that talks to db |
web | https://gitlab.com/node-3tier-application/web | frontend app that talks to api |
infra | https://gitlab.com/node-3tier-application/infra | defines all gcp resources as code (IAC: terraform) |
Infrastructure resources is defined at infra
- Project is deployed to kubernetes (k8s) cluster on google cloud platform
- nodes (autoscaled defaults: min:1 and max:3, instancetype: g1-small)
- database used is cloudsql(postgresql)
- deployed with private ip only
- terraform runbooks is written HA enabled, replica and backup (to save money, demo; those flags are turned off on the app)
Deployment:
- trigger: every commit pushed on gitlab triggers a deployment pipeline (lint- build-deploy)
notification: is sent to a telegram room: https://t.me/node_3tier_application
pipeline: gitlab-ci.yml on both web and api has 3 stages:
- lint: to check if developers are following proper lint practises (In real world we run CI test there)
- build: gitlab ci runner(free) is authenticated to publish build to CloudBuild on gcp
deploy: gitlab ci runner is also authenticated to trigger deployment of container built on build step earlier.
If all these pipeline steps completes, then we have new changes deployed to k8s cluster with a roll out policy as:
strategy: rollingUpdate: maxSurge: 25% #max num of pods that could be created over desired num of pods => 125% maxUnavailable: 25% #max num of pods that could be unavailable during update => 75% type: RollingUpdate
Instrumentation
- prometheus operator chart is deployed using helm
- sample grafana dashboard to dash custom metrics
Technologies Used
items | remarks |
---|---|
GKE | free (300$ credits) and more mature than EKS |
terraform | easier to build cluster from code, test it and nuke it later |
Makefile | easier to prepare and streamline the demo |
cloudsql | avoid dealing with persistent state onk8s cluster and other HA configuration |
gitlab-ci | easy and straight forward ci/cd also free for demo |
CloudBuild | to build the container images |
stackdriver | log the error on application |
Google CDN | caching the static resources |
prometheus | with grafana to instrument/graph metrics |
just for tryout, its simple straight forward logging solution |
Directory Structure
The directory structure application is: