Skip to content

idanhoro/CI-CD-k8s-weightapp

Repository files navigation

Kubernetes

Introduction

Deploy WeightTracker App using Azure Kubernetes Cluster, Plus deployment with helm option.

Project Overview

First of all we will create a Kubernetes Cluster in Microsoft’s Azure Kubernetes Service (AKS) for the project infrastructure.

Once the cluster is created we are going to run our NodeWeightTracker application on top of AKS. This means that we need to write all the configuration files that are needed for running our application in a Kubernetes Cluster.

Finally we will, update or CI/CD process to deploy our already dockerized application into the Kubernetes cluster.

Goals

  • Provision an AKS cluster
  • Install the Nginx ingress controller
  • Deploy the NodeWeightTracker application on AKS meeting the following requirements:
  • The NodeWeightTracker application must be accessible from the internet
  • The NodeWeightTracker application must be exposed to the internet on port 80
  • The NodeWeightTracker must have at least 3 instances to ensure high availability
  • Use configmaps/secrets to store your application configurations
  • You must expose your application using the ingress controller

Bonus

  • Helm: Package your kubernetes manifests using helm and use it to deploy your application in your CI/CD pipeline.
  • PostgreSQL on Kubernetes: Instead of using the PostgreSQL managed service of Azure, deploy the database into the AKS cluster (ensure the database is accessible only within the cluster)
  • Terraform: Manage your Azure resources using Infrastructure as Code

Running instructions

  1. Create two environments using terraform aks module at Terraform-AKS directory
  2. Install Ngnix ingress controller using the following command: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.4/deploy/static/provider/cloud/deploy.yaml
  3. Link the repository to the pipeline (Azure DevOps Pipeline for example).
  4. Create variable group for each environment including the following variables:
HOST=''
HOST_URL=''
k8s_conn='Your k8s connection name'
NODE_ENV='development'
OKTA_CLIENT_ID=''
OKTA_CLIENT_SECRET=''
OKTA_ORG_URL=''
COOKIE_ENCRYPT_PWD=''
PGDATABASE='postgres'
PGHOST='my-postgresql3'/'Your PGHOST ip/name'
PGPASSWORD='Your password'
PGPORT='5432'
PGUSERNAME='postgres'
PORT='8080'
CLUSTER_LOGIN='Your cluster connection command'
  1. Follow instructions for k8s+Helm deploy at charts directory -> charts directory.
  2. Follow instructions for k8s deploy at k8s directory -> k8s directory.

Node.js Weight Tracker

Demo

This sample application demonstrates the following technologies.

  • hapi - a wonderful Node.js application framework
  • PostgreSQL - a popular relational database
  • Postgres - a new PostgreSQL client for Node.js
  • Vue.js - a popular front-end library
  • Bulma - a great CSS framework based on Flexbox
  • EJS - a great template library for server-side HTML templates

Requirements:

Install and Configuration

  1. Clone or download source files
  2. Run npm install to install dependencies
  3. If you don't already have PostgreSQL, set up using Docker
  4. Create a free Okta developer account and add a web application for this app
  5. Copy .env.sample to .env and change the OKTA_* values to your application
  6. Initialize the PostgreSQL database by running npm run initdb
  7. Run npm run dev to start Node.js

The associated blog post goes into more detail on how to set up PostgreSQL with Docker and how to configure your Okta account.