Hands on DevOps Coaching provided on AWS and Azure Cloud platforms. please contact at devops.coaching@gmail.com for more info. You can also directly reach out to Coach AK at +1(469) 733-5248
How to Automate AKS cluster using Terraform and Azure Pipelines
What is Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS) is a managed container orchestration service, based on the open source Kubernetes system, which is available on the Microsoft Azure public cloud. AKS allows you to quickly deploy a production ready Kubernetes cluster in Azure, deploy and manage containerized applications more easily with a fully managed Kubernetes service. We will see how to create AKS cluster in Azure cloud using Terraform.
AKS cluster can be created by many ways as mentioned below:
Creating an AKS resource with Terraform is incredibly easy, it only requires a single resource azurerm_kubernetes_cluster and in this post, we are going to walk through the necessary steps to create this with Terraform. We will create ACR and create a role with ACRpull assignment as well
How to setup monitoring on AKS Cluster using Prometheus and Grafana?
Prometheus Architecture
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 tool.
It allows you to query, visualize, alert on, and explore your metrics no matter where they are stored.
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.
Below is helm command to install kube-prometheus-stack. The helm repo kube-stack-prometheus (formerly prometheus-operator) comes with a grafana deployment embedded.
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.
Clean up AKS Cluster
To avoid Azure charges, you should clean up the resources created. We can use the az group delete command to remove the resource group, AKS cluster, and all related resources.
az group delete --name myResourceGroup --yes --no-wait
Amazon Elastic Container Registry (ECR) is a fully managed Docker container registry that makes it easy to store, share, and deploy container images. We
will learn how to build docker image for a springboot microservices app
using Azure DevOps(ADO) build pipeline and push docker image into AWS
ECR.
What are we going to do in this lab?
1. Create a Repository in AWS ECR for storing docker images
2. Create an IAM user and AmazonEC2ContainerRegistryFullAccess policy.
3. Create access keys for IAM user in AWS console
4. Create service connection in AzureDevOps to connect to AWS using IAM user
access & secret keys.
5. Create Azure DevOps Build pipeline with below tasks:
maven build for building JAR
build docker image
push docker image into ECR
6. Verify if docker image has been pushed to AWS ECR
Pre-requisites:
Azure DevOps Account setup and project is created in ADO