GithubHelp home page GithubHelp logo

rdwns / devops-capstone Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 1.09 MB

Automated Jenkins pipeline for deploying a Kubernetes cluster running a nodeJS app using blue-green deployments

Dockerfile 19.05% JavaScript 21.91% Shell 10.84% Makefile 48.20%

devops-capstone's Introduction

Project Overview

Build Status

This repository contains a capstone project which deals with cloud-native container orchestration. This project is a requirement to graduate for the DevOps Nanodegree at Udacity. The project requires the skills and knowledge which were developed throughout the Cloud DevOps Nanodegree program to set up a pipeline for deploying Kubernetes Cluster running a containerized nodeJS app using Jenkins.

Sreenshot of Jenkins Pipeline

The main tasks involved in the project included:

  • Working with AWS CLI
  • Using Jenkins to build pipelines implementing Continuous Integration and Continuous Deployment
  • Working with CloudFormation to deploy infrastructre
  • Building Docker containers in pipelines
  • Building Kubernetes clusters
  • Deploying the docker containers to the Kubernetes Clusters

Main tools used were:

  • AWS CLI
  • Jenkins
  • eksctl for cluster creation
  • kubectl for managing kubernetes cluster
  • aws cloudformation for deploying IaC

Roadmap:

  • Create Cloudformation Template for Network Stack
  • Create Cloudformation Template for deploying Jenkins Server
  • Application Code
  • Containerize the application using Dockerfile
  • Create Jenkinsfile
  • DryTest the Kubernetes Cluster
  • Deploy to AWS

The screenshots for successful deployment can be found in /screenshots.The app using Blue-Green deployment methodology and is hosted here


Technological Background

Docker

Docker is the most widely used container technology and really what most people mean when they refer to containers. Docker is built on cgroups and namespacing provided by the Linux kernel and recently Windows as well.

A Docker container is made up of layers of images, binaries packed together into a single package. The base image contains the operating system of the container, which can be different from the OS of the host.

The OS of the container is in the form an image. This is not the full operating system as on the host, and the difference is that the image is just the file system and binaries for the OS while the full OS includes the file system, binaries, and the kernel.

On top of the base image are multiple images that each build a portion of the container. For example, on top of the base image may be the image that contains the apt-get dependencies. On top of that may be the image that contains the application binary, and so on.

Kubernetes

Making use of Kubernetes requires understanding the different abstractions it uses to represent the state of the system, such as services, pods, volumes, namespaces, and deployments.

  • Pod - generally refers to one or more containers that should be controlled as a single application. A pod encapsulates application containers, storage resources, a unique network ID and other configuration on how to run the containers. In other words, pods are the smallest deployable units of computing in a cluster.
  • Service - pods by nature are not reliable. Kubernetes does not guarantee a given physical pod will be kept alive. Therefore, communicating directly with a pod is highly discouraged. Instead, a service represents a logical set of pods and acts as a gateway, allowing pods to send requests to the service without needing to keep track of which physical pods actually make up the service.
  • Replica Set - is an API Object that helps to manage the scaling of Pods. It ensures that a specified number of pods are always running inside the cluster. As such, it is often used to guarantee the availability of a specified number of identical Pods.
  • Volume - ****similar to a container volume in Docker, but a Kubernetes volume applies to a whole pod and is mounted on all containers in the pod. Kubernetes guarantees data is preserved across container restarts. The volume will be removed only when the pod gets destroyed. Also, a pod can have multiple volumes (possibly of different types) associated.
  • Namespace - a virtual cluster (a single physical cluster can run multiple virtual ones) intended for environments with many users spread across multiple teams or projects, for isolation of concerns. Resources inside a namespace must be unique and cannot access resources in a different namespace. Also, a namespace can be allocated a resource quota to avoid consuming more than its share of the physical cluster’s overall resources.
  • Deployment - describes the desired state of a pod or a replica set, in a yaml file. The deployment controller then gradually updates the environment (for example, creating or deleting replicas) until the current state matches the desired state specified in the deployment file. For example, if the yaml file defines 2 replicas for a pod but only one is currently running, an extra one will get created. Note that replicas managed via a deployment should not be manipulated directly, only via new deployments.

To prepare your local system to use Kubernetes you need to:

You can run make install in the root directory of the project to run through all these installations automatically. Make sure make is installed in your system first

  1. Install and configureaws cli on your local system. Official Docs
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Run aws configure after successful installation to set up your API keys

  1. Install kubectl. Official Docs
sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
  1. Install eksctl. Official Docs
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version
  1. Install Docker. Official Docs
sudo apt-get install \
                apt-transport-https \
                ca-certificates \
                curl \
                gnupg-agent \
                software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
                "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
                $(lsb_release -cs) \
                stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
  1. Install hadolint, for liniting Dockerfiles. Official Docs
wget https://github.com/hadolint/hadolint/releases/latest/download/hadolint-Linux-x86_64
mv hadolint-Linux-x86_64 hadolint
chmod +x hadolint
sudo mv hadolint /usr/bin

Running this project:

First you need to build the Docker Images for Blue and Green Deployments of the nodeJS app. To do that execute the following in the project root directoy:

docker build -t yourhubusername/node-docker-green ./green && \
docker build -t yourhubusername/node-docker-blue ./blue

Then push the build images to Docker hub:

docker push yourhubusername/repositoryname

Make sure you login to docker before pushing.

Now deploy the Kubernetes cluster which will host the nodeJS app using the eksctl command. It's recommended to use instance t2.medium for the nodes.

eksctl create cluster \
--name udacity-capstone \
--version 1.16 \
--region ap-south-1 \
--nodegroup-name capstone-nodes \
--node-type t2.medium \
--nodes 2 \
--nodes-min 1 \
--nodes-max 2 \
--managed

This operation is expected to take around 15-20 minutes.

After the Kubernetes cluster has been deployed. Run the following from the root directory of the project to create the blue-replication controller:

kubectl apply -f ./blue/blue-controller.yml

Repeat the same for the green controller:

kubectl apply -f green/green-controller.yml

Create the blue service to deploy the blue container to the Kubernetes cluster:

kubectl apply -f ./blue-service.yml

This will create a loadbalancer for your kubernetes cluster which you can display by using:

kubectl get svc

To shift the deployment to green, simply apply the green service:

kubectl apply -f ./green-service.yml

devops-capstone's People

Contributors

rdwns avatar

Watchers

 avatar  avatar

Forkers

salmanspice

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.