DevOps workflow

DevOps workflow for Java (Vaadin) app - microservices. Technologies used Docker, Jenkins, Helm, Kubernetes, Webhooks, Sonarqube, Elastic stack...

For more details and code check out the Github repo here.

Table of contents

Description:

  • Every component is deployed with Helm (Kubernetes)
  • On every pull request, GitHub will trigger Jenkins via a webhook and Jenkins will start the SonarQube code quality checks
  • After every new release (on GitHub), Jenkins will build the new Docker images, push them to Docker Hub and upgrade the app to a new version
  • Elastic stack is used for monitoring the logs

Requirements:

  • Kubernetes cluster
  • Helm
  • curl (optional)

Setup

# Clone the repository
git clone https://github.com/DKSadx/DevOps-microservices-workflow.git && cd DevOps-microservices-workflow/
# Checkout v1 branch
git checkout v1

Installation

Automatically:

Run the install.sh script and all the components will be installed

./install.sh

Manual:

cd helm-charts/

NOTE: You can change the default chart values inside the helm-charts/CHART_NAME/values.yaml file

Demo-app

Install the demo-app chart

helm install -f demo-app/values.yaml ./demo-app --name demo-app --namespace demo-app

Jenkins

Environment setup

Change the read and write permissions for docker.sock (required if using Jenkins with Docker)

chmod 666 /var/run/docker.sock

Set hosts $HOME path as an environment variable inside Jenkins slave container (required for .m2 caching)

sed -i 's@<HOST_HOME_PATH>@'"$HOME"'@' ./jenkins/values.yaml

Create ClusterRoleBinding for Jenkins (required if using kubectl or helm with Jenkins)

kubectl create clusterrolebinding permissive-binding --clusterrole=cluster-admin --user=admin --user=kubelet --group=system:serviceaccounts:jenkins

Install Jenkins chart with custom values

helm install -f jenkins/values.yaml stable/jenkins --name jenkins --namespace jenkins

Build and deploy pipelines

Required plugin: Generic Webhook Trigger Plugin

Pull the build image:

docker pull dkabh/build:v1

Create a Jenkins pipeline and use this repository as SCM for the Jenkinsfile

Define these parameters inside the pipeline job:

ParametersExample
MS_NAMEadmin
FOLDER_NAMEdemo-app
GITHUB_REPOhttps://github.com/DKSadx/DevOps-microservices-workflow.git
MICROSERVICEadmin-application
BRANCH_NAMEv1
BUILD_IMAGE_NAMEbuild
BUILD_IMAGE_TAGv1
BUILD_CONTAINER_NAMEbuildA
DEPLOY_IMAGE_NAMEadmin-deploy
JAR_FILEadmin-application-0.0.1-SNAPSHOT
DOCKER_HUB_USER[username or repo]
DOCKER_HUB_CREDENTIALS[jenkins credentials id]
CHART_NAMEdemo-app
CHART_PATH./helm-charts/demo-app

SonarQube job

Required plugin: GitHub Pull Request Builder

Pull the SonarQube build image:

docker pull dkabh/sq:v1

Create a freestyle job, add a new build step (execute shell) and paste the code from ./helm-charts/sonarqube/jenkinsJob into the input field

ParametersExample
FOLDER_NAMEdemo-app
BUILD_CONTAINER_NAMEbuildSQ
BUILD_IMAGE_NAMEdkabh/sq
BUILD_IMAGE_TAGv1
PROJECT_NAME[SQ_PROJECT_NAME]
PROJECT_URL[SQ_URL]
PROJECT_LOGIN[SQ_LOGIN_TOKEN]

WebHooks

1. For releases

Add a new webhook in the github repository settings and point it to the Jenkins public ip JENKINS_PUBLIC_IP/generic-webhook-trigger/invoke?token=TOKEN_HERE

2. For pull requests

Add a new webhook in the github repository settings and point it to the Jenkins public ip JENKINS_PUBLIC_IP/ghprbhook/

SonarQube

Plugins installed:

  • SonarJava
  • Java I18n Rules

Add SonarQube repository (stable/sonarqube is deprecated):

helm repo add oteemocharts https://oteemo.github.io/charts

Install SonarQube with custom values:

helm install -f sonarqube/values.yaml oteemocharts/sonarqube --name sonarqube --namespace sonarqube

Monitoring

Add elastic repository:

helm repo add elastic https://helm.elastic.co

Install Elasticsearch, Filebeat and Kibana.

Elasticsearch

helm install -f elasticsearch/values.yaml elastic/elasticsearch --name elasticsearch --namespace monitoring

Filebeat

helm install -f filebeat/values.yaml elastic/filebeat --name filebeat --namespace monitoring

Kibana

helm install -f kibana/values.yaml elastic/kibana --name kibana --namespace monitoring