<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Louay Kharouf on Medium]]></title>
        <description><![CDATA[Stories by Louay Kharouf on Medium]]></description>
        <link>https://medium.com/@louay.khrouf?source=rss-54381b85545e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*020gdZ_gL3Z40TiJ</url>
            <title>Stories by Louay Kharouf on Medium</title>
            <link>https://medium.com/@louay.khrouf?source=rss-54381b85545e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 01:30:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@louay.khrouf/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deployment of Dynatrace on an EKS cluster using Gitlab]]></title>
            <link>https://medium.com/@louay.khrouf/deployment-of-dynatrace-on-an-eks-cluster-using-gitlab-7eba2e73b624?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eba2e73b624</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Mon, 20 Jan 2025 15:52:16 GMT</pubDate>
            <atom:updated>2025-01-20T16:07:53.588Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will discuss the process of automating the monitoring of an EKS cluster using Dynatrace and GitLab.</p><h4>Tools to use</h4><ul><li>Dynatrace</li><li>Gitlab</li><li>Terraform</li></ul><h4>Github Repo</h4><p><a href="https://github.com/LouayKharouf26/Dynatrace-Deployment.git">GitHub - LouayKharouf26/Dynatrace-Deployment</a></p><h4>Dynatrace</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/0*biTtFr-FH7Mk1nYy" /></figure><p>Dynatrace is a software intelligence platform for dynamic, cloud-native environments, offering real-time observability into application performance, infrastructure, and user experience. Leveraging AI and automation, it helps organizations monitor and optimize their tech stack, detect problems proactively, and improve digital services, ensuring reliable performance across complex IT ecosystems.</p><p>In order to ensure the real time monitoring Dynatrace relies on a component called OneAgent responsible for collecting the metrics and the real time monitoring</p><p><strong>OneAgent</strong></p><p>Dynatrace OneAgent is a lightweight monitoring solution that automatically discovers and instruments applications, services, and infrastructure. It provides deep visibility into performance and health by capturing metrics, traces, and logs with minimal overhead. OneAgent simplifies monitoring by eliminating manual configuration and multiple agents, enabling seamless integration, real-time observability, and quick issue resolution for optimized performance and user experience.</p><p><strong>Carbon Impact</strong></p><p>The Dynatrace Carbon Impact module helps organizations track and reduce their carbon footprint by providing insights into the energy consumption and environmental impact of their IT operations. It integrates seamlessly with existing monitoring capabilities, offering real-time data on resource usage and emissions. By analyzing this information, teams can identify inefficiencies, optimize resource utilization, and make data-driven decisions to lower their carbon impact, contributing to more sustainable and eco-friendly IT practices.</p><h4>Terraform</h4><p>Terraform is used to automate the provision of the EKS cluster for this we need to provision first an S3 bucket in order to store the terraform state.</p><p>The terraform file responsible for the provision of the bucket is the following</p><pre>provider &quot;aws&quot; {<br>    region = var.region<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;state&quot; {<br>  bucket = &quot;${var.aws_account_id}-bucket-state-file-dynatrace&quot;<br><br>  tags = {<br>    Environment = var.environment<br>  }<br>}</pre><p>The second usage of terraform is the provision of the EKS cluster for this we use the following file</p><pre>provider &quot;aws&quot; {<br>    region = var.region<br>}<br><br>terraform {<br>  backend &quot;s3&quot; {<br>    bucket = &quot;${var.aws_account_id}-bucket-state-file-dynatrace&quot;<br>    key    = &quot;eks-dynatrace.tfstate&quot;<br>    region = &quot;eu-west-3&quot;<br>  }<br>  <br>  required_providers {<br>    kubectl = {<br>      source  = &quot;gavinbunney/kubectl&quot;<br>      version = &quot;~&gt; 1.14&quot;<br>    }<br>  }<br>}<br>data &quot;aws_caller_identity&quot; &quot;current&quot; {}<br><br>data &quot;aws_eks_addon_version&quot; &quot;ebs_csi&quot; {<br>  addon_name         = &quot;aws-ebs-csi-driver&quot;<br>  kubernetes_version = &quot;1.30&quot;<br>  most_recent        = true<br>}<br><br>module &quot;vpc&quot; {<br>  source  = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;5.13.0&quot;<br><br>  name = &quot;${var.app_name}-vpc&quot;<br>  cidr = &quot;10.0.0.0/16&quot;<br><br>  azs             = [&quot;${var.region}a&quot;, &quot;${var.region}b&quot;, &quot;${var.region}c&quot;]<br>  private_subnets = [&quot;10.0.1.0/24&quot;, &quot;10.0.2.0/24&quot;, &quot;10.0.3.0/24&quot;]<br>  public_subnets  = [&quot;10.0.101.0/24&quot;, &quot;10.0.102.0/24&quot;, &quot;10.0.103.0/24&quot;]<br>  intra_subnets   = [&quot;10.0.104.0/24&quot;, &quot;10.0.105.0/24&quot;, &quot;10.0.106.0/24&quot;]<br><br>  enable_nat_gateway     = true<br>  single_nat_gateway     = true<br>  one_nat_gateway_per_az = false<br><br>  private_subnet_tags = {<br>    &quot;kubernetes.io/role/elb&quot; = 1<br>  }<br><br>  public_subnet_tags = {<br>    &quot;kubernetes.io/role/internal-elb&quot; = 1<br>  }<br><br>  tags = {<br>    Terraform   = &quot;true&quot;<br>    Environment = var.environment<br>  }<br>}<br><br>module &quot;kms&quot; {<br>  source  = &quot;terraform-aws-modules/kms/aws&quot;<br>  version = &quot;3.1.0&quot;<br><br>  description = &quot;EKS Cluster&quot;<br>  key_usage   = &quot;ENCRYPT_DECRYPT&quot;<br><br>  # Policy<br>  key_administrators                 = [data.aws_caller_identity.current.arn]<br>  key_owners                         = [data.aws_caller_identity.current.arn]<br>  key_service_roles_for_autoscaling  = [&quot;arn:aws:iam::${var.aws_account_id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling&quot;]<br><br>  # Aliases<br>  aliases = [&quot;eks/${var.app_name}&quot;]<br><br>  tags = {<br>    Terraform   = &quot;true&quot;<br>    Environment = var.environment<br>  }<br>}<br>module &quot;eks&quot; {<br>  source  = &quot;terraform-aws-modules/eks/aws&quot;<br>  version = &quot;20.23.0&quot;<br><br>  cluster_name    = var.app_name<br>  cluster_version = &quot;1.30&quot;<br><br>  cluster_endpoint_public_access  = true<br><br>  cluster_addons = {<br>    coredns                = {}<br>    eks-pod-identity-agent = {}<br>    kube-proxy             = {}<br>    vpc-cni                = {}<br>  }<br><br>  vpc_id                   = module.vpc.vpc_id<br>  subnet_ids               = module.vpc.private_subnets<br>  control_plane_subnet_ids = module.vpc.intra_subnets<br><br>  # EKS Managed Node Group(s)<br>  eks_managed_node_group_defaults = {<br>    instance_types = [&quot;t3.medium&quot;]<br>  }<br><br>  eks_managed_node_groups = {<br>    &quot;${var.app_name}-ng&quot; = {<br><br>      ami_type       = &quot;AL2023_x86_64_STANDARD&quot;<br>      instance_types = [&quot;t3.medium&quot;]<br><br>      min_size     = 2<br>      max_size     = 10<br>      desired_size = 2<br><br>      block_device_mappings = {<br>        xvda = {<br>          device_name = &quot;/dev/xvda&quot;<br>          ebs = {<br>            volume_size           = 20<br>            volume_type           = &quot;gp3&quot;<br>            iops                  = 3000<br>            throughput            = 125<br>            encrypted             = true<br>            kms_key_id            = module.kms.key_arn<br>            delete_on_termination = true<br>          }<br>        }<br>      }<br><br>    }<br>  }<br><br><br>  enable_cluster_creator_admin_permissions = true<br><br>  create_kms_key = false<br>  cluster_encryption_config = {<br>    resources        = [&quot;secrets&quot;]<br>    provider_key_arn = module.kms.key_arn<br>  }<br><br>  tags = {<br>    Environment = var.environment<br>    Terraform   = &quot;true&quot;<br>  }<br>}<br><br>module &quot;ebs_csi_irsa_role&quot; {<br>  source  = &quot;terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks&quot;<br>  version = &quot;5.44.0&quot;<br><br>  role_name = &quot;${var.app_name}-ebs-csi&quot;<br><br>  attach_ebs_csi_policy = true<br>  ebs_csi_kms_cmk_ids   = [module.kms.key_arn]<br><br>  oidc_providers = {<br>    ex = {<br>      provider_arn               = module.eks.oidc_provider_arn<br>      namespace_service_accounts = [&quot;kube-system:ebs-csi-controller-sa&quot;]<br>    }<br>  }<br><br>  tags = {<br>    Environment = var.environment<br>    Terraform   = &quot;true&quot;<br>  }<br>}<br><br>resource &quot;aws_eks_addon&quot; &quot;ebs_csi&quot; {<br>  cluster_name = module.eks.cluster_name<br>  addon_name   = &quot;aws-ebs-csi-driver&quot;<br><br>  addon_version               = data.aws_eks_addon_version.ebs_csi.version<br>  resolve_conflicts_on_update = &quot;PRESERVE&quot;<br>  service_account_role_arn    = module.ebs_csi_irsa_role.iam_role_arn<br><br>  tags = {<br>    Environment = var.environment<br>    Terraform   = &quot;true&quot;<br>  }<br>}</pre><p>This terraform file will just be responsible to provision the EKS cluster with its own network configurations and addons.</p><h4>Dynatrace configuration</h4><p>In order to monitor the EKS using Dynatrace we have to deploy Dynatrace OneAgent on our cluster therefore we need to have the configuration as a yaml file to be deployed in the cluster and in order to get this deployment file we need to navigate to OneAgent deployment on the dynatrace portal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*yVNPEmOPTn6BoT-EzxS3-g.png" /></figure><p>Here we choose Kubernetes and we be redirected to the setup page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*yq1yU8uLbMTwMDQyeLdMuw.png" /></figure><p>Now our deployment file is ready and it looks like the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*nGDAq-JgYmZiVun8VplgkA.png" /></figure><p>The rest of the file is on the github repository</p><h4>Gitlab CI/CD</h4><p>To automate the provisioning and the deployment of dynatrace we use the following Gitlab</p><pre>stages:<br>  - setup<br>  - terraform_bucket<br>  - terraform_eks <br>  - cluster_connection<br>  - dynatrace_eks<br>  - fetch_metrics<br><br>variables:<br>  AWS_ACCESS_KEY_ID: &quot;&quot;<br>  AWS_SECRET_ACCESS_KEY: &quot;&quot;<br><br>before_script:<br>  - apt-get update -y<br>  # Install AWS CLI<br>  - curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>  - unzip awscliv2.zip<br>  - ./aws/install<br>  # Install Terraform<br>  - apt-get update &amp;&amp; apt-get install -y wget unzip curl<br>  - wget https://releases.hashicorp.com/terraform/1.10.3/terraform_1.10.3_linux_amd64.zip<br>  - unzip terraform_1.10.3_linux_amd64.zip<br>  - mv terraform /usr/local/bin/<br>  - terraform --version<br><br>  # Install Helm<br>  - curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash<br>  - helm version<br><br>  # Install kubectl<br>  - curl -LO &quot;https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl&quot;<br>  - install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl<br>  - kubectl version --client<br><br>setup: <br>  stage: setup<br>  script: <br>    - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID<br>    - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY<br>    - terraform version<br>terraform_bucket:<br>  stage: terraform_bucket<br>  script:<br>     - cd bucket<br>     - terraform init -upgrade<br>     - terraform apply --auto-approve -var-file=&quot;./terraform.tfvars&quot;<br><br>terraform_eks:<br>  stage: terraform_eks<br>  script:<br>     - cd eks-terraform<br>     - terraform init -upgrade<br>     - terraform apply --auto-approve -var-file=&quot;./terraform.tfvars&quot;<br><br>cluster_connection: <br>  stage: cluster_connection<br>  script: <br>      - aws eks update-kubeconfig --region eu-west-3 --name dynatrace<br><br>dynatrace_eks:<br>  stage: dynatrace_eks<br>  script: <br>    - aws eks update-kubeconfig --region eu-west-3 --name dynatrace<br>    - kubectl get nodes<br>    - helm install dynatrace-operator oci://public.ecr.aws/dynatrace/dynatrace-operator --create-namespace --namespace dynatrace<br>    - echo &quot;Waiting for 5 minutes before applying dynakube...&quot;<br>    - sleep 300<br>    - kubectl apply -f dynakube.yaml<br><br>fetch_metrics:<br>  stage: fetch_metrics<br>  image: python:3.9  <br>  before_script:<br>    - pip install --upgrade pip<br>    - pip install requests matplotlib<br>  script:<br>    - echo &quot;Waiting for 5 minutes before fetching metrics...&quot;<br>    - sleep 300<br>    - python dynatrace.py <br>  artifacts:<br>    paths:<br>      - metrics.csv  <br>      - plot.png</pre><p>Our pipeline will have 6 stages</p><p>The first stage is to connect to aws and validate the configurations</p><p>The second stage is for the provisioning of the s3 bucket</p><p>Third stage is reponsible to provision the EKS cluster</p><p>Fourth stage is the connection to the EKS cluster in order to be able to use helm and kubectl</p><p>The stage five is the deployment of dynatrace on the first level we need to create a namespace and then we install dynatrace operator and after it we only deploy the Yaml configuration that we got earlier</p><p>The last stage is to fetch metrics that we discuss later on</p><p>Once the stages are passed we get the following hosts on Dynatrace</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yMsNKOKgaKO-HGU82Izemw.png" /></figure><p>This hosts presents the node managers</p><p>Here we see our cluster also being monitored</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKAnMSLMkY4fosJ5J3p1gg.png" /></figure><h4>Fetching metrics</h4><p>In order to automate fetching the metrics (such the CPU, network, memory and even the energy consumption) and integrate it in the pipeline to be used in future we adopt the following python script</p><pre>import requests<br>import csv<br>import matplotlib.pyplot as plt<br>from datetime import datetime<br><br># Dynatrace API configuration<br>DT_API_TOKEN = &quot;&quot;<br>DT_BASE_URL = &quot;https://stm14109.live.dynatrace.com/api/v2/metrics/query&quot;<br><br># Query parameters for carbon measurement<br>carbon_query = &quot;&quot;&quot;<br>fetch bizevents<br>| filter contains (event.provider, &quot;dynatrace.biz.carbon&quot;)<br>| filter contains (event.type, &quot;carbon.measurement&quot;)<br>| summarize totalEnergy = sum(energy.measurement.computing), totalCO2e = sum(carbon.emissions), by:dt.entity.host<br>&quot;&quot;&quot;<br>carbon_url = &quot;https://stm14109.live.dynatrace.com/api/v2/events&quot;  <br><br><br>headers = {<br>    &quot;Authorization&quot;: f&quot;Api-Token {DT_API_TOKEN}&quot;<br>}<br><br><br>response_carbon = requests.get(carbon_url, headers=headers, params={&quot;query&quot;: carbon_query})<br><br>if response_carbon.status_code == 200:<br>    carbon_data = response_carbon.json()<br><br><br>    host_names = []<br>    total_energy = []<br>    total_co2e = []<br><br>    if &quot;result&quot; in carbon_data:<br>        for event in carbon_data[&quot;result&quot;]:<br>            host_names.append(event.get(&quot;dt.entity.host&quot;, &quot;Unknown&quot;))<br>            total_energy.append(event.get(&quot;totalEnergy&quot;, 0))<br>            total_co2e.append(event.get(&quot;totalCO2e&quot;, 0))<br>    else:<br>        print(&quot;No carbon measurement data found.&quot;)<br><br>   <br>    metric_selector = &quot;builtin:host.cpu.usage&quot; <br>    timeframe = &quot;now-1h&quot;  <br>    params = {<br>        &quot;metricSelector&quot;: metric_selector,<br>        &quot;resolution&quot;: &quot;1m&quot;  <br>    }<br><br>    # Fetch CPU usage data<br>    response_cpu = requests.get(DT_BASE_URL, headers=headers, params=params)<br><br>    # Check if the request was successful for CPU data<br>    if response_cpu.status_code == 200:<br>        data = response_cpu.json()<br><br>        # Parse and save to CSV<br>        timestamps_list = []<br>        values_list = []<br>        if &quot;result&quot; in data and data[&quot;result&quot;]:<br>            metric_results = data[&quot;result&quot;][0]<br>            with open(&quot;metrics.csv&quot;, &quot;w&quot;, newline=&quot;&quot;) as csvfile:<br>                writer = csv.writer(csvfile)<br>                # Write header with Host, CPU Usage, Energy, CO2<br>                writer.writerow([&quot;Timestamp&quot;, &quot;Value&quot;, &quot;Host&quot;, &quot;Total Energy&quot;, &quot;Total CO2e&quot;])<br><br>                # Extract and write metric data<br>                if &quot;data&quot; in metric_results:<br>                    for datapoint in metric_results[&quot;data&quot;]:<br>                        timestamps = datapoint.get(&quot;timestamps&quot;, [])<br>                        values = datapoint.get(&quot;values&quot;, [])<br>                        for ts, value in zip(timestamps, values):<br>                           <br>                            host = host_names.pop(0) if host_names else &quot;Unknown&quot;<br>                            energy = total_energy.pop(0) if total_energy else 0<br>                            co2e = total_co2e.pop(0) if total_co2e else 0<br>                            <br>                            # Write data to CSV<br>                            writer.writerow([ts, value, host, energy, co2e])<br>                            timestamps_list.append(datetime.utcfromtimestamp(ts / 1000))  # Convert from ms to datetime<br>                            values_list.append(value)<br><br>            print(&quot;Metrics with carbon data saved to metrics.csv&quot;)<br><br>            plt.figure(figsize=(10, 5))<br>            plt.plot(timestamps_list, values_list, marker=&#39;o&#39;, linestyle=&#39;-&#39;, color=&#39;b&#39;)<br>            plt.title(&quot;CPU Usage Over Time&quot;)<br>            plt.xlabel(&quot;Time&quot;)<br>            plt.ylabel(&quot;CPU Usage (%)&quot;)<br>            plt.grid()<br>            plt.xticks(rotation=45)<br>            plt.tight_layout()<br>            plt.savefig(&quot;plot.png&quot;)<br>            plt.show()<br>        else:<br>            print(&quot;No CPU data found or invalid response format.&quot;)<br>    else:<br>        print(f&quot;API call for CPU data failed with status code {response_cpu.status_code}: {response_cpu.text}&quot;)<br>else:<br>    print(f&quot;API call for carbon data failed with status code {response_carbon.status_code}: {response_carbon.text}&quot;)</pre><p>This script will at the first level use the dynatrace api to fetch the metrics (CPU and energy in this case) and then save it in a csv file. At a second level we use python package to plot the CPU usage over time and this will plot a graph of this usage similar to the one on the dashboard.</p><p>The files we find them as artifact of the pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8SICjT-D2zHDpPCmhcGfLQ.png" /></figure><p>The csv file and the graph will be like the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*xaQGSD2GkUTvL45PvSCQ2g.png" /></figure><p>In order to get the other metrics it is just required to update the script with the required metric</p><p>Finally i hope that this article was usefull and it was not that much long</p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eba2e73b624" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Todo CRUD to AWS Lambda]]></title>
            <link>https://awstip.com/deploying-todo-crud-to-aws-lambda-96de686aa47b?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/96de686aa47b</guid>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Mon, 19 Aug 2024 23:37:25 GMT</pubDate>
            <atom:updated>2024-08-21T18:21:59.144Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i am going to details the steps necessary to deploy a nodeJS CRUD with AWS DynamoDB as a database on a serverless architecture using AWS Lambda</p><h4><strong>Tools to use</strong></h4><ul><li>DynamoDB</li><li>AWS Lambda</li><li>API Gateway</li></ul><h4><strong>Github Repo</strong></h4><p><a href="https://github.com/LouayKharouf26/Todo_API_Serverless.git">GitHub - LouayKharouf26/Todo_API_Serverless</a></p><p>lets start by a quick overview of the whole architecture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*nwC0_Xrm6jQvcCnFGbmGTA.png" /><figcaption>Architecture Overview</figcaption></figure><p>So the user will send requests through the API Gateway this requests will trigger the AWS lambda that will execute the functions based on the logic defined on the handler . DynamoDB will store the data and AWS IAM will be responsible of the access permissions needed by lambda to scan the tables , add elements to the tables and read elements to the tables on DynamoDB</p><p>lets go now by details for each component of the diagram</p><h4><strong>AWS API Gateway</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/0*LZuMAhXH-wIZ067P.png" /></figure><p>AWS API Gateway is a service responsible for creating and publishing Rest , HTTP , websocket api at any scale . API gateway is used to create RESTfull api that can implement HTTP methods such as GET , PUT , DELETE , POST … and this implement stateless client-server communication.</p><h4><strong>AWS Lambda</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*HJMvj_LEagcnx3Ck.png" /></figure><p>AWS Lambda is a service given by AWS that allows to run the code without provisioning or managing infrastructure . Instead of setting up and maintaining a server to run the code, the user can hand it off to AWS Lambda. Users just write the code, and Lambda takes care of the rest. When the event occurs, Lambda instantly springs into action, runs the code, and scales automatically to handle as many requests as needed. The lambda function will be executed by a trigger which is an event such a http request recieved through an api gateway and that will instantly execute the function to serve the requests .</p><h4><strong>DynamoDB</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/0*Jk3VgVOHwtW-aVU4.png" /></figure><p>Amazon DynamoDB is a fully managed NoSQL database service designed for fast and predictable performance. It allows users to store and retrieve any amount of data with automatic scaling, high availability, and low latency.</p><h4>AWS IAM</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UvQotrmoNfkeDszx.png" /></figure><p>AWS Identity and Access Management (IAM) is a service that helps you securely manage access to AWS resources. It allows users to create and manage users, groups, and roles, and define their permissions using policies. With IAM, users can control who can access specific resources and what actions they can perform, ensuring that only authorized users can interact with the AWS environment.</p><h4>Implementation</h4><p>The implementation will take few steps</p><p>the first thing is to prepare the handler and the controller of our Todo API</p><p>The controller will be the code of the CRUD made on nodeJS it will be just by creating tasks , listing the tasks , updating or deleting specific tasks</p><p>the full code of the controller is in the <a href="https://github.com/LouayKharouf26/Todo_API_Serverless.git">github repository</a></p><p>The handler is the code that will be executed by the lambda function this handler will be responsible on handling the routes and executing the CRUD</p><p>The full code of the handler is in the <a href="https://github.com/LouayKharouf26/Todo_API_Serverless.git">github repository</a> too</p><p>The records will be stored in the dynamoDB database</p><p>The first step will be then to create the DynamoDB table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*dBXK1m9xyG9x-zMLsIR7gQ.png" /><figcaption>DynamoDB Table</figcaption></figure><p>So the table will be Todo and we define the id as a partition key</p><p>The partition key is a primary attribute that determines how data is distributed across underlying partitions</p><p>moving now to create our lambda function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*9Ym1qimAdV1KlxkooUb1eA.png" /><figcaption>Lambda</figcaption></figure><p>The function will take TodoAPI as name and will use NodeJS 20 as a runtime</p><p>once the function is created we will be redirected and invited to add the code of our application because we choose the option of creating the function from zero</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jziqk1XTuEcWWDycXCETwQ.png" /><figcaption>Lambda Code</figcaption></figure><p>So in the code tab we add the index.js that will contain the handler and the controller of our CRUD</p><p>lets just test our api</p><p>before testing we have to add The permissions to get a full access to the Todo table on dynamoDB as the following</p><p>navigating to the IAM then to roles and we choose the role of our lambda and we add the json containing the permessions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*oCtdF7CPNJ5tNIJGKLR-Og.png" /></figure><p>this json will just give a full access to the dynamodb table</p><p>Now we can easly test our lambda by sending a post request as the following json says</p><pre>{<br>  &quot;httpMethod&quot;: &quot;POST&quot;,<br>  &quot;headers&quot;: {<br>    &quot;Content-Type&quot;: &quot;application/json&quot;<br>  },<br>  &quot;body&quot;: &quot;{\&quot;title\&quot;:\&quot;task6\&quot;,\&quot;description\&quot;:\&quot;This is a sample task description.\&quot;}&quot;,<br>  &quot;isBase64Encoded&quot;: false<br>}</pre><p>This will send a post request and add a task to the database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x60qCDk1InLL5O_fcGOcXQ.png" /></figure><p>here we can see that the todo is added successfully</p><p>we can check this in the table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IQalQXhCePLwBTX8EDyxnQ.png" /></figure><p>so the todo is successfully added</p><p>lets go now to deal with the API Gateway</p><p>we start by choosing http API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*8c3GBjXh7zsINOulDVmE7A.png" /></figure><p>and then indicate that it will be using the lambda so in the integration we indicate that it will be a lambda and then we give it a name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*vsP5FF4f_75nBgnSq6iL9w.png" /></figure><p>the next step is where we define our routes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*-uvac6u96tI9vE8UINsiEA.png" /></figure><p>and then we check the deployment stage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*-xx7j3lqQupN_bblzczj-Q.png" /></figure><p>and in the end we get the URL of the API gateway</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UYG7wKUjwFkITEgn22c_WQ.png" /></figure><p>at the level of the lambda we add a trigger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fP3v9oLGn1oYcFt_84fTKg.png" /></figure><p>and now we can test the gettodos with postman</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*xpO9qen1XUtI_7oOnJyevA.png" /></figure><p>and as we see it fetch the data from dynamodb .</p><p>Finally i hope that this article was usefull and it was not that much long</p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96de686aa47b" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/deploying-todo-crud-to-aws-lambda-96de686aa47b">Deploying Todo CRUD to AWS Lambda</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate the Deployment of a web Application on EC2 instance using Gitlab]]></title>
            <link>https://awstip.com/automate-the-deployment-of-a-web-application-on-ec2-instance-using-gitlab-cb2854288013?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb2854288013</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Mon, 27 May 2024 07:34:08 GMT</pubDate>
            <atom:updated>2024-05-27T10:44:29.044Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i m going to explain how to automate the process of deploying a web application developed using laravel on an AWS EC2 intance created using terraform and configured using ansible</p><h3>Tools to use</h3><ul><li>Gitlab</li><li>Terraform</li><li>Ansible</li></ul><h3>Github Repo</h3><p><a href="https://github.com/LouayKharouf26/TodoAPP-aws.git">GitHub - LouayKharouf26/TodoAPP-aws</a></p><h3>Gitlab</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*j9boagG4l5NYyP36MhE1cQ.png" /></figure><h4>what is gitlab ?</h4><p>GitLab is an Open Source code repository and collaborative software development platform for large DevOps and DevSecOps projects</p><h4>Gitlab CI / CD</h4><p>GitLab CI/CD can catch bugs early in the development cycle, and help ensure that the code deployed to production complies with your established code standards.</p><p>So to use the gitlab CI / CD solution we have to follow this steps</p><h4>gitlab-ci yaml file :</h4><p>This file specifies the stages, jobs, and scripts to be executed during our CI/CD pipeline</p><p>our file will look like this</p><pre>stages:<br>  - setup<br>  - deploy<br>  - terraform <br>  - ansible <br><br>variables:<br>  AWS_ACCESS_KEY_ID: &quot;&quot;<br>  AWS_SECRET_ACCESS_KEY: &quot;&quot;<br><br>before_script:<br>  - apt-get update -y<br><br>setup: <br>  stage: setup<br>  script: <br>    - apt-get install -y curl unzip gnupg<br>  # Install AWS CLI<br>    - curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>    - unzip awscliv2.zip<br>    - ./aws/install<br>  # Install Terraform<br>    - curl -fsSL https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_linux_amd64.zip -o /tmp/terraform.zip<br>    - unzip /tmp/terraform.zip -d /usr/local/bin/<br>  # Install Ansible<br>    - echo &quot;deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main&quot; | tee /etc/apt/sources.list.d/ansible.list<br>    - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367<br>    - apt-get update -qy<br>    - apt-get install -y ansible<br>  # Verify Ansible installation<br>    - ansible --version<br>  # Create the SSH private key file<br>    - mkdir -p ~/.ssh<br>  #- echo &quot;$SSH_PRIVATE_KEY&quot; | tr -d &#39;\r&#39; &gt; ~/.ssh/id_rsa<br>    - cat &quot;$SSH_PRIVATE_KEY&quot; &gt;&gt; ~/.ssh/id_rsa<br> # - chmod 700 ~/.ssh<br>    - chmod 400 ~/.ssh/id_rsa<br>    - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID<br>    - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY<br><br>deploy:<br>  stage: deploy<br>  script:<br>    - aws --version<br>    - ansible --version<br>    # Verify Terraform installation<br>    - terraform version<br>    # Verify Ansible installation<br>    - ansible --version<br><br><br>terraform:<br>  stage: terraform<br>  script:<br>     - cd Aws_Terraform<br>     - terraform init -upgrade<br>     - terraform apply --auto-approve -var-file=&quot;./keys.tfvars&quot;<br><br>ansible:<br>  stage: ansible<br>  script:<br>    - cd ansible<br>    - ansible-playbook update-hosts.yml<br>    - cat hosts<br>    - ansible-playbook -i hosts web-app-config.yml --private-key=~/.ssh/id_rsa --ssh-common-args=&#39;-o StrictHostKeyChecking=no&#39;</pre><p>so our pipeline will have 4 stages the setup the deploy the terraform and the ansible</p><p>The variables part is used to declare variables that are going to be used in the scripts of each stage</p><p>The before script part is used to define a set of commands that should be run before each job in our pipeline</p><p>The setup stage is used to install all the necessary tools that we are going to use like aws -cli , ansible and terraform and then we login to the aws-cli</p><p>The deploy stage is just a stage we use to verify the installations of our tools</p><p>Terraform stage is used to provision the necessary infrastructure which is an EC2 instance in our case</p><p>Ansible stage is used to run the playbooks available for the configuration of the EC2 instance</p><p>and in the end we have our pipeline successfully running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*YD90fbpDxwligyl6-Iu7_Q.png" /></figure><p>and as everything is successfully running we can see our EC2 instance in aws console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*kL2c1Fr0MvckaBHugfM40g.png" /></figure><p>so we can see that our instance is running well which was provisionned by terraform</p><p>if we see the logs of the ansible stage it will looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*fP_61ccvbz6CcSxQrfemgw.png" /></figure><p>let’s just ssh to the ec2 instance and verify that the containers are running well</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*HtMJ7pIkfkWJ-i8mfbP7ZA.png" /></figure><p>and now we can open the url in the format public_ip:port and we will see our app served already</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*BqHyudGhkxFa8XsINiZtqA.png" /></figure><p>we can login and see our user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Pzw1y7g_q3zCM6h7flRYlQ.png" /></figure><p>and now we can add a task</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*aGZtuXbUYIc4wiFaFMMfDg.png" /></figure><p>and here we can see that our app is deployed correctly in the EC2 instance</p><p>let’s get now more in details for each step (terraform and ansible )</p><h3>Terraform</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/0*cpp1PImaNbKXEaVd.png" /></figure><h3>what is terraform ?</h3><p>Terraform is an infrastructure as code tool that lets you build, change, and version infrastructure safely and efficiently.</p><p>Terraform automates and manages the infrastructure so it is a tool used for infrastructure provisioning</p><h3>Terraform Configuration</h3><p>First we have to write a terraform template to configure the ubuntu virtual machine</p><p>the template will look like this</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 3.74.0&quot;<br>    }<br>  }<br>}<br><br>provider &quot;aws&quot; {<br>  region     = &quot;eu-central-1&quot;<br>  access_key = var.access_key<br>  secret_key = var.secret_key<br>}<br><br>resource &quot;aws_vpc&quot; &quot;vpc&quot; {<br>  cidr_block = &quot;10.0.0.0/16&quot;<br>}<br><br>resource &quot;aws_subnet&quot; &quot;subnet&quot; {<br>  vpc_id            = aws_vpc.vpc.id<br>  cidr_block        = &quot;10.0.0.0/24&quot;<br>  availability_zone = &quot;eu-central-1a&quot;<br>  tags = {<br>    Name : &quot;my-subnet&quot;<br>  }<br>}<br><br>resource &quot;aws_route_table&quot; &quot;route-table&quot; {<br>  vpc_id = aws_vpc.vpc.id<br>  route {<br>    cidr_block = &quot;0.0.0.0/0&quot;<br>    gateway_id = aws_internet_gateway.gateway.id<br>  }<br>  tags = {<br>    Name : &quot;route-table&quot;<br>  }<br>}<br><br>resource &quot;aws_internet_gateway&quot; &quot;gateway&quot; {<br>  vpc_id = aws_vpc.vpc.id<br>  tags = {<br>    Name : &quot;gateway&quot;<br>  }<br>}<br><br>resource &quot;aws_route_table_association&quot; &quot;rtb-assoc&quot; {<br>  subnet_id      = aws_subnet.subnet.id<br>  route_table_id = aws_route_table.route-table.id<br>}<br><br>resource &quot;aws_security_group&quot; &quot;sg&quot; {<br>  vpc_id = aws_vpc.vpc.id<br>  ingress {<br>    from_port   = 0<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 0<br>    to_port     = 8000<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 0<br>    to_port     = 23<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 0<br>    to_port     = 3306<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port        = 0<br>    to_port          = 0<br>    protocol         = &quot;-1&quot;<br>    cidr_blocks      = [&quot;0.0.0.0/0&quot;]<br>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>  }<br>  tags = {<br>    Name : &quot;instances security group&quot;<br>  }<br>}<br><br>resource &quot;aws_instance&quot; &quot;ec2&quot; {<br>  ami                         = &quot;ami-06dd92ecc74fdfb36&quot;<br>  instance_type               = &quot;t2.micro&quot;<br>  subnet_id                   = aws_subnet.subnet.id<br>  vpc_security_group_ids      = [aws_security_group.sg.id]<br>  count                       = 1<br>  availability_zone           = &quot;eu-central-1a&quot;<br>  associate_public_ip_address = true<br>  key_name                    = &quot;ec2keyspem&quot;<br><br>  tags = {<br>    Name : &quot;myapp-instance&quot;<br>  }<br>}<br><br>output &quot;ip-one&quot; {<br>  value = aws_instance.ec2[0].public_ip<br>}</pre><p>we add a variable file and a key file also for the aws keys for the authentification between terraform and aws</p><p>we define also the security rules and we give the permissions for the ports in which our app will be served</p><h3>Ansible</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/0*EjMaLWdVtEmaP0AO.png" /></figure><h3>what is ansible ?</h3><p>Ansible is like terraform an automation tool that helps to automate the IT tasks , by just making a configuration file we can make tasks from a machine to another and use the same file in different environments</p><p>ansible architecture is based on modules where a module is a small program that is responsible of doing the task and each module is responsible of a specific task it is pushed to the server than removed after it is done</p><p>to know on which server it is gonna be pushed ansible use the inventory list that will get the hosts names and all the data about the ansible client</p><p>the ansible playbook contains a group of modules where each task performs the action that we want to do .the ansible playbook contains also the host to describe where the tasks are going to be running and also contains the remote user to tell with which user the tasks should be executed</p><h4>Update hosts playbook</h4><pre>---<br>- name: Update hosts<br>  hosts: localhost<br>  vars:<br>    ansible_ssh_extra_args: &quot;-o StrictHostKeyChecking=no&quot;<br>    region_name: eu-central-1<br>    instance_name: myapp-instance<br>    ansible_user: &quot;ubuntu&quot;<br>    ansible_ssh_private_key_file: &quot;../ec2keyspem.pem&quot;<br>  tasks:<br>    - name: Retrieve public IP using AWS CLI for active instance<br>      command: &quot;aws ec2 describe-instances --region {{ region_name }} --filters &#39;Name=tag:Name,Values={{ instance_name }}&#39; &#39;Name=instance-state-name,Values=running&#39; --query &#39;Reservations[*].Instances[*].PublicIpAddress&#39; --output text&quot;<br>      register: publicIP<br><br>    - name: Update the host file with the public IP of active instance<br>      lineinfile:<br>        dest: ./hosts<br>        line: &quot;{{ publicIP.stdout }} ansible_user={{ ansible_user }} &quot;<br>        insertafter: EOF</pre><p>so now we have our hosts file is updated each time a vm is created and with that way we can avoid problems while ansible ssh to the host machine</p><h4>Web-app-configuration file :</h4><pre>---<br>- name: Install Docker and set up the ToDo app<br>  hosts: vm<br>  become: true<br>  vars:<br>    ansible_ssh_extra_args: &quot;-o StrictHostKeyChecking=no&quot;<br>  tasks: <br>    - name: Update the packages<br>      apt: <br>        update_cache: yes # apt-get update<br><br>    - name: Install packages <br>      apt: <br>        name: <br>          - ca-certificates<br>          - curl <br>          - gnupg<br>          - lsb-release<br>          - apt-transport-https<br>        state: latest <br><br>    - name: Add the Docker official GPG key <br>      apt_key: <br>        url: https://download.docker.com/linux/ubuntu/gpg<br>        state: present<br><br>    - name: Set up the repository <br>      apt_repository:<br>        repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable<br>        state: present<br><br>    - name: Update the package cache again <br>      apt:<br>        update_cache: yes<br><br>    - name: Install Docker<br>      apt:<br>        name: <br>          - docker-ce <br>          - docker-ce-cli <br>          - containerd.io <br>          - docker-buildx-plugin <br>          - docker-compose-plugin<br>        state: latest <br><br>    - name: Download Docker Compose binary<br>      get_url:<br>        url: &quot;https://github.com/docker/compose/releases/download/1.29.2/docker-compose-{{ ansible_system | lower }}-{{ ansible_architecture }}&quot;<br>        dest: /usr/local/bin/docker-compose<br>        mode: &#39;0755&#39;<br><br>    - name: Verify Docker Compose installation<br>      command: /usr/local/bin/docker-compose --version<br>      register: compose_version<br><br>    - name: Print Docker Compose version<br>      debug:<br>        msg: &quot;{{ compose_version.stdout }}&quot;<br>    - name: Create docker group<br>      group:<br>        name: docker<br>        state: present<br><br>    - name: Add user to docker group<br>      user:<br>        name: &quot;ubuntu&quot;<br>        groups: docker<br>        append: yes<br><br>    - name: Restart Docker service<br>      systemd:<br>        name: docker<br>        state: restarted<br>        enabled: yes<br>    - name: Install Composer<br>      apt:<br>        name: composer<br>        state: present<br>    - name: Clone the app repository<br>      git:<br>        repo: &#39;https://github.com/Louaykharouf26/ToDo-APP.git&#39;<br>        dest: &quot;/home/ubuntu/ToDo_App&quot;<br>        clone: yes<br>        update: yes<br><br>    - name: Install php-cli and unzip<br>      apt:<br>        name:<br>          - php-cli<br>          - unzip<br>          - php-curl<br>        state: present <br><br>    - name: Install PHP XML extension<br>      apt:<br>        name: php-xml<br>        state: present<br><br>    - name : composer install command <br>      shell : cd /home/ubuntu/ToDo_App/web-app &amp;&amp; composer install <br>      environment:<br>        COMPOSER_ALLOW_SUPERUSER: 1 <br>    - name : execute docker compose <br>      shell : cd /home/ubuntu/ToDo_App/web-app &amp;&amp; docker-compose up -d --build<br>    - name: Copy .env.example to .env<br>      shell: docker exec -it web-app_web_1 bash -c &quot;cp TESTENV .env&quot;<br><br>    - name: Generate application key<br>      shell: docker exec -it web-app_web_1 bash -c &quot;php artisan key:generate&quot;<br>    - name: Run Migrations <br>      shell: docker exec -it web-app_web_1 bash -c &quot;php artisan migrate&quot;</pre><p>So here will install docker and laravel dependencies</p><p>then we will execute the docker-compose to run our docker images and containers and have our app served already</p><p>the last 3 tasks are used to configure the .env file of the application and then generate an application key for it and the last one is to run the migration to get the database well configured with the necessary tables for our web application</p><p>and in the end of this we will have everything configured and the app is working well as showed in the previous screenshot</p><p>Finally i hope that this article was usefull and it was not that much long</p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb2854288013" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/automate-the-deployment-of-a-web-application-on-ec2-instance-using-gitlab-cb2854288013">Automate the Deployment of a web Application on EC2 instance using Gitlab</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Prometheus and Grafana on an Azure VM using ansible]]></title>
            <link>https://awstip.com/install-prometheus-and-grafana-on-an-azure-vm-using-ansible-b8384218a300?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8384218a300</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Thu, 09 Nov 2023 10:19:48 GMT</pubDate>
            <atom:updated>2023-11-11T16:59:39.042Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i m going to explain the provision of an Azure Virtual machine using terraform and the configuration of prometheus and grafana using ansible .</p><h3>Github Repo</h3><p><a href="https://github.com/Louaykharouf26/VM_Monitoring.git">GitHub - Louaykharouf26/VM_Monitoring</a></p><h3>Architecture Used</h3><p>For the whole process of the vm provision and the configuration i have used a Jenkins pipeline to automatise the whole process the pipeline architecture will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*_PbxntikAVuOoV-P3sWoPg.png" /><figcaption>Jenkins Pipeline</figcaption></figure><p>So the terraform files and the ansible files will get pulled from the github repository the jenkinsfile will define 3 stages the stage of pulling the configuration files from the repo and then the stage of the VM provision and at the end configuring this virtual machine using ansible</p><p>so the jenkinsfile will look like this</p><pre>pipeline{<br>    agent any<br>    stages{<br>        stage(&quot;getting code&quot;) {<br>            steps {<br>                git url: &#39;https://github.com/Louaykharouf26/VM_Monitoring.git&#39;, branch: &#39;master&#39;,<br>                credentialsId: &#39;github-credentials&#39; //jenkins-github-creds<br>                sh &quot;ls -ltr&quot;<br>            }<br>        }<br>       stage(&quot;Create the VM&quot;) {<br>            steps {                <br>                script {<br>                    echo &quot;======== executing ========&quot;<br>                    dir (&quot;Terraform&quot;) {<br>                        sh &quot;pwd&quot;<br>                        sh &quot;terraform init&quot;<br>                        sh &quot;terraform apply --auto-approve --var-file=/var/jenkins_home/workspace/VM-Monitoring/Terraform/terraform.tfvars.json&quot;<br>                         }    }        <br>                        }<br>                    } <br>                stage(&quot;Ansible Playbooks&quot;) {<br>            steps {                <br>                script {<br>                    echo &quot;======== executing ========&quot;<br>                    dir (&quot;ansible&quot;) {<br>                        sh &quot;pwd&quot;<br>                        sh &quot;ansible-playbook  update-hosts.yml&quot;<br>                        sh &quot;ansible-playbook -i hosts install_prometheus.yml&quot;<br>                        sh &quot;ansible-playbook -i hosts install_grafana.yml&quot;<br>                         }         }   <br>                        }<br>                    } <br>                }<br>            post{<br>                success{<br>                    echo &quot;======== Setting up infra executed successfully ========&quot;<br>                }<br>                failure{<br>                    echo &quot;======== Setting up infra execution failed ========&quot;<br>                }<br>            }<br>             <br>        }          <br>   /* <br>    post{<br>        success{<br>            echo &quot;========pipeline executed successfully ========&quot;<br>        }<br>        failure{<br>            echo &quot;========pipeline execution failed========&quot;<br>        }<br>    }*/</pre><p>so this what the pipeline will do and once we lunch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*0XNfqIR398fTIaxLSrdSnw.png" /></figure><p>and that is how everything will work let’s now go in details for the ansible playbooks and the terraform configurations</p><h3>VM provision</h3><p>This part is made with terraform configuration to provision a ubuntu virtual machine on azure</p><p>the terraform configuration file will look like this</p><pre>terraform {<br>  required_providers {<br>    azurerm = {<br>      source  = &quot;hashicorp/azurerm&quot;<br>      version = &quot;~&gt;3.0.0&quot;<br>    }<br>  }<br>  required_version = &quot;&gt;= 0.14.9&quot;<br>}<br><br>provider &quot;azurerm&quot; {<br>  features {}<br>  subscription_id =var.subscription_id<br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;resource-group&quot; {<br>  name     = &quot;VirtualMachine1&quot;<br>  location = &quot;West Europe&quot;<br>}<br><br>resource &quot;azurerm_network_security_group&quot; &quot;network-security-group&quot; {<br>  name                = &quot;default-security-group&quot;<br>  location            = azurerm_resource_group.resource-group.location<br>  resource_group_name = azurerm_resource_group.resource-group.name<br>}<br><br>resource &quot;azurerm_network_security_rule&quot; &quot;nsr-1&quot; {<br>  name                        = &quot;ssh-in&quot;<br>  priority                    = 100<br>  direction                   = &quot;Inbound&quot;<br>  access                      = &quot;Allow&quot;<br>  protocol                    = &quot;Tcp&quot;<br>  source_port_range           = &quot;*&quot;<br>  destination_port_range      = &quot;22&quot;<br>  source_address_prefix       = &quot;*&quot;<br>  destination_address_prefix  = &quot;*&quot;<br>  resource_group_name         = azurerm_resource_group.resource-group.name<br>  network_security_group_name = azurerm_network_security_group.network-security-group.name<br>}<br><br>resource &quot;azurerm_network_security_rule&quot; &quot;nsr-2&quot; {<br>  name                        = &quot;ping&quot;<br>  priority                    = 200<br>  direction                   = &quot;Inbound&quot;<br>  access                      = &quot;Allow&quot;<br>  protocol                    = &quot;Icmp&quot;<br>  source_port_range           = &quot;*&quot;<br>  destination_port_range      = &quot;*&quot;<br>  source_address_prefix       = &quot;*&quot;<br>  destination_address_prefix  = &quot;*&quot;<br>  resource_group_name         = azurerm_resource_group.resource-group.name<br>  network_security_group_name = azurerm_network_security_group.network-security-group.name<br>}<br><br>resource &quot;azurerm_network_security_rule&quot; &quot;nsr-3&quot; {<br>  name                        = &quot;connexion&quot;<br>  priority                    = 300<br>  direction                   = &quot;Outbound&quot;<br>  access                      = &quot;Allow&quot;<br>  protocol                    = &quot;Tcp&quot;<br>  source_port_range           = &quot;*&quot;<br>  destination_port_range      = &quot;22&quot;<br>  source_address_prefix       = &quot;*&quot;<br>  destination_address_prefix  = &quot;*&quot;<br>  resource_group_name         = azurerm_resource_group.resource-group.name<br>  network_security_group_name = azurerm_network_security_group.network-security-group.name<br>}<br>resource &quot;azurerm_network_security_rule&quot; &quot;nsr-4&quot; {<br>  name                        = &quot;HTTP&quot;<br>  priority                    = 150<br>  direction                   = &quot;Inbound&quot;<br>  access                      = &quot;Allow&quot;<br>  protocol                    = &quot;Tcp&quot;<br>  source_port_range           = &quot;*&quot;<br>  destination_port_range      = &quot;80&quot;<br>  source_address_prefix       = &quot;*&quot;<br>  destination_address_prefix  = &quot;*&quot;<br>  resource_group_name         = azurerm_resource_group.resource-group.name<br>  network_security_group_name = azurerm_network_security_group.network-security-group.name<br>}<br>resource &quot;azurerm_network_security_rule&quot; &quot;nsr-5&quot; {<br>  name                        = &quot;prometheus&quot;<br>  priority                    = 200<br>  direction                   = &quot;Inbound&quot;<br>  access                      = &quot;Allow&quot;<br>  protocol                    = &quot;Any&quot;<br>  source_port_range           = &quot;*&quot;<br>  destination_port_range      = &quot;9090&quot;<br>  source_address_prefix       = &quot;*&quot;<br>  destination_address_prefix  = &quot;*&quot;<br>  resource_group_name         = azurerm_resource_group.resource-group.name<br>  network_security_group_name = azurerm_network_security_group.network-security-group.name<br>}<br>resource &quot;azurerm_network_security_rule&quot; &quot;nsr-6&quot; {<br>  name                        = &quot;grafana&quot;<br>  priority                    = 200<br>  direction                   = &quot;Inbound&quot;<br>  access                      = &quot;Allow&quot;<br>  protocol                    = &quot;Any&quot;<br>  source_port_range           = &quot;*&quot;<br>  destination_port_range      = &quot;3000&quot;<br>  source_address_prefix       = &quot;*&quot;<br>  destination_address_prefix  = &quot;*&quot;<br>  resource_group_name         = azurerm_resource_group.resource-group.name<br>  network_security_group_name = azurerm_network_security_group.network-security-group.name<br>}<br><br><br>resource &quot;azurerm_public_ip&quot; &quot;public_ip&quot; {<br>  name                = &quot;VirtualMachine-public-ip&quot;<br>  resource_group_name = azurerm_resource_group.resource-group.name<br>  location            = &quot;West Europe&quot;<br>  allocation_method   = &quot;Dynamic&quot;<br>}<br>resource &quot;azurerm_virtual_network&quot; &quot;virtual-network&quot; {<br>  name                = &quot;VirtualMachine-vnet&quot;<br>  location            = azurerm_resource_group.resource-group.location<br>  resource_group_name = azurerm_resource_group.resource-group.name<br>  address_space       = [&quot;10.0.0.0/16&quot;]<br>}<br><br>resource &quot;azurerm_subnet&quot; &quot;subnet&quot; {<br>  name                 = &quot;VirtualMachine-subnet&quot;<br>  resource_group_name  = azurerm_resource_group.resource-group.name<br>  virtual_network_name = azurerm_virtual_network.virtual-network.name<br>  address_prefixes     = [&quot;10.0.1.0/24&quot;]<br>}<br><br>resource &quot;azurerm_subnet_network_security_group_association&quot; &quot;name&quot; {<br>  subnet_id                 = azurerm_subnet.subnet.id<br>  network_security_group_id = azurerm_network_security_group.network-security-group.id<br>}<br><br>resource &quot;azurerm_network_interface&quot; &quot;network-interface&quot; {<br>  name                = &quot;VirtualMachine-nic&quot;<br>  location            = azurerm_resource_group.resource-group.location<br>  resource_group_name = azurerm_resource_group.resource-group.name<br>    ip_configuration {<br>        name                           = &quot;internal&quot;<br>         subnet_id                     = azurerm_subnet.subnet.id<br>         private_ip_address_allocation = &quot;Dynamic&quot;<br>         public_ip_address_id          = azurerm_public_ip.public_ip.id<br>  }<br>}<br><br><br>resource &quot;azurerm_linux_virtual_machine&quot; &quot;linux-virtual-machine&quot; {<br>  name                            = &quot;VirtualMachine&quot;<br>  resource_group_name             = azurerm_resource_group.resource-group.name<br>  location                        = azurerm_resource_group.resource-group.location<br>  size                            = &quot;Standard_B2s&quot; <br>  computer_name                   = &quot;VirtualMachine&quot;<br>  admin_username                  = &quot;louaykharouf&quot;<br>  admin_password                  = &quot;PassStudent123&quot;<br>  disable_password_authentication = false<br>  network_interface_ids = [<br>    azurerm_network_interface.network-interface.id,<br>  ]<br>connection {<br>    type     = &quot;ssh&quot;<br>    user     = &quot;louaykharouf&quot;<br>    password = &quot;PassStudent123&quot;<br>    host     = azurerm_linux_virtual_machine.linux-virtual-machine.public_ip_address<br><br>  }<br>  os_disk {<br>    name                 = &quot;myOsDisk&quot;<br>    caching              = &quot;ReadWrite&quot;<br>    storage_account_type = &quot;Standard_LRS&quot; <br>  }<br><br>  source_image_reference {<br>    publisher = &quot;Canonical&quot;    <br>    offer     = &quot;UbuntuServer&quot; <br>    sku       = &quot;18.04-LTS&quot;    <br>    version   = &quot;latest&quot;<br>  }<br>}</pre><p>this file will help us to provision a ubuntu virtual machine on Azure with the necessary network security rules</p><h3>Ansible Configuration</h3><p>Once the virtual machine is provisioned and fully up we move to the part of installing prometheus and grafana without any access to the virtual machine for this i adopt 3 playbooks</p><p>Ansible will just make an ssh inside the virtual machine and then launch the playbook responsible of the installation so for that we need an inventory file where all the target hosts will be stored for this i made a small playbook called update hosts</p><h4>update hosts :</h4><p>this playbook will be responsible of fetching the public ip of the virtual machine and store it in the inventory file</p><p>the playbook will look like this</p><pre>---<br>- name: Update hosts<br>  hosts: localhost<br> # become: true<br>  vars:<br>    ansible_ssh_extra_args: &quot;-o StrictHostKeyChecking=no&quot;<br>    resource_group_name: pfa<br>    vm_name: &quot;VirtualMachine&quot;<br>    ansible_user: &quot;louaykharouf&quot;<br>    ansible_ssh_pass: &quot;PassStudent123&quot;<br>  tasks: <br>  - name: trigger the API<br>    shell: az vm show -d -g VirtualMachine -n {{ vm_name }} --query publicIps -o tsv<br>    register: publicIP<br>  - name: update the host file<br>    lineinfile: <br>     dest: ./hosts<br>     line: &quot;{{ publicIP.stdout }} ansible_user={{ ansible_user }} ansible_ssh_pass={{ ansible_ssh_pass }}&quot;<br>     insertafter: EOF</pre><p>this playbook will just execute a command from azure and add a line in the inventory file to store the public ip on it</p><p>the second step is to install prometheus so the playbook will be like the following</p><pre>---<br>- name: Install Prometheus<br>  hosts: vm<br>  become: true<br>  vars:<br>    ansible_ssh_extra_args: &quot;-o StrictHostKeyChecking=no&quot;<br>  tasks:<br>    - name: Download Prometheus<br>      get_url:<br>        url: https://github.com/prometheus/prometheus/releases/download/v2.43.0/prometheus-2.43.0.linux-amd64.tar.gz<br>        dest: ./prometheus-2.43.0.linux-amd64.tar.gz  # Corrected version number<br><br>    - name: Extract Prometheus files<br>      command: tar xvf ./prometheus-2.43.0.linux-amd64.tar.gz<br><br>    - name: Create the start_prometheus.sh script<br>      copy:<br>        content: |<br>          #!/bin/bash<br>          cd ./prometheus-2.47.0.linux-amd64<br>          nohup ./prometheus &gt; prometheus.log 2&gt;&amp;1 &amp;<br>        dest: ./start_prometheus.sh<br>        mode: 0755<br><br>    - name: Make the start_prometheus.sh script executable<br>      command: chmod +x ./start_prometheus.sh<br><br>    - name: Run Prometheus<br>      become: yes<br>      command: ./start_prometheus.sh</pre><p>so in this file i have just installed prometheus and i made the start_prometheus.sh for keep the service running in background</p><p>the third step is to install grafana by this playbook</p><pre>---<br>- name: Install Prometheus<br>  hosts: vm<br>  become: true<br>  vars:<br>    ansible_ssh_extra_args: &quot;-o StrictHostKeyChecking=no&quot;<br>  tasks:<br>    - name: Download Grafana key<br>      get_url:<br>        url: https://packages.grafana.com/gpg.key<br>        dest: ./grafana-gpg.key  # Corrected version number<br><br>    - name: Add Grafana GPG Key<br>      become: yes<br>      command: sudo apt-key add ./grafana-gpg.key<br><br>    - name: Add the Grafana repository to APT sources<br>      become: yes<br>      command: sudo add-apt-repository &quot;deb https://packages.grafana.com/oss/deb stable main&quot;<br>    - name: Update APT cache<br>      apt:<br>       update_cache: yes<br>    - name: Install Grafana<br>      become: yes<br>      apt:<br>        name: grafana<br>        state: present<br>        update_cache: yes<br>    - name: Start Grafana Server<br>      systemd:<br>        name: grafana-server<br>        state: started<br>        enabled: yes</pre><p>lets now access to promtheus and check if it is working</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kJAEMtg_HRq0zXSBxJUMqA.png" /></figure><p>here is the target our vm on the port 9090 now lets just link it to grafana</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1_rJcwpnKOMCuaogtwiFA.png" /></figure><p>and here we can start monitoring i will just show in a dashboard the http requests for prometheus and the cpu and memory of the virtual machines</p><p>for the http request it will be just “prometheus_http_requests_total”</p><p>for the cpu it is “process_cpu_seconds_total”</p><p>and for the memory “process_resident_memory_bytes”</p><p>and now we can create our dashboards</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1h9GIZZrtQBsWQ-DO7AP2w.png" /></figure><p>and that is it we can monitor our VM</p><p>Finally i hope that this article was useful and it was not that much long</p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><p>and also u will find more details about terraform and ansible in my previous articles</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8384218a300" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/install-prometheus-and-grafana-on-an-azure-vm-using-ansible-b8384218a300">Install Prometheus and Grafana on an Azure VM using ansible</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring of a K8S Multi-Cluster architecture Using Prometheus and Grafana]]></title>
            <link>https://awstip.com/monitoring-of-a-k8s-multi-cluster-architecture-using-prometheus-and-grafana-e29440e518a7?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e29440e518a7</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Fri, 29 Sep 2023 21:56:21 GMT</pubDate>
            <atom:updated>2023-10-02T17:00:58.701Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i m going to explain the process of the provision of a K8S multi-cluster architecutre on Azure and monitor it using Prometheus and Grafana</p><h4>Github Repo</h4><p><a href="https://github.com/Louaykharouf26/Multi-Cluster-Monitoring.git">GitHub - Louaykharouf26/Multi-Cluster-Monitoring</a></p><h4>Architecture Used</h4><p>So for this Project we will adopt the following architecture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*nSIHaHFRN2xyyHWDRuQQDA.png" /></figure><p>A quick Overview for this architecture is that i m going to provision 2 k8s clusters on AKS (Azure Kubernetes Service) then i m going to install prometheus node exporter inside each cluster once the provision of the 2 clusters and the configuration is done i m going to create an azure virtual machine (ubuntu server) on which i m going to deploy prometheus server and configure it in a way that this server will scrape data from the 2 nodes-exporter deployed inside each cluster and then i will just install grafana and use it to draw dashboards to visualise the behaviour of our clusters</p><h4>Tools Used</h4><p>The provision of the 2 cluster was made by Terraform , The deployment of prometheus node exporters i did it by the help a jenkins pipeline , and the configuration of the virtual machine was manually made</p><h4>Provision of the Clusters :</h4><p>As mentioned in the previous part i m going to provision the clusters using Terraform</p><p>Well Terraform is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share</p><p>So as it is based on configuration files i write the following file to provision my 2 clusters</p><pre>terraform {<br>  required_providers {<br>    azurerm = {<br>      source  = &quot;hashicorp/azurerm&quot;<br>      version = &quot;3.54.0&quot;<br>    }<br>  }<br>  required_version = &quot;&gt;= 0.14.9&quot;<br>}<br><br>provider &quot;azurerm&quot; {<br>  features {}<br>  subscription_id = var.subscription_id<br>}<br>resource &quot;azurerm_resource_group&quot; &quot;resource-group&quot; {<br>  name     = &quot;AKS-resource-group&quot;<br>  location = &quot;East US&quot;<br>  <br>}<br>resource &quot;azurerm_kubernetes_cluster&quot; &quot;cluster1&quot; {<br>  name                = &quot;cluster1-aks&quot;<br>  location            = azurerm_resource_group.resource-group.location<br>  resource_group_name = azurerm_resource_group.resource-group.name<br>  dns_prefix          = &quot;cluster1-k8s-dns&quot;<br>  kubernetes_version  = &quot;1.26.3&quot;<br><br>  default_node_pool {<br>    name            = &quot;default&quot;<br>    node_count      = 1<br>    vm_size         = &quot;Standard_A2_v2&quot;<br>    os_disk_size_gb = 30<br>  }<br><br> identity {<br>    type = &quot;SystemAssigned&quot;<br>  }<br>  tags = {<br>    environment = &quot;Demo&quot;<br>  }<br>}<br>resource &quot;azurerm_kubernetes_cluster&quot; &quot;cluster2&quot; {<br>  name                = &quot;cluster2-aks&quot;<br>  location            = azurerm_resource_group.resource-group.location<br>  resource_group_name = azurerm_resource_group.resource-group.name<br>  dns_prefix          = &quot;cluster2-k8s-dns&quot;<br>  kubernetes_version  = &quot;1.26.3&quot;<br><br>  default_node_pool {<br>    name            = &quot;default&quot;<br>    node_count      = 1<br>    vm_size         = &quot;Standard_A2_v2&quot;<br>    os_disk_size_gb = 30<br>  }<br><br> identity {<br>    type = &quot;SystemAssigned&quot;<br>  }<br>  tags = {<br>    environment = &quot;Demo&quot;<br>  }<br>}</pre><p>Ok here i just created a resource group and i added 2 clusters inside it with 1 node and a standard_A2_v2 vm_size so that my node take only 2vcpu</p><p>i apply this configuration by terraform apply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qv_cx3FtC2exNh-R7jX4Gg.png" /></figure><p>and once the provision is done</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*_oEAmgVJP_vn7Gr1AXolZA.png" /></figure><p>We can simply check the existence on Azure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W-pUS8OdlDb2Hs9JudsETQ.png" /></figure><h4>Prometheus</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*rh4lF2bYgMJmYbnU.png" /></figure><p>Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud.</p><p>Prometheus collects and stores its metrics as time series data, which means that metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels.</p><p>To get metrics, Prometheus requires an exposed HTTP endpoint. Once an endpoint is available, Prometheus can start scraping numerical data, capture it as a time series, and store it in a local database suited to time-series data. Prometheus can also be integrated with remote storage repositories.</p><h4>Deployment of the Prometheus</h4><p>I defined this Pipeline</p><pre>pipeline{<br>    agent any<br>    stages{<br>        stage(&quot;getting code&quot;) {<br>            steps {<br>                git url: &#39;https://github.com/Louaykharouf26/Multi-Cluster-Monitoring.git&#39;, branch: &#39;master&#39;,<br>                credentialsId: &#39;github-credentials&#39; //jenkins-github-creds<br>                sh &quot;ls -ltr&quot;<br>            }<br>        }<br>       stage(&quot;Setting up cluster 1&quot;) {<br>            steps {                <br>                script {<br>                    echo &quot;======== executing ========&quot;<br>                        sh &quot;pwd&quot;<br>                        sh &quot;az login&quot;<br>                        sh &quot;az aks get-credentials --resource-group AKS-resource-group --name cluster1-aks&quot;<br>                        sh &quot;kubectl apply -f https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3&quot;<br>                        echo &quot;installing prometheus using helm&quot;<br>                        sh &quot;helm repo add prometheus-community https://prometheus-community.github.io/helm-charts&quot;<br>                        sh &quot;helm install prometheus prometheus-community/prometheus&quot;<br>                        sh &quot;kubectl get pods&quot;<br>                         }            <br>                        }<br>                    } <br>                stage(&quot;Setting up cluster 2&quot;) {<br>            steps {                <br>                script {<br>                    echo &quot;======== executing ========&quot;<br>                        sh &quot;pwd&quot;<br>                        sh &quot;az login&quot;<br>                        sh &quot;az aks get-credentials --resource-group AKS-resource-group --name cluster2-aks&quot;<br>                        sh &quot;kubectl apply -f https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3&quot;<br>                        echo &quot;installing prometheus using helm&quot;<br>                        sh &quot;helm repo add prometheus-community https://prometheus-community.github.io/helm-charts&quot;<br>                        sh &quot;helm install prometheus prometheus-community/prometheus&quot;<br>                        sh &quot;kubectl get pods&quot;<br>                         }            <br>                        }<br>                    } <br>                }<br>            post{<br>                success{<br>                    echo &quot;======== Setting up infra executed successfully ========&quot;<br>                }<br>                failure{<br>                    echo &quot;======== Setting up infra execution failed ========&quot;<br>                }<br>            }<br>             <br>        }          <br>   /* <br>    post{<br>        success{<br>            echo &quot;========pipeline executed successfully ========&quot;<br>        }<br>        failure{<br>            echo &quot;========pipeline execution failed========&quot;<br>        }<br>    }*/</pre><p>Through this pipeline i will just install helm inside each cluster and then with the help of helm i will deploy the prometheus inside each cluster</p><p>Helm is a tool that streamlines installing and managing Kubernetes applications</p><p>the execution will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*MT7p3LNttTtPNyI15LXRZw.png" /></figure><p>and with the success of our pipeline now we have prometheus installed succesfully inside our clusters</p><p>Ok now lets keep our clusters and focus on the preparation of prometheus server and grafana on an azure virtual machine</p><h4>Grafana And Prometheus Configuration</h4><p>To install and configure prometheus server and grafana i provisioned this virtual machine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GKbQpCDxS4XWT2yFfyG7qQ.png" /></figure><p>Before i start here is a quick overview of what is grafana about</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/0*PaHYrXjcb1k1sY3j.png" /></figure><p>Grafana is an open source interactive data-visualization platform, developed by Grafana Labs, which allows users to see their data via charts and graphs that are unified into one dashboard (or multiple dashboards!) for easier interpretation and understanding. You can also query and set alerts on your information and metrics from wherever that information is stored, whether that’s traditional server environments, Kubernetes clusters, or various cloud services, etc.</p><p>ok with a quick ssh to our vm we can start the installation by installing prometheus by running this command</p><pre>curl -LO https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz<br>tar xvf prometheus-2.0.0.linux-amd64.tar.gz<br>sudo cp -r prometheus-2.0.0.linux-amd64/consoles /etc/prometheus<br>sudo cp -r prometheus-2.0.0.linux-amd64/console_libraries /etc/prometheus</pre><p>Ok now it is installed previously in the step of the deployment of prometheus in the cluster we had defined the service of the node exporter and from the azure portal i can get the endpoint of the 2 node-exporters of the cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*qp2wY8mJjG9duUVLKStNQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*558wbEcKc4hOAYqD9OXRAg.png" /></figure><p>ok now lets configure our prometheus server to scrape data from this 2 nodes this will be done through a prometheus.yml file that contains the endpoints that prometheus will use to scrape data for the metrics that the user needs</p><p>the configuration file will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*5VWqRYj12Gq_1pZ-O5r4Fg.png" /></figure><p>ok here prometheus will scrape data from the endpoints and even from the local virtual machine</p><p>lets now apply this configuration</p><pre>sudo /usr/local/bin/prometheus \<br>    --config.file /etc/prometheus/prometheus.yml \<br>    --storage.tsdb.path /var/lib/prometheus/ \<br>    --web.console.templates=/etc/prometheus/consoles \<br>    --web.console.libraries=/etc/prometheus/console_libraries</pre><p>and we can check from the browser that the node-exporters are succefully linked to our prometheus server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjzLplWTd6Q0dje1uir0wA.png" /></figure><p>and here all our node exporters are UP and prometheus is scrapping succefully data</p><p>lets move now to the configuration of grafana</p><p>lets install it first on the VM</p><pre>wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -<br>sudo add-apt-repository &quot;deb https://packages.grafana.com/oss/deb stable main&quot;<br>sudo apt update<br>sudo apt install grafana<br>sudo systemctl start grafana-server<br>sudo systemctl enable grafana-server</pre><p>now let’s open it through our browser and connect using admin admin and set our password</p><p>the UI will look like this once logged in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KcFiuryKjXOB8lwlld2ypw.png" /></figure><p>First Step is to add a new data source which will be our prometheus</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TjN6PXwfmuFPhg4uDX27EA.png" /></figure><p>then once the data source is connected i will use it to draw the first dashboard</p><p>The use case here is that i m going to monitor a multiple node-exporters so i will check in grafana-labs a template and here i find it</p><p><a href="https://grafana.com/grafana/dashboards/9990-node-exporter-server-metrics/">Node Exporter multiple Server Metrics | Grafana Labs</a></p><p>so i will use this id to import it to my grafana</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XYlJpvAi6iqozfdcylVsLw.png" /></figure><p>by clicking on load we load our dashboard and we can visualize the data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORR3XsZnYnsBvUtHQo-M5Q.png" /></figure><p>and in the end to visualize some changes i just deployed a web application that i found on azure labs and watch the changes and it was not that remarquable change on the network and the i/o of disk</p><p>and by this here we are able to monitor our multi-cluster architecture by a simple cooperation between prometheus and grafana</p><p>Finally i hope that this article was useful and it was not that much long</p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e29440e518a7" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/monitoring-of-a-k8s-multi-cluster-architecture-using-prometheus-and-grafana-e29440e518a7">Monitoring of a K8S Multi-Cluster architecture Using Prometheus and Grafana</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Laravel web Application on AKS using ArgoCD and Jenkins pipeline]]></title>
            <link>https://awstip.com/deploy-laravel-web-application-on-aks-using-argocd-and-jenkins-pipeline-9d8f72ec6f87?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d8f72ec6f87</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 13:41:46 GMT</pubDate>
            <atom:updated>2023-09-05T17:37:51.075Z</atom:updated>
            <content:encoded><![CDATA[<p>In this Article I am going to explain the process of deploying a laravel Application on AKS cluster but this time using a jenkins and an argoCD pipeline</p><h4><strong>Github Repo</strong></h4><p><a href="https://github.com/Louaykharouf26/BNPL-System.git">GitHub - Louaykharouf26/BNPL-System</a></p><h4><strong>Overview of the web application</strong></h4><p>our web application is a BNPL (buy now pay later ) System so our application will play the role of a middelware between the user and the seller of the products</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*dIXo8P4tEvfa1M5ZYqf15A.png" /></figure><p>So the User will buy some items from the e-commerce website then once he is called to pay and he choose the option to use our BNPL Sytem by that way he will be redirected to our system and he is called to log In or create an account and he will be redirected to the page of payment the payment will be splitted for 3 installments and once the user pay an email with the invoice will be sent to him and a reminder each mounth with the url to pay the next installment</p><p>the system contains an admin dashboard where the admin have the right to create a user , update a user , delete a user and see the payments of user</p><p>the dashboard looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3mfFBhK8Fv6sBm-HAWx7oA.png" /></figure><p>The second part of this project is the process of deploying the system on AKS cluster with the help of a jenkins pipeline and argoCD</p><p>In my previous articles i talked about jenkins and about AKS so now let me take this article as a reason to explain a little bit what is argoCD and how it works</p><h4>ArgoCD</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*XVULrusF4NwjVHNy.png" /></figure><p>Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.</p><p>Argo CD is implemented as a kubernetes controller which continuously monitors running applications and compares the current, live state against the desired target state (as specified in the Git repo). A deployed application whose live state deviates from the target state is considered OutOfSync. Argo CD reports &amp; visualizes the differences, while providing facilities to automatically or manually sync the live state back to the desired target state. Any modifications made to the desired target state in the Git repo can be automatically applied and reflected in the specified target environments.</p><p>As a GitOps continuous delivery tool, Argo CD continuously monitors your running infrastructure (the actual state) to compare it to declaratively-defined code (the desired state or target state) to determine whether they are out of sync, which helps to remediate configuration drift.</p><p>Argo CD automatically deploys new configurations and new version code to the target environment. Depending on how you’ve configured Argo CD to work, it’ll either notify you that things are out of sync after a new git commit, or take action. If you’ve set it up to automatically enforce changes, it’ll overwrite the production configuration with what’s stored in your immutable, versioned Git repository. The tool is great for complex application rollouts.</p><p>Furthermore, Argo CD is essential when your developer team is working in version-controlled environments. By automating lifecycle management and application deployment, Argo CD proactively monitors your application configuration for any potential syncing issues before it reaches your production environment.</p><h4>Deploy the application using argoCD and Jenkins :</h4><p>To start we need to create an AKS and this will happens using a jenkins pipeline for this we need a jenkins file that will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vyIon51I4rxaXje217SQYw.png" /></figure><p>now our jenkins pipeline will run to create a resource group and then create an AKS cluster inside the resource group</p><p>once this AKS is created we connect to it to have kubectl available and so we can start managing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xe1Gw22quIeAjYERhm5h4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*m2Vn8Mtx5ZRmniDxf0cx_Q.png" /></figure><p>as a first step we will have to install argocd inside our cluster and that is by applying a manifest file that have the configuration of argo and then expose argocd service as a loadbalancer to have an external access to it</p><p>once this is done i want to move the azure shell and finish the installation of the argocd cli from there so that it be more easier to manage it</p><p>but first i need to add the AKS cluster to the argocd</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6d0NF4x9bLgg0CAQNrJvg.png" /></figure><p>i will apply an argocd configuration to take the url of my laravel application to deploy it and the manifest file will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*qmvae2XX66xr4s-FKBN2ZQ.png" /></figure><p>lets just apply this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aHrgNq95UV0QSpxyAlpvng.png" /></figure><p>here we see that our application is created</p><p>ok once the application is created we can see our pipeline in argocd dashboard as the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iQwAHYktK4Lvt2PtIJTgKg.png" /></figure><p>so now our application is deployed in the cluster and we can check the external ip by clicking on the service name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EIcZ-zPdGaQGksKz-p411A.png" /></figure><p>and we can now access from our browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8vwg_xj6jdxgYmLFUvu1cg.png" /></figure><p>a quick check to the pods from the cli and we can see that our pipeline is working well and everything is healthy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SuM5CXPtRodKE57wfX3_Sg.png" /></figure><p>so now everything is working Great</p><p>so using argoCD the deployment become much more easier than the usual process</p><p>Finally i hope that this article was useful and it was not that much long</p><p>the full web application is in this repo where you can check also the full configuration files since the screenshots were so limited</p><p><a href="https://github.com/Louaykharouf26/BNPL-System.git">GitHub - Louaykharouf26/BNPL-System</a></p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d8f72ec6f87" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/deploy-laravel-web-application-on-aks-using-argocd-and-jenkins-pipeline-9d8f72ec6f87">Deploy Laravel web Application on AKS using ArgoCD and Jenkins pipeline</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a MERN web application on AKS (Azure Kubernetes Service) cluster]]></title>
            <link>https://awstip.com/deploy-a-mern-web-application-on-aks-azure-kubernetes-service-cluster-537dd3f03b74?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/537dd3f03b74</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Fri, 04 Aug 2023 11:25:46 GMT</pubDate>
            <atom:updated>2023-08-31T15:07:33.869Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i am going to explain the process of deploying a web application that i developed using ReactJS for the FrontEnd , NodeJS for the backend and mongoDB for the database on an AKS cluster</p><h3>Github Repo</h3><p><a href="https://github.com/Louaykharouf26/FilesReposProject.git">GitHub - Louaykharouf26/FilesReposProject</a></p><p>The Application will take as name FilesRepo and let’s start with a small overview of the application</p><h3>Overview for the web application</h3><p>FilesRepo is a web application where the user after he is logged in or signed up will have the chance to store his files or delete an existing file</p><p>So in summary it is a storage management application , the files will be stored in an azure storage account which means that an azure subscription is required for this application and we will go through some details of how the process will be</p><p>we start now with the home page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Rxz7inZ21V3pJSQJeZKPA.png" /><figcaption>Home Page</figcaption></figure><p>so this is the home page for our application where there is a description for the app and the authentication buttons</p><p>once logged in the user will be redirected to the Dashboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OTv7IUIFhZwvZC9MyruixA.png" /><figcaption>Dashboard</figcaption></figure><p>As it is a storage management app the user is invited to start by creating an azure storage account by filling this form</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fbnhjx4aAfYpLvu2MzK50A.png" /></figure><p>once the form is submitted a jenkins pipeline will be initiated and the creation of the storage account will happens through this pipeline</p><p>and there is the result of the pipeline to say that everything is successfully set up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wb0GY_zfzg7jymvwnQQRXA.png" /><figcaption>Jenkins dashboard</figcaption></figure><p>once the storage account is created the user needs to create a container inside the storage account where the files will be stored also the container creation will be by filling this form</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RK29YsccqUapL7ysHepl7w.png" /></figure><p>here the user needs to put the same storage account as the previous form and by submitting the second pipeline will create the container using terraform and here we will have our container created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jw6kkzwSKUpxW8R9_sPNiQ.png" /><figcaption>Jenkins Dashboard — CreateRepo-</figcaption></figure><p>and here we see that the provision of the container is succefully done</p><p>and now we are in the page of the details of our container</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7WOgLWeRz4A_NtJgOkjZwQ.png" /><figcaption>FilesRepo Dashboard</figcaption></figure><p>here we provide some details related to our container and we give the chance to the user to upload a file lets now upload the file</p><p>well the file upload will be made through the following powershell script</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*QMNpErIYQkdEvWac6-7EeQ.png" /></figure><p>and now once the user choose the file this script file will be running and be uploaded in the container</p><p>one the file is uploaded it will appear in the the list of files like the following screenshot shows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9T2GSIYPnqZtPwarEkZr7A.png" /></figure><p>and now the user have the right to delete the file which will be using another powershell script</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*4987SiCqZJjVq3NUiVbuFw.png" /></figure><p>once the file is deleted a notification will appear to the user using rabbitmq</p><p>That is a Quick overview for our application let’s now move to the deployment of this app on an AKS cluster</p><h3>Deployment on AKS</h3><h4>AKS ?</h4><p>Azure Kubernetes Service (AKS) offers the fastest way to start developing and deploying cloud-native applications in Azure, in data centers or at the edge, with built-in pipelines and code-to-cloud protection. Get unified management and governance for on-premises, edge, and multi-cloud Kubernetes clusters. Interact with Azure security, identity, cost management, and migration services.</p><h4>How to deploy an APP on AKS</h4><p>The first step is the creation of our cluster and it is for us to choose the way either using azure portal or azure CLI</p><p>for me i will use Azure CLI</p><ul><li>Provision of the cluster</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KE8Z3hZKVFRPnU0n_5GraA.png" /><figcaption>Azure CLI</figcaption></figure><p>We start by creating a resource group and then we provision our cluster inside the resource group and we wait until the cluster is up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-YXNPY7U4vGEdthNJUNnug.png" /></figure><p>the next step is to create the configuration files for our application for this we will need 3 files the database deployment , the backend deployment and the frontend deployment and here we need also for each one a service so that they can connect to each other</p><p>the application is dockized and pushed to docker hub</p><p>here is an example of the backend deployment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*zME2lw3RksZRo-uPG-114Q.png" /></figure><p>the other are similar and will be found in the github repository</p><p>so we upload the configuration files in the storage related to the shell</p><p>and then we connect to our cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*P40I2xzypY5XX-ZRRrApqg.png" /></figure><p>and now we apply the configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mbbgCG3XPuNndenDk6nnA.png" /></figure><p>lets see our deployments and pods</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g7rizQWZNxMrMNX7n-Dc6w.png" /><figcaption>pods list</figcaption></figure><p>here all our pods are running</p><p>lets now see the services and get the external ip</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*h5ps_Wts6A8NGYksbZmpfg.png" /></figure><p>and here is now our external IP where we can access to the frontend part</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3HcC00m2jf5utKDtkWq7Q.png" /></figure><p>and that is all now our cluster is UP and our application is deployed there</p><p>Finally i hope that this article was useful and it was not that much long</p><p>the full web application is in this repo where you can check also the full configuration files since the screenshots were so limited</p><p><a href="https://github.com/Louaykharouf26/FilesReposProject.git">GitHub - Louaykharouf26/FilesReposProject</a></p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=537dd3f03b74" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/deploy-a-mern-web-application-on-aks-azure-kubernetes-service-cluster-537dd3f03b74">Deploy a MERN web application on AKS (Azure Kubernetes Service) cluster</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Development of a web interface for managing and monitoring virtual machines in the Cloud]]></title>
            <link>https://medium.com/@louay.khrouf/development-of-a-web-interface-for-managing-and-monitoring-virtual-machines-in-the-cloud-f8d17acecd8b?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8d17acecd8b</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Sat, 03 Jun 2023 10:30:24 GMT</pubDate>
            <atom:updated>2023-06-03T10:30:24.083Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i m going to resume our end of year project that consists on the development of a web interface to create , manage and monitor virtual machines in the Cloud . The application will take CloudiVops as name and i will present for you the main features and the process of the development of this application</p><h4><strong>Tools to use</strong></h4><ul><li>ReactJS , NodeJS , MongoDB , ChartJS</li><li>Jenkins</li><li>Ansible</li><li>Terraform</li><li>Azure</li></ul><h4>Github Repo</h4><p><a href="https://github.com/Louaykharouf26/CloudiVops-App.git">GitHub - Louaykharouf26/CloudiVops-App</a></p><h4>How CloudiVops works ?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*txYenDfftaNOa8T3-M6s6w.png" /></figure><p>Once the user access to our application he will be face to a web interface after the creation of an account and the login the user will find a form where he can fulfill the desired infrastructure and the he can choose to configure the existent infra by our application that it will acts as an intermediary between the user and Azure because all the infra will be set up on Azure (me and my team we choosed azure so that we can use our subscription that contains 100$) our application will set up the infra and do all the configurations using pipelines and to understand more the workflow lets go through the next diagram</p><h4>workflow of the Application</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*PRxJzlsD4Pwfb45feDhuEA.png" /><figcaption>Workflow of CloudiVops</figcaption></figure><p>Well this can make the system of cloudivops more clear</p><p>Our system contains the frontend part developed on reactJS and the backend that is developed with expressJS and that will initiate the pipelines and will play a role on the automation of the processes .The api will contains the functions for the login and signup and the functions to trigger the pipelines</p><p>first of all the user will create and account which will be saved on our database then he will be redirected to the home page inside the home page the user will find a button to create a virtual machine or a button to navigate to the dashboard and configure the VMs that exists once the form is submitted the function called is to trigger pipeline and that make a call to jenkins api and jenkins api will initiate terraform api and this will create the desired virtual machine by a simple trigger to azure api and azure will return the details to the user through our front pages</p><p>if the user wants to configure a VM our api will trigger a second jenkins pipeline and this time jenkins api will call ansible api to configure the desired resource inside azure and then the state of the configuration will be passed to the user on the front pages .</p><p>let me now give some definitions of the used tools for the automation</p><h4>Jenkins</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/0*wnlEG7R_s5a4VjHN.png" /><figcaption>Jenkins Logo</figcaption></figure><p>Jenkins is a Java-based program considered as an automation build tool that should be installed on a dedicated server , it is used to configure the tasks , install the tools used for the build and automatically trigger the workflow</p><p>jenkins offer different jobs the most used one and suitable for our usecase is the pipeline job</p><h4>Terraform</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/0*ZM74l4c8lpKKMYYr.png" /><figcaption>Terraform Logo</figcaption></figure><p>Terraform is an infrastructure as code tool that lets you build, change, and version infrastructure safely and efficiently.</p><p>Terraform automates and manages the infrastructure so it is a tool used for infrastructure provisioning</p><p>Terraform take the desired state from the provided code and set up the infrastructed that will be stored in a state file</p><h4>Ansible</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/0*ydjsCt5lclbA5Ral.png" /><figcaption>Ansible Logo</figcaption></figure><p>Ansible is like terraform an automation tool that helps to automate the IT tasks , by just making a configuration file we can make tasks from a machine to another and use the same file in different environments</p><p>ansible architecture is based on modules where a module is a small program that is responsible of doing the task and each module is responsible of a specific task it is pushed to the server than removed after it is done</p><p>to know on which server it is gonna be pushed ansible use the inventory list that will get the hosts names and all the data about the ansible client</p><p>the ansible playbook contains a group of modules where each task performs the action that we want to do .the ansible playbook contains also the host to describe where the tasks are going to be running and also contains the remote user to tell with which user the tasks should be executed</p><h4>Development of CloudiVops</h4><p>The home page will looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrOSFrS7hIK5q_2K6aeC-w.png" /><figcaption>HomePage</figcaption></figure><p>it is just a simple page that contains a description of our services , button for login and button for sign up</p><p>once logged in the email will appear in the place of the buttons of login and sign up and the page will looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9bi--FUqZ41bG1nvij38w.png" /><figcaption>After Login</figcaption></figure><p>If the user wants to create a vm the vm creation will happens through this form</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8UokPA4_Wsf-L6sFzhYuIA.png" /></figure><p>and once the vm is created the dashboard will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3E-CvYsxSYOhKFcoAnDJtA.png" /><figcaption>Dashboard</figcaption></figure><p>So here the user will find the IP of the machine the region and 2 buttons either to install docker or mysql and he can also delete the resource</p><p>also the dashboard contains monitoring graphs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*TiCTxGfaKdSz5y_-ZgbcAw.png" /></figure><p>the submit of the form will initiate jenkins pipeline and the page that we got on the front will gives an idea about the state of the build of the pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBfvnemVeTDQQNx_eAWwLA.png" /></figure><p>means that our infrastructure is gonna be created and once the pipeline is build succesfully we got a changed status</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xU0CXTghx1eqjhG6xvfZzA.png" /></figure><p>and the same for the ansible pipeline</p><p>The code of the pipelines , the playbooks , the terraform templates are in the github repository</p><p>So that was a brieve summary of this web application that we would like to improve it in the future by adding more features</p><p>Finally i hope that this article was usefull and it was not that much long</p><p>the full web application is in this repo where you can check also the full configuration files since the screenshots were so limited</p><p><a href="https://github.com/Louaykharouf26/CloudiVops-App.git">GitHub - Louaykharouf26/CloudiVops-App</a></p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8d17acecd8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate the Deployment of Web Application on Azure virtual machine]]></title>
            <link>https://awstip.com/automate-the-deployment-of-web-application-on-azure-virtual-machine-f944dcf36f00?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f944dcf36f00</guid>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Wed, 19 Apr 2023 16:47:06 GMT</pubDate>
            <atom:updated>2023-09-01T11:11:27.690Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i m going to explain how to automate the process of deploying a web application developed using laravel on an azure virtual machine created using terraform and configured using ansible</p><h4><strong>Tools to use</strong></h4><ul><li>Jenkins</li><li>Terraform</li><li>Ansible</li></ul><h3>Github Repo</h3><p><a href="https://github.com/Louaykharouf26/ToDo-APP.git">GitHub - Louaykharouf26/ToDo-APP</a></p><h3><strong>Jenkins</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*KT29k0uPewOQY8qcU6ts_g.png" /><figcaption>Jenkins Logo</figcaption></figure><h4>what is jenkins ?</h4><p>Jenkins is a Java-based program considered as an automation build tool that should be installed on a dedicated server , it is used to configure the tasks , install the tools used for the build and automatically trigger the workflow</p><p>jenkins offer different jobs the most used one and suitable for our usecase is the pipeline job</p><h4>Pipeline :</h4><p>it is a job suitable for CI/CD , it can be defined using a script , the script is just a simple syntax for the pipeline and it can be declarative or scripted . The scripted one is based on groovy means the whole configuration is made with groovy but the declarative has just a predefined structure</p><p>the pipeline is so usefull when we have many tasks to be executed in parallel</p><p>in our case we are going to adapt a declarative pipeline</p><p>In this project the pipeline will be used to apply terraform configuration and then configure the deployed server to host our web app inside using ansible</p><p>for this i just prepared a jenkins file that will looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*E-0LNEgIAnoUrSQTZ7hcug.png" /></figure><p>i defined 3 stages</p><p>the first stage is to get the code from the github repository</p><p>the second stage is to set up the infrastructure based on the terraform configuration (i will explain it in the next section)</p><p>the third stage is to configure the infrastructure using ansible which will be explained later in this article</p><p>on Jenkins i created a pipeline that i called Todo-App and i link it to my github so that it can get the jenkins file from the github repo the configuration on jenkins UI is like the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*swefB4NFLd_kMOS6RHJPow.png" /><figcaption>Pipeline configuration</figcaption></figure><p>let’s now launch the build of the pipeline</p><p>lets check the console output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*-_Veq7JSsTJmYhFh3Lltfw.png" /></figure><p>this result is the one responsible for the first stage that it took the repo and clone in on the workspace of the Todo-App pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*ar1_0-BNCGe513Cz_Ea_JQ.png" /></figure><p>this declare that the stage of setting up the infra using terraform is taking place lets see the end of this stage now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*CvExTPL1O7ePsDl969z2JQ.png" /></figure><p>lets just check the azure portal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lIf-E8ZQpBeJD0a96JE9EA.png" /><figcaption>Todo-App ressource group</figcaption></figure><p>so the stage is successefully done and we have our infra already up</p><p>the last stage of our pipeline is to configure our infrastructure using ansible</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*seG-OEX1JqjNZXhW-Ekpvg.png" /></figure><p>before that ansible start the configuration we have to declare the hosts file for this just to get the public ip of the created infrastructure (more details later on the article)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*lzn_B6TL202diE642msL_w.png" /></figure><p>now the next step of the ansible configuration is to install dependencies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*g-D51mSuJ-72UE5vmWXSOA.png" /></figure><p>now we just configure our web application and we got it finally hosted and we can access to it from the dns</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*bnuvb40wJekOM5oLmMRHtw.png" /></figure><p>and we can login and add tasks and mark tasks as done</p><p>let’s now just see the different steps with more details</p><h3><strong>Terraform</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/1*mmnUk-wNCXB34hPMEKVHuA.png" /></figure><h4>what is terraform ?</h4><p>Terraform is an infrastructure as code tool that lets you build, change, and version infrastructure safely and efficiently.</p><p>Terraform automates and manages the infrastructure so it is a tool used for infrastructure provisioning</p><h4>Terraform architecture :</h4><p>Terraform is based on 2 main components</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WPfJ0qMC-b5J9QNI" /></figure><p><strong>Terraform Core :</strong></p><p>Core is the main component for terraform it takes 2 inputs sources the first the configuration created by the user , the second input is the terraform state which define the current state of the setup . The core take the inputs and compare the current state with the desired state and plan what needs to be done</p><p><strong>Terraform Providers :</strong></p><p>This component gives the access to the ressources and the providers are the cloud providers used to host the ressources by terraform such as AWS , Azure , Google cloud …</p><p>let’s see now how to configure terraform to create a ubuntu virtual machine where i will host my web application</p><h3>Terraform Configuration</h3><p>First we have to write a terraform template to configure the ubuntu virtual machine</p><p>the template will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*Jtbw0wmCxCh1yDrJfTBYxQ.png" /></figure><p>So here we are creating a new ressource using the azurerm provider which is the provider responsible of creating ressources on azure</p><p>we define the network security rules , the ressource group name and the virtual machine configuration such as the network , the public ip , the disk …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*a976SFXKO8IDLdJjVEGqGg.png" /><figcaption>Vm configuration</figcaption></figure><p>in this part of the terraform configuration file we will create a ubuntu server 18.04 virtual machine , we allow the ssh connection for the user louaykharouf and with the password PassStudent123 and we have configured the os disk</p><p>once the file is saved let’s now just apply our configuration</p><p>by running the terraform apply we can just set up our configuration and we can see it on azure portal (because we already applied using our pipeline)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*lIf-E8ZQpBeJD0a96JE9EA.png" /></figure><h3>Ansible</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/1*ZQ1RUjWfBqApobPGX9a1qw.png" /></figure><h4>what is ansible ?</h4><p>Ansible is like terraform an automation tool that helps to automate the IT tasks , by just making a configuration file we can make tasks from a machine to another and use the same file in different environments</p><p>ansible architecture is based on modules where a module is a small program that is responsible of doing the task and each module is responsible of a specific task it is pushed to the server than removed after it is done</p><p>to know on which server it is gonna be pushed ansible use the inventory list that will get the hosts names and all the data about the ansible client</p><p>the ansible playbook contains a group of modules where each task performs the action that we want to do .the ansible playbook contains also the host to describe where the tasks are going to be running and also contains the remote user to tell with which user the tasks should be executed</p><h4>for our app :</h4><p>first i created a playbook that will update the host file each time a virtual machine is created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*pc7SmjAccObMzxfPn-z7kw.png" /></figure><p>so now we have our hosts file is updated each time a vm is created and with that way we can avoid problems while ansible ssh to the host machine</p><p>To host a web application inside a virtual machine we have to install dependencies and configure the environment</p><p>first of all we have to install all the dependencies</p><p>since our app is developed using laravel so we have to install php , mysql , composer and then clone our application also it is gonna be hosted on nginx so we have to install it here</p><p>this is resumed in this playbook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*2jlnvx3102pzskU2_4vTFg.png" /><figcaption>NB : the rest is on the github repo</figcaption></figure><p>the result is shown in the part of jenkins pipeline that everything was successfully installed</p><p>now as everything is ready we have to configure our application</p><p>first we need to update the .env file , then create the database and migrate and create a link for the storage also we need to update the file of configuration of nginx so that it can be listening on our public folder of the app and listen on the dns created for our vm and then we just run composer install to install dependencies and we change the permissions and we got our app ready</p><p>this is resumed in this playbook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*UWAmzSQPVgM_MP4VxEyJNw.png" /><figcaption>NB: The rest is on the github repo</figcaption></figure><p>so each step is represented by a task that have its own name and its own action to be performed</p><p>and then we access to the dns and we got our app as it was shown in the jenkins part</p><p>Finally i hope that this article was usefull and it was not that much long</p><p>the full web application is in this repo where you can check also the full configuration files since the screenshots were so limited</p><p><a href="https://github.com/Louaykharouf26/ToDo-APP.git">GitHub - Louaykharouf26/ToDo-APP</a></p><p>feel free to contact me for any explanation and follow me for more content on my linkedin <a href="https://www.linkedin.com/in/louay-k-77072083/">https://www.linkedin.com/in/louay-k-77072083/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f944dcf36f00" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/automate-the-deployment-of-web-application-on-azure-virtual-machine-f944dcf36f00">Automate the Deployment of Web Application on Azure virtual machine</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a web application on minikube]]></title>
            <link>https://medium.com/@louay.khrouf/deploy-a-web-application-on-minikube-d1f850daee6c?source=rss-54381b85545e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1f850daee6c</guid>
            <dc:creator><![CDATA[Louay Kharouf]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 23:32:19 GMT</pubDate>
            <atom:updated>2023-02-19T23:32:19.420Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article i m going to show how to deploy a small web application on kubernetes using Minikube</p><p>To show the deployment process i create a small ToDo application with laravel for the web part and MySql for the database</p><p>u can find the application code source here : <a href="https://github.com/Louaykharouf26/ToDo-APP">https://github.com/Louaykharouf26/ToDo-APP</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*qZHIoB3Ra-EhMJMutzRDfQ.png" /></figure><h3><strong>What is Kubernetes ?</strong></h3><p>Kubernetes , also known as <strong><em>K8S </em></strong>, is an open source container orchestration tool that helps u to manage containerized applications in different deployment environment . K8S offers high availability , scalability or high performance and easier disaster recovery .</p><h3><strong>Kubernetes architecture</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*3WyYGYSxy_R3_oteYoipkA.png" /></figure><p>Basically Kubernetes operates on 2 types of nodes the fist is the master node and the second is the worker node so let’s have a look of how the structure of each node</p><p><strong><em>Master Node :</em></strong></p><p>It is the master server that will create the cluster and that will plan , monitor , schedule all the worker nodes using its own component and services</p><p>the first component of the master node is the <strong>“API SERVER” </strong>that is responsible for orchestrating all the operations in the cluster and it acts like the gateway to the cluster . The second component is the <strong>“SCHEDULER”</strong> that is used to schedule new pods by forwarding it to its own worker node , the job of the scheduler is just limited on associating every pod to its node without running it . <strong>“CONTROLLER MANAGER”</strong> is another component for the master that is responsible for watching the state of the cluster and then request to the scheduler to reschedule pods in case of any state change . The last component is the “<strong>ETCD</strong>” which is similar to a key value storage for the cluster state that means that any state change is stored in the etcd and generally the etcd store just the keys of the cluster that will be used for other processes .</p><p><strong><em>Worker Node :</em></strong></p><p>Mainly the worker node contains 3 processes</p><p>“<strong>Container Runtime</strong>” it is installed in the node so that the pod can run inside it . “<strong>Kubelet</strong>” which is the main service on a node that start the pod with a container inside ensure the connection between the master and the node and make sure that this connection is healthy and the pods and its container are running in the desired state by assigning the ressources from the node to the container . “<strong>Kube-proxy</strong>” that is responsible of forwarding the request from services to the responsible pod and also expose services to the external world</p><p>So now we have an idea about the architecture of K8S , now let’s talk about some kubernetes concepts that we are going to use on our application</p><h3><strong>Kubernetes concepts :</strong></h3><p><strong><em>pod : </em></strong>a pod present an abstraction layer over containers , and usually we made 1 application per pod and the pod once created it get an ip address</p><p><strong><em>kubectl: </em></strong>command line tool that interacts with the api server and send commands to the master node</p><p><strong><em>deployment :</em></strong> allowes to describe the application lifecycle such us the image , the number of pods , the number of replicasets …</p><p><strong><em>Service :</em></strong> a stable endpoint to connect to one or multiple containers(layer 4 so we have to indicate a port number) . Here is some types of services “<strong>external service</strong>” is the service that open the communication from external sources and “<strong>internal service</strong>” are used when we don’t want to expose an app to the public</p><p><strong><em>Minikube :</em></strong> one node cluster where master processes and worker processes are running in the same machine <br>MiniKube is used for test purposes</p><h3>Deploying the App :</h3><p>The app that i made is a Todo App where a user is invited to create an account or login to an existant account and then he can add a task , update an existing task or delete a task . The application is made by Laravel and MySql</p><p>Let’s start by creating the docker image for the laravel app and that is by a simple dockerfile based on the laravel image that exists on the docker hub</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*U1rqfHRk-pKM3kUbKzKL9A.png" /><figcaption>TodoAPP dockerfile</figcaption></figure><p>Once the image is created we have to push it on a private repository in the docker hub so that is can be accessible in the rest of the deployment process</p><p>The second step is to create the configuration file for the database and this is how the file will look like</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: todoappdb<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: todoappdb<br>  template:<br>    metadata:<br>      labels:<br>        app: todoappdb<br>    spec:<br>      containers:<br>        - name: db<br>          image: mysql:8<br>          env:<br>            - name: MYSQL_DATABASE<br>              value: todoapp<br>            - name: MYSQL_USER<br>              valueFrom: <br>                        secretKeyRef: <br>                          name: db-secret<br>                          key: username<br>              <br>            - name: MYSQL_PASSWORD<br>              valueFrom: <br>                        secretKeyRef: <br>                            name: db-secret<br>                            key: password<br>            - name: MYSQL_ROOT_PASSWORD<br>              valueFrom: <br>                        secretKeyRef: <br>                            name: db-secret<br>                            key: password<br>          ports:<br>            - containerPort: 3306<br>          volumeMounts:<br>            - name: mysql-persistent-storage<br>              mountPath: /var/lib/mysql<br>      volumes:<br>        - name: mysql-persistent-storage<br>          persistentVolumeClaim:<br>            claimName: mysql-pv-claim</pre><p>here the kind will define the type of configuration and which will be a deployment that will have as name todoappdb and that will create the container db based on a mysql image and in the env section we define the credentials of the mysql user and root and the passwords and here we will define a secret file</p><p><strong><em>Secret :</em></strong> The concept of Secrets refers to any type of confidential credential that requires privileged access with which to interact</p><p>so in our file we will for example define the username and the password used to access to the database for more security purposes</p><p>the secret file will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*40NkWUL6xQEUB2baEy-wcA.png" /><figcaption>Secret file</figcaption></figure><p>so here the kind of the deployment will be secret and we will put the username and the password that i m hiding in the previous image but they should be encoded on base64</p><p>and we reference to the values of the username and the password from this file like in the previous code and then we have to deploy the secret file after starting minikube</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*CbhdW0RvzXtznhCYQ_sGNA.png" /><figcaption>Secret deployment</figcaption></figure><p>For the communication between pods and for the communication with the main app later we have to define a service for the database and this will be in a configuration file that will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/215/1*tAY5gRU2GlvsDc5DhJ-mdA.png" /><figcaption>db service</figcaption></figure><p>here the type of the service is a nodeport that will use the TCP protocol and the pod port will be 3306</p><p>and now we can just apply this configurations file by the following command</p><p>“<strong>kubectl apply -f dbdeployment.yml </strong>”and this will create the db service also because i created it in the same file</p><p>now lets create a configuration file for the laravel web application and the configuration will have this following code</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: todoappweb<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: todoappweb<br>  template:<br>    metadata:<br>      labels:<br>        app: todoappweb<br>    spec:<br>      containers:<br>        - name: todoapp<br>          image: louaykharouf/todoapp-web<br>          ports:<br>            - containerPort: 8000<br>          env:<br>            - name: DB_CONNECTION<br>              value: mysql<br>            - name: DB_HOST<br>              value: todoappdb-svc<br>            - name: DB_PORT<br>              value: &quot;3306&quot;<br>            - name: DB_DATABASE<br>              value: todoapp<br>            - name: DB_USERNAME<br>              valueFrom: <br>                       secretKeyRef: <br>                             name: db-secret<br>                             key: username<br>            - name: DB_PASSWORD<br>              valueFrom: <br>                       secretKeyRef: <br>                             name: db-secret<br>                             key: password</pre><p>so here we will just define the image for the container the image that i pushed on the docker hub repository and the we link the app to the database service and we give the credentials for the database connection</p><p>once everything is done we have to create an external service on which we are going to expose our app to the external world and that will be by creating a service configuration that will take the type of a loadbalancer</p><p>here is the configuration for this service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*6TbdnqwVXiPxmB0Htcqz6w.png" /><figcaption>External Service</figcaption></figure><p>so now everything is configured lets apply our configurations by running this command “kubectl apply -f laraveldeployment.yml” and here we will create the web app and the service</p><p>we will now check if everything is created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*g2lCh5fKEHedBwZlr3LOIg.png" /><figcaption>pod list</figcaption></figure><p>here we see that the pods were created and running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*hgfNQczxs3D6dxPXhTOruw.png" /><figcaption>deployment list</figcaption></figure><p>here is the database deployment and the web deployment ready</p><p>we check now our services</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*gK6HFGbJItxX86W7xpQ6JQ.png" /><figcaption>services list</figcaption></figure><p>here we see that our services are successfully created but the external service todoapp-service we see that the external IP status is pending which is waiting that minkube will associate for it an external IP which will be by running the following command in the next image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*idsEdbcZHLuHJOS19D1lkg.png" /><figcaption>external service</figcaption></figure><p>and now we will be redirected to the default browser and we will have the home page of the todo app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ZIReCmqlUKQb5lYMcFP5g.png" /></figure><p>and that is it we can see now that it is working lets just try to sign up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZEbG1BE9p4AKRxTsrEDDTQ.png" /><figcaption>sign up</figcaption></figure><p>and after that we can add a task and we will get the following result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdbH_JUfSUxM_1IzykoAHw.png" /></figure><p>we can update and delete or make it done and that will be redirected to the done page</p><p>we can verify the data in the database by executing the pod of the database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYTESihZDsNFy0Nu2YlP2g.png" /></figure><p>so it is succefully deployed and the data is persisted thanks to the volumes that we declared in the configuration file</p><p>I hope u enjoyed the article and see you in the next article soon !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1f850daee6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>