<?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 Aashisaxena on Medium]]></title>
        <description><![CDATA[Stories by Aashisaxena on Medium]]></description>
        <link>https://medium.com/@aashisaxena15?source=rss-760ecded3118------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xNTxVQCf_UdSniVc</url>
            <title>Stories by Aashisaxena on Medium</title>
            <link>https://medium.com/@aashisaxena15?source=rss-760ecded3118------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 17:03:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aashisaxena15/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[Automating Flask App Deployment Using Jenkins, Docker, and Ansible (CI/CD Project)]]></title>
            <link>https://aashisaxena15.medium.com/automating-flask-app-deployment-using-jenkins-docker-and-ansible-ci-cd-project-fd77f7745f98?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd77f7745f98</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Sun, 15 Jun 2025 18:16:25 GMT</pubDate>
            <atom:updated>2025-06-15T18:16:25.118Z</atom:updated>
            <content:encoded><![CDATA[<h3>Project Overview</h3><p>In this project, I automated the CI/CD pipeline to:</p><ul><li>Pull a Flask application from GitHub.</li><li>Build a Docker image.</li><li>Push the image to a remote server.</li><li>Deploy it using Ansible.</li></ul><p>The pipeline was executed from Jenkins and deployed the application to a separate EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*REsBrT6Hgonjy8QzSDUYug.png" /></figure><h3>Tech Stack Used</h3><ul><li><strong>Jenkins</strong> — CI/CD Orchestration</li><li><strong>Docker</strong> — Containerization</li><li><strong>Ansible</strong> — Remote Deployment Automation</li><li><strong>GitHub</strong> — Source Code Management</li><li><strong>EC2</strong> — Cloud Hosting (Remote Server)</li></ul><h3>Step-by-Step Implementation</h3><p>Create 2 servers as follows:</p><p>Jenkins server (ubuntu instance: t2.medium):</p><p>use the following configurations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9S6vDbS40f0A3tPnTIbSFA.png" /></figure><p>Another server for target, use the following configurations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkNp_P6h4PKSZxRzQLOw1w.png" /></figure><h3>1. Jenkins Installation</h3><pre>sudo apt update<br>sudo apt install openjdk-11-jdk -y</pre><pre># Add Jenkins repository key<br>wget -q -O - <a href="https://pkg.jenkins.io/debian-stable/jenkins.io.key">https://pkg.jenkins.io/debian-stable/jenkins.io.key</a> | sudo apt-key add -</pre><pre># Add Jenkins source<br>sudo sh -c &#39;echo deb <a href="https://pkg.jenkins.io/debian-stable">https://pkg.jenkins.io/debian-stable</a> binary/ &gt; /etc/apt/sources.list.d/jenkins.list&#39;</pre><pre># Install Jenkins<br>sudo apt update<br>sudo apt install jenkins -y<br>sudo systemctl start jenkins</pre><p>📝 <em>Jenkins needs Java to run, so we install OpenJDK first. Then we set up the Jenkins repository and install Jenkins.</em></p><h3>2. Install Docker and Ansible</h3><pre>sudo apt install docker.io -y<br>sudo usermod -aG docker jenkins<br>sudo apt install ansible -y<br>sudo systemctl restart jenkins</pre><p>💡 <em>Jenkins needs Docker to build and export the image, so we add the Jenkins user to the Docker group.</em></p><h3>3. Setup SSH for Jenkins to Connect Remote Server</h3><pre>sudo mkdir -p /var/lib/jenkins/.ssh<br>sudo cp /root/.ssh/id_rsa /var/lib/jenkins/.ssh/<br>sudo cp /root/.ssh/id_rsa.pub /var/lib/jenkins/.ssh/<br>sudo chmod 600 /var/lib/jenkins/.ssh/id_rsa<br>sudo chown -R jenkins:jenkins /var/lib/jenkins/.ssh<br>sudo chmod 700 /var/lib/jenkins/.ssh</pre><pre># Add remote server to known hosts<br>sudo ssh-keyscan -H 13.204.65.9 &gt;&gt; /var/lib/jenkins/.ssh/known_hosts<br>sudo chmod 644 /var/lib/jenkins/.ssh/known_hosts</pre><p>🔐 <em>This setup is important for password-less SSH between Jenkins and the remote EC2 server.</em></p><h3>4. GitHub Project Structure</h3><pre>ci-cd-jenkins-ansible-docker/<br>├── app/<br>│   └── app.py<br>├── Dockerfile<br>├── Jenkinsfile<br>└── ansible/<br>    └── deploy.yaml</pre><p>📝 <em>The Flask app code is in the </em><em>app/ folder, the </em><em>Dockerfile defines the container, the </em><em>Jenkinsfile controls the pipeline, and </em><em>deploy.yaml defines the Ansible tasks.</em></p><h3>5. Jenkinsfile</h3><pre>pipeline {<br>    agent any<br>    stages {<br>        stage(&#39;Clone Code&#39;) {<br>            steps {<br>                git branch: &#39;main&#39;, url: &#39;https://github.com/aashisaxena15/ci-cd-jenkins-ansible-docker.git&#39;<br>            }<br>        }</pre><pre>        stage(&#39;Build Docker Image&#39;) {<br>            steps {<br>                sh &#39;docker build -t my-flask-app:latest .&#39;<br>            }<br>        }</pre><pre>        stage(&#39;Export Image as TAR&#39;) {<br>            steps {<br>                sh &#39;docker save my-flask-app:latest -o my-flask-app.tar&#39;<br>            }<br>        }</pre><pre>        stage(&#39;Copy Image to Remote&#39;) {<br>            steps {<br>                sh &#39;scp -i /var/lib/jenkins/.ssh/id_rsa my-flask-app.tar ubuntu@13.204.65.9:/tmp/&#39;<br>            }<br>        }</pre><pre>        stage(&#39;Deploy via Ansible&#39;) {<br>            steps {<br>                sh &#39;ansible-playbook -i ansible/inventory ansible/deploy.yaml&#39;<br>            }<br>        }<br>    }<br>}</pre><p>💡 <em>Each stage in Jenkins represents a step in the pipeline. The image is saved, securely copied, and then deployed.</em></p><h3>6. Ansible inventory File</h3><pre>[web]<br>13.204.65.9 ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa</pre><p>🔧 <em>Defines the remote EC2 instance as the target for Ansible tasks.</em></p><h3>7. Ansible deploy.yaml</h3><pre>- name: Deploy Flask App Container<br>  hosts: web<br>  become: true<br>  tasks:<br>    - name: Load Docker image from tar<br>      shell: docker load &lt; /tmp/my-flask-app.tar</pre><pre>    - name: Remove old container (if exists)<br>      shell: docker rm -f flaskapp || true</pre><pre>    - name: Run the Docker container<br>      shell: docker run -d --name flaskapp -p 80:5000 my-flask-app:latest</pre><p>This playbook:</p><ol><li>Loads the Docker image from the .tar file,</li><li>Removes any existing container named flaskapp,</li><li>Runs the new container on port 80.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CPMMO5hrQ8syRCbjI6lESQ.png" /></figure><h3>Final Verification</h3><ol><li>Access your Flask App by navigating to:<br> http://&lt;EC2-IP&gt; → Example: <a href="http://13.204.65.9/">http://13.204.65.9</a></li><li>Jenkins logs should show each stage’s success:</li></ol><ul><li>Clone ✅</li><li>Build ✅</li><li>Export ✅</li><li>SCP ✅</li><li>Ansible Deploy ✅</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0W-aFwJL5sV1FqEK2XIdPw.png" /></figure><h3>Troubleshooting</h3><p>Error Solution docker: not found Install Docker on the remote server Host key verification failed Add remote IP to known_hosts for Jenkins Permission denied (publickey) Ensure correct key permissions and user ownership</p><h3>Conclusion</h3><p>This project demonstrates a real-world CI/CD pipeline using Jenkins, Docker, and Ansible without relying on DockerHub or third-party registries.</p><p>Github-repo : <a href="https://github.com/aashisaxena15/ci-cd-jenkins-ansible-docker.git">https://github.com/aashisaxena15/ci-cd-jenkins-ansible-docker.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd77f7745f98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins-Cluster-Setup-in-Docker-Kubernetes]]></title>
            <link>https://aashisaxena15.medium.com/jenkins-cluster-setup-in-docker-kubernetes-569aa19e6b4f?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/569aa19e6b4f</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Sat, 14 Jun 2025 11:16:09 GMT</pubDate>
            <atom:updated>2025-06-14T11:19:08.952Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WVqDOb7rQC6_zBLUJ1VVJQ.png" /></figure><p>In this project, we will demonstrate how to <strong>manually configure a Jenkins Master-Agent cluster</strong> using the following approach:</p><ul><li><strong>Docker containers</strong> based on Ubuntu images (no pre-built Jenkins images)</li><li><strong>Step-by-step installation</strong> of Jenkins and its dependencies</li><li><strong>Custom Docker images</strong> for both Jenkins Master and Agents</li><li><strong>Kubernetes</strong> to orchestrate and scale the Jenkins setup in a production-like environment</li></ul><p>This hands-on setup provides a deep understanding of Jenkins architecture, its operation within Docker containers, and how to manage scalability using Kubernetes.</p><h3>Part 1: Jenkins Cluster Setup on Docker (Manual Way)</h3><h3>Step 1: AWS EC2 Setup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cd-E6gZ-qO24xoG2Kla-Lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xoLOeepC0pymtQRM4BcoOw.png" /></figure><h3>Step 2: Install Docker on EC2</h3><pre># Add Docker&#39;s official GPG key:<br>sudo apt-get update<br>sudo apt-get install ca-certificates curl<br>sudo install -m 0755 -d /etc/apt/keyrings<br>sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc<br>sudo chmod a+r /etc/apt/keyrings/docker.asc<br><br># Add the repository to Apt sources:<br>echo \<br>  &quot;deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \<br>  $(. /etc/os-release &amp;&amp; echo &quot;${UBUNTU_CODENAME:-$VERSION_CODENAME}&quot;) stable&quot; | \<br>  sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt install docker.io<br>sudo usermod -aG docker ubuntu<br>sudo systemctl restart docker<br>docker ps </pre><h3>Step 3 : Jenkins Docker Network &amp; Master Setup:</h3><pre>docker network create jenkins<br>docker run -dit --name jenkins-master -p 8080:8080 --network jenkins ubuntu:22.04<br>docker exec -it jenkins-master bash</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhskKN4HLhLN83EkOx8teA.png" /></figure><h3>Step 4: Install Java &amp; Jenkins Manually (Inside Jenkins Master Container)</h3><pre>apt-get update<br>apt-get install -y wget curl git unzip nano software-properties-common<br>add-apt-repository ppa:openjdk-r/ppa<br>apt-get update<br>apt-get install -y openjdk-18-jdk<br>java -version<br>mkdir -p /opt/jenkins &amp;&amp; cd /opt/jenkins<br>wget https://get.jenkins.io/war-stable/latest/jenkins.war<br>java -jar jenkins.war --enable-future-java</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJl_Dx4KYWGH3lGRnLypyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yx6EtLS8x3ZrLyFLU6KoIg.png" /></figure><p>Edit the inbound rules for the ec2-instance that you are in, open port 8080 for accessing the jenkins application. Here for demo purpose only I have given permissions to all traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l3mrLc-L0Ic3y9C3r3hXvA.png" /></figure><p>Open: http://&lt;EC2_PUBLIC_IP&gt;:8080</p><p>Get the initial admin password:</p><pre>cat /root/.jenkins/secrets/initialAdminPassword</pre><p>As you can see, the application is up and running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7yq99FB7zJIWK4Fu8EyGA.png" /></figure><h3>Step 5: Jenkins Agent Setup (Manual Docker)</h3><pre>docker run -dit --name jenkins-agent-1 --network jenkins ubuntu:22.04<br>docker exec -it jenkins-agent-1 bash<br><br># Inside agent:<br>apt update<br>apt install -y software-properties-common<br>add-apt-repository ppa:openjdk-r/ppa<br>apt update<br>apt install -y openjdk-18-jdk wget git curl unzip nano</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6iIpUHZAwbxbW9xe.png" /></figure><pre>mkdir -p /home/jenkins/agent &amp;&amp; cd /home/jenkins/agent<br>wget http://jenkins-master:8080/jnlpJars/agent.jar</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eA9ZbftEJhWTVU6i.png" /></figure><h3>Step 6: Connect Agent to Jenkins Master</h3><p>In Jenkins UI:<br>Navigate to: Jenkins → Manage Jenkins → Nodes → New Node Set configuration:</p><ul><li>Name: agent-1</li><li>Type: Permanent Agent</li><li>Remote root dir: /home/jenkins/agent</li><li>Labels: agent-1</li><li>Usage: Use this node as much as possible</li><li>Launch Method: Launch agent by connecting it to the controller</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*apbFi1n8QWHDQi9e.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CcgNq3Q-I9hJhIm8.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xMpFTgXCVaQHSgaI.png" /></figure><ul><li>Jenkins will show a command like:</li></ul><pre>java -jar agent.jar -url http://jenkins-master:8080/ -secret &lt;SECRET_KEY&gt; -name &quot;agent-1&quot; -workDir &quot;/home/jenkins/agent&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RtOl4QnvZdmFNicS.png" /></figure><p>Run this inside the agent container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fUYb5Yklj7fxZZsg.png" /></figure><p>✅ Agent should now show as <strong>Connected</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y9DkOVxq9FPUox0_.png" /></figure><h3>Step 7 : Test Job on Agent</h3><ul><li>Create a freestyle job</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0iH3yF5khX33UOFp.png" /></figure><ul><li>→ Restrict it to agent-1</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kTwXpHKunY9-35gp.png" /></figure><ul><li>Add shell build step:</li></ul><pre>echo &quot;Running on Jenkins Agent 1&quot;<br>hostname<br>whoami</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rZsDCamqfZr0j_Wo.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uoLankNo1TmrCgHD.png" /></figure><h3>Part 2: Jenkins Cluster Setup on kubernetes (Manual Way)</h3><p>Create Dockerfile and deployment files for master and slaves setup seperately</p><p>mkdir project/jenkins-master &amp;&amp; cd jenkins-master</p><p>vi Dockerfile (master)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hCfMc3-AAOAn-cfmlY1RJg.png" /></figure><blockquote><em>Build and push:</em></blockquote><pre>docker build -t aashisaxena15/jenkins-master .<br>docker push aashisaxena15/jenkins-master</pre><p>mkdir project/jenkins-slave &amp;&amp; cd jenkins-slave</p><p>vi Dockerfile (slave)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oUUaQbo4XUi9Zf66TpClWA.png" /></figure><blockquote><em>Build and push:</em></blockquote><pre>docker build -t aashisaxena15/jenkins-slave .<br>docker push aashisaxena15/jenkins-slave</pre><h3>Kubernetes Deployment for Jenkins Master</h3><p>cd project/jenkins-master</p><p>vi deployment-service-master.yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*SagV-eltjZc8dX-Q7gBJBQ.png" /></figure><p>cd project/jenkins-slave</p><p>vi deploy-slave.yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*-BlNAPgtjEcJ9f3xS37P9A.png" /></figure><p>start the minikube cluster and apply the files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kKmzoDo_wsCLpBu1QQ0wAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VsYOQNLUIBeuOxz0QBe8hg.png" /></figure><p>Access Jenkins UI:<br>http://&lt;Node IP&gt;:30080</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ACu31PBAICdF9Cup8EarQ.png" /></figure><h3>Final Agent Connection</h3><ul><li>Add SSH credentials in Jenkins UI (Manage Jenkins -&gt; Credentials).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v98tQFO_JGi5uD1x.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jvIceEMWFSc1WxAq.png" /></figure><ul><li>Add new node via SSH in Jenkins.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HdCt7gR_WDMV8Kcc.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KRWT1bFSPDPX64tM.png" /></figure><p><strong>One node has been added. Now, add the second slave node in the same way.</strong></p><p><strong>click on right side settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*vJe-AVC_usLZCcp-.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*5DsI98455L1AMRfS.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/0*3TGLMn6V11-kQMx4.png" /></figure><ul><li>for all nodes <strong>do 0 for now</strong></li><li>just for quick future testing</li><li>Test the agent by running a job on the slave node.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/0*rHutqKZnlBxzI0EL.png" /></figure><ul><li>Restrict it to label for agent</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w7aMiXTJr_DX22OX.png" /></figure><h3>Conclusion</h3><p>This project gives you <strong>a hands-on understanding of Jenkins clusters inside Docker and Kubernetes without relying on official images.</strong> You built everything manually, from the OS layer to Java, Jenkins installation, and even SSH key-based agent communication.</p><p>For codes, check the github-repository :</p><p><a href="https://github.com/aashisaxena15/Jenkins-Cluster-Setup-in-Docker-Kubernetes.git">https://github.com/aashisaxena15/Jenkins-Cluster-Setup-in-Docker-Kubernetes.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=569aa19e6b4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerized Flask Web App Deployment using Ansible on Kubernetes]]></title>
            <link>https://aashisaxena15.medium.com/dockerized-flask-web-app-deployment-using-ansible-on-kubernetes-89af2e74146b?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/89af2e74146b</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Fri, 13 Jun 2025 16:31:01 GMT</pubDate>
            <atom:updated>2025-06-13T16:31:01.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4y0sdHE4zNBiyz-igKJsqg.png" /></figure><p>This project followed a hands-on approach to orchestrating the deployment of a containerized web application using Docker, Kubernetes, and Ansible — without relying on pre-configured images or automated provisioning tools. The process began by manually setting up Docker, Kubernetes, and Ansible environments on the target systems to ensure full visibility and control over each component. A simple Python Flask web application was then created, accompanied by a Dockerfile to containerize the application. Ansible playbooks were written to automate key tasks: copying application files to the necessary directory, building the Docker image, optionally pushing the image to Docker Hub, and applying Kubernetes manifests to deploy the app within a Kubernetes cluster. After deployment, the setup was tested by accessing the application via the Kubernetes service endpoint to confirm successful deployment and functionality. This end-to-end workflow provided a clear understanding of how infrastructure automation, containerization, and orchestration work together in a DevOps pipeline</p><p>STEP BY STEP IMPLEMENTATION:</p><p><strong>Environment Setup</strong></p><p>Manually installed Docker, Kubernetes, and Ansible on the local machine to simulate a production-like DevOps environment without using any pre-built tools or images.</p><p>Here’s a clean and concise breakdown of the <strong>Environment Setup</strong> steps taken from your command history:</p><h3>1) Environment Setup</h3><p><strong>Install Docker</strong></p><pre>sudo apt update &amp;&amp; sudo apt install docker.io -y sudo systemctl start docker sudo systemctl enable docker sudo usermod -aG docker $USER</pre><p><strong>Install Ansible</strong></p><pre>sudo apt install ansible -y</pre><p><strong>Install kubectl</strong></p><pre>sudo snap install kubectl --classic</pre><h3>2) Environment Setup for AWS EKS</h3><h4>1. Install AWS CLI</h4><pre>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>unzip awscliv2.zip<br>sudo ./aws/install</pre><p><strong>Verify Installation:</strong></p><pre>aws --version</pre><h4>2. Configure AWS CLI</h4><p>Use your IAM user credentials with programmatic access:</p><pre>aws configure</pre><p>You will be prompted to enter:</p><pre>AWS Access Key ID [None]: &lt;your-access-key-id&gt;<br>AWS Secret Access Key [None]: &lt;your-secret-access-key&gt;<br>Default region name [None]: &lt;e.g., ap-south-1&gt;<br>Default output format [None]: json</pre><h4>3. Install eksctl</h4><pre>curl -LO &quot;https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz&quot;<br>tar -xzf eksctl_$(uname -s)_amd64.tar.gz<br>sudo mv eksctl /usr/local/bin</pre><p><strong>Verify Installation:</strong></p><pre>eksctl version</pre><h4>4. Install kubectl (if not already installed)</h4><pre>sudo snap install kubectl --classic</pre><p><strong>Verify:</strong></p><pre>kubectl version --client</pre><h4>5. Create an EKS Cluster</h4><p>Replace cluster-name and region with your values:</p><pre>eksctl create cluster \<br>--name devops-cluster \<br>--region ap-south-1 \<br>--nodes 2 \<br>--node-type t3.medium \<br>--with-oidc \<br>--ssh-access \<br>--ssh-public-key &lt;your-key-name&gt;</pre><p>This will:</p><ul><li>Provision a VPC</li><li>Launch EC2 instances</li><li>Deploy EKS control plane and worker nodes</li></ul><h4>6. Verify EKS Cluster Setup</h4><pre>kubectl get nodes<br>kubectl get pods --all-namespaces</pre><h3>3) Web-application Development</h3><p>Developed a basic Python Flask web application that serves a simple message or page.</p><p>Created a Dockerfile to containerize the application.</p><p>Create a folder project/webapp and inside the folder create the following files.</p><p>app.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W5rRNFEj0cP-l3IzaPfhqg.png" /></figure><p>requirements.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*5lYrgwUjwviIZT3Qt_1lQg.png" /></figure><p>Now create a dockerfile for the same application, in the same folder project/webapp.</p><p>Dockerfile</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2yPU1f6D0CQkqJmGTIoYQ.png" /></figure><p>No need to build the image, we will do it using ansible-pipleine. You can build it for local testing.</p><h3>4) kubernetes deployment</h3><p>Create Kubernetes YAML manifests (Deployment and Service) to define how the application should run inside the cluster.</p><p>Used Ansible to apply these Kubernetes manifests to the cluster using the kubectl command module.</p><p>In the same project folder create another folder for k8s-manifests (mkdir project/k8s-manifests)</p><p>create the following manifest files for deployment and services.</p><p>deployment.yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znyP4wZy-7rrchHd3G4cZQ.png" /></figure><p>service.yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*wDtMa52gd1ZMCA_TZLIA_Q.png" /></figure><h3>5) Ansible automation</h3><p>Write an Ansible playbook to automate the following tasks:</p><p>Copy the web app source code to a temporary directory.</p><p>Build the Docker image from the Dockerfile.</p><p>Push the image to a Docker Hub repository for use in Kubernetes.</p><p>Create another folder project/playbook and create the following playbook yaml file</p><p>deploy.yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXLDJ3N6DRjrBoGtImV-LA.png" /></figure><p>inventory.ini</p><pre>localhost ansible_connection=local ansible_python_interpreter=/home/ubuntu/ansible-venv/bin/python</pre><p>To run this ansible playbook run the following command:</p><pre>ansible-playbook -i inventory.ini deploy.yaml</pre><p>It should show like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*saxHBHom92CDYoIHxGRSPA.png" /></figure><p>verify the deployment , you can check if the deployment and services are created successfully or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NihwMbLBEej_1JLojMPzSA.png" /></figure><p>For application code, use the github repo:</p><p><a href="https://github.com/aashisaxena15/Dockerized-Web-App-Using-Ansible-on-K8s.git">https://github.com/aashisaxena15/Dockerized-Web-App-Using-Ansible-on-K8s.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89af2e74146b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3-Tier Architecture on AWS CLOUD]]></title>
            <link>https://aashisaxena15.medium.com/3-tier-architecture-on-aws-cloud-5f4724764a4d?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f4724764a4d</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Sun, 08 Jun 2025 21:45:41 GMT</pubDate>
            <atom:updated>2025-06-08T21:45:41.410Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pj92qvEpBotq1YQLd9XrUA.png" /></figure><p>This architecture diagram illustrates a <strong>highly available, fault-tolerant three-tier web application deployment on AWS</strong>, structured within a single Virtual Private Cloud (VPC) with a CIDR block of 10.0.0.0/16. The design spans <strong>three Availability Zones (AZs)</strong>—A, B, and C—to ensure high availability and disaster resilience. The VPC is segmented into multiple subnets: <strong>public web subnets</strong>, <strong>private web subnets</strong>, <strong>private app subnets</strong>, and <strong>private database subnets</strong>—each with a /20 CIDR range per AZ to maintain logical separation and security.</p><p>At the <strong>frontend (presentation) layer</strong>, user traffic is routed through a <strong>public Application Load Balancer (ALB)</strong> deployed in the public subnets of AZs B and C. This ALB distributes HTTP traffic to NGINX-based <strong>frontend EC2 instances</strong>, which reside in private web subnets across all three AZs. These NGINX servers serve static content such as HTML, CSS, and JavaScript, and forward API requests to the internal backend layer.</p><p>The <strong>backend (application) layer</strong> is managed by another internal <strong>Application Load Balancer</strong>, situated in the private app subnet of AZ B. This backend ALB balances load between <strong>Apache + PHP EC2 servers</strong> located in private app subnets in all three AZs. These backend instances host the business logic of the application, exposing PHP APIs for handling requests like reading from or writing to the database.</p><p>Finally, the <strong>database (data) layer</strong> is powered by an <strong>Amazon RDS MySQL instance</strong> configured in <strong>Multi-AZ deployment mode</strong>, ensuring data durability and high availability. The RDS instances are hosted in private DB subnets across AZs A, B, and C, and are only accessible by backend EC2 instances through tightly controlled security groups.</p><p>This design uses <strong>Auto Scaling Groups</strong> (implied in the diagram) for both frontend and backend EC2 tiers, allowing the infrastructure to automatically scale based on demand. Security is tightly managed through multiple <strong>security groups</strong>, ensuring that each layer can only communicate with the necessary adjacent layers. The system leverages <strong>public subnets for external exposure (ALBs)</strong>, while all application logic and data storage components are isolated in private subnets, adhering to <strong>best practices for security and performance in AWS cloud architecture</strong>.</p><p>Let’s do the step by step implementation of this Architecture on AWS Console:</p><h3>1. Create a VPC</h3><ul><li>Go to the <strong>VPC Dashboard</strong> → <strong>Create VPC</strong></li><li>Select <strong>VPC only</strong> option</li><li>CIDR Block: 10.0.0.0/16</li><li>Enable DNS support and DNS hostnames</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5lFmoD3E4PmshKBIqYHvw.png" /></figure><h3>2. Create Subnets</h3><p>You’ll create 12 subnets across 3 Availability Zones (AZs).</p><h4>a. Web Public Subnets (For NGINX servers)</h4><p>Web-Public-1a: 10.0.0.0/20<br> Web-Public-1b: 10.0.16.0/20<br> Web-Public-1c: 10.0.32.0/20</p><h4>b. Web Private Subnets</h4><p>Web-Private-1a: 10.0.48.0/20<br> Web-Private-1b: 10.0.64.0/20<br> Web-Private-1c: 10.0.80.0/20</p><h4>c. App Private Subnets (For PHP backend)</h4><p>App-Private-1a: 10.0.96.0/20<br> App-Private-1b: 10.0.112.0/20<br> App-Private-1c: 10.0.128.0/20</p><h4>d. DB Private Subnets (For RDS)</h4><p>DB-Private-1a: 10.0.144.0/20<br> DB-Private-1b: 10.0.160.0/20<br> DB-Private-1c: 10.0.176.0/20</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w2-o--jUHKkn8rp_dwzq8g.png" /></figure><h3>3. Create Route Tables</h3><ul><li><strong>Web Public Route Table</strong>: Associate with Web-Public-* subnets</li><li><strong>Web Private Route Table</strong>: Associate with Web-Private-* subnets</li><li><strong>App Private Route Table</strong>: Associate with App-Private-* subnets</li><li><strong>DB Private Route Table</strong>: Associate with DB-Private-* subnets</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Pcr3MjfV5uch2DZZYqRCw.png" /></figure><h3>4. Associate Route Tables with Subnets</h3><ul><li>Link each subnet to the appropriate route table:</li><li>Web-Public → Web Public Route Table</li><li>Web-Private → Web Private Route Table</li><li>App-Private → App Private Route Table</li><li>DB-Private → DB Private Route Table</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hdcykddALKecnSDhebglEQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ZHpRCP7v5ibeeJ2S5VIBQ.png" /></figure><h3>5. Create Internet Gateway (IGW)</h3><ul><li>Create an <strong>Internet Gateway</strong></li><li>Attach it to your VPC</li><li>Add <strong>route to </strong><strong>0.0.0.0/0</strong> in Web Public Route Table pointing to IGW</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nmL4zveDX5JnC7pm2YKGew.png" /></figure><h3>6. Create NAT Gateway</h3><ul><li>Create an <strong>Elastic IP (EIP)</strong></li><li>Launch a <strong>NAT Gateway</strong> in one of the <strong>Web Public</strong> subnets using the EIP</li><li>Add <strong>route to </strong><strong>0.0.0.0/0</strong> in all private route tables (Web, App, DB) pointing to the NAT</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*90VLLctwKZnHGmuzMTkGXA.png" /></figure><h3>7. Add IGW and NAT routes in route table</h3><ol><li>Public -&gt; IGW</li><li>Private -&gt; NAT</li></ol><h3>8. Create security groups</h3><h4>a. Frontend ALB SG</h4><ul><li>Allow: HTTP 80 from 0.0.0.0/0</li></ul><h4>b. Frontend EC2 SG</h4><ul><li>Allow: HTTP 80 from Frontend ALB SG</li></ul><h4>c. Backend ALB SG</h4><ul><li>Allow: HTTP 80 from Frontend EC2 SG</li></ul><h4>d. Backend EC2 SG</h4><ul><li>Allow: HTTP 80 from Backend ALB SG</li></ul><h4>e. RDS SG</h4><ul><li>Allow: MySQL 3306 from Backend EC2 SG</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uVMDu3wXWcYHMFQ6gZNtZw.png" /></figure><h3>9. Create RDS Subnet Group</h3><ul><li>Go to RDS → Subnet Groups → Create</li><li>Name: demo-db-subnet-group</li><li>Select <strong>DB-Private-1a, 1b, 1c</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AkZfW3021mYaDFzD7nqaNA.png" /></figure><h3>10. Launch RDS Database Instance</h3><ul><li>Engine: MySQL</li><li>Multi-AZ enabled</li><li>DB Subnet Group: demo-db-subnet-group</li><li>Endpoint example: demo-database.cb0qe2wsafpo.ap-south-1.rds.amazonaws.com</li><li>Username: admin</li><li>Password: aashi123</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-3PIFy95o3e6TkbNznTwHQ.png" /></figure><h3>10. Create ALBs</h3><h4>a. Frontend ALB</h4><ul><li>Scheme: internet-facing</li><li>Listener: HTTP 80</li><li>Target group: frontend-ec2-targets</li></ul><h4>b. Backend ALB</h4><ul><li>Scheme: internal</li><li>Listener: HTTP 80</li><li>Target group: backend-ec2-targets</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hl0Gn5eHi3Nc25sS30GxtA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4taPiBnm7aKNDel5WQsTPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FMZVt1PvXvSOxvOttFR72g.png" /></figure><h3>11. Create Frontend Server AMI</h3><ul><li>Launch an EC2 instance in Web Public subnet</li><li>Install NGINX, Git:</li></ul><pre>sudo apt update</pre><pre>sudo apt install -y nginx git</pre><ul><li>Clone your frontend repo and replace update-me in nginx.conf with <strong>backend ALB DNS</strong></li></ul><p>Stop instance → Create Image → Name: frontend-ami</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BXX-qcl8QeufrnXYSH0J0g.png" /></figure><h3>12 . Create Backend Server AMI</h3><ul><li>Launch EC2 in App Private subnet</li><li>Install Apache, PHP, Git, MySQL client:</li></ul><pre>sudo yum update -y</pre><pre>sudo yum install -y httpd php php-mysqlnd git</pre><ul><li>Clone backend code → move API → update DB credentials in db_connection.php</li><li>Run the SQL setup script (from your repo) if MySQL client is present</li><li>Stop instance → Create Image → Name: backend-ami</li></ul><h3>13. Create Launch Templates</h3><h4>a. Frontend LT</h4><ul><li>Image ID: frontend-ami</li><li>Instance Type: t2.micro</li><li>Security Group: Frontend EC2 SG</li><li>IAM Role: (optional) S3/CloudWatch access</li></ul><h4>b. Backend LT</h4><ul><li>Image ID: backend-ami</li><li>Instance Type: t2.micro</li><li>Security Group: Backend EC2 SG</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJnR7TKoU4VXTSkSvULWYg.png" /></figure><h3>14. Create Auto Scaling Groups</h3><h4>a. Frontend ASG</h4><ul><li>Launch Template: frontend LT</li><li>Target Group: frontend ALB TG</li><li>Subnets: Web Private (1a, 1b, 1c)</li><li>Min/Max/Desired: 1/3/2</li><li>Health Check: ALB</li></ul><h4>b. Backend ASG</h4><ul><li>Launch Template: backend LT</li><li>Target Group: backend ALB TG</li><li>Subnets: App Private (1a, 1b, 1c)</li><li>Min/Max/Desired: 1/3/2</li><li>Health Check: ALB</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1DD6Pinkja3wFPerhM2c0g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hmm8ZWSq9c_oBQTsV6g-Pg.png" /></figure><p>All the components are configured and the app can be accessed through the url of the frontend-alb. copy the url in the browser and you can then access the simple 3-tier-application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73KZmdGWIIR53Sg1l_gvIw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NVkWPg__YUROOd65PvuS8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uN3nxtOelhRJXvpyrTSETQ.png" /></figure><h3>Frontend Development</h3><p>The frontend of this application is developed using plain <strong>HTML, CSS, and JavaScript</strong>. It presents the user interface and handles interactions such as submitting or displaying messages. Communication with the backend is achieved using the <strong>Fetch API</strong>, allowing the frontend to send requests to and receive responses from the PHP backend seamlessly.<br> To modify or enhance the frontend, developers can edit the files located in the frontend directory. Once the changes are made, it’s recommended to test them locally using a browser or a lightweight server to ensure that the layout and functionality behave as expected.</p><h3>Backend Development</h3><p>The backend is implemented in <strong>PHP</strong> and is responsible for processing the application’s business logic. It includes simple <strong>API endpoints</strong> that allow retrieval and storage of messages in the database. These endpoints are found inside the backend/api directory.<br> To make backend changes, developers can modify the corresponding PHP files and test them on a local environment that supports PHP and MySQL, such as <strong>XAMPP, MAMP, or WAMP</strong>. Testing locally ensures that the API behaves correctly before deployment.</p><h3>Security Considerations</h3><p>While this is a demo application built to demonstrate architecture concepts, it currently <strong>lacks several essential security mechanisms</strong> that are required for production environments. These include:</p><ul><li><strong>Input validation and sanitization</strong> to protect against malicious data entry.</li><li><strong>Authentication and authorization</strong> to control user access.</li><li><strong>HTTPS encryption</strong> to secure data in transit.</li><li><strong>SQL injection protection</strong>, although <strong>PDO with prepared statements</strong> helps reduce this risk.</li><li>Proper <strong>CORS (Cross-Origin Resource Sharing)</strong> configuration to prevent unauthorized access from other origins.</li></ul><p>It’s important to implement these measures when deploying similar applications in real-world scenarios.</p><h3>Acknowledgements</h3><p>This sample application was created as a <strong>demonstration of AWS three-tier architecture</strong> principles. It showcases best practices for designing scalable and highly available web applications using AWS services like VPC, ALB, EC2, and RDS.</p><p>Github Repository for code : <a href="https://github.com/aashisaxena15/3tier-architecture-aws.git">https://github.com/aashisaxena15/3tier-architecture-aws.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f4724764a4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Netflix Clone on Cloud Using Jenkins — A DevSecOps Project]]></title>
            <link>https://aashisaxena15.medium.com/deploying-a-netflix-clone-on-cloud-using-jenkins-a-devsecops-project-da346a960234?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/da346a960234</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Tue, 20 May 2025 18:19:54 GMT</pubDate>
            <atom:updated>2025-05-20T18:22:01.601Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploying a Netflix Clone on Cloud Using Jenkins — A DevSecOps Project</h3><h3>Introduction</h3><p>In this blog, we will walk through a complete <strong>DevSecOps pipeline</strong> to deploy a Netflix Clone on the cloud using Jenkins. This project integrates security at multiple stages using <strong>SonarQube</strong>, <strong>Trivy</strong>, and <strong>OWASP Dependency-Check</strong>. We will also automate deployment using <strong>Jenkins</strong>, monitor the application using <strong>Prometheus and Grafana</strong>, and finally deploy the application on <strong>Kubernetes using ArgoCD</strong>.</p><h3>Project Architecture</h3><ol><li>Initial Deployment on EC2 using Docker</li><li>Integrating Security with SonarQube and Trivy</li><li>CI/CD Pipeline with Jenkins</li><li>Monitoring using Prometheus and Grafana</li><li>Deploying to Kubernetes using ArgoCD</li><li>Notifications and Cleanup</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Dmq5aOcReh5x3pfh3MxLA.png" /></figure><p><strong>PHASE 1: INITIAL SETUP AND DEPLOYMENT</strong></p><h4>1. Creating an EC2 Instance for Jenkins, SonarQube, and Other Tools</h4><ul><li>Launch an EC2 instance.</li><li>Choose <strong>Ubuntu 22</strong> as the AMI.</li><li>Select <strong>T2.large</strong> as the instance type (not in the free tier).</li><li>Assign a meaningful name (e.g., Netflix-Jenkins).</li></ul><h4>2. Configuring Key Pair</h4><ul><li>Use an existing key pair or create a new one.</li><li>For Linux/Mac: Use .pem format.</li><li>For Windows: Use .ppk format (compatible with PuTTY).</li></ul><h4>3. Configuring Network and Security Settings</h4><ul><li>Use the <strong>default VPC and subnet</strong>.</li><li>Create a <strong>new security group</strong> with only required ports:</li><li><strong>SSH (22)</strong> — for remote access.</li><li><strong>HTTP (80)</strong> and <strong>HTTPS (443)</strong> — for communication.</li><li>Additional ports to be opened later:</li><li><strong>8080</strong> (Jenkins)</li><li><strong>9000</strong> (SonarQube)</li></ul><h4>4. Allocating Storage</h4><ul><li>Set storage size to 30GB (recommended for Jenkins and required plugins).</li></ul><h4>5. Launching the Instance</h4><ul><li>Click <strong>Launch Instance</strong> to start the server.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*yXpHuow1clOK5GaBXAqg4w.png" /></figure><h4>6. Attaching an Elastic IP</h4><ul><li>Go to <strong>EC2 Dashboard → Elastic IPs</strong> under <strong>Network &amp; Security</strong>.</li><li>Click <strong>Allocate Elastic IP</strong> and name it (e.g., Netflix-EIP).</li><li>Associate the Elastic IP with the running EC2 instance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tAldUuMtjKZwql9Yt1ueVQ.png" /></figure><h4>7. Connecting to the EC2 Instance</h4><ul><li>Navigate to <strong>EC2 Dashboard → Instances</strong>.</li><li>Select the running instance and click <strong>Connect</strong>.</li><li>Available connection methods:</li><li><strong>EC2 Instance Connect</strong> (recommended for Ubuntu and Amazon Linux).</li><li><strong>SSH client</strong> (for Linux/Mac users).</li><li><strong>PuTTY</strong> (for Windows users).</li></ul><h4>8. Clone the repository</h4><pre>sudo apt-get update<br>sudo apt-get install git -y<br>git clone https://github.com/aashisaxena15/DevSecOps-Project.git</pre><h4>9. Install docker using the following commands</h4><pre>sudo apt-get install docker.io -y<br>sudo usermod -aG docker $USER<br>newgrp docker<br>sudo chmod 777 /var/run/docker.sock</pre><h4>10. Build and run your application using Docker containers</h4><pre>docker build -t netflix .<br>docker run -d --name netflix -p 8081:80 netflix:latest<br><br>#to delete<br>docker stop &lt;containerid&gt;<br>docker rmi -f netflix</pre><p>Please don’t forget to open the necessary ports in the security group by adding ports in the edit inbound rules</p><p>Now you can access the dockerized application on 8081 port of the public ip address of the instance.</p><p>It will show an error cause you need API key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pxzrqifkkin7O5GAMoy1-g.png" /></figure><h4>11. Get the API Key</h4><ul><li>Open a web browser and navigate to TMDB (The Movie Database) website.</li><li>Click on “Login” and create an account.</li><li>Once logged in, go to your profile and select “Settings.”</li><li>Click on “API” from the left-side panel.</li><li>Create a new API key by clicking “Create” and accepting the terms and conditions.</li><li>Provide the required basic details and click “Submit.”</li><li>You will receive your TMDB API key.</li></ul><h3>Rebuilding Docker Image with API Key</h3><p>Since the API key is required, we need to rebuild the Docker image with the argument:</p><p>COPY</p><pre>docker build --build-arg TMDB_V3_API_KEY=&lt;your-api-key&gt; -t netflix .</pre><p>Then, run the new container:</p><p>COPY</p><pre>Docker run -d -p 8081:80 netflix</pre><p>Now, refresh the application. You should see all the movies and series listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A6JHdwnCYugSM4cWnv_ZNw.png" /></figure><p>Our Dev part is done, now will do Sec Part</p><h3>Phase2: Security part</h3><h3>Adding Security with SonarQube</h3><p>Understanding SonarQube</p><ul><li>SonarQube is used for code analysis and security scanning.</li><li>It helps in identifying code issues, vulnerabilities, and dependencies</li></ul><p>Running SonarQube as a Docker Container</p><p>Use the following command to deploy SonarQube:</p><p>COPY</p><pre>docker run -d --name sonar -p 9000:9000 sonarqube</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ndDGgPp9N8GEFLct" /></figure><p>Verify the running containers:</p><p>COPY</p><pre>docker ps</pre><p>Accessing SonarQube</p><ul><li>Open http://localhost:9000 in a browser.</li><li>To access:</li><li>publicIP:9000 (by default username &amp; password is admin)</li><li>Once logged in, you can start scanning your code for vulnerabilities.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CHdu1NUB0b4o2blk" /></figure><h3>Installing and Using Trivy for Security Scanning</h3><p>Trivy is an open-source security scanner for detecting vulnerabilities in containers, file systems, and repositories. Provide reports what’s problem is with your file system or docker image.</p><p>To install Trivy:</p><p>COPY</p><pre>sudo apt-get install wget apt-transport-https gnupg lsb-release<br>wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -<br>echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list<br>sudo apt-get update<br>sudo apt-get install trivy     <br>trivy version</pre><p>We will install Trivy directly on Jenkins instance, as Jenkins don’t have trivy as plugin.</p><h4>Scanning the File System</h4><p>To scan the current file system for vulnerabilities:</p><p>COPY</p><pre>trivy fs .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rvUEHQ9p8zPXvpMKELalw.png" /></figure><h4>Scanning Docker Images for Vulnerabilities</h4><p>Check for security issues in your Netflix app image:</p><p>COPY</p><pre>docker images<br>trivy image netflix:latest # or write image id</pre><p>For security we have used SonarQube and Trivy</p><h3>Phase 3: CI/CD Setup</h3><h3>Install Jenkins for Automation:</h3><ul><li>Install Jenkins on the EC2 instance to automate deployment: Install Java as pre-requisite</li></ul><p>COPY</p><pre>sudo apt update<br>sudo apt install fontconfig openjdk-17-jre<br>java -version<br>openjdk version &quot;17.0.8&quot; 2023-07-18<br>OpenJDK Runtime Environment (build 17.0.8+7-Debian-1deb12u1)<br>OpenJDK 64-Bit Server VM (build 17.0.8+7-Debian-1deb12u1, mixed mode, sharing)</pre><pre>#jenkins<br>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>https://pkg.jenkins.io/debian-stable 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<br>sudo systemctl start jenkins<br>sudo systemctl enable jenkins</pre><ul><li>Access Jenkins in a web browser using the public IP of your EC2 instance.</li><li>publicIp:8080</li></ul><p>Install Necessary Plugins in Jenkins:</p><p>Goto: Manage Jenkins →Plugins → Available Plugins → Install below plugins</p><ol><li>Eclipse Temurin Installer (Install without restart)</li><li>SonarQube Scanner (Install without restart)</li><li>NodeJs Plugin (Install Without restart)</li><li>Email Extension Plugins</li></ol><h3>Configure Java and Nodejs in Global Tool Configuration</h3><p>Goto: Manage Jenkins → Tools → Install JDK(17) and NodeJs(16)→ Click on Apply and Save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JUNVguIu-WLVE4jp" /></figure><p><em>Make sure you select the jdk version 17 from above</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eh4jQ28MowkfPuQc" /></figure><h3>SonarQube</h3><p>Create the token: Go to Sonarqube → Administration → Security → Users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Cg9DiqRJ7tBcA_o" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GFVxUz5nNy3r-F_N" /></figure><p>Goto: Jenkins Dashboard → Manage Jenkins → Credentials → Add Secret Text. It should look like this</p><p>After adding sonar token</p><p>Click on Apply and Save</p><p>The Configure System option is used in Jenkins to configure different server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yYzL3KZjIvTHTGWJ" /></figure><p>Global Tool Configuration is used to configure different tools that we install using Plugins</p><p>We will install a sonar scanner in the tools also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OxJCwt6KWZZ0fLdr" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*67ImeQ9ax6ppk0xs" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ri3wUS35GKFU8u-w" /></figure><h3>Enhancing Security in CI/CD Pipeline</h3><p>To ensure security in the pipeline, we are integrating:<br>OWASP Dependency Check → Identifies vulnerabilities in dependencies<br>Trivy → Scans Docker images for security issues</p><p>Installing OWASP Dependency Check Plugin in Jenkins</p><p>To scan dependencies for security vulnerabilities:</p><ul><li>Navigate to Manage Jenkins &gt; Plugin Manager &gt; Available Plugins</li><li>Search for “OWASP Dependency Check” and install it</li><li>Configure the plugin in Manage Jenkins &gt; Global Tool Configuration</li><li>Set the name as DP-Check for consistency</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JsS8g6XEG5-zvmf_" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OlNbLH4KX3wep4lw" /></figure><p>Installing Docker Plugins in Jenkins</p><p>Since the pipeline will build Docker images, we need these plugins:</p><ul><li>Docker Commons</li><li>Docker Pipeline</li><li>Docker API</li><li>Docker Build Step</li></ul><p>Install them by navigating to Manage Jenkins &gt; Plugin Manager &gt; Available Pluginsand searching for “Docker”.</p><h3>Configuring Docker Hub Credentials in Jenkins</h3><p>To push Docker images from Jenkins to Docker Hub:</p><ul><li>Go to Manage Jenkins &gt; Credentials &gt; System &gt; Global Credentials</li><li>Click Add Credentials for Dockerhub and Save the credentials</li></ul><p>Configure the docker in global tools also</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lnFbO4kCQUYfYvQh" /></figure><p>COPY</p><pre>pipeline{<br>    agent any<br>    tools{<br>        jdk &#39;jdk17&#39;<br>        nodejs &#39;node16&#39;<br>    }<br>    environment {<br>        SCANNER_HOME=tool &#39;sonar-scanner&#39;<br>    }<br>    stages {<br>        stage(&#39;clean workspace&#39;){<br>            steps{<br>                cleanWs()<br>            }<br>        }<br>         stage(&#39;Checkout from Git&#39;) {<br>            steps {<br>                git branch: &#39;main&#39;, url: &#39;https://github.com/amitsinghs98/DevSecOps-Project-Netflix.git&#39;<br>            }<br>        }<br>        stage(&quot;Sonarqube Analysis &quot;){<br>            steps{<br>                withSonarQubeEnv(&#39;sonar-server&#39;) {<br>                    sh &#39;&#39;&#39; $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Netflix \<br>                    -Dsonar.projectKey=Netflix &#39;&#39;&#39;<br>                }<br>            }<br>        }<br>         stage(&quot;quality gate&quot;) {<br>            steps {<br>                script { timeout(time: 40, unit: &#39;MINUTES&#39;) {<br>                    waitForQualityGate abortPipeline: true, credentialsId: &#39;sonar-token&#39;<br>                }<br>            }<br>            }    <br>        }<br>        stage(&#39;Install Dependencies&#39;) {<br>            steps {<br>                sh &quot;npm install&quot;<br>            }<br>        }<br>        stage(&#39;OWASP FS SCAN&#39;) {<br>            steps {<br>                dependencyCheck additionalArguments: &#39;--scan ./ --disableYarnAudit --disableNodeAudit&#39;, odcInstallation: &#39;DP-Check&#39;<br>                dependencyCheckPublisher pattern: &#39;**/dependency-check-report.xml&#39;<br>            }<br>        }<br>        stage(&#39;TRIVY FS SCAN&#39;) {<br>            steps {<br>                sh &quot;trivy fs . &gt; trivyfs.txt&quot;<br>            }<br>        }<br>        stage(&quot;Docker Build &amp; Push&quot;){<br>            steps{<br>                script{<br>                   withDockerRegistry(credentialsId: &#39;docker&#39;, toolName: &#39;docker&#39;){   <br>                       sh &quot;sudo docker build --build-arg TMDB_V3_API_KEY=7e83d9491367017e316fdd3719d01779 -t netflix .&quot;<br>                       sh &quot;sudo docker tag netflix aashisaxena15/netflix:latest &quot;<br>                       sh &quot;sudo docker push aashisaxena15/netflix:latest &quot;<br>                    }<br>                }<br>            }<br>        }<br>        stage(&quot;TRIVY&quot;){<br>            steps{<br>                sh &quot;sudo trivy image aashisaxena15/netflix:latest &gt; trivyimage.txt&quot; <br>            }<br>        }<br>        stage(&#39;Deploy to container&#39;){<br>            steps{<br>                sh &#39;sudo docker run -d -p 8085:80 aashisaxena15/netflix:latest&#39;<br>            }<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*svLxXG5NprTzdaZDr06ubA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uEeDNG96BsmOwR2E" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1V0wXkXK91qpLN8U2qrW-w.png" /></figure><p>Note: sh &#39;docker run -d -p 8085:80 aashisaxena15/netflix:latest&#39; we dont specify the name because each time pipeline will start it will create a new random name so that no error occurs.</p><h3>Phase 4: Monitoring</h3><p>We will create a new t2.medium instance for monitoring</p><ol><li>Install Prometheus and Grafana:</li><li>Set up Prometheus and Grafana to monitor your application.</li><li>Installing Prometheus:</li><li>First, create a dedicated Linux user for Prometheus and download Prometheus:</li><li>COPY</li></ol><ul><li>sudo useradd --system --no-create-home --shell /bin/false prometheus wget <a href="https://github.com/prometheus/prometheus/releases/download/v2.47.1/prometheus-2.47.1.linux-amd64.tar.gz">https://github.com/prometheus/prometheus/releases/download/v2.47.1/prometheus-2.47.1.linux-amd64.tar.g</a>z</li></ul><ol><li>Extract Prometheus files, move them, and create directories:</li><li>COPY</li></ol><pre>tar -xvf prometheus-2.47.1.linux-amd64.tar.gz  cd prometheus-2.47.1.linux-amd64/  sudo mkdir -p /data /etc/prometheus  sudo mv prometheus promtool /usr/local/bin/  sudo mv consoles/ console_libraries/ /etc/prometheus/  sudo mv prometheus.yml /etc/prometheus/prometheus.ym</pre><ol><li>Set ownership for directories:</li><li>COPY</li></ol><pre>sudo chown -R prometheus:prometheus /etc/prometheus/ /data</pre><ol><li>Create a systemd unit configuration file for Prometheus:</li><li>COPY</li></ol><ul><li>sudo nano /etc/systemd/system/prometheus.service</li></ul><ol><li>Add the following content to the prometheus.service file:</li><li>COPY</li></ol><pre>[Unit]  Description=Prometheus  Wants=network-online.target  After=network-online.target   StartLimitIntervalSec=500  StartLimitBurst=5   [Service]  User=prometheus  Group=prometheus  Type=simple  Restart=on-failure  RestartSec=5s  ExecStart=/usr/local/bin/prometheus \    --config.file=/etc/prometheus/prometheus.yml \    --storage.tsdb.path=/data \    --web.console.templates=/etc/prometheus/consoles \    --web.console.libraries=/etc/prometheus/console_libraries \    --web.listen-address=0.0.0.0:9090 \    --web.enable-lifecycle   [Install]  WantedBy=multi-user.target</pre><ol><li>Here’s a brief explanation of the key parts in this prometheus.service file:</li><li>User and Group specify the Linux user and group under which Prometheus will run.</li></ol><ul><li>ExecStart is where you specify the Prometheus binary path, the location of the configuration file (prometheus.yml), the storage directory, and other settings.</li><li>web.listen-address configures Prometheus to listen on all network interfaces on port 9090.</li><li>web.enable-lifecycle allows for management of Prometheus through API calls.</li></ul><p>Enable and start Prometheus:</p><p>COPY</p><pre>sudo systemctl enable prometheus<br>sudo systemctl start prometheus</pre><p>Verify Prometheus’s status:</p><p>COPY</p><pre>sudo systemctl status prometheus</pre><p>You can access Prometheus in a web browser using your server’s IP and port 9090: Make sure you open the port 9090 in security group of ec2.</p><p>http://&lt;your-server-ip&gt;:9090 Login and go to &gt; Targets, but before checking targets you need to have a node exporter installed. Node exporter will fetch the metric from application and will be used by Prometheuscat.</p><p>COPY</p><pre>cat /etc/prometheus/prometheus.yml</pre><p>You can see in prometheus file target. Let’s add node exporter in job name</p><h3>Installing Node Exporter:</h3><ol><li>Create a system user for Node Exporter and download Node Exporter:</li><li>COPY</li></ol><ul><li>sudo useradd --system --no-create-home --shell /bin/false node_exporter wget <a href="https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz">https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz</a></li></ul><ol><li>Extract Node Exporter files, move the binary, and clean up:</li><li>COPY</li></ol><ul><li>tar -xvf node_exporter-1.6.1.linux-amd64.tar.gz sudo mv node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/ rm -rf node_exporter*</li></ul><ol><li>Create a systemd unit configuration file for Node Exporter:</li><li>COPY</li></ol><ul><li>sudo nano /etc/systemd/system/node_exporter.service</li></ul><ol><li>Add the following content to the node_exporter.service file:</li><li>COPY</li></ol><ul><li>[Unit] Description=Node Exporter Wants=network-online.target After=network-online.target StartLimitIntervalSec=500 StartLimitBurst=5 [Service] User=node_exporter Group=node_exporter Type=simple Restart=on-failure RestartSec=5s ExecStart=/usr/local/bin/node_exporter --collector.logind [Install] WantedBy=multi-user.target</li></ul><ol><li>Replace --collector.logind with any additional flags as needed.</li><li>Enable and start Node Exporter:</li><li>COPY</li></ol><ul><li>sudo systemctl enable node_exporter sudo systemctl start node_exporter</li></ul><ol><li>Verify the Node Exporter’s status:</li><li>COPY</li></ol><ul><li>sudo systemctl status node_exporter</li></ul><ol><li>You can access Node Exporter metrics in Prometheus.</li><li>Configure Prometheus Plugin Integration:</li><li>Integrate Jenkins with Prometheus to monitor the CI/CD pipeline.</li><li>Prometheus Configuration:</li><li>To configure Prometheus to scrape metrics from Node Exporter and Jenkins, you need to modify the prometheus.yml file. Here is an example prometheus.ymlconfiguration for your setup:</li><li>COPY</li></ol><ul><li>global: scrape_interval: 15s scrape_configs: - job_name: &#39;node_exporter&#39; static_configs: - targets: [&#39;localhost:9100&#39;]</li></ul><p>Check the validity of the configuration file:</p><p>COPY</p><pre>promtool check config /etc/prometheus/prometheus.yml</pre><p>Reload the Prometheus configuration without restarting:</p><p>COPY</p><pre>curl -X POST http://localhost:9090/-/reload</pre><p>You can access Prometheus targets at: http://&lt;your-prometheus-ip&gt;:9090/targets</p><p>You can see our node exporter is up and running,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W6l5gUy1G-ERBoG2" /></figure><h3>Grafana</h3><p>Install Grafana on Ubuntu 22.04 and Set it up to Work with Prometheus</p><p>Step 1: Install Dependencies:</p><p>First, ensure that all necessary dependencies are installed:</p><p>COPY</p><pre>sudo apt-get update<br>sudo apt-get install -y apt-transport-https software-properties-common</pre><p>Step 2: Add the GPG Key:</p><p>Add the GPG key for Grafana:</p><p>COPY</p><pre>wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -</pre><p>Step 3: Add Grafana Repository:</p><p>Add the repository for Grafana stable releases:</p><p>COPY</p><pre>echo &quot;deb https://packages.grafana.com/oss/deb stable main&quot; | sudo tee -a /etc/apt/sources.list.d/grafana.list</pre><p>Step 4: Update and Install Grafana:</p><p>Update the package list and install Grafana:</p><p>COPY</p><pre>sudo apt-get update<br>sudo apt-get -y install grafana</pre><p>Step 5: Enable and Start Grafana Service:</p><p>To automatically start Grafana after a reboot, enable the service:</p><p>COPY</p><pre>sudo systemctl enable grafana-server</pre><p>Then, start Grafana:</p><p>COPY</p><pre>sudo systemctl start grafana-server</pre><p>Step 6: Check Grafana Status:</p><p>Verify the status of the Grafana service to ensure it’s running correctly:</p><p>COPY</p><pre>sudo systemctl status grafana-server</pre><p>Step 7: Access Grafana Web Interface:</p><p>Open a web browser and navigate to Grafana using your server’s IP address. The default port for Grafana is 3000. For example:</p><p>http://&lt;your-server-ip&gt;:3000</p><p>You’ll be prompted to log in to Grafana. The default username is “admin,” and the default password is also “admin.”</p><p>Step 8: Change the Default Password:</p><p>When you log in for the first time, Grafana will prompt you to change the default password for security reasons. Follow the prompts to set a new password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ueZTHcwIsXSHeSUp2U7W1w.png" /></figure><p>Step 9: Add Prometheus Data Source:</p><p>To visualize metrics, you need to add a data source. Follow these steps:</p><ul><li>Click on the gear icon (⚙️) in the left sidebar to open the “Configuration” menu.</li><li>Select “Data Sources.”</li><li>Click on the “Add data source” button</li><li>Choose “Prometheus” as the data source type.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U8Iehg5qpU0x46a2" /></figure><ul><li>In the “HTTP” section:</li><li>Set the “URL” to <a href="http://localhost:9090/">http://localhost:9090</a> (assuming Prometheus is running on the same server).</li><li>Click the “Save &amp; Test” button to ensure the data source is working.</li></ul><p>Step 10: Import a Dashboard:</p><p>To make it easier to view metrics, you can import a pre-configured dashboard. Follow these steps:</p><ul><li>Click on the “+” (plus) icon in the left sidebar to open the “Create” menu.</li><li>Select “Dashboard.”</li><li>Click on the “Import” dashboard option.</li><li>Enter the dashboard code you want to import (e.g., code 1860).</li><li>Click the “Load” button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j1YKoHhbLZUfVKwF" /></figure><ul><li>Select the data source you added (Prometheus) from the dropdown.</li><li>Click on the “Import” button.</li></ul><p>You should now have a Grafana dashboard set up to visualize metrics from Prometheus.</p><p>Grafana is a powerful tool for creating visualizations and dashboards, and you can further customize it to suit your specific monitoring needs.</p><p>That’s it! You’ve successfully installed and set up Grafana to work with Prometheus for monitoring and visualization.</p><ol><li>Configure Prometheus Plugin Integration:</li></ol><ul><li>Integrate Jenkins with Prometheus to monitor the CI/CD pipeline.</li><li>Install “Prometheus Metric” plugin, then setup system now in jenkins for prometheus server</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J5QGf0-rVgHmAC5Y" /></figure><ol><li>Need to add jenkins in prometheus.yml file same like node exporter</li><li>COPY</li></ol><pre>cd /etc/prometheus  nano prometheus.yml</pre><ol><li>COPY</li></ol><pre>- job_name: &#39;jenkins&#39;      metrics_path: &#39;/prometheus&#39;      static_configs:        - targets: [&#39;&lt;your-jenkins-ip&gt;:&lt;your-jenkins-port&gt;&#39;]</pre><ol><li>Make sure to replace &lt;your-jenkins-ip&gt; and &lt;your-jenkins-port&gt; with the appropriate values for your Jenkins setup.</li><li>cd /etc/prometheus/</li><li>Check the validity of the configuration file:</li><li>COPY</li></ol><pre>promtool check config /etc/prometheus/prometheus.yml</pre><ol><li>Reload the Prometheus configuration without restarting:</li><li>COPY</li></ol><pre>curl -X POST http://localhost:9090/-/reload</pre><ol><li>You can access Prometheus targets at: http://&lt;your-prometheus-ip&gt;:9090/targets</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOr_fg4yIeUEHHN0IqGWYw.png" /></figure><p>we can see Jenkins is up and running now add grafana dashboard.</p><p>search “jenkins grafana dashboard” copy ID</p><p>and load the dashboard</p><p>Tried running pipeline and see the data here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J1e5XMrjysy3wFI2vqn9HA.png" /></figure><h3>Set Up Gmail Email Notification</h3><ol><li>Login to Gmail</li></ol><ul><li>For Gmail notifications, you’ll need to set up an app password for your Gmail account.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Cl85hAAKawhXSk51" /></figure><ul><li>Log in to Gmail and create an app password by navigating to your Google Account &gt; Security &gt; App Passwords.</li><li>Use this app password when setting up email notifications in Jenkins.</li><li>Add to global credential in Jenkins with token</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T4humz4v-hKwrZud" /></figure><ol><li>Now go to Jenkins</li></ol><ul><li>In Manage Jenkins &gt; Configure System, scroll to Extended Email Notification.</li><li>Set the SMTP server as <a href="http://smtp.gmail.com/">smtp.gmail.com</a>.</li><li>Port: 465 (for SSL).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ByttFYgtiWxmXfsW" /></figure><ul><li>Credentials: Use the Gmail credentials you created earlier.</li><li>Enable SSL and OAuth2 for secure communication.</li></ul><h3>Phase 6: Kubernetes</h3><h3>Setting Up AWS EKS Cluster</h3><p>Create an EKS cluster with help of eksctl CLI command.</p><p>Install ArgoCD in your EKS Cluster in a Namespace</p><p>COPY</p><pre>kubectl create ns argocd  kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml  kubectl get svc -n argocd #get argocd url  kubectl --namespace argocd port-forward argocd-server 80  kubectl get deployments -n argocd  kubectl logs -l app.kubernetes.io/name=argocd-server -n argocd</pre><h3>Create Kubernetes Cluster with Nodegroups</h3><p>In this phase, you’ll set up a Kubernetes cluster with node groups. This will provide a scalable environment to deploy and manage your applications.</p><h3>Monitor Kubernetes with Prometheus</h3><p>Prometheus is a powerful monitoring and alerting toolkit, and you’ll use it to monitor your Kubernetes cluster. Additionally, you’ll install the node exporter using Helm to collect metrics from your cluster nodes.</p><h3>Install Node Exporter using Helm</h3><p>To begin monitoring your Kubernetes cluster, you’ll install the Prometheus Node Exporter. This component allows you to collect system-level metrics from your cluster nodes. Here are the steps to install the Node Exporter using Helm:</p><ol><li>Add the Prometheus Community Helm repository:</li><li>COPY</li></ol><pre>elm repo add prometheus-community https://prometheus-community.github.io/helm-chart</pre><ol><li>Create a Kubernetes namespace for the Node Exporter:</li><li>COPY</li></ol><pre>kubectl create namespace prometheus-node-exporter</pre><ol><li>Install the Node Exporter using Helm:</li><li>COPY</li></ol><pre>helm install prometheus-node-exporter prometheus-community/prometheus-node-exporter --namespace prometheus-node-exporter</pre><p>Add a Job to Scrape Metrics on nodeip:9001/metrics in prometheus.yml:</p><p>COPY</p><pre>kubectl get ns<br>kubectl get pods -n prometheus-node-exporter<br>  export ARGOCD_SERVER=$(kubectl get svc argocd-server -n argocd -o json | jq --raw-output &#39;.status.loadBalancer.ingress[0].hostname&#39;)<br> kubectl get svc argocd-server -n argocd -o jsonpath=&#39;{.status.loadBalancer.ingress[0].hostname}&#39;<br>kubectl get svc argocd-server -n argocd<br> echo $ARGOCD_SERVER<br> curl -Ik https://a2670e81d307041e1b9a748e36770042-1876744319.ap-south-1.elb.amazonaws.com</pre><p>Node exporter installed using helm</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NBwan9ZH8gC2XS44" /></figure><p>To get argocd password</p><p>COPY</p><pre>kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=&quot;{.data.password}&quot; | base64 -d</pre><p>Now connect our repo with argocd</p><ol><li>Login to argocd &gt; Settings &gt; Repositories &gt; Connect a repo</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3NOONXRisxqG2My9" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vtwe2nDBEub_IwVK" /></figure><ol><li>Go to apps &gt; Create app</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CVNMD35WsE1jKQLK" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d56Vyg0OHA9urtGX" /></figure><p>See our netflix app using nodeport service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zl0DqvUY27aE8BcM" /></figure><p><em>Our application is running on port 30007 we have mentioned in our svc file.</em></p><p>Start inbound rule for port 30007 go to your eks &gt; nodes &gt; security group</p><p>Now do monitoring for this EKS Cluster</p><p>Go to monitoring instance &gt; cd /etc/prometheus</p><p>sudo nano prometheus.yml</p><p>Add in prometheus.yml file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOr_fg4yIeUEHHN0IqGWYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYvwIfzpttm8f_Zi5ycQNw.png" /></figure><p>github repository for code : <a href="https://github.com/aashisaxena15/netflix-clone-devsecops-project.git">https://github.com/aashisaxena15/netflix-clone-devsecops-project.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da346a960234" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Kubernetes Voting App with ArgoCD on EC2 using Kind]]></title>
            <link>https://aashisaxena15.medium.com/deploying-a-kubernetes-voting-app-with-argocd-on-ec2-using-kind-066d8035c3e2?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/066d8035c3e2</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Thu, 01 May 2025 18:46:26 GMT</pubDate>
            <atom:updated>2025-05-01T18:46:26.820Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, I’ll walk you through how I set up a Kubernetes-based Voting App using <strong>Kind</strong>, deployed on an <strong>AWS EC2 instance</strong>, and managed it with <strong>ArgoCD</strong> and <strong>Kubernetes Dashboard</strong>. This setup is perfect for learning GitOps, ArgoCD, and local Kubernetes clusters.</p><p><strong>Architecture Overview:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B1xC7pMFP9XtndJB8FxnRg.png" /></figure><h3>GitOps Flow (as shown in the image):</h3><ol><li><strong>Source Code</strong> (Python, Node.js, .NET, Redis, PostgreSQL) is hosted on <strong>GitHub</strong>.</li><li><strong>ArgoCD</strong> watches the GitHub repository for any changes to the Kubernetes YAML manifests.</li><li>Upon detecting a change, <strong>ArgoCD automatically syncs the new configuration</strong> and deploys the updated services to the <strong>Kubernetes cluster</strong> (running via Kind).</li><li>Kubernetes runs the workloads in <strong>multiple pods</strong>, ensuring scalability and availability.</li></ol><p>Prerequisites:</p><ul><li>You have an Ubuntu EC2 instance (t2.medium or higher recommended)</li><li>The security group allows <strong>inbound ports</strong>: 22 (SSH), 8080 (ArgoCD), 5000/5001 (Voting app), 8443 (K8s Dashboard)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ogz2xoeGB8VRm-BWanux4w.png" /></figure><h3>Step 1: Install Docker</h3><pre>sudo apt-get update<br>sudo apt install docker.io -y<br>sudo usermod -aG docker ubuntu<br>sudo systemctl restart docker</pre><blockquote><em>Docker is required for running the Kind cluster, as Kind uses Docker containers to simulate Kubernetes nodes.</em></blockquote><h3>Step 2: Install kubectl</h3><pre>sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl<br>kubectl version</pre><blockquote><em>This installs </em><em>kubectl, the Kubernetes CLI tool.</em></blockquote><h3>Step 3: Clone the Voting App Repository</h3><pre>CopyEdit</pre><pre>git clone https://github.com/LondheShubham153/k8s-kind-voting-app.git<br>cd k8s-kind-voting-app/kind-cluster</pre><blockquote><em>This repo has all the Kubernetes specs and Kind setup scripts.</em></blockquote><h3>Step 4: Install and Set Up Kind</h3><pre>bash install_kind.sh<br>kind create cluster --config=config.yml<br>kubectl cluster-info --context kind-kind<br>kubectl get nodes</pre><blockquote><em>This creates a local K8s cluster using Kind with a multi-node configuration defined in </em><em>config.yml.</em></blockquote><h3>Step 5: Install ArgoCD</h3><pre>kubectl create namespace argocd<br>kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml<br>kubectl get pods -n argocd</pre><blockquote><em>ArgoCD is a GitOps continuous delivery tool for Kubernetes. We deploy it into its own namespace.</em></blockquote><h3>Step 6: Expose ArgoCD Server</h3><p>We need ArgoCD to be accessible from our browser</p><pre>kubectl patch svc argocd-server -n argocd -p &#39;{&quot;spec&quot;: {&quot;type&quot;: &quot;LoadBalancer&quot;}}&#39;<br>kubectl port-forward svc/argocd-server -n argocd 8080:443 --address=0.0.0.0 &amp;</pre><p>Now access ArgoCD at:<br> 👉 http://&lt;EC2-PUBLIC-IP&gt;:8080 → example: <a href="http://13.49.41.3:8080/">http://13.49.41.3:8080</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VM7-xRGAYRfoqelBjGrRXA.png" /></figure><h3>Step 7: Get ArgoCD Admin Password</h3><pre>kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath=&quot;{.data.password}&quot; | base64 -d</pre><blockquote><em>Use </em><em>admin as the username and the decoded password for login.</em></blockquote><h3>Step 8: Deploy the Voting App via ArgoCD</h3><p>You can now create an ArgoCD Application using the YAML specs in k8s-specifications/ folder. Or, deploy manually via kubectl:</p><pre>kubectl apply -f ../k8s-specifications/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0jGfmf-IuZPtHECnXXg4Bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_dbW2d68g89I2R6YieXkXg.png" /></figure><h3>Step 9: Expose Voting and Result Services</h3><pre>kubectl port-forward service/vote 5000:5000 --address=0.0.0.0 &amp;<br>kubectl port-forward service/result 5001:5001 --address=0.0.0.0 &amp;</pre><blockquote><em>Access the apps using:</em></blockquote><ul><li>Vote App: http://&lt;EC2-IP&gt;:5000</li><li>Result App: http://&lt;EC2-IP&gt;:5001</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D0lC7m30s9OJ-bz6UqCVaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*prS9u_BQUxcF-N9zj-2TBA.png" /></figure><h3>Step 10: Install Kubernetes Dashboard (Optional but Recommended)</h3><pre>kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml<br>kubectl apply -f dashboard-adminuser.yml</pre><blockquote><em>The YAML for </em><em>dashboard-adminuser.yml should define a </em><em>ServiceAccount and appropriate </em><em>ClusterRoleBinding.</em></blockquote><h3>🌐 Step 11: Access K8s Dashboard</h3><pre>kubectl port-forward --address=0.0.0.0 svc/kubernetes-dashboard -n kubernetes-dashboard 8443:443</pre><p>Visit https://&lt;EC2-IP&gt;:8443 in your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dfkgvNjlc-9dDP1v_bRhXQ.png" /></figure><p>To login:</p><pre>kubectl -n kubernetes-dashboard create token admin-user</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VnmcNC3xprOhS2QXVWaMyw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6deXWHVkUopD9y-x1o4GNg.png" /></figure><h3>Final Result</h3><ul><li>🎯 ArgoCD available at: http://&lt;EC2-IP&gt;:8080</li><li>📊 Vote App at: http://&lt;EC2-IP&gt;:5000</li><li>📈 Result App at: http://&lt;EC2-IP&gt;:5001</li><li>🛠️ K8s Dashboard at: https://&lt;EC2-IP&gt;:8443</li></ul><h3>Key Takeaways</h3><ul><li><strong>Kind</strong> is perfect for running a K8s cluster locally in Docker, even on cloud VMs.</li><li><strong>ArgoCD</strong> makes app deployment and sync easy via GitOps.</li><li>Exposing services securely and correctly is important when running on cloud VMs.</li><li>Port-forwarding + public IP = simple dev/test setup.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=066d8035c3e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes]]></title>
            <link>https://aashisaxena15.medium.com/kubernetes-3aaa9cf06345?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aaa9cf06345</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 19:57:14 GMT</pubDate>
            <atom:updated>2025-03-28T19:57:14.963Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes Architecture Explained</h3><h3>Creating a Kubernetes Cluster</h3><ul><li>You can create a Kubernetes cluster locally using tools like <strong>Minikube</strong> or <strong>kubeadm</strong>.</li><li>Alternatively, you can use public cloud provider services like <strong>EKS (AWS), AKS (Azure), or GKE (Google Cloud)</strong> to create Kubernetes clusters.</li><li>Inside a Kubernetes cluster, we have two types of machines: <strong>Master Node</strong> and <strong>Worker Nodes</strong>.</li></ul><h3>Worker Node Components</h3><ul><li><strong>Worker nodes</strong> are responsible for running application containers inside Kubernetes clusters.</li><li>These containers run inside <strong>Pods</strong>, the smallest deployable unit in Kubernetes. A pod can contain one or more containers.</li><li>A <strong>single worker node</strong> can run multiple pods.</li></ul><h4>Key Components Inside a Worker Node</h4><p><strong>Kubelet</strong></p><p>Acts as an agent running on every worker node.</p><p>Communicates with the master node to receive instructions on pod deployment and management.</p><p><strong>Container Runtime Interface (CRI)</strong></p><ul><li>Required to create and manage containers.</li><li>Examples: <strong>Docker, containerd, and Rocket</strong>.</li></ul><p><strong>Kube-proxy</strong></p><ul><li>Handles <strong>pod-to-pod communication</strong>.</li><li>Provides <strong>service proxying, load balancing, and application exposure</strong> to users.</li></ul><h3>Master Node (Control Plane) Components</h3><p>The <strong>Master Node</strong> manages the entire cluster, ensuring everything runs smoothly.</p><ul><li>It consists of four key components:</li></ul><h4>1. Kube-API Server</h4><ul><li>Acts as the <strong>entry point</strong> for all Kubernetes operations.</li><li>Validates <strong>requests</strong>, checks user authentication, and forwards requests to other components.</li><li>You can interact with it via:</li><li><strong>kubectl</strong> command-line tool</li><li>Kubernetes Dashboard</li><li>SDKs or APIs</li></ul><h4>2. Scheduler</h4><ul><li>Assigns <strong>pods</strong> to available worker nodes.</li><li>Ensures pods are placed on nodes with sufficient resources.</li><li>Works with the API Server to notify <strong>kubelet</strong> to launch pods on the correct nodes.</li></ul><h4>3. Controller Manager</h4><ul><li>Monitors the cluster to ensure it meets the <strong>desired state</strong>.</li><li>Ensures that the specified number of pods is always running.</li><li>If a pod fails, it instructs the <strong>API Server</strong> to recreate it.</li></ul><h4>4. etcd (Key-Value Store)</h4><ul><li>Stores <strong>all cluster data</strong>, including:</li><li>What applications are running</li><li>Which pods are running on which nodes</li><li><strong>etcd only communicates with the Kube-API Server</strong>, ensuring secure data access.</li></ul><h3>Summary</h3><ul><li>Kubernetes architecture consists of <strong>Master Node (Control Plane)</strong> and <strong>Worker Nodes</strong>.</li><li>Worker nodes contain <strong>Pods, Kubelet, CRI (Docker), and Kube-proxy</strong>.</li><li>Master node manages the cluster with <strong>Kube-API Server, Scheduler, Controller Manager, and etcd</strong>.</li><li>API Server is the central point for <strong>all Kubernetes interactions</strong>.</li><li>The Controller Manager ensures the cluster remains in the <strong>desired state</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y3ldhWoOjqtvVeM3WkxI4w.png" /></figure><h3>Using kubectl for Kubernetes Cluster Management</h3><h3>Introduction</h3><p>kubectl is the command-line tool used to manage Kubernetes clusters. It allows users to deploy applications, inspect resources, and troubleshoot cluster issues. Understanding how to use kubectl efficiently is essential for managing Kubernetes workloads effectively.</p><h3>Basic kubectl Commands</h3><p>Kubernetes follows a declarative model where you define the desired state of your applications, and kubectl helps interact with the cluster to maintain that state.</p><h3>Listing and Describing Resources</h3><pre>kubectl get pods                 # List all running pods<br>kubectl describe pod &lt;pod-name&gt;   # Get detailed information about a specific pod<br>kubectl get events               # View cluster events</pre><p>These commands provide real-time insights into the state of your workloads.</p><h3>Managing Pods</h3><pre>kubectl delete pod &lt;pod-name&gt;  # Delete a specific pod<br>kubectl logs &lt;pod-name&gt;        # View logs of a pod<br>kubectl exec -it &lt;pod-name&gt; -- /bin/bash  # Access a running pod&#39;s shell</pre><p>Managing pods effectively ensures applications run smoothly and recover from failures.</p><h3>Advanced kubectl Commands</h3><h3>Applying and Managing YAML Configurations</h3><p>Kubernetes resources are often defined using YAML files, allowing you to maintain configurations in version control.</p><pre>kubectl apply -f myconfig.yaml  # Apply a YAML configuration file</pre><h3>Labeling and Selecting Resources</h3><pre>kubectl get pods --selector=team=prod  # Filter pods by label<br>kubectl label pod &lt;pod-name&gt; env=production  # Assign a label to a pod</pre><p>Labels are essential for organizing and selecting specific workloads efficiently.</p><h3>Troubleshooting Pods and Clusters</h3><pre>kubectl get pods --field-selector=status.phase=Failed  # List failed pods</pre><p>When a pod fails, debugging it using logs and events helps identify issues.</p><h3>Interacting with Kubernetes</h3><h3>Command-Line Interface (CLI)</h3><p>The kubectl CLI is the primary interface for interacting with Kubernetes resources.</p><pre>kubectl apply -f mydeployment.yaml</pre><p>Using declarative configurations with YAML ensures consistency and easy rollback.</p><h3>Kubernetes Dashboard</h3><p>To access the Kubernetes Dashboard, follow these steps:</p><h3>1. Deploy the Kubernetes Dashboard</h3><p>If the dashboard is not already installed, deploy it using:</p><pre>kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml</pre><h3>2. Create an Admin User</h3><p>Create a ServiceAccount and ClusterRoleBinding:</p><pre>kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard<br>kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin</pre><h3>3. Retrieve the Access Token</h3><pre>kubectl get secret $(kubectl get serviceaccount dashboard-admin -n kubernetes-dashboard -o jsonpath=&quot;{.secrets[0].name}&quot;) -n kubernetes-dashboard -o jsonpath=&quot;{.data.token}&quot; | base64 --decode</pre><p>Copy this token — you’ll need it to log in.</p><h3>4. Start the Proxy Server</h3><pre>kubectl proxy</pre><h3>5. Access the Dashboard</h3><p>Open this URL in your browser:</p><pre>http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/</pre><p>Choose <strong>Token Login</strong> and paste the copied token.</p><h3>YAML for Kubernetes Configurations</h3><p>YAML (Yet Another Markup Language) is used in Kubernetes for defining resources like Deployments, Services, and ConfigMaps. It allows for structured, human-readable configuration management.</p><h3>Basic YAML Structure</h3><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: my-pod<br>  labels:<br>    app: myapp<br>spec:<br>  containers:<br>    - name: my-container<br>      image: nginx<br>      ports:<br>        - containerPort: 80</pre><h3>Deployment Example</h3><p>Deployments manage multiple replicas of pods to ensure high availability.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: my-deployment<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: myapp<br>  template:<br>    metadata:<br>      labels:<br>        app: myapp<br>    spec:<br>      containers:<br>        - name: my-container<br>          image: nginx<br>          ports:<br>            - containerPort: 80</pre><p>Apply the deployment:</p><pre>kubectl apply -f deployment.yaml</pre><h3>Managing Pods &amp; Containers</h3><h3>Understanding Pods</h3><p>A <strong>Pod</strong> is the smallest deployable unit in Kubernetes. It can contain one or more containers, sharing storage and network resources.</p><h3>Creating and Managing Pods</h3><h4>Single-Container Pod</h4><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: nginx-pod<br>spec:<br>  containers:<br>    - name: nginx-container<br>      image: nginx<br>      ports:<br>        - containerPort: 80</pre><p>Deploy and check status:</p><pre>kubectl apply -f nginx-pod.yaml<br>kubectl get pods<br>kubectl describe pod nginx-pod</pre><h4>Multi-Container Pod</h4><p>Multi-container pods allow multiple applications to run in a tightly coupled manner.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: multi-container-pod<br>spec:<br>  containers:<br>    - name: nginx<br>      image: nginx<br>      ports:<br>        - containerPort: 80<br>    - name: log-container<br>      image: busybox<br>      command: [&quot;sh&quot;, &quot;-c&quot;, &quot;while true; do echo &#39;Logging...&#39;; sleep 5; done&quot;]</pre><p>Deploy and check logs:</p><pre>kubectl apply -f multi-container-pod.yaml<br>kubectl logs multi-container-pod -c log-container</pre><h3>Scaling and Updating Deployments</h3><p>Scaling is crucial for handling increased traffic and improving application availability.</p><h3>Scaling Pods</h3><pre>kubectl scale deployment my-deployment --replicas=5<br>kubectl get pods</pre><h3>Updating Deployments</h3><p>Modify the container image in YAML:</p><pre>spec:<br>  template:<br>    spec:<br>      containers:<br>        - name: nginx<br>          image: nginx:1.21</pre><p>Apply the update:</p><pre>kubectl apply -f deployment.yaml<br>kubectl rollout status deployment my-deployment</pre><p>If needed, rollback:</p><pre>kubectl rollout undo deployment my-deployment</pre><h3>Declarative Configuration in Kubernetes</h3><p>Declarative configuration defines the desired state using YAML and kubectl apply.</p><h3>Declarative vs. Imperative Approaches</h3><p>Approach Description Example Imperative Directly modifies resources kubectl create deployment nginx --image=nginx Declarative Defines state in YAML and applies it kubectl apply -f nginx-deployment.yaml</p><p><strong>Benefits of Declarative Approach:</strong></p><ul><li>Easier version control with GitOps</li><li>Repeatable and consistent deployments</li><li>Ensures self-healing when the state drifts</li></ul><h3>Deleting Resources</h3><h3>Deleting Pods</h3><pre>kubectl delete pod nginx-pod</pre><h3>Deleting Deployments</h3><pre>kubectl delete deployment my-deployment</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aaa9cf06345" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DevSecOps End-to-End CI/CD Pipeline: Setting Up Jenkins, Docker, SonarQube & Trivy]]></title>
            <link>https://aashisaxena15.medium.com/devsecops-end-to-end-ci-cd-pipeline-setting-up-jenkins-docker-sonarqube-trivy-0c54edd82ff0?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c54edd82ff0</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Thu, 06 Mar 2025 12:22:00 GMT</pubDate>
            <atom:updated>2025-03-06T12:22:00.072Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will walk through the step-by-step setup of a <strong>DevSecOps</strong> CI/CD pipeline using <strong>Jenkins, Docker, SonarQube, and Trivy</strong>.</p><h3>What is DevSecOps?</h3><p>DevOps is <strong>Development + Operations</strong>, which is a culture and mindset to automate the <strong>Software Development Lifecycle (SDLC)</strong>.</p><p>When we introduce the <strong>Security</strong> aspect to this mindset, it becomes <strong>DevSecOps</strong> (<strong>Development + Security + Operations</strong>).</p><p>Security is mandatory in every organization, so every DevOps professional is essentially a <strong>DevSecOps engineer</strong>.</p><p>Some levels of security our application code needs to pass before deployment:</p><ul><li><strong>GitHub</strong>: Our code is placed here. When the code is pushed, it might have security issues.</li><li><strong>SonarQube</strong>: The code from GitHub might have security vulnerabilities. SonarQube scans the code for security purposes and detects malicious or vulnerable code coming from GitHub.</li><li><strong>Trivy</strong>: It checks whether the Docker image or file system has vulnerabilities. Image scanning with Trivy is essential. Other similar tools include Docker Scout and Snyk.</li><li><strong>Tests</strong>: We can write test cases inside our Docker setup or have them written by the developer.</li><li><strong>Deploy</strong>: Finally, our code is successfully deployed on Docker.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKRrF1qRq1llfWRcZzTl0g.png" /></figure><h3>Step 1: Install Docker and Docker Compose</h3><p>Docker is a containerization tool that allows us to run applications in isolated environments. Docker Compose helps manage multi-container applications.</p><p>Run the following command to install Docker and Docker Compose:</p><pre>sudo apt update &amp;&amp; sudo apt install -y docker.io docker-compose</pre><p>After installation, add your user to the Docker group so you can run Docker commands without sudo:</p><pre>sudo usermod -aG docker $USER<br>exit  # Log out and log back in for changes to take effect</pre><p>Verify Docker is running:</p><pre>docker ps</pre><h3>Step 2: Install OpenJDK 17</h3><p>Jenkins requires Java to run. Install OpenJDK 17 using:</p><pre>sudo apt update &amp;&amp; sudo apt install -y openjdk-17-jdk</pre><p>Verify the installation:</p><pre>java -version</pre><h3>Step 3: Install and Start Jenkins</h3><p>Jenkins is an automation server that helps in implementing CI/CD pipelines.</p><ol><li><strong>Add Jenkins Repository &amp; Key</strong></li></ol><pre>wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc</pre><ol><li><strong>Add Jenkins to the Package Sources</strong></li></ol><pre>echo &quot;deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/&quot; | sudo tee /etc/apt/sources.list.d/jenkins.list</pre><ol><li><strong>Install Jenkins</strong></li></ol><pre>sudo apt update &amp;&amp; sudo apt install -y jenkins</pre><ol><li><strong>Start Jenkins Service</strong></li></ol><pre>sudo systemctl start jenkins</pre><ol><li><strong>Check Jenkins Status</strong></li></ol><pre>sudo systemctl status jenkins</pre><ol><li><strong>Get Initial Admin Password</strong> (needed for first-time setup)</li></ol><pre>sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><h3>Step 4: Configure Jenkins &amp; Docker Permissions</h3><p>By default, Jenkins runs under a restricted user, so we must add Jenkins to the Docker group to allow it to run Docker commands:</p><pre>sudo usermod -aG docker jenkins</pre><p>Restart Jenkins for changes to take effect:</p><pre>sudo systemctl restart jenkins</pre><h3>Step 5: Deploy SonarQube for Code Analysis</h3><p>SonarQube helps analyze code quality and security vulnerabilities.</p><p>Run the following command to deploy SonarQube using Docker:</p><pre>docker run -dit --name sonarserver -p 9000:9000 sonarqube:lts-community</pre><p>Verify if SonarQube is running:</p><pre>docker ps</pre><p>Now, open http://your-server-ip:9000 in a browser to access SonarQube.</p><h3>Step 6: Install Trivy for Security Scanning</h3><p>Trivy is a vulnerability scanner for Docker images.</p><ol><li><strong>Install Dependencies</strong></li></ol><pre>sudo apt-get install wget apt-transport-https gnupg lsb-release -y</pre><ol><li><strong>Add Trivy Repository &amp; Key</strong></li></ol><pre>wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -<br>echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list</pre><ol><li><strong>Install Trivy</strong></li></ol><pre>sudo apt-get update -y<br>sudo apt-get install trivy -y</pre><p>Verify Trivy installation:</p><pre>trivy --version</pre><h3>Step 7: Verify Docker Compose Installation</h3><p>Docker Compose is essential for running multi-container applications.</p><p>Check if it’s installed:</p><pre>docker-compose version</pre><p>If it’s not installed correctly, reinstall it:</p><pre>sudo apt-get install docker-compose -y</pre><h3>Step 8: Configure CI/CD Pipeline in Jenkins</h3><ol><li><strong>Install Required Jenkins Plugins</strong></li></ol><ul><li>Go to Jenkins Dashboard → Manage Jenkins → Manage Plugins.</li><li>Install: <em>Pipeline, Blue Ocean, Docker Pipeline, SonarQube Scanner, Trivy Plugin (if available)</em>.</li></ul><p><strong>2. Create a Jenkins Pipeline Job</strong></p><ul><li>Go to Jenkins Dashboard → New Item → Select <em>Pipeline</em> → Click OK.</li><li>In the <em>Pipeline</em> section, select <em>Pipeline script</em> and enter the following basic example:</li></ul><pre>pipeline {<br>    agent any<br>    environment {<br>        SONAR_HOME = tool &quot;Sonar&quot;<br>        OWASP_HOME = &#39;/opt/dependency-check&#39;<br>    }<br><br>    stages {<br><br>        stage(&quot;Github code&quot;) {<br>            steps {<br>                git url: &quot;https://github.com/krishnaacharyaa/wanderlust.git&quot;, branch: &quot;devops&quot;<br>            }<br>        }<br><br>        stage(&quot;Sonarqube quality analysis&quot;) {<br>            steps {<br>                withSonarQubeEnv(&quot;Sonar&quot;) {<br>                    sh &quot;&quot;&quot;$SONAR_HOME/bin/sonar-scanner -Dsonar.projectName=wanderlust -Dsonar.projectKey=wanderlust&quot;&quot;&quot;<br>                }<br>            }<br>        }<br><br>        stage(&quot;SonarQube Quality Gate Scan&quot;) {<br>            steps {<br>                timeout(time: 2, unit: &quot;MINUTES&quot;) {<br>                    waitForQualityGate abortPipeline: false<br>                }<br>            }<br>        }<br><br>        stage(&quot;Trivy File Scan&quot;) {<br>            steps {<br>                sh &quot;trivy fs --format table -o trivy-fs-report.html .&quot;<br>            }<br>        }<br><br>        stage(&quot;Deploy With Docker Compose&quot;) {<br>            steps {<br>                sh &quot;docker-compose up -d&quot;<br>            }<br>        }<br>    }<br>}</pre><ol><li><strong>Trigger and Monitor the Build</strong></li></ol><ul><li>Click <em>Build Now</em> to start the pipeline.</li><li>View logs under <em>Console Output</em>.</li></ul><p>With these steps, you have successfully set up a <strong>DevSecOps CI/CD pipeline</strong> with Jenkins, Docker, SonarQube, and Trivy. This setup enables automated security scanning and code quality analysis before deployment.</p><p>Next steps:</p><ul><li>Integrate SonarQube and Trivy with Jenkins pipelines.</li><li>Implement an automated build-and-deploy workflow.</li><li>Monitor logs and security reports.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c54edd82ff0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerized Web Scraper with MySQL Integration Using Python]]></title>
            <link>https://aashisaxena15.medium.com/dockerized-web-scraper-with-mysql-integration-using-python-fefbe1d86fb4?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/fefbe1d86fb4</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 16:43:06 GMT</pubDate>
            <atom:updated>2025-02-07T16:43:06.852Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>This project demonstrates how to build a <strong>Dockerized web scraper</strong> that fetches <strong>movie quotes</strong> from a website and stores the data in a <strong>MySQL database</strong> running in a separate <strong>Docker container</strong>. The project utilizes a <strong>custom Docker network</strong> with the bridge driver to enable communication between the containers.</p><h3>🚀 Features:</h3><ul><li><strong>Web Scraping</strong> using Python’s requests and BeautifulSoup libraries.</li><li><strong>Dockerized MySQL</strong> container to store scraped data.</li><li><strong>Container Communication</strong> via Docker networking.</li><li><strong>Automation</strong> of MySQL database setup within the container.</li></ul><h3>🛠️ Prerequisites:</h3><ul><li><strong>Docker installed</strong> on your machine.</li><li><strong>Basic understanding</strong> of Docker, Python, and MySQL.</li><li><strong>Required Python Packages:</strong></li></ul><pre>requests<br>beautifulsoup4<br>mysql-connector-python</pre><h3>Step 1: Setup and Install Dependencies</h3><h3>Install Docker and Required Packages</h3><pre>sudo apt update<br>sudo apt install docker.io -y</pre><h3>Check Docker Installation</h3><pre>docker --version</pre><h3>Set Up Docker Group (Optional)</h3><p>If you don’t want to use sudo every time you run Docker commands:</p><pre>sudo usermod -aG docker $USER<br>newgrp docker</pre><h3>Step 2: Create a MySQL Container</h3><p>Run the following command to create and run a MySQL container:</p><pre>docker run -d \<br>  --name mysql-container \<br>  -e MYSQL_ROOT_PASSWORD=redhat \<br>  -e MYSQL_DATABASE=scraper_db \<br>  -p 3306:3306 \<br>  mysql:latest</pre><h3>Verify Running Containers</h3><pre>docker ps</pre><h3>Access MySQL Container</h3><pre>docker exec -it mysql-container mysql -u root -predhat</pre><h3>Create a Table for Quotes</h3><p>Inside the MySQL prompt, run:</p><pre>USE scraper_db;<br>CREATE TABLE quotes (<br>    id INT AUTO_INCREMENT PRIMARY KEY,<br>    text TEXT NOT NULL,<br>    author VARCHAR(255) NOT NULL<br>);</pre><h3>Step 3: Create a Python Web Scraper</h3><h3>Install Required Python Packages</h3><pre>sudo apt install python3-pip python3-venv -y<br>python3 -m venv venv<br>source venv/bin/activate<br>pip install requests beautifulsoup4 mysql-connector-python</pre><h3>Write app.py for Web Scraping and Database Insertion</h3><pre>import requests<br>from bs4 import BeautifulSoup<br>import mysql.connector<br>import time</pre><pre>DB_CONFIG = {<br>    &#39;host&#39;: &#39;localhost&#39;,<br>    &#39;user&#39;: &#39;root&#39;,<br>    &#39;password&#39;: &#39;redhat&#39;,<br>    &#39;database&#39;: &#39;scraper_db&#39;<br>}</pre><pre>def wait_for_db():<br>    while True:<br>        try:<br>            conn = mysql.connector.connect(**DB_CONFIG)<br>            conn.close()<br>            print(&quot;MySQL is ready!&quot;)<br>            break<br>        except mysql.connector.Error:<br>            print(&quot;Waiting for MySQL to start...&quot;)<br>            time.sleep(3)</pre><pre>def scrape_quotes():<br>    url = &quot;http://quotes.toscrape.com/&quot;<br>    response = requests.get(url)<br>    soup = BeautifulSoup(response.text, &#39;html.parser&#39;)<br>    quotes = soup.find_all(&quot;span&quot;, class_=&quot;text&quot;)<br>    authors = soup.find_all(&quot;small&quot;, class_=&quot;author&quot;)<br>    <br>    conn = mysql.connector.connect(**DB_CONFIG)<br>    cursor = conn.cursor()<br>    <br>    for quote, author in zip(quotes, authors):<br>        cursor.execute(&quot;INSERT INTO quotes (text, author) VALUES (%s, %s)&quot;, (quote.text, author.text))<br>    <br>    conn.commit()<br>    cursor.close()<br>    conn.close()<br>    print(&quot;Quotes inserted successfully!&quot;)</pre><pre>if __name__ == &quot;__main__&quot;:<br>    wait_for_db()<br>    scrape_quotes()</pre><h3>Step 4: Dockerize the Web Scraper</h3><h3>Create a Dockerfile</h3><pre># Use an official Python runtime as a parent image<br>FROM python:3.12</pre><pre># Set the working directory<br>WORKDIR /app</pre><pre># Copy project files into the container<br>COPY . /app</pre><pre># Install dependencies<br>RUN pip install --no-cache-dir -r requirements.txt</pre><pre># Run the application<br>CMD [&quot;python&quot;, &quot;app.py&quot;]</pre><h3>Build and Run the Docker Image</h3><pre>sudo docker build -t web-scrapper .<br>sudo docker run -it web-scrapper</pre><h3>Step 5: Push the Docker Image to Docker Hub</h3><h3>Log in to Docker Hub</h3><pre>sudo docker login</pre><h3>Tag the Image</h3><pre>sudo docker tag web-scrapper aashisaxena15/web-scrapper:latest</pre><h3>Push to Docker Hub</h3><pre>sudo docker push aashisaxena15/web-scrapper:latest</pre><h3>Verify the Image on Docker Hub</h3><p>Go to <strong>Docker Hub</strong> and check for the uploaded image.</p><h3>Conclusion</h3><p>By following this guide, you have successfully:</p><ul><li>Built a <strong>Dockerized web scraper</strong> using Python.</li><li>Set up a <strong>MySQL container</strong> to store scraped data.</li><li><strong>Pushed the image</strong> to Docker Hub.</li></ul><p>You can now pull and run this scraper from any machine using:</p><pre>docker pull aashisaxena15/web-scrapper:latest<br>docker run -it aashisaxena15/web-scrapper</pre><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fefbe1d86fb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is DNS? A Comprehensive Overview]]></title>
            <link>https://aashisaxena15.medium.com/what-is-dns-a-comprehensive-overview-6c5d78a8e692?source=rss-760ecded3118------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c5d78a8e692</guid>
            <dc:creator><![CDATA[Aashisaxena]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 15:03:58 GMT</pubDate>
            <atom:updated>2025-02-05T15:03:58.849Z</atom:updated>
            <content:encoded><![CDATA[<p>The Domain Name System (DNS) is one of the foundational technologies that make the internet work seamlessly. It acts as the internet’s phonebook, translating human-friendly domain names (like www.google.com) into machine-readable IP addresses (like 142.250.190.78). Without DNS, we’d have to memorize long strings of numbers to access websites, which is neither practical nor user-friendly.</p><p>In this blog, we’ll break down how DNS works, its components, and why it’s so important for the internet. Whether you’re a beginner or someone looking to deepen your understanding, this guide will provide a clear and comprehensive overview.</p><h3>Table of Contents</h3><ol><li><strong>What is DNS?</strong></li><li><strong>How DNS Works</strong></li><li><strong>Key Components of DNS</strong></li></ol><ul><li>Domain Names</li><li>IP Addresses</li><li>DNS Server</li></ul><p><strong>4. The DNS Resolution Process</strong></p><p><strong>5.Types of DNS Queries</strong></p><ul><li>Recursive Query</li><li>Iterative Query</li></ul><p><strong>6. DNS Record Types</strong></p><ul><li>A Record</li><li>CNAME Record</li><li>MX Record</li><li>TXT Record</li></ul><p><strong>7. DNS Caching</strong></p><p><strong>8. Common DNS Issues</strong></p><p><strong>9. Conclusion</strong></p><h3>1. What is DNS?</h3><p>DNS stands for <strong>Domain Name System</strong>. It’s a decentralized system that maps human-readable domain names to their corresponding IP addresses. Every device connected to the internet has a unique IP address, which is used to identify and communicate with it. However, IP addresses are difficult for humans to remember. DNS bridges this gap by allowing us to use easy-to-remember domain names instead.</p><p>For example:</p><ul><li>Domain Name: <a href="http://www.google.com/">www.google.com</a></li><li>IP Address: 142.250.190.78</li></ul><p>When you type www.google.com into your browser, DNS translates it into the IP address so your browser can load the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*Es9xCdC2wtFzZIiM-AiKyQ.png" /></figure><h3>2. How DNS Works</h3><p>DNS operates like a distributed database. When you enter a domain name in your browser, your computer doesn’t immediately know the corresponding IP address. Instead, it queries a series of DNS servers to find the correct IP address. This process is called <strong>DNS resolution</strong>.</p><h3>3. Key Components of DNS</h3><h3>Domain Names</h3><ol><li><strong>Top-Level Domains (TLDs):</strong></li></ol><ul><li><strong>Generic TLDs (gTLDs):</strong> These are the most common types of domain names. Examples include .com, .org, .net, .edu, .gov, and new gTLDs like .tech, .ai, .app.</li><li><strong>Country Code TLDs (ccTLDs):</strong> These are assigned to specific countries or territories. Examples include .us (United States), .ca (Canada), .uk (United Kingdom), and .in (India).</li><li><strong>Sponsored TLDs (sTLDs):</strong> These are specialized TLDs regulated by a sponsor, such as .gov (for government), .edu (for educational institutions), or .mil (for military).</li></ul><p><strong>2. Second-Level Domains (SLDs):</strong> These are the part of the domain name directly to the left of the TLD, like “example” in example.com. They are usually chosen by the domain owner.</p><p><strong>3. Subdomains:</strong> These are created within a domain to organize or categorize content. For example, blog.example.com or shop.example.com.</p><h3>IP Addresses</h3><p>An IP address is a numerical label assigned to each device connected to a network. It serves two main purposes:</p><ul><li>Identifying the host or device.</li><li>Providing the location of the host in the network.</li></ul><h3>DNS Servers</h3><p>DNS servers are specialized computers that store DNS records and respond to DNS queries. There are four main types of DNS servers:</p><ol><li><strong>Recursive Resolver:</strong> Receives DNS queries from clients and works to resolve them.</li><li><strong>Root Name Server:</strong> The first step in translating domain names into IP addresses.</li><li><strong>TLD Name Server:</strong> Handles the specific top-level domain (e.g., .com, .org).</li><li><strong>Authoritative Name Server:</strong> Holds the actual DNS records for a domain.</li></ol><h3>4. The DNS Resolution Process</h3><p>The DNS resolution process involves multiple steps to translate a domain name into an IP address. Here’s how it works:</p><ol><li><strong>User Query:</strong> You type www.example.com into your browser.</li><li><strong>Recursive Resolver:</strong> Your computer contacts a recursive resolver (usually provided by your ISP).</li><li><strong>Root Name Server:</strong> The recursive resolver queries a root name server to find the TLD name server.</li><li><strong>TLD Name Server:</strong> The root server directs the resolver to the .com TLD server.</li><li><strong>Authoritative Name Server:</strong> The TLD server provides the IP address of the authoritative name server for example.com.</li><li><strong>DNS Response:</strong> The authoritative name server returns the IP address for www.example.com to the resolver.</li><li><strong>Website Access:</strong> The resolver sends the IP address to your browser, which then loads the website.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*xCPYE5zdQJcx12fhC_85sg.png" /></figure><h3>5. Types of DNS Queries</h3><h3>Recursive Query</h3><p>In a recursive query, the DNS server must provide a complete answer or an error message. The server does the heavy lifting and returns the final result to the client.</p><h3>Iterative Query</h3><p>In an iterative query, the DNS server returns the best answer it can. If it doesn’t know the answer, it refers the client to another server that might have the information</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*jSDwhVgI4SMNUTfmUWCmGQ.png" /></figure><h3>6. DNS Record Types</h3><ol><li><strong>A Record (Address Record):</strong></li></ol><ul><li>Maps a domain name to an <strong>IPv4 address</strong>.</li><li>For example, when you visit example.com, the A record helps your browser connect to the server using its IP address, like 192.168.1.1.</li></ul><p><strong>2. CNAME Record (Canonical Name Record):</strong></p><ul><li>Maps a domain name to <strong>another domain name</strong> (an alias).</li><li>For example, www.example.com could point to example.com. When you access www.example.com, the CNAME record redirects you to example.com.</li></ul><p><strong>3. MX Record (Mail Exchange Record):</strong></p><ul><li>Specifies which <strong>mail servers</strong> are responsible for receiving email on behalf of a domain.</li><li>For example, mail.example.com could be listed as the server that handles emails for example.com.</li></ul><p><strong>4. TXT Record (Text Record):</strong></p><ul><li>Stores <strong>textual information</strong> that can be used for various purposes.</li><li>Often used for <strong>security</strong> or <strong>verification</strong>, like setting up SPF (Sender Policy Framework) records to prevent email spoofing, or Google verification for website ownership.</li></ul><p><strong>5. NS Record (Name Server Record):</strong></p><ul><li>Specifies the <strong>authoritative name servers</strong> for a domain.</li><li>These servers are responsible for providing the DNS information for that domain. For example, an NS record might point to ns1.example.com, indicating that it’s the primary server for DNS queries related to the domain.</li></ul><p><strong>6. SOA Record (Start of Authority Record):</strong></p><ul><li>Contains <strong>administrative information</strong> about the DNS zone.</li><li>Includes details like the primary name server, the email of the domain administrator, and the timing of DNS record refreshes (e.g., how often the records are updated).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*VmEdjYsvHrDAXzNYnWksUA.png" /></figure><h3>7. DNS Caching</h3><p>DNS caching is a mechanism that stores DNS query results temporarily to speed up future requests. When a DNS resolver receives a query, it first checks its cache. If the answer is already stored, it returns the cached result instead of querying other servers. This reduces latency and improves performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*pI3zPZ6H_PvQWwajC01Wug.png" /></figure><h3>8. Common DNS Issues</h3><ul><li><strong>DNS Propagation Delay:</strong> Changes to DNS records can take time to propagate across all servers.</li><li><strong>DNS Cache Poisoning:</strong> Malicious actors corrupt the DNS cache with false information.</li><li><strong>Server Downtime:</strong> If a DNS server is down, users may not be able to access the domain.</li></ul><h3>9. Conclusion</h3><p>DNS is a critical component of the internet that ensures seamless communication between devices. By translating domain names into IP addresses, it simplifies how we access websites and services. Understanding how DNS works can help you troubleshoot issues, optimize performance, and appreciate the complexity of the internet’s infrastructure.</p><p>Whether you’re a learner or a professional, DNS is a fascinating topic that underscores the importance of efficient and reliable systems in our digital world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c5d78a8e692" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>