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 v1Installation
Automatically:
Run the install.sh script and all the components will be installed
./install.shManual:
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-appJenkins
Environment setup
Change the read and write permissions for docker.sock (required if using Jenkins with Docker)
chmod 666 /var/run/docker.sockSet hosts $HOME path as an environment variable inside Jenkins slave container (required for .m2 caching)
sed -i 's@<HOST_HOME_PATH>@'"$HOME"'@' ./jenkins/values.yamlCreate 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:jenkinsInstall Jenkins chart with custom values
helm install -f jenkins/values.yaml stable/jenkins --name jenkins --namespace jenkinsBuild and deploy pipelines
Required plugin: Generic Webhook Trigger Plugin
Pull the build image:
docker pull dkabh/build:v1Create a Jenkins pipeline and use this repository as SCM for the Jenkinsfile
Define these parameters inside the pipeline job:
| Parameters | Example | 
|---|---|
| MS_NAME | admin | 
| FOLDER_NAME | demo-app | 
| GITHUB_REPO | https://github.com/DKSadx/DevOps-microservices-workflow.git | 
| MICROSERVICE | admin-application | 
| BRANCH_NAME | v1 | 
| BUILD_IMAGE_NAME | build | 
| BUILD_IMAGE_TAG | v1 | 
| BUILD_CONTAINER_NAME | buildA | 
| DEPLOY_IMAGE_NAME | admin-deploy | 
| JAR_FILE | admin-application-0.0.1-SNAPSHOT | 
| DOCKER_HUB_USER | [username or repo] | 
| DOCKER_HUB_CREDENTIALS | [jenkins credentials id] | 
| CHART_NAME | demo-app | 
| CHART_PATH | ./helm-charts/demo-app | 
SonarQube job
Required plugin: GitHub Pull Request Builder
Pull the SonarQube build image:
docker pull dkabh/sq:v1Create a freestyle job, add a new build step (execute shell) and paste the code from ./helm-charts/sonarqube/jenkinsJob into the input field
| Parameters | Example | 
|---|---|
| FOLDER_NAME | demo-app | 
| BUILD_CONTAINER_NAME | buildSQ | 
| BUILD_IMAGE_NAME | dkabh/sq | 
| BUILD_IMAGE_TAG | v1 | 
| 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/chartsInstall SonarQube with custom values:
helm install -f sonarqube/values.yaml oteemocharts/sonarqube --name sonarqube --namespace sonarqubeMonitoring
Add elastic repository:
helm repo add elastic https://helm.elastic.coInstall Elasticsearch, Filebeat and Kibana.
Elasticsearch
helm install -f elasticsearch/values.yaml elastic/elasticsearch --name elasticsearch --namespace monitoringFilebeat
helm install -f filebeat/values.yaml elastic/filebeat --name filebeat --namespace monitoringKibana
helm install -f kibana/values.yaml elastic/kibana --name kibana --namespace monitoring