<?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 Sejal Maniyar on Medium]]></title>
        <description><![CDATA[Stories by Sejal Maniyar on Medium]]></description>
        <link>https://medium.com/@sejalmaniyar9?source=rss-130be922487c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h_nNsP2d-f46RGY1ksVbiQ.jpeg</url>
            <title>Stories by Sejal Maniyar on Medium</title>
            <link>https://medium.com/@sejalmaniyar9?source=rss-130be922487c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:47:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sejalmaniyar9/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[Streamlining Nginx Deployment with Ansible on AWS EC2 Instances]]></title>
            <link>https://medium.com/@sejalmaniyar9/streamlining-nginx-deployment-with-ansible-on-aws-ec2-instances-2f67bb898e39?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f67bb898e39</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Sun, 19 Nov 2023 20:48:34 GMT</pubDate>
            <atom:updated>2023-11-19T20:49:29.974Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In today’s fast-paced technological landscape, deploying and managing web servers efficiently is paramount. This blog post aims to provide a detailed guide on using Ansible to streamline the deployment of Nginx across four AWS EC2 instances — one serving as the Ansible master and the remaining three as Nginx servers. We’ll walk through the process of creating the instances, installing Ansible, and orchestrating Nginx deployment.</p><h3><strong>Step 1: Setting Up AWS EC2 Instances</strong></h3><p><strong>Server Configuration:<br></strong>Launch four AWS EC2 instances with the following specifications:<br>Instance Type: t2.micro<br>Operating System: Ubuntu</p><p><strong>Instance Naming:<br></strong>Assign distinct names to the instances for clarity:<br>Instance 1: Ansible-Master<br>Instance 2: Server-1<br>Instance 3: Server-2<br>Instance 4: Server-3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MG_3U162QFb61wW_WKZQXQ.png" /></figure><h3>Step 2: Installing Ansible on Ansible-Master</h3><p>Here are the steps to install Ansible on an Ubuntu EC2 instance:</p><pre># Update the package index<br>sudo apt update<br><br># Install the required dependencies<br>sudo apt install software-properties-common<br><br># Add the Ansible repository<br>sudo apt-add-repository --yes --update ppa:ansible/ansible<br><br># Install Ansible<br>sudo apt install ansible</pre><h3>Step 3: Ansible Configuration</h3><p><strong>Understanding the Ansible Inventory File<br></strong>The Ansible inventory file/Host file is a critical component that defines the hosts to be managed and includes variables that tailor the configuration to specific needs.</p><p>Edit /etc/ansible/hosts to include the IP addresses of Server-1, Server-2, and Server-3.</p><pre>ubuntu@ip-172-31-37-65:~$ sudo vim /etc/ansible/hosts</pre><pre>[servers]<br>server1 ansible_host=18.206.189.126<br>server2 ansible_host=3.81.158.72<br>server3 ansible_host=54.162.81.197<br><br>[servers:vars]<br>ansible_python_interpreter=/usr/bin/python3<br>ansible_user=ubuntu<br>ansible_ssh_private_key_file=/home/ubuntu/.ssh/ansible-key.pem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tDog88YQuTHyI-t_maQcg.png" /></figure><h3>Step 4: Connectivity Testing with Ansible Ping</h3><p>Use the Ansible ping module to test connectivity between the Ansible host and the deployed servers.<br>Confirm that all servers respond successfully, ensuring a well-connected infrastructure.</p><p>Ansible trying to establish an SSH connection to the target hosts.</p><pre>ansible servers -m ping -k</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g5-Hq1Ksipv-6swEYuufFA.png" /></figure><p>The ansible-inventory command is part of Ansible and can be used to list information about the configured inventory.</p><pre>ansible-inventory --list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ONekNR3XHCJY0ucSunVBtw.png" /></figure><p>This command will output the inventory in JSON format, displaying information about hosts, groups, and variables defined in your inventory.</p><h3>Step 5: Ansible Playbook for Nginx Installation</h3><p>It’s designed to install Nginx on the hosts specified in the servers group and start the Nginx service. The become: yes is used to run the tasks with elevated privileges (sudo).</p><pre>---<br>- name: This playbook will install nginx<br>  hosts: servers<br>  become: yes<br>  tasks:<br>    - name: Install nginx<br>      apt:<br>        name: nginx<br>        state: latest<br><br>    - name: Start nginx<br>      service:<br>        name: nginx<br>        state: started<br>        enabled: yes</pre><p>To run this playbook, save it to a file (e.g., nginx_install.yml) and execute the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*V6QaHE-x0hJucSLbTg6dOA.png" /></figure><p>To run an Ansible playbook, you need to use the ansible-playbook command followed by the filename of your playbook.</p><pre>ansible-playbook istall_nginx_play.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBkR-mJgukNXBWCOha3Qrg.png" /></figure><h3>Step 6: Web Content Deployment</h3><p>Now that we have successfully installed Nginx on Server-3, it’s time to deploy a beautiful static page and ensure that it’s seamlessly accessible through the web server. In this step, we’ll create an index.html file and use Ansible to copy it to the appropriate directory on Server-3.</p><p><strong>Create the index.html file:</strong></p><p>Using your preferred text editor, create a simple yet engaging HTML file.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Sejal Maniyar&#39;s Ansible Blog&lt;/title&gt;<br>    &lt;style&gt;<br>        body {<br>            font-family: &#39;Segoe UI&#39;, Tahoma, Geneva, Verdana, sans-serif;<br>            margin: 0;<br>            padding: 0;<br>            background-color: #f5f5f5;<br>            color: #333;<br>        }<br><br>        header {<br>            background-color: #3498db;<br>            padding: 20px;<br>            text-align: center;<br>            color: white;<br>        }<br><br>        main {<br>            padding: 40px;<br>            text-align: center;<br>        }<br><br>        section {<br>            max-width: 800px;<br>            margin: 0 auto;<br>            background-color: white;<br>            padding: 20px;<br>            border-radius: 10px;<br>            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);<br>        }<br><br>        footer {<br>            background-color: #3498db;<br>            padding: 10px;<br>            text-align: center;<br>            color: white;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;header&gt;<br>        &lt;h1&gt;Sejal Maniyar&#39;s Ansible Blog&lt;/h1&gt;<br>    &lt;/header&gt;<br><br>    &lt;main&gt;<br>        &lt;section&gt;<br>            &lt;h2&gt;Welcome to My Ansible Blog&lt;/h2&gt;<br>            &lt;p&gt;<br>                Hello, I&#39;m Sejal Maniyar. Welcome to my Ansible blog! Here, I&#39;ll be sharing insights, tips, and tutorials<br>                about Ansible and automation. Stay tuned for exciting content!<br>            &lt;/p&gt;<br>            &lt;!-- You can add more content, images, and styling as needed. --&gt;<br>        &lt;/section&gt;<br>    &lt;/main&gt;<br><br>    &lt;footer&gt;<br>        &lt;p&gt;&amp;copy; 2023 Sejal Maniyar. All rights reserved.&lt;/p&gt;<br>    &lt;/footer&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Save the file as index.html in the /home/ubuntu/ directory on your Ansible master machine.</p><p><strong>Ansible Playbook for Web Content Deployment<br></strong>Create an Ansible playbook (deploy_static_page.yml):</p><pre>---<br>- name: Deploy Beautiful Static Page on Server-3<br>  hosts: server3<br>  become: yes<br>  tasks:<br>    - name: Install Nginx<br>      apt:<br>        name: nginx<br>        state: latest<br><br>    - name: Start Nginx<br>      service:<br>        name: nginx<br>        state: started<br>        enabled: yes<br><br>    - name: Copy index.html<br>      copy:<br>        src: /home/ubuntu/index.html<br>        dest: /var/www/html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*Wwcciywg7mlVD_i26HzUcg.png" /></figure><p><strong>Running the Ansible Playbook</strong></p><pre>ansible-playbook deploy_static_page.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B8eXTb1lIVGCij1txMm3lg.png" /></figure><p>This command will execute the playbook, and you should see output indicating the tasks being performed.</p><p><strong>Verifying the Deployment<br></strong>Open a web browser and navigate to http://&lt;server3-public-ip&gt;. You should see your beautiful static page displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*56gR408B_wbRZJP7PWXKUA.png" /></figure><p>Congratulations! You’ve successfully deployed a static page on Server-3 using Ansible, adding a touch of elegance to your Nginx-powered web server. This step not only showcases the power of Ansible in automating tasks but also sets the stage for more complex and sophisticated deployments in your infrastructure.</p><h3>Conclusion:</h3><p>In this comprehensive guide, we embarked on a journey to streamline the deployment of Nginx across multiple AWS EC2 instances using the powerful automation tool, Ansible. From the inception of creating AWS EC2 instances to the orchestration of Nginx installation and the deployment of a beautiful static page, we covered crucial steps in building a robust and automated web server infrastructure.</p><p>By adopting Ansible, we harnessed the ability to manage infrastructure as code, ensuring consistency, repeatability, and scalability. The provided Ansible playbook exemplifies the elegance of automation, simplifying complex tasks such as software installation, service management, and content deployment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f67bb898e39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Docker Image to AWS EKS (Terraform, ECR, IAM)]]></title>
            <link>https://medium.com/@sejalmaniyar9/deploying-a-docker-image-to-aws-eks-504f4fec6fee?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/504f4fec6fee</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Mon, 06 Nov 2023 08:37:15 GMT</pubDate>
            <atom:updated>2023-11-15T09:10:33.120Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>This documentation outlines the step-by-step process of building a Docker image, setting up an Amazon Elastic Container Registry (ECR) repository, pushing the Docker image to ECR, configuring and deploying the application on an Amazon Elastic Kubernetes Service (EKS) cluster, and verifying its functionality. The tasks were performed using the provided AWS credentials.</p><p><strong>Prerequisites</strong></p><p>Before starting, ensure you have the following prerequisites in place:<br>● AWS credentials for console login, AWS CLI access, and Kubernetes access.<br>● Docker installed on your local Ubuntu machine.<br>● AWS CLI installed and configured with the provided AWS credentials.<br>● kubectl installed and configured to work with your AWS EKS cluster.<br>● A Dockerfile for building the Docker image.<br>● A deployment.yaml manifest for deploying the application.</p><h3>Step 1: Installing Docker on Ubuntu</h3><p>1.1 Create a working directory named sejal_work. Install docker using the following commands.</p><pre>mkdir project<br>cd project<br>sudo apt-get update<br>sudo apt-get install docker.io<br>sudo systemctl start docker<br>sudo systemctl enable docker</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cTBn9tUuzV_eCGO4" /></figure><p>1.2 Create a Dockerfile using a text editor (e.g., Vim):</p><pre>vim Dockerfile</pre><p>In the Dockerfile, add the following content.</p><pre># Use the nginx:stable as the base image<br>FROM nginx:stable<br><br># Update and upgrade the installed packages, and install required utilities<br>RUN apt-get update &amp;&amp; \<br>    apt-get upgrade -y<br>    <br># Expose port 80 to the outside world<br>EXPOSE 80<br><br># CMD instruction to start Nginx when the container starts<br>CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]</pre><p>Save and exit the Dockerfile in Vim (usually by pressing Esc, then :wq).</p><p>1.3 Building the Docker Image Build the Docker image using the corrected Dockerfile:</p><pre>docker build -t sejal_image:latest -f Dockerfile .</pre><h3>Step 2 : Configure the AWS CLI</h3><p>2.1 Install the AWS CLI:</p><p>If the AWS CLI is not already installed on your EC2 instance, you can install it by running the following command:</p><pre>sudo apt update<br>sudo apt install awscli<br>aws --version</pre><p>2.2 Configure AWS CLI Credentials:</p><p>Once the AWS CLI is installed, you can configure it with your AWS access key ID and secret access key. Run the following command:</p><pre>aws configure</pre><p>This command will prompt you to enter the following information:</p><p>Enter your AWS Access Key ID.<br>Enter your AWS Secret Access Key.<br>Specify the default region.<br>Choose the desired output format (e.g., JSON)</p><p>2.3 Verify AWS CLI Configuration:</p><p>To verify that your AWS CLI configuration has been correctly set, you can run the following command:</p><pre>aws configure list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yy3uEC7uLsUFlZD9" /></figure><h3>Step 3: Installing Terraform on Ubuntu</h3><p>Download the latest Terraform binary for Linux:</p><pre>wget https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip<br>sudo apt install unzip<br>unzip terraform_1.5.7_linux_amd64.zip<br>sudo mv terraform /usr/local/bin/<br>terraform --version</pre><p>3.1. Create a file named ecr_sejal.tf using a text editor (e.g., Vim).</p><pre>vim ecr_sejal.tf</pre><p>Add the following Terraform configuration code to ecr_sejal.tf:</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 4.16&quot;<br>    }<br>  }<br>}<br><br>provider &quot;aws&quot; {<br>  region = &quot;eu-central-1&quot;<br>}<br><br>resource &quot;aws_ecr_repository&quot; &quot;sejal_docker_image&quot; {<br>  name = &quot;sejal_docker_image&quot;<br>}</pre><p>Save and exit the file in Vim (usually by pressing Esc, then :wq).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6UF44j3HuBb5Noaf" /></figure><p><strong>3.2. Initialize Terraform and apply the configuration:</strong></p><p>Apply the Terraform configuration to create the AWS ECR repository. Terraform will prompt you to confirm the creation. Type yes and press Enter.</p><pre>terraform init<br>terraform plan<br>terraform apply</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m2hPfvV-zM24cruL" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KdyByU9PwZd1usdM" /></figure><p>Step 4: Pushing Docker Image to ECR</p><ol><li>In the AWS Management Console, search for “ECR” or find “Elastic Container Registry” under “Services.”</li><li>Click on “Repositories” in the left navigation pane to view a list of ECR repositories.</li><li>Verify that the sejal_docker_image repository is listed. If it appears in the list, the ECR repository has been successfully created.</li><li>Click on the sejal_docker_image repository to access its details.</li><li>Inside the ECR repository, you should see a navigation tab labeled “Push commands.”</li><li>Click on it to view the commands required to push a Docker image to this repository.</li><li>Copy and paste the provided commands into your terminal one by one to push your Docker image to the ECR repository. The commands typically include authentication and the docker push command.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qkcuXN3Ln9TUl50w" /></figure><p>We can see that docker image has been pushed successfully.</p><h3>Step 5: Configure kubectl to Connect to an EKS Cluster</h3><p>To install kubectl on your Ubuntu terminal and configure it to use AWS credentials for connecting to an EKS cluster, you can follow these steps:</p><p><strong>5.1 Install kubectl</strong></p><p>You can install kubectl on your Ubuntu machine using the following commands:</p><pre>curl -LO &quot;https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl&quot;<br>chmod +x kubectl<br>sudo mv kubectl /usr/local/bin/</pre><p>This will download the latest stable version of kubectl and make it executable.</p><p><strong>5.2 Configure kubectl to Use AWS EKS</strong></p><p>Now, you need to configure kubectl to use the AWS credentials and connect to your EKS cluster. You can do this by updating your kubeconfig file:</p><pre>aws eks update-kubeconfig --region eu-central-1 --name sejal-m</pre><p><strong>5.3 Verify kubectl Configuration</strong></p><p>You can verify that kubectl is configured correctly by running:</p><pre>kubectl config view</pre><p><strong>5.4 Create the deployment.yaml file using vim.</strong></p><pre>kind: Deployment<br>metadata:<br>  name: nginx-deployment<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>        - name: nginx<br>          image: //ECR-image<br>          ports:<br>            - containerPort: 80<br>          resources:<br>            requests:<br>              cpu: 100m<br>              memory: 256Mi<br>            limits:<br>              cpu: 100m<br>              memory: 256Mi</pre><p><strong>5.5 Deploy the manifest file:</strong></p><pre>kubectl apply -f deployment.yaml</pre><p>In case you encounter errors when using kubectl to apply the manifest to your AWS EKS cluster, particularly with API versions, try the following debugging steps:<br>In my case, changing apiVersion to v1beta1 in the kube configuration file helped:<br>Go to ~/.kube/config file to make the necessary changes.</p><pre>apiVersion: client.authentication.k8s.io/v1beta1</pre><p><strong>5.6 Deploying and Verifying the Application</strong></p><pre>aws eks update-kubeconfig --region eu-central-1 --name sejal-m</pre><p><strong>5.7 Check the status of the deployment and pods</strong></p><pre>kubectl get deployments<br>kubectl get pods</pre><p><strong>5.8 Create a port-forward to access the application:</strong></p><pre>kubectl port-forward //name of the pod// 8080:80</pre><p>Open a web browser and navigate to <a href="http://localhost:8080/">http://localhost:8080</a> to verify the deployed web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDkRZZiHqKvrddxFqHdW8Q.png" /></figure><p>I see the nginx server running on port localhost:8080, it confirms that the deployment on the AWS EKS cluster is successful.</p><p>These are files created in the project directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2sjDMJyAEcOIpuWj" /></figure><h4>Conclusion</h4><p>In conclusion, I have successfully accomplished the following tasks:</p><ul><li>Built a Docker image using a provided Dockerfile.</li><li>Created an Amazon Elastic Container Registry (ECR) repository using Terraform.</li><li>Pushed the Docker image to the ECR repository.</li><li>Configured kubectl to work seamlessly with the Amazon Elastic Kubernetes Service (EKS) cluster.</li><li>Deployed the application onto the AWS EKS cluster.</li><li>Verified the functionality of the deployed application by accessing it via <a href="http://localhost:8080.">http://localhost:8080.</a></li></ul><p>This documentation serves as a reference for these tasks and can be used for future deployments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=504f4fec6fee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Single Cluster Monitoring on AWS: A Deep Dive into Prometheus, Grafana, cAdvisor, and…]]></title>
            <link>https://medium.com/@sejalmaniyar9/mastering-single-cluster-monitoring-a-deep-dive-into-prometheus-grafana-cadvisor-and-node-2cd076b20870?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cd076b20870</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Sat, 07 Oct 2023 20:11:38 GMT</pubDate>
            <atom:updated>2023-10-08T18:30:33.998Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Single Cluster Monitoring on AWS: A Deep Dive into Prometheus, Grafana, cAdvisor, and Node Exporter</h3><p>In the ever-evolving landscape of IT infrastructure, the need for comprehensive monitoring solutions has never been greater. In this detailed guide, we will enhance our monitoring setup to include Docker Compose, cAdvisor, and Node Exporter for a powerful and detailed view of our single cluster environment.</p><h3>Why Prometheus and Grafana?</h3><h3>Prometheus:</h3><p>Prometheus is an open-source monitoring and alerting toolkit designed to handle the complexities of modern, containerized environments. It excels in collecting and storing time-series data, making it an ideal choice for dynamic systems. Prometheus has a powerful query language called PromQL, enabling users to gain deep insights into their infrastructure’s behavior.</p><h3>Grafana:</h3><p>Grafana is a flexible analytics and monitoring platform that seamlessly integrates with various data sources, including Prometheus. It provides a rich set of visualization options, enabling users to create dashboards that are not only informative but also aesthetically pleasing. Grafana’s strength lies in its ability to aggregate data from different sources into cohesive and customizable dashboards.</p><h3>cAdvisor: Unveiling Container Insights</h3><p>cAdvisor (Container Advisor): cAdvisor is a tool that analyzes and exposes resource usage and performance data from running containers. It serves as a valuable addition to our monitoring stack, providing detailed insights into containerized environments within our single cluster. cAdvisor exposes Prometheus metrics out of the box, making it a perfect complement to our Prometheus setup.</p><h3>Setting Up Prometheus</h3><h3>1. Installation:</h3><p>Begin by downloading the latest release of Prometheus from the <a href="https://github.com/prometheus/prometheus/releases">official GitHub releases page</a>.</p><pre># Example for Linux<br>tar -xvf prometheus-*.tar.gz<br>cd prometheus-*<br>./prometheus --config.file=prometheus.yml</pre><h3>2. Configuration:</h3><p>Create a prometheus.yml configuration file that reflects the multi-cluster setup. Define scrape jobs for each cluster, ensuring that the configuration is dynamic enough to adapt to the evolving nature of cluster environments.</p><pre>global:<br>  scrape_interval: 15s<br><br>scrape_configs:<br>  - job_name: &#39;prometheus&#39;<br>    static_configs:<br>      - targets: [&#39;localhost:9090&#39;]<br><br>  - job_name: &#39;cluster-1&#39;<br>    static_configs:<br>      - targets: [&#39;cluster-1-prometheus:9090&#39;]<br><br>  - job_name: &#39;cluster-2&#39;<br>    static_configs:<br>      - targets: [&#39;cluster-2-prometheus:9090&#39;]<br><br>  # Add more cluster configurations as needed</pre><h3>3. Running Prometheus:</h3><p>Launch Prometheus with the configured file:</p><pre>./prometheus --config.file=prometheus.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oEbEQhQzrrTJoiz-z1UYtg.png" /></figure><h3>Setting Up Prometheus with Docker Compose</h3><h3>1. Docker Compose Configuration:</h3><p>Create a docker-compose.yml file to define the services required for our monitoring stack:</p><pre>version: &#39;3.2&#39;<br>services:<br>  prometheus:<br>    image: prom/prometheus:latest<br>    container_name: prometheus<br>    ports:<br>      - 9090:9090<br>    command:<br>      - --config.file=/etc/prometheus/prometheus.yml<br>    volumes:<br>      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro<br>    depends_on:<br>      - cadvisor<br><br>  cadvisor:<br>    image: gcr.io/cadvisor/cadvisor:latest<br>    container_name: cadvisor<br>    ports:<br>      - 8080:8080<br>    volumes:<br>      - /:/rootfs:ro<br>      - /var/run:/var/run:rw<br>      - /sys:/sys:ro<br>      - /var/lib/docker/:/var/lib/docker:ro<br>    depends_on:<br>      - redis<br><br>  redis:<br>    image: redis:latest<br>    container_name: redis<br>    ports:<br>      - 6379:6379</pre><h3>2. Run Docker Compose:</h3><pre>docker-compose up -d<br>docker-compose ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iq-kn2H6AqxsMl4zIECnFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_H-L7Mrn-Me55RkbStx9w.png" /></figure><h3>Setting Up Grafana</h3><h3>1. Installation:</h3><p>Install Grafana by following the instructions on the official <a href="https://grafana.com/grafana/download">Grafana download page</a>.</p><h3>2. Configuration:</h3><p>Start Grafana and configure it to connect to your Prometheus server. Add Prometheus as a data source in Grafana using the URL where Prometheus is running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FFxVrot0jLDS6bARUovxBg.png" /></figure><h3>Adding Node Exporter for System Metrics</h3><p>Node Exporter: Node Exporter is an integral part of our monitoring arsenal. It is designed to expose a wide variety of system metrics from the host machine. Node Exporter plays a crucial role in providing insights into the health and performance of the underlying system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69R3DdTGtorV4pkMnWCYSw.png" /></figure><h3>1. Node Exporter Installation:</h3><p>Extend our Docker Compose file to include Node Exporter:</p><pre>version: &#39;3.2&#39;<br>services:<br>  prometheus:<br>    # ... existing configuration<br><br>  cadvisor:<br>    # ... existing configuration<br><br>  redis:<br>    # ... existing configuration<br><br>  node-exporter:<br>    image: prom/node-exporter:latest<br>    container_name: node-exporter<br>    ports:<br>      - 9100:9100</pre><h3>2. Update Prometheus Configuration:</h3><p>Include the Node Exporter target in the prometheus.yml file:</p><pre>scrape_configs:<br>  - job_name: &#39;prometheus&#39;<br>    # ... existing configuration<br><br>  - job_name: &#39;node-exporter&#39;<br>    static_configs:<br>      - targets: [&#39;node-exporter:9100&#39;]</pre><h3>3. Run Docker Compose Again:</h3><pre>docker-compose up -d<br>docker-compose ps</pre><h3>Creating a Grafana Dashboard with Prometheus Metrics</h3><p>Access the Grafana dashboard by visiting http://localhost:3000 in your browser. Log in with the default credentials (admin/admin). Configure Prometheus as a data source in Grafana by specifying the URL where Prometheus is running.</p><h3>1. Create a Dashboard:</h3><ul><li>Click on the &quot;+&quot; icon in the left sidebar and select &quot;Dashboard.&quot;</li><li>Click on &quot;Add new panel&quot; to create visualizations.</li></ul><h3>2. Adding Metrics:</h3><ul><li>Choose Prometheus as the data source.</li><li>Use PromQL queries to fetch metrics. For example, you can use the query rate(container_cpu_usage_seconds_total{name=&quot;redis&quot;}[1m]) to visualize CPU usage for the Redis container.</li></ul><h3>3. Visualization:</h3><ul><li>Enhance your panels with various visualizations such as graphs, gauges, and tables.</li><li>Group panels logically and arrange them for a clear and intuitive layout.</li></ul><p>Adding cdAdvisory Panels:</p><ul><li>Create panels in Grafana that leverage cdAdvisory metrics. Use the specific queries or metrics exposed by cdAdvisory to monitor the health and performance of your application or infrastructure.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eOx57bS_aiU8HLbEJQNkKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ye_rORuXmNK1Ole9k0K7GA.png" /></figure><h3>Accessing Grafana Dashboard</h3><p>Visit http://localhost:3000 (default Grafana port) in your browser, and log in with the default credentials (admin/admin). Configure Prometheus as a data source in Grafana and start building your dashboards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_d6XiWOtBdYc5zVVzwe-EQ.png" /></figure><h3>Test PromQL Queries</h3><pre>rate(container_cpu_usage_seconds_total{name=&quot;redis&quot;}[1m])<br>container_memory_usage_bytes{name=&quot;redis&quot;}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8wbx3yD4hcIOMw23Edm56g.png" /></figure><h3>Conclusion</h3><p>By leveraging Docker Compose to orchestrate our monitoring services and integrating cAdvisor and Node Exporter, we’ve transformed our single cluster into a powerhouse of insights. Prometheus, Grafana, cAdvisor, and Node Exporter work harmoniously to provide detailed metrics for both containers and the underlying system.</p><p>Feel free to customize and extend your Grafana dashboards to visualize the metrics that matter most to your specific use case. Happy monitoring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cd076b20870" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Continuous Integration Pipeline with GitLab, Maven, and SonarQube on AWS]]></title>
            <link>https://medium.com/@sejalmaniyar9/building-a-continuous-integration-pipeline-with-gitlab-maven-and-sonarqube-on-aws-474e4df07913?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/474e4df07913</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Fri, 22 Sep 2023 11:39:56 GMT</pubDate>
            <atom:updated>2023-09-22T11:39:56.284Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Continuous Integration (CI) has become an integral part of modern software development, allowing developers to automate the building, testing, and analysis of their code. In this blog post, we’ll walk you through the process of creating a CI pipeline in GitLab for a Java repository. We’ll use Maven for building, SonarQube for code quality analysis, and deploy SonarQube on an AWS EC2 instance.</p><h3>Prerequisites</h3><p>Before we dive into setting up our CI pipeline, make sure you have the following in place:</p><ol><li>A GitLab account and a Java repository.</li><li>GitLab Runner (either shared or your own).</li><li>An AWS account to create an EC2 instance.</li><li>Basic knowledge of Maven and SonarQube.</li></ol><h3>Step 1: Setting Up Your GitLab Repository</h3><p>If you haven’t already, create a GitLab repository for your Java project and push your code into it. Make sure your project contains a pom.xml file, which is essential for Maven.</p><p>GitHub:- <a href="https://github.com/sejal1011/GitLab_CI">https://github.com/sejal1011/GitLab_CI</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3miLBfOZNX7Sr6ZbQmUTg.png" /></figure><h3>Step 2: Creating a .gitlab-ci.yml File</h3><p>The heart of your CI/CD pipeline in GitLab is the .gitlab-ci.yml file, which defines the stages and jobs to be executed. Create this file in the root directory of your GitLab repository and add the following code:</p><pre>image: &#39;abhishekf5/maven-abhishek-docker-agent:v1&#39;<br><br>variables:<br>  DOCKER_HOST: tcp://docker:2375<br>  DOCKER_TLS_CERTDIR: &#39;&#39;<br>  SONAR_HOST_URL: http://54.237.226.245:9000<br>  SONAR_LOGIN: ${SONAR_LOGIN}<br><br># Define the default working directory for the pipeline<br>before_script:<br>  - cd java-maven-sonar-argocd-helm-k8s/spring-boot-app<br><br>stages:   <br>  - build<br>  - test<br>  - sonarqube<br> <br><br>build-job:  <br>  stage: build<br>  script:<br>    - echo &quot;Compiling the code...&quot;<br>    - mvn clean package<br><br>unit-test-job:  <br>  stage: test  <br>  script:<br>    - echo &quot;Running unit tests... This will take about 60 seconds.&quot;<br>    - mvn test<br><br>code-quality-job:  <br>  stage: sonarqube <br>  script:<br>    - echo &quot;scanning code&quot;<br>    -  mvn sonar:sonar -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_LOGIN}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yDaLCcjF_PcD16BZAFMaug.png" /></figure><p>This YAML file defines three stages: build, test, and sonarqube. In the build stage, we clean and package our Java application using Maven. The test stage runs our unit tests, and the sonarqube stage analyzes the code using SonarQube.</p><h3>Step 3: Set Up SonarQube on an AWS EC2 Instance</h3><p>Now, let’s set up SonarQube on an AWS EC2 instance:</p><p>Launch an EC2 instance with Ubuntu.<br>Open port 9000 for both inbound and outbound traffic in your security group rules.<br>SSH into your EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tbExtBUIiBnbTBPUxhtFSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nn0N8UefnYIkvPJ_TAdEmw.png" /></figure><h3>Step 4: Generating a SonarQube Authentication Token</h3><p>To secure the interaction between your GitLab CI/CD pipeline and SonarQube, you’ll need to generate an authentication token in SonarQube and configure it in your CI/CD environment variables. This token will allow the pipeline to communicate with SonarQube securely.</p><p>Follow these steps to generate a SonarQube authentication token:</p><ol><li>Log in to SonarQube: Access your SonarQube web interface by navigating to <a href="http://your-ec2-public-ip:9000/">http://your-ec2-public-ip:9000</a> in your web browser. Log in using your SonarQube administrator credentials.</li><li>Navigate to User Settings: Click on your profile picture or username in the top-right corner of the SonarQube interface, and select “My Account” from the dropdown menu.</li><li>Generate Token: In the user settings page, click on the “Security” tab. Here, you will find an option to generate a token. Click on the “Generate” button.</li><li>Provide Token Name: Give your token a meaningful name that will help you identify its purpose. For example, you can name it “GitLab CI/CD Token.”</li><li>Copy the Token: Once generated, a token will be displayed on the screen. This token is crucial for authenticating your GitLab CI/CD pipeline with SonarQube. Copy the token and keep it secure as it will not be displayed again.</li><li>Configure GitLab CI/CD Variables: Return to your GitLab project’s settings and navigate to Settings &gt; CI/CD &gt; Variables.</li><li>Add a New Variable: Create a new variable with the name SONAR_LOGIN and paste the token you generated from SonarQube as the variable’s value.</li><li>Save Variables: Click on the “Add Variable” button to save the SONAR_LOGIN variable.</li></ol><p>Now, your GitLab CI/CD pipeline is configured to use this authentication token when interacting with SonarQube. This token ensures that only authorized access is granted to SonarQube for code analysis and other operations, enhancing the security of your CI/CD process.</p><p>With the SonarQube authentication token in place, your CI/CD pipeline can seamlessly integrate with SonarQube to analyze your code for quality and security without compromising on security.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2iGDOxje0hhcwxXY-1AFwA.png" /></figure><h3>Step 5: Configuring Environment Variables</h3><p>In your GitLab project settings, navigate to the “CI/CD” section and add the following environment variables:</p><p>SONAR_HOST_URL: The URL of your SonarQube server or cloud instance.<br>SONAR_TOKEN: An access token or authentication key for SonarQube.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pnZOnbh_1caTzrqOfrhQ9g.png" /></figure><h3>Step 6: Registering Your GitLab Runner</h3><p>If you haven’t already, ensure that you have a GitLab Runner registered and properly configured for your repository. The runner is responsible for executing the pipeline jobs. You can use shared runners provided by GitLab or set up your own runner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuooLeNMohXp5_yMzmzo6A.png" /></figure><h3>Step 7: Running CI Pipeline</h3><p>With everything set up, push your changes (including the .gitlab-ci.yml file) to your GitLab repository. This will trigger the CI/CD pipeline automatically. You can monitor the pipeline’s progress in the GitLab UI.</p><ol><li>The “build” stage will compile your Java code.</li><li>The “test” stage will run your unit tests using Maven.</li><li>The “sonarqube” stage will perform static code analysis and send the results to SonarQube.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-onnLq_4oOpPgufJUc26mw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GH7Q--0drmEhBEY1iRd41A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCKHu0y5MBQlrL4VAaHa_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUhGZiw3veTy5dpwxy8EQw.png" /></figure><p>View the Dashboard: The project dashboard provides an overview of various aspects of code quality, including:</p><p>Bugs: Actual coding errors that need to be fixed.<br>Vulnerabilities: Security-related issues that could lead to vulnerabilities.<br>Code Smells: Indications of poor code structure or design.<br>Coverage: Test coverage information.</p><h3>Conclusion</h3><p>Congratulations! You’ve successfully set up a CI/CD pipeline in GitLab for your Java project, integrating Maven for building and testing and SonarQube for code quality analysis. This pipeline will help you catch bugs early, ensure code quality, and streamline your development process.</p><p>Remember that CI/CD pipelines are highly customizable, and you can extend them to include additional stages, such as deployment to various environments. Continuously improving and automating your development workflows is key to delivering high-quality software efficiently.</p><p>By leveraging GitLab’s CI/CD capabilities, you are taking a significant step towards a more agile and efficient software development process. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=474e4df07913" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an End-to-End DevOps CI/CD Pipeline for Java Applications on Kubernetes with Jenkins]]></title>
            <link>https://medium.com/@sejalmaniyar9/building-an-end-to-end-devops-ci-cd-pipeline-for-java-applications-on-kubernetes-with-jenkins-98664e1e51cc?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/98664e1e51cc</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Sun, 03 Sep 2023 13:55:26 GMT</pubDate>
            <atom:updated>2023-09-04T07:16:41.104Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating a CI/CD pipeline for a Java application to deploy on a Kubernetes cluster using Jenkins is a complex and multi-step process. In this blog post, we’ll walk through each step in detail, from installing and configuring the necessary tools to deploying the application on Kubernetes. We will also discuss the integration of Jenkins with SonarQube for static code analysis, Dockerizing the application, identifying misconfigurations in Helm charts using Datree, and enabling pull request triggers. Let’s get started.</p><h3>Prerequisites</h3><p>Before we begin, ensure that you have the following prerequisites in place:</p><ol><li>AWS EC2 Instances: You mentioned that you have 5 AWS EC2 instances. Ensure that these instances are set up correctly with the necessary security groups and permissions.</li><li>Docker: Install Docker on your EC2 instances. Docker will be used for containerizing your Java application.</li><li>Kubernetes (K8s): Set up a Kubernetes cluster on your EC2 instances.</li><li>Jenkins: Install Jenkins on one of your EC2 instances. Jenkins will be the core of our CI/CD pipeline.</li><li>SonarQube: Set up SonarQube for static code analysis. You can install it on another EC2 instance.</li><li>Nexus: Install Nexus as a private artifact repository for storing Docker images and Helm charts.</li><li>Helm: Install Helm, a package manager for Kubernetes, on your Jenkins server.</li><li>Datree: Install Datree for identifying misconfigurations in Helm charts.</li><li>Mail Server: Set up a mail server for configuring email notifications.</li></ol><h3>Step 1: Installing and Configuring Tools</h3><p>In this section, we’ll cover the installation and configuration of essential tools required for setting up our end-to-end DevOps CI/CD pipeline for Java applications on Kubernetes. We’ll be using AWS t2.medium instances for this purpose. Please refer to the installation guide provided in my<a href="https://github.com/sejal1011/CICD_Pipeline_for_Java_Applications/tree/main"> GitHub repository</a>.</p><h4>Docker:</h4><p>Docker is a containerization platform that allows you to package applications and their dependencies into containers. Install Docker on your EC2 instances using the official documentation.</p><h4>Kubernetes (k8s):</h4><p>Kubernetes is an open-source container orchestration platform. Set up a Kubernetes cluster on your EC2 instances using tools like kubeadm, kops, or a managed Kubernetes service like EKS.</p><h4>Jenkins:</h4><p>Jenkins is a widely used automation server. Install Jenkins on one of your EC2 instances, and configure it to be accessible via your domain name. Install the necessary plugins for Kubernetes, SonarQube, Nexus, and email notifications.</p><h4>SonarQube:</h4><p>SonarQube is a code quality and security analysis tool. Install and configure SonarQube on a separate EC2 instance. Integrate Jenkins and SonarQube using the Jenkins SonarQube plugin for static code analysis.</p><h4>Nexus:</h4><p>Nexus is a repository manager for storing Docker images and Helm charts. Install Nexus on another EC2 instance and configure Docker repositories for storing Docker images and Helm repositories for storing Helm charts.</p><h4>Helm:</h4><p>Helm is a package manager for Kubernetes. Install Helm on one of your EC2 instances and configure it to work with your Kubernetes cluster. Create Helm charts for your Java application.</p><h4>Datree:</h4><p>Datree is a tool for identifying misconfigurations in Helm charts. Install Datree on one of your EC2 instances and set up policies to check your Helm charts for misconfigurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MaR5xskF6UjDhr8KJ2njOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*uPVIexqjHamMsKlp3myL7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*I_3LClanQrbS_E4-z8CBhw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*-xxhte1IE3GgUANPQDxApQ.png" /></figure><h3>Step 2: Building the CI/CD Pipeline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtZEvn0j7Z-wIUC2bdM8bw.png" /><figcaption>Flow Chart of our CI/CD Pipeline.</figcaption></figure><h4>2.1 Dockerizing the Application:</h4><p>Containerize your Java application using a Dockerfile. Build the Docker image and push it to your private Docker registry in Nexus.</p><h4>2.2 Identifying Misconfigurations in Helm Charts:</h4><p>Integrate Datree into your Jenkins pipeline to automatically check your Helm charts for misconfigurations before deploying to Kubernetes.</p><h4>2.3 Pushing Helm Charts to Nexus:</h4><p>Push your Helm charts to Nexus for reusability and versioning.</p><h4>2.4 Manual Approval for Deployment:</h4><p>Set up a manual approval step in your Jenkins pipeline to ensure a controlled deployment process.</p><h4>2.5 Deploying the Application on Kubernetes:</h4><p>Use Helm to deploy your Java application on your Kubernetes cluster. Jenkins should automate this process as part of your CI/CD pipeline.</p><h3>Step 3: Configuring Email Notifications</h3><p>Configure Jenkins to send email notifications to notify stakeholders about the build and deployment status. Ensure that email notifications are sent in case of failures or successful deployments.</p><h3>Step 4: Enabling Pull Request Trigger</h3><p>Configure Jenkins to trigger the CI/CD pipeline automatically when changes are pushed to your source code repository. This ensures that your pipeline is triggered on every pull request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hgUp42QvBYQeRhWfel_Z_w.png" /><figcaption>The complete CI/CD Pipeline.</figcaption></figure><p>Above is a screenshot of the complete CI/CD pipeline we’ve built throughout this guide. This visual representation gives you an overview of the entire process, from code commits to deployment on the Kubernetes cluster.</p><h4>Key Highlights of the CI/CD Pipeline:</h4><ul><li>Code Commit: The pipeline starts with developers committing their code to the version control system (e.g., Git).</li><li>Static Code Analysis: Jenkins seamlessly integrates with SonarQube to perform static code analysis, ensuring code quality and security.</li><li>Docker Image Build: Docker builds the application into a container image and pushes it to the private Docker registry in Nexus.</li><li>Helm Chart Validation: Datree checks Helm charts for misconfigurations before proceeding with deployment.</li><li>Manual Approval: Developers and stakeholders have control over the deployment process. They can approve or reject deployments.</li><li>Kubernetes Deployment: Helm deploys the application on the Kubernetes cluster, leveraging Helm charts stored in Nexus.</li><li>Email Notifications: Jenkins sends email notifications to keep stakeholders informed about build and deployment statuses.</li><li>Pull Request Trigger: The pipeline is triggered automatically whenever changes are pushed to the source code repository</li></ul><h3>Conclusion:</h3><p>In this blog post, we’ve successfully set up a comprehensive CI/CD pipeline for a Java application to deploy on a Kubernetes cluster using Jenkins and various DevOps tools. We covered the installation and configuration of Docker, Kubernetes, Jenkins, SonarQube, Nexus, Helm, and Datree, as well as the integration of these tools into a cohesive pipeline. By following these steps, you can streamline your software delivery process, improve code quality, and ensure efficient deployments on Kubernetes. Building a robust CI/CD pipeline is a critical step in achieving a modern and efficient DevOps workflow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98664e1e51cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing Log Monitoring with Grafana, Loki, and Promtail: A Comprehensive Guide]]></title>
            <link>https://medium.com/@sejalmaniyar9/building-a-monitoring-dashboard-with-grafana-311c29ab8571?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/311c29ab8571</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Sat, 02 Sep 2023 10:11:27 GMT</pubDate>
            <atom:updated>2023-09-02T10:20:13.830Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In today’s fast-paced digital world, keeping an eye on the health and performance of your applications and infrastructure is crucial. One of the best ways to achieve this is by setting up a robust monitoring system, and Grafana is an exceptional tool for this purpose. In this blog post, I’ll walk you through the process of creating a monitoring dashboard using Grafana on an AWS EC2 t1.micro instance running Ubuntu. <strong>We’ll also integrate Loki and Promtail to capture and visualize logs, focusing on monitoring an Nginx installation as an example.</strong></p><p>Before we dive into the installation and configuration, let’s go over the prerequisites to ensure a smooth setup.</p><h3>Prerequisites</h3><ol><li>AWS EC2 Instance:</li></ol><ul><li>You should have an AWS account and access to the EC2 service.</li><li>Launch an EC2 t1.micro instance with Ubuntu (or any Linux distribution of your choice).</li><li>Make sure you have SSH access to your EC2 instance.</li></ul><p>2.Basic Linux Skills:</p><p>Familiarity with basic Linux command-line operations is essential.</p><p>3. Configure your AWS security group:</p><p>Configure your AWS security group to allow incoming traffic on ports 22 (SSH) and 3000 (Grafana).</p><p>Now that we’ve covered the prerequisites, let’s move on to the installation and configuration steps.</p><p>Installation Steps</p><p>Installation Steps</p><p>Step 1: SSH into your AWS EC2 Instance</p><p>Open your terminal and use the SSH command to connect to your EC2 instance:</p><pre>ssh -i &lt;your-key.pem&gt; ubuntu@&lt;your-ec2-public-ip&gt;</pre><p>Step 2: Update and Upgrade</p><ul><li>Ensure that your system packages are up to date by running the following commands:</li></ul><pre>sudo apt update<br>sudo apt upgrade -y</pre><p>Step 3: Install Grafana</p><ul><li>Add the Grafana APT repository and install Grafana using these commands:</li></ul><pre>sudo apt install -y software-properties-common<br>sudo add-apt-repository &quot;deb https://packages.grafana.com/oss/deb stable main&quot;<br>wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -<br>sudo apt update<br>sudo apt install grafana -y</pre><p>Step 4: Start and Enable Grafana</p><ul><li>Start the Grafana service and enable it to start on boot:</li></ul><pre>sudo systemctl start grafana-server<br>sudo systemctl enable grafana-server</pre><p>Step 5: Install Loki and Promtail (for Log Collection)</p><ul><li>Download and install Loki and Promtail using the official Loki repository:</li></ul><pre>##Download Loki Config<br><br>wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml<br><br>##Run Loki Docker container<br><br>docker run -d --name loki -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:2.8.0 --config.file=/mnt/config/loki-config.yaml<br><br>##Download Promtail Config<br><br>wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml<br><br>##Run Promtail Docker container<br><br>docker run -d --name promtail -v $(pwd):/mnt/config -v /var/log:/var/log --link loki grafana/promtail:2.8.0 --config.file=/mnt/config/promtail-config.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2oYESZcKT_sNs2NfxSdmQA.png" /><figcaption>2 images created.</figcaption></figure><p>Step 6: Configure Nginx Logs for Loki and Promtail</p><ul><li>Configure Nginx to log access and error logs to a JSON format that Loki can understand. Update your Nginx site configuration file accordingly.</li></ul><p>Step 7: Configure Loki and Promtail</p><ul><li>Configure Promtail to scrape the Nginx log files and send them to Loki. Ensure the Promtail configuration file reflects the correct log file paths.</li></ul><p>Step 8: Access the Grafana Web Interface</p><ul><li>Open a web browser and navigate to your EC2 instance’s public IP address on port 3000 (http://&lt;your-ec2-public-ip&gt;:3000).</li><li>Log in with the default credentials (username: admin, password: admin).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*VT3nb-WOXywHm-GiDvrgpw.png" /><figcaption>Grafana Login</figcaption></figure><ul><li>Change your password and set up data sources for Loki and Prometheus.</li></ul><p>Step 9: Configure Loki Data Source</p><p>In the “Add data source” page, search for “Loki” in the list of available data sources and click on it.<br>In the “HTTP” section, enter the Loki URL as <a href="http://localhost:3100/">http://localhost:3100</a> since Loki is running on the same server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VCyiEF77Bz7uA-WtkJumEw.png" /><figcaption>Data Source</figcaption></figure><p>Step 10: Scroll down to the “Label filters” section.<br>Click on the “Add value” button next to the “job” label filter.<br>Enter “varlogs” as the value for the “job” label filter. This filter will help you narrow down logs from the “varlogs” job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNvpLZlu8MlRvZOA2GzV0Q.png" /><figcaption>Add the label to see logs</figcaption></figure><p>Step 11: Click on Run query</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kG3kI3hRuV8Mt_wrnf-PBA.png" /><figcaption>Varlogs</figcaption></figure><p>Step 12: You can add other log sources to Promtail.yaml.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*mooiy8ere0sHqGQ5dRjzbw.png" /><figcaption>Edited Promtail.yaml</figcaption></figure><p>Finally, we can see our Nginx logs monitoring dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*l7zfYcI1PLwE6lb3gTcBWw.png" /><figcaption>Final Dashboard.</figcaption></figure><h3>Conclusion</h3><p>In conclusion, we’ve successfully created a powerful monitoring dashboard that allows us to track and analyze Nginx logs with precision and ease. By combining Grafana, Loki, and Promtail on an AWS EC2 t1.micro instance running Ubuntu, we’ve harnessed the capabilities of these tools to visualize and gain insights from our log data.</p><p>With our Grafana dashboard configured to use Loki as a data source and equipped with label filters, we can efficiently focus on monitoring specific aspects of our infrastructure, such as the “varlogs” job. This setup not only simplifies log monitoring but also enables us to proactively detect issues, troubleshoot problems, and ensure the smooth operation of our Nginx server.</p><p>By extending the power of Grafana and Loki, we’ve taken a significant step toward improving the overall health and performance of our applications and infrastructure, making our system more robust and reliable. This monitoring solution is a valuable asset in the world of DevOps, enabling us to stay ahead of potential issues and ensure the seamless operation of our services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=311c29ab8571" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Linux Commands: From Basics to Advanced  with File Permissions ]]></title>
            <link>https://medium.com/@sejalmaniyar9/mastering-linux-commands-from-basics-to-advanced-with-file-permissions-8d15c0236834?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d15c0236834</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Sat, 02 Sep 2023 05:17:22 GMT</pubDate>
            <atom:updated>2023-09-02T05:17:22.645Z</atom:updated>
            <content:encoded><![CDATA[<p>Linux commands are the building blocks of the open-source operating system, and learning how to use them can empower you to take full control of your computer. Whether you’re a beginner or a seasoned user, this guide will walk you through essential Linux commands, from the basics to more advanced operations. We’ll also explore the concept of file permissions, a fundamental aspect of Linux security.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZEhgP0nZgn5C-Pgd1Fhmg.jpeg" /></figure><p>Basics of Navigation and File Operations<br>1. 📂 pwd (Print Working Directory): Shows your current directory.</p><pre>pwd</pre><p>2.📄 ls (List): Lists files and directories in the current directory.</p><pre>ls</pre><p>3.✍️ touch: Creates an empty file.</p><pre>touch filename</pre><p>4.📁 mkdir (Make Directory): Creates a new directory.</p><pre>mkdir directory_name</pre><p>5.📦 cp (Copy): Copies files or directories.</p><pre>cp source destination</pre><p>6.🚚 mv (Move): Moves or renames files and directories.</p><pre>mv source destination</pre><p>7.🗑️ rm (Remove): Deletes files or directories.</p><pre>rm filename</pre><p>8. 🚶 cd (Change Directory): Moves you to a different directory.</p><pre>cd directory_name</pre><h3>Working with Text Files:</h3><ol><li>📝 cat: Concatenates and displays file content.</li></ol><pre>cat filename</pre><p>2.📜 more/less: Allows you to view text files one screen at a time.</p><pre>more filename</pre><h3>File Permissions:</h3><p>Linux uses a robust file permission system to control who can perform specific actions on files and directories, such as reading, writing, or executing. These permissions are categorized into three groups:</p><p>1. Owner (User): The user who owns the file or directory. Typically, the person who created it.<br>2. Group: A collection of users who share the same permissions on the file or directory.<br>3. Others (World): All other users who are not the owner or part of the group.</p><ol><li>🔒 chmod (Change Mode): Modifies file permissions.</li></ol><pre>chmod permissions filename</pre><p>‘permissions’ can be expressed as numbers (e.g., 755) or symbolic notation (e.g., u+rwx, g+rx, o+r).</p><p>1. 👤 chown (Change Owner): Changes the owner of a file or directory.</p><pre>chown new_owner filename</pre><p>2. 👥 chgrp (Change Group): Changes the group of a file or directory.</p><pre>chgrp new_group filename</pre><p>Understanding file permissions is critical for maintaining security and privacy on your Linux system. Here’s what the numbers and symbols mean:</p><p>4: Read permission (r).<br>2: Write permission (w).<br>1: Execute permission (x).<br>0: No permission.</p><p>For example, chmod 755 filename gives the owner read, write, and execute permissions, while others only have read and execute permissions.</p><p>Advanced Commands:<br>Let’s explore a few advanced Linux commands that can help you manage files and directories efficiently:</p><ol><li>👑 chown (Change Owner): This command allows you to change the owner of a file or directory.</li></ol><pre>chown new_owner: new_group myfile.txt</pre><p>2.👥 chgrp (Change Group): Use this command to change the group associated with a file or directory.</p><pre>chgrp new_group myfile.txt</pre><p>3.🔐 umask: This command helps set default permissions for newly created files and directories on your system. It’s useful for controlling security.</p><pre>umask 022</pre><h3>Conclusion:</h3><p>Understanding and managing file permissions is a crucial skill for Linux users. It allows you to control who can access and modify your files, enhancing the security and integrity of your system. By combining this knowledge with essential Linux commands, you can efficiently navigate, organize, and secure your Linux environment while harnessing the full power of the command line. So, dive into the world of Linux commands, experiment, and enjoy the flexibility and control they provide! 🌟</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d15c0236834" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streamlining Development with Jenkins Declarative Pipelines: From GitHub to DockerHub]]></title>
            <link>https://medium.com/@sejalmaniyar9/building-a-declarative-pipeline-in-jenkins-1885a209c291?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1885a209c291</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Sat, 02 Sep 2023 04:10:09 GMT</pubDate>
            <atom:updated>2023-09-02T04:10:42.816Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to the Jenkins Declarative Pipeline project! 🚀</p><p>In this project, we’ve harnessed the power of Jenkins to automate our entire CI/CD pipeline. Leveraging the simplicity and readability of Declarative Pipelines, our process unfolds seamlessly.</p><p>Here’s the essence of our project:</p><ol><li><strong>GitHub Integration</strong>: Our codebase resides on GitHub, making collaboration and version control a breeze.</li><li><strong>Automated SCM Setup</strong>: We’ve automated the setup using GitHub Webhooks, ensuring that code changes automatically trigger our pipeline.</li><li><strong>Clone and Build:</strong> Jenkins fetches our code from GitHub, compiles it, and performs any necessary testing and quality checks.</li><li><strong>DockerHub Deployment: </strong>Once the build is successful, our application is packaged into Docker containers and pushed to DockerHub, ensuring a streamlined and efficient deployment process.</li><li><strong>Deployment:</strong> Finally, our application is deployed to its target environment, ready to serve its purpose.</li></ol><p>Join us on this journey as we showcase the power of Jenkins Declarative Pipelines in orchestrating this end-to-end automation, empowering us to focus on innovation and delivering value to our users.</p><h3>Jenkins Declarative Pipeline</h3><p>The Jenkins Declarative Pipeline is a higher-level abstraction built on top of the traditional Jenkins Pipeline scripting language. It provides a simpler and more structured way to define continuous integration and continuous delivery (CI/CD) pipelines in Jenkins. The Declarative Pipeline uses a predefined set of stages, steps, and directives to cover common CI/CD scenarios, making it easier to create and maintain pipelines compared to writing complex Groovy scripts.</p><h3><strong>There are two main types of Jenkins Pipelines:</strong></h3><p>What is a Pipeline — A pipeline is a collection of steps or jobs interlinked in a sequence.</p><ol><li>Scripted Pipeline: This is the original Pipeline DSL for Jenkins. It involves writing Groovy scripts to define your pipeline steps. While it offers flexibility, it can sometimes become complex and harder to manage as pipelines grow in size and complexity.</li><li>Declarative Pipeline: Introduced as a simpler and more structured way to define pipelines, the Declarative Pipeline allows you to define pipelines using a more concise syntax. It provides a predefined set of stages, steps, and directives to cover common CI/CD scenarios, while still allowing you to customize and extend as needed.</li></ol><h3>The benefits of Jenkins Declarative Pipeline include:</h3><ol><li><strong>Simplicity</strong>: Easier to read and write compared to scripted pipelines.</li><li><strong>Maintainability</strong>: Simplifies pipeline maintenance and updates.</li><li><strong>Reusability</strong>: Encourages reuse of defined stages and steps.</li><li><strong>Scalability</strong>: Scales well for small to large projects.</li><li><strong>Error Handling</strong>: Built-in error handling and recovery mechanisms.</li><li><strong>Code Review</strong>: Supports easier code review and collaboration.</li><li><strong>Parallel Execution</strong>: Simplifies parallel job execution.</li><li><strong>Integration</strong>: Seamless integration with Jenkins and plugins.</li></ol><h3><strong>Steps to create a Jenkins Declarative Pipeline</strong></h3><p>step 1: Launch an AWS EC2 instance.</p><p>step 2: Clone the Repo in your terminal.</p><p>Link:- <a href="https://github.com/sejal1011/django-notes-cicd">https://github.com/sejal1011/django-notes-cicd</a></p><p>step 3: Now install docker and check the version. Then add your current user to the docker group and reboot it. Also, install docker-compose.</p><pre>sudo apt update<br>sudo apt-get install docker.io<br>docker --version<br>sudo usermod -aG docker $USER<br>sudo reboot</pre><p>step 6: Once this is done, let’s install Jenkins and continue our project in Jenkins😊</p><p><em>Within this step we have certain sub-steps to install Jenkins, let’s see those</em></p><p>A. Install Java and check the version.</p><pre>sudo apt update<br>sudo apt install openjdk-17-jre<br>java -version</pre><p>B. Install Jenkins and check the version</p><pre>curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \<br>  /usr/share/keyrings/jenkins-keyring.asc &gt; /dev/null<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>  https://pkg.jenkins.io/debian binary/ | sudo tee \<br>  /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt-get install jenkins</pre><p>Please Refer:- <a href="https://www.jenkins.io/doc/book/installing/linux/">https://www.jenkins.io/doc/book/installing/linux/</a></p><p>step 7: Edit inbound security rules to add ports 8080 on which Jenkins runs and port 8000 on which our docker container is exposed. Give permission to Jenkins to access docker.</p><pre>sudo usermod -aG docker jenkins<br>sudo reboot</pre><p>step 8: Now copy your public IP address and paste it into the browser followed by the port number 8080. Unlock Jenkins with a password. Then install the suggested plugins and fill in the admin details.</p><p>step 9: Click on Create a job →Enter the item name →Select pipeline &amp; press ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L5W44Jax9marVOC2GQXI9w.png" /><figcaption>Click on the pipeline.</figcaption></figure><p>step 10: Give a simple description and then select GitHub Project and paste the below URL. Click on Build Triggers, GitHub hook trigger for GitScm pooling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8qNUUebbYZpRVGepAd4Rw.png" /><figcaption>Add the necessary configuration.</figcaption></figure><p>step 11: Select pipeline → Type pipeline code → press save.</p><pre>pipeline { <br>    agent any <br>    stages{ <br>        stage(&quot;Code&quot;){ <br>            steps { <br>                echo &quot;Cloning the code&quot;<br>                git url: &#39;https://github.com/sejal1011/django-notes-cicd.git&#39;, branch: &#39;main&#39;<br>                } <br>            <br>        } <br>        stage(&quot;Build&quot;){ <br>            steps {<br>                echo &quot;Building the image&quot; <br>                sh &quot;docker build . -t my-notes-app&quot;} <br>            <br>        } <br>        stage(&quot;Push to Docker Hub&quot;){<br>            steps { <br>                echo &quot;Pushing the image to docker hub&quot; <br>                withCredentials([usernamePassword(credentialsId:&quot;dockerHub&quot;,passwordVariable:&quot;dockerHubPass&quot;,usernameVariable:&quot;dockerHubUser&quot;)]){<br>                 sh &quot;docker tag my-notes-app ${env.dockerHubUser}/my-notes-app:latest&quot;<br>                 sh &quot;docker login -u ${env.dockerHubUser} -p ${env.dockerHubPass}&quot;<br>                 sh &quot;docker push ${env.dockerHubUser}/my-notes-app:latest&quot;   <br>                }<br>                } <br>            <br>        }<br>        stage(&quot;Deploy&quot;){<br>             steps { echo &quot;Deploying the container&quot; <br>                    sh &quot;docker-compose down &amp;&amp; docker-compose up -d&quot;    <br>                    } <br>                } <br>             }<br>        }</pre><p>Before editing the code in configure, let’s create environment variables to safeguard our credentials :)</p><p>Goto Dashboard → click on Manage Jenkins → Credentials.</p><p>Add the dockerHub credentials in Jenkins and then use them as a variable in our script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ILhKtJC6PFnRvYj2Uu_wuA.png" /><figcaption>Add the dockerHub credentials.</figcaption></figure><p>step 12: Click on Build Now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fVKKufCB8oRS7DnP8x_b5w.png" /><figcaption>The Build is successful.</figcaption></figure><p>Now goto Docker Hub, refresh and check for your image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*VaV_m6AFvRtqEe2kv_yEOA.png" /><figcaption>My Image is pushed to DockerHub.</figcaption></figure><h3>Source Code Management</h3><p>Now let’s try with the SCM(source code management) where we get our pipeline code directly from Github itself. Let’s try…</p><p>step 1: Now go to the configure and change from pipeline to SCM. Create a file in our GitHub repo known as Jenkinsfile. Add the code to our file as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RCeaTUQqq2cZvSJGBP4KQ.png" /><figcaption>Jenkinsfile added to our GitHub repo.</figcaption></figure><p>step 2: Fill in the fields with the proper URL and specify the branch name properly. Now save and build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bl7jPp4KAGY4Crm580MVAg.png" /><figcaption>Our pipeline is getting deployed.</figcaption></figure><h3><strong>GitHub webhooks</strong></h3><p>Setting up GitHub webhooks with Jenkins allows you to automate builds triggered by events in your GitHub repositories. Here are the steps to achieve this:</p><p>Step 1: GitHub Repository Configuration:</p><ul><li>In your GitHub repository, go to “Settings” &gt; “Webhooks” &gt; “Add webhook.”</li><li>Enter the Payload URL, which should be your Jenkins server’s URL followed by /github-webhook/. Example: <a href="https://your-jenkins-url/github-webhook/">https://your-jenkins-url/github-webhook/</a></li><li>Set the Content type to application/json.</li><li>Choose the events that should trigger the webhook (e.g., Pushes, Pull Requests).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcYHnEtOZ-Nkd_U6YlTBrw.png" /><figcaption>GitHub Webhook Configuration.</figcaption></figure><p>Step 2: Jenkins Job Configuration:</p><p>In your Jenkins job configuration, under the “Build Triggers” section, enable “GitHub hook trigger for GITScm polling” if you haven’t already.<br>Build Configuration:</p><p>Configure your Jenkins job to perform the desired build and deployment actions when triggered by the webhook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*1vPqDv4t8WEphyMUWtWNig.png" /><figcaption>This is our app running on port 8000.</figcaption></figure><p>Now, whenever the configured GitHub events occur (e.g., code pushes or pull requests), GitHub will send a webhook payload to Jenkins, triggering your job to automate builds and other actions. This setup streamlines your CI/CD process, ensuring that code changes trigger the necessary pipeline automatically.</p><h3>Conclusion: 🚀</h3><p>In wrapping up this Jenkins Declarative Pipeline project, we’ve unlocked the true potential of automation. From GitHub to DockerHub, our pipeline seamlessly manages code, builds, and deployments, making development a breeze.</p><p>With Jenkins at the helm, we’ve embraced efficiency, reliability, and consistency in our development process. No more manual intervention — just code, build, and deploy with ease.</p><p>Here’s to continuous improvement and innovation! 🌟 #AutomationMastery #JenkinsMagic #CI/CD #DevOps #EfficiencyUnleashed</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1885a209c291" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy a Reddit Copy on Kubernetes with Ingress-Enabled]]></title>
            <link>https://medium.com/@sejalmaniyar9/deploy-a-reddit-copy-on-kubernetes-with-ingress-enabled-4b5f7964632a?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b5f7964632a</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Wed, 30 Aug 2023 20:50:53 GMT</pubDate>
            <atom:updated>2023-08-30T21:30:59.679Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to a concise exploration of deploying a Reddit Clone App using Kubernetes and Kubeatm on AWS EC2. In this condensed guide, we’ll navigate through essential steps, from setting up your Kubernetes cluster with Kubeatm to configuring Ingress for external access. Whether you’re a newcomer or an experienced Kubernetes enthusiast, this guide provides valuable insights into a seamless deployment process. Let’s embark on this journey of efficiently bringing a Reddit Clone App to life in a Kubernetes environment.</p><h3>📋 Step 1: Pre-requisites 🛠️</h3><p><strong>Setting Up the Kubernetes Cluster on AWS EC2 with Kubeatm:</strong></p><p>Follow the steps outlined in the Kubeatm installation guide to set up Kubeatm on both the master and worker nodes. Please click on the GitHub link to follow the guide.</p><p><a href="https://github.com/sejal1011/Kubernetes/blob/main/kubeadm_installation.md">GitHub Link</a></p><h3>📂 Step 2: Clone the Source Code 📥</h3><p>The first step is to clone the source code for the app. You can do this by using this command git clone <a href="https://github.com/sejal1011/reddit-clone-k8s-ingress.git">https://github.com/sejal1011/reddit-clone-k8s-ingress.git</a>.</p><h3>🛳️ Step 3: Containerize the Application using Docker</h3><p>Write a Dockerfile with the following code:</p><pre><br>FROM node:19-alpine3.15<br><br>WORKDIR /reddit-clone<br><br>COPY . /reddit-clone<br><br>RUN npm install <br><br>EXPOSE 3000<br><br>CMD [&quot;npm&quot;,&quot;run&quot;,&quot;dev&quot;]</pre><h3>🛠️ Step 4: Building Docker-Image</h3><p>Now it’s time to build Docker Image from this Dockerfile. docker build -t &lt;DockerHub_Username&gt;/&lt;Imagename&gt; . use this command to build a docker image.</p><h3>🚀 Step 5: Push the Image To DockerHub 🐳</h3><p>Now push this Docker Image to DockerHub so our Deployment file can pull this image &amp; run the app in Kubernetes pods.</p><ul><li>First login to your DockerHub account using Command i.e docker login and give your username &amp; password.</li><li>Then use docker push &lt;DockerHub_Username&gt;/&lt;Imagename&gt; for pushing to the DockerHub.</li><li>You can use an existing docker image i.e <em>sejal1011m/reddit-clone-app</em> for deployment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*32dXGJQK9LIER7jGWAFcgQ.png" /><figcaption>This is Docker image pushed on DockerHub.</figcaption></figure><h3>Step 6:📄 Write a Kubernetes Manifest File</h3><p>Now, You might be wondering what this manifest file in Kubernetes is. Don’t worry, I’ll tell you in brief.</p><p>When you are going to deploy to Kubernetes or create Kubernetes resources like a pod, replica-set, config map, secret, deployment, etc, you need to write a file called manifest that describes that object and its attributes either in yaml or json. Just like you do in the ansible playbook.</p><p>Of course, you can create those objects by using just the command line, but the recommended way is to write a file so that you can version control it and use it in a repeatable way.</p><h3><strong>Write Deployment.yml file</strong></h3><p>Let’s Create a Deployment File For our Application. Use the following code for the <em>Deployment.yml</em> file.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: reddit-clone-deployment<br>  labels:<br>    app: reddit-clone<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: reddit-clone<br>  template:<br>    metadata:<br>      labels:<br>        app: reddit-clone<br>    spec:<br>      containers:<br>      - name: reddit-clone<br>        image: trainwithshubham/reddit-clone<br>        ports:<br>        - containerPort: 3000</pre><h3><strong>Write Service.yml file</strong></h3><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: reddit-clone-service<br>  labels:<br>    app: reddit-clone<br>spec:<br>  type: NodePort<br>  ports:<br>  - port: 3000<br>    targetPort: 3000<br>    nodePort: 31000<br>  selector:<br>    app: reddit-clone</pre><h3>🚀 Step 7: Deploy the app to Kubernetes and create a Service For It</h3><p>Now, we have a deployment file for our app and we have a running Kubernetes cluster, we can deploy the app to Kubernetes. To deploy the app you need to run following the command: kubectl apply -f Deployment.yml Just Like this create a Service using kubectl apply -f Service.yml</p><p>If You want to check your deployment &amp; Service use the command kubectl get deployment &amp; kubectl get services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*WeaxMmX_3I_mxDly77Jx4w.png" /><figcaption>Code Snippet</figcaption></figure><h3>🛠️ Step 8: Let’s Configure Ingress 🌐</h3><h3>Ingress:</h3><p>In Kubernetes, “Ingress” is like a traffic controller for incoming network connections. It manages how external requests get routed to specific services within the cluster, like directing web traffic to the right web application. It simplifies handling different domains, paths, and protocols, making it easier to manage external access to your applications.</p><p>Let’s write ingress.yml and put the following code in it:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: ingress-reddit-app<br>spec:<br>  rules:<br>  - host: &quot;domain.com&quot;<br>    http:<br>      paths:<br>      - pathType: Prefix<br>        path: &quot;/test&quot;<br>        backend:<br>          service:<br>            name: reddit-clone-service<br>            port:<br>              number: 3000<br>  - host: &quot;*.domain.com&quot;<br>    http:<br>      paths:<br>      - pathType: Prefix<br>        path: &quot;/test&quot;<br>        backend:<br>          service:<br>            name: reddit-clone-service<br>            port:<br>              number: 3000</pre><p>Create an ingress for your service using the command kubectl apply -f ingress.yml to apply ingress settings.</p><p>To access your application, you can use the NodePort service you defined in the Deployment.yaml file. Allow traffic on NodePort 31000 for our worker instance.</p><p>🎉 Congratulations! You’ve Successfully Deployed a Reddit Clone App Using Kubernetes! 🚀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*SCMfr2FJTLnXKE5_8Mx1Ig.png" /><figcaption>A Reddit Clone App.</figcaption></figure><h3>🧪 Test Ingress🌐</h3><p>Now It’s time to test your ingress so use the <em>curl -L domain/test</em> command in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*WOyAX9Y41x3mts1M57_Idw.png" /><figcaption>The backend of my application.</figcaption></figure><h3><strong>🔚 Conclusion: Wrapping Up the Journey 🌟</strong></h3><p>In conclusion, this journey through setting up a Kubernetes cluster on AWS EC2 with Kubeatm has equipped you with valuable insights into a seamless deployment process. Here’s a recap of the key steps covered:</p><ol><li>Kubeatm Installation: Followed the comprehensive guide to install Kubeatm on both master and worker nodes. Refer to the provided GitHub link for detailed instructions.</li><li>Source Code Cloning: Kickstarted the process by cloning the application’s source code using the command git clone <a href="https://github.com/sejal1011/reddit-clone-k8s-ingress.git.">https://github.com/sejal1011/reddit-clone-k8s-ingress.git.</a></li><li>Containerizing with Docker: Crafted a Dockerfile to containerize the application, making it deployable. The Dockerfile snippet was provided for your convenience.</li><li>Docker Image Building and Pushing: Built the Docker Image using docker build and pushed it to DockerHub for effortless access by Kubernetes pods.</li><li>Kubernetes Manifests: Introduced to Kubernetes manifests and their significance in describing and managing resources. Created a Deployment.yml and a Service.yml file for the application.</li><li>Deployment and Service Creation: Deployed the app using kubectl apply -f Deployment.yml and created a service with kubectl apply -f Service.yml.</li><li>Ingress Configuration: Understood the role of Ingress as a traffic controller for external requests and learned to configure it using an ingress.yml file.</li><li>Testing Ingress: Verified the deployment’s success by testing the Ingress with a curl command, ensuring external access to the app.</li></ol><p>With this journey’s conclusion, you’ve gained the tools to confidently deploy a Reddit Clone App using Kubernetes, marking a significant achievement in your Kubernetes journey. 🚀📦🌐</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b5f7964632a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying ToDo App using Helm Charts (K8s)]]></title>
            <link>https://medium.com/@sejalmaniyar9/deploying-node-todo-app-using-helm-charts-6d3c07dc3c3d?source=rss-130be922487c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d3c07dc3c3d</guid>
            <dc:creator><![CDATA[Sejal Maniyar]]></dc:creator>
            <pubDate>Wed, 30 Aug 2023 10:49:07 GMT</pubDate>
            <atom:updated>2023-08-30T11:54:59.092Z</atom:updated>
            <content:encoded><![CDATA[<h3>📍 Section 1: Introduction 🌟</h3><p>Welcome to this blog post, where we’ll guide you through the seamless deployment of a Docker image from Docker Hub using the robust Helm. Helm stands out as a versatile package manager designed for Kubernetes, enabling the definition, installation, and upgrading of intricate Kubernetes applications.</p><h3>Why Helm?</h3><p>Harnessing Helm’s Power! 🚀</p><p>Helm, the Kubernetes package manager, redefines deployment ease:</p><ol><li><strong>Package Magic</strong>: Bundle apps with dependencies into “charts” for a breeze in distribution and setup.</li><li><strong>Version Control</strong>: Chart versions, safely stored, simplify management, and swift rollbacks.</li><li><strong>Dynamic Templates</strong>: Craft dynamic Kubernetes manifests using Go templates — effortless customization, zero redundancy.</li><li><strong>Upgrade Bliss</strong>: Seamlessly update or roll back apps, minimizing downtime and ensuring smooth transitions.</li><li><strong>Team Synergy</strong>: Collaborate seamlessly with shareable Helm charts, slashing configuration risks.</li></ol><p>Helm: Your DevOps gem, making Kubernetes a cakewalk! 🎯🛠️</p><p><strong>Important Helm Commands</strong></p><pre>helm create [CHART]: Scaffold a new Helm chart.<br>helm package [CHART]: Package the chart into a chart archive.<br>helm install [NAME] [CHART]: Install a Helm chart.<br>helm upgrade [NAME] [CHART]: Upgrade an installed Helm chart.<br>helm uninstall [NAME]: Uninstall an installed Helm chart.<br>helm list: List all installed Helm charts.<br>helm rollback [NAME] [REVISION]: Roll back a release to a specific revision.</pre><h3>📋 Section 2: Pre-requisites 🛠️</h3><ol><li>Create Kubernetes Cluster on AWS EC2 with Kubeatm</li><li>Install Helm</li><li>Install Docker (Optional for custom images)</li></ol><p><strong>Setting Up the Kubernetes Cluster on AWS EC2 with Kubeatm:</strong></p><p>Follow the steps outlined in the Kubeatm installation guide to set up Kubeatm on both the master and worker nodes. Please click on the GitHub link to follow the guide.</p><p><a href="https://github.com/sejal1011/Kubernetes/blob/main/kubeadm_installation.md?source=post_page-----aaf28f10ab38--------------------------------">GitHub Link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EyyLnkbBYQztc7wo.png" /><figcaption>Two Instances are running successfully.</figcaption></figure><p><strong>How to Install Helm in Ubuntu</strong></p><pre>curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg &gt; /dev/null<br>sudo apt-get install apt-transport-https --yes<br>echo &quot;deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main&quot; | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list<br>sudo apt-get update<br>sudo apt-get install helm</pre><h3>📂 Section 3: Create Helm Chart Structure 🏗️</h3><p>First, we need to create a Helm chart to define the deployment of our application. Open your terminal and run the following command to create a Helm chart named “node-app”:</p><pre>helm create node-app-chart</pre><p>This will create a folder named node-app-chart with the initial chart structure.</p><h3>📋Section 4: Chart Metadata (Chart.yaml)</h3><p>Open Chart.yaml and modify it for your application:</p><pre>apiVersion: v2<br>name: node-app-chart<br>description: A Helm chart for a Node.js application<br>version: 0.1.0</pre><h3>📋 Section 5: Default Values (values.yaml)</h3><p>Navigate to the “node-app” directory and open the values.yaml file in your preferred text editor. Edit values.yaml to include:</p><pre>replicaCount: 1<br><br>image:<br>  repository: sejal1011m/node-todo-app<br>  tag: latest<br>  pullPolicy: IfNotPresent<br><br>service:<br>  type: NodePort<br>  port: 30007<br>  targetPort: 8000</pre><p>Use my Docker image published on Docker Hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*W6v5wY13XMBsKLdlPN5anQ.png" /><figcaption>This is Docker Image for Node ToDo App.</figcaption></figure><p>This configuration specifies the number of replicas, Docker image details, and service specifications for your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*Yg3bPXZxrQ4ZQAEQw1BzSA.png" /><figcaption>values.yaml file can be edited as per requirements.</figcaption></figure><h3>📄 Section 7: Service Manifest (service.yaml)</h3><p>Open templates/service.yaml under templates/ and modify it. Verify whether the port numbers are mapped correctly. Also add security rule on port 30007 on our worker node. Allow traffic on NodePort 30007 for our worker instance.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: {{ .Release.Name }}-service<br>spec:<br>  type: {{ .Values.service.type }}<br>  ports:<br>  - port: {{ .Values.service.port }}<br>    targetPort: {{ .Values.service.targetPort }}<br>    nodePort: {{ .Values.service.port }}<br>  selector:<br>    app: {{ .Release.Name }}</pre><h3>🚀Section 8: Deploying the Helm Chart</h3><p>Now that our Helm chart is configured, we can deploy our application to the Kubernetes cluster. Use the following command:</p><pre># Package the chart (Optional)<br>helm package node-app-chart<br><br># Deploy the chart<br>helm install my-node-app ./node-app-chart</pre><p>This command deploys the “node-app” Helm chart to your Kubernetes cluster. Helm will create all the necessary Kubernetes resources based on the configuration in your chart.</p><h3>🔎 Section 9: Verify the Deployment 🧐</h3><p>To verify that your application has been deployed successfully, you can run the following command to list all the deployments in your cluster:</p><pre>kubectl get deployments<br>or<br>kubectl get all</pre><h3>🔗 Section 10: Access Your Application 🌐</h3><p>To access your application, you can use the NodePort service you defined in the values.yaml file. Find the NodePort assigned to your service:</p><pre>kubectl get svc<br>kubectl get pods</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*MsPOf6ia8YD5zC66AXNMbw.png" /><figcaption>It shows Pods are running.</figcaption></figure><p>🎉 Congratulations! You have successfully deployed a Docker image from Docker Hub using Helm. This app is running on the NodePort 30007.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NLTvUYAJkbYn92QirLSL7w.png" /><figcaption>ToDo App Deployed Successfully!</figcaption></figure><h3>🔍 Conclusion:</h3><p>In summary, this guide has walked you through deploying a Docker image from Docker Hub using Helm, the dynamic package manager for Kubernetes. To recap:</p><ol><li><strong>Prerequisites</strong>: Ensured Kubernetes cluster, Helm installation, and local Docker setup.</li><li><strong>Creating Helm Chart</strong>: Crafted a vital “node-app” Helm chart, pivotal for defining and packaging Kubernetes apps.</li><li><strong>Editing values.yaml</strong>: Tailored application specifics in values.yaml — Docker image, replicas, and service setup.</li><li><strong>Deploying Helm Chart</strong>: Utilized helm install to deploy the app onto Kubernetes.</li><li><strong>Verification</strong>: Ensured a successful deployment by validating deployment and service statuses.</li><li><strong>Accessing App</strong>: Demonstrated how to access your app via the chart’s NodePort service.</li></ol><p>With Helm’s prowess, complex Kubernetes deployments are now a simplified reality. 🚀📦🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d3c07dc3c3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>