Wednesday, July 6, 2022

How to Deploy Springboot App into AKS cluster using Azure Pipelines | Deploy Docker Containers into AKS cluster using Azure Rlease Pipelines | Deploy Microservices into AKS cluster using Azure Pipelines

We are going to learn how to deploy Springboot Microservices Docker containers into Azure Kubernetes Cluster(AKS) using Azure pipelines. I have created a sample Springboot App setup in GitHub. Click here to access code base in GitHub.


Watch the steps in YouTube Channel:

Pre-requisites:

1. AKS cluster needs to be up running. You can create AKS cluster using any of one of the below options:

2. ACR is also setup in Azure cloud. 
3.  Have Azure DevOps project dashboard in 
4. Dockerfile created along with the application source code for springboot App.
6. Modify K8S manifest file per acr, image name for AKS Deployment




Implementation Steps:

Step 1 - Create Azure Build pipeline for building Docker images and uploading into ACR
Step 2 - Create Azure Release pipeline for deploying Springboot Docker containers into AKS
 
Step 1 - How to create a Azure Build Pipeline

1. Login into your Azure DevOps dashboard
2. Click on Pipelines.

3. Click on New Pipeline

4. Click on use the classic editor
Enter your repo name and branch name where you have stored your source code along with Dockerfile:



Click on Continue. Now choose the template by typing Docker, Select Docker container and Apply.
 

Now pipeline is created with two tasks already. We need to more tasks:
Let's add Maven build task for building the JAR file.
Click on + icon and type Maven
And then enter maven goal as package



Let's modify Build an image task.


Select Push an image task

Add a task for Copying YAML file, enter the Kubernetes deployment YAML file - 

Add Publish artifact task


Now click Save + Queue and run to start Building the pipeline



Once the build is completed, you should be able to see the Docker images under 
Services --> Repositories


Step 2 - How to Create Release pipeline for deploying Docker containers into AKS Cluster 

Go to Pipelines --> Click on Releases --> New Release pipeline

Click on Stage 1 and choose a template by selecting
Deploy to a Kubernetes cluster and click on Apply


Change the stage name to Deploy to AKS


Now click on Add an artifact


Select the Build pipeline and click on the latest version

Now click on Deploy to AKS stage
Add Replace token task

Click on + to add task, type token and choose replace token task. 


Now click on replace token task and Clik on root directory, click on ... dots
 select the drop directory from below:



and enter Target file as  aks-deploy-from-acr.yaml





Click on kubectl apply


Now Click on New to enter AKS cluster connection info


Choose the Azure subscription and enter Microsoft user credentials.



Select AKS cluster from the drop down, choose default namespace


Choose command as apply and select the yaml file from the dropdown from Configuration file 



Now click on Save,
Click on Create a release

and then click Create to run the deployment


Click on Stage to see the logs

Now you will see the following tasks are in green to confirm Deployment was successful.



Let's check if deployment created any pods

kubectl get deployments


kubectl get pods


kubectl get svc

Now try to access spring boot application running inside AKS cluster by using external IP and port number


Go to the browser enter http://external IP

Thursday, May 26, 2022

How to setup monitoring on Kubernetes Cluster using Prometheus and Grafana | Setup monitoring on EKS Cluster using Prometheus and Grafana

 

What is Prometheus?

  • Prometheus is an open source monitoring tool
  • Provides out-of-the-box monitoring capabilities for the Kubernetes container orchestration platform. It can monitor servers and databases as well.
  • Collects and stores metrics as time-series data, recording information with a timestamp 
  • It is based on pull and collects metrics from targets by scraping metrics HTTP endpoints.

What is Grafana?

  • Grafana is an open source visualization and analytics software. 
  • It allows you to query, visualize, alert on, and explore your metrics no matter where they are stored.
Please Watch this steps in YouTube Channel:

Prometheus Architecture


Key components:

    1. Prometheus server - Processes and stores metrics data
    2. Alert Manager - Sends alerts to any systems/channels
    3. Grafana - Visualize scraped data in UI

Installation Method

The are are many ways you can setup Prometheus and Grafana. You can install in following ways:

1. Create all configuration files of both Prometheus and Grafana and execute them in right order.

2. Prometheus Operator - to simplify and automate the configuration and management of the Prometheus monitoring stack running on a Kubernetes cluster

3. Helm chart (Recommended) - Using helm to install Prometheus Operator including Grafana

Why to use Helm?

Helm is a package manager for Kubernetes. Helm simplifies the installation of all components in one command. Install using Helm is recommended as you will not be missing any configuration steps and very efficient. 

Prerequisites

Implementation steps

We need to add the Helm Stable Charts for your local client. Execute the below command:

helm repo add stable https://charts.helm.sh/stable


# Add prometheus Helm repo
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts


helm search repo prometheus-community

Prometheus and grafana helm chart moved to kube prometheus stack

Create Prometheus namespace
kubectl create namespace prometheus


Below is helm command to install kube-prometheus-stack. The helm repo kube-stack-prometheus (formerly prometheus-operator) comes with a grafana deployment embedded.

helm install stable prometheus-community/kube-prometheus-stack -n prometheus
Lets check if prometheus and grafana pods are running already

kubectl get pods -n prometheus


kubectl get svc -n prometheus


This confirms that prometheus and grafana have been installed successfully using Helm.

In order to make prometheus and grafana available outside the cluster, use load balancer or NodePort.

Edit Prometheus Service

kubectl edit svc stable-kube-prometheus-sta-prometheus -n prometheus

Edit Grafana Service

kubectl edit svc stable-grafana -n prometheus

Verify if service is changed to LoadBalancer and also to get the Load Balancer URL.

kubectl get svc -n prometheus


Access Grafana UI in the browser

Get the URL from the above screenshot and put in the browser


UserName: admin
Password: prom-operator

Create Dashboard in Grafana

In Grafana, we can create various kinds of dashboards as per our needs.

How to Create Kubernetes Monitoring Dashboard?

For creating a dashboard to monitor the cluster:


Click '+' button on left panel and select ‘Import’.

Enter 12740 dashboard id under Grafana.com Dashboard.

Click ‘Load’.

Select ‘Prometheus’ as the endpoint under prometheus data sources drop down.

Click ‘Import’.


This will show monitoring dashboard for all cluster nodes



How to Create Kubernetes Cluster Monitoring Dashboard?

For creating a dashboard to monitor the cluster:


Click '+' button on left panel and select ‘Import’.

Enter 3119 dashboard id under Grafana.com Dashboard.

Click ‘Load’.

Select ‘Prometheus’ as the endpoint under prometheus data sources drop down.

Click ‘Import’.

This will show monitoring dashboard for all cluster nodes









    Create POD Monitoring Dashboard

    For creating a dashboard to monitor the cluster:


    Click '+' button on left panel and select ‘Import’.

    Enter 6417 dashboard id under Grafana.com Dashboard.

    Click ‘Load’.

    Select ‘Prometheus’ as the endpoint under prometheus data sources drop down.

    Click ‘Import’.



    This will show monitoring dashboard for all cluster nodes.





    No such property: docker for class: groovy.lang.Binding | Jenkins Pipeline Error Docker Build | Jenkins docker pipeline error

     Jenkins Pipeline Error: 

    groovy.lang.MissingPropertyException: No such property: docker for class: groovy.lang.Binding.

    We most likely encountered the same issue, in order to fix it, install Docker Pipeline plugin in Jenkins:

    Root Cause and Fix:

    Jenkins need to have Docker Pipeline plug-in to perform Docker builds.

    Jenkins > Manage Jenkins > Manage Plugins > Available tab

    Search for Docker Pipeline install it, restart Jenkins and you are ready to go.