<?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 Nahidul Islam on Medium]]></title>
        <description><![CDATA[Stories by Nahidul Islam on Medium]]></description>
        <link>https://medium.com/@nahidkishore99?source=rss-d7ea8447cd0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pvmjqlNJ_fUSPnHeoqpc1Q.png</url>
            <title>Stories by Nahidul Islam on Medium</title>
            <link>https://medium.com/@nahidkishore99?source=rss-d7ea8447cd0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:52:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nahidkishore99/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[Docker volumes]]></title>
            <link>https://nahidkishore99.medium.com/docker-volumes-d0d788ec7ac3?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0d788ec7ac3</guid>
            <category><![CDATA[docker-volume]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 18:44:45 GMT</pubDate>
            <atom:updated>2024-01-16T18:44:45.769Z</atom:updated>
            <content:encoded><![CDATA[<p>Docker volumes are used in various scenarios where persistent data storage and sharing are essential. Here are some common situations when Docker volumes are needed:</p><ol><li>Persisting Data Across Container Lifecycles:</li></ol><ul><li>Scenario: When you want to ensure that data persists even if the container is stopped or removed.</li><li>Use Case: Storing database data, application logs, or configuration files that need to survive container restarts.</li></ul><ol><li>Sharing Data Between Containers:</li></ol><ul><li>Scenario: When multiple containers need access to the same data.</li><li>Use Case: Microservices architecture where different containers rely on shared configuration files, databases, or other persistent data.</li></ul><ol><li>Database Storage:</li></ol><ul><li>Scenario: When running database containers that need persistent storage.</li><li>Use Case: Storing database files or data volumes for databases like MySQL, PostgreSQL, or MongoDB.</li></ul><ol><li>Application Configuration:</li></ol><ul><li>Scenario: When applications require configuration files or settings that need to be consistent across multiple containers.</li><li>Use Case: Storing application configuration files, SSL certificates, or environment-specific settings.</li></ul><ol><li>Data Backups and Migration:</li></ol><ul><li>Scenario: When you need to back up or migrate data easily.</li><li>Use Case: Creating Docker volumes allows you to back up or migrate data by moving the volume to another host or container.</li></ul><ol><li>Performance Improvements:</li></ol><ul><li>Scenario: When you want to optimize read and write operations.</li><li>Use Case: Using Docker volumes can improve performance by avoiding the overhead of container filesystems, especially in write-heavy scenarios.</li></ul><ol><li>Sharing Data Between Host and Container:</li></ol><ul><li>Scenario: When you need to share data between the host and a container.</li><li>Use Case: Sharing files, logs, or directories between the host machine and a running container.</li></ul><ol><li>Distributed Applications:</li></ol><ul><li>Scenario: When deploying applications in a distributed environment.</li><li>Use Case: Docker volumes support distributed storage solutions, enabling data sharing and synchronization across multiple nodes in a cluster.</li></ul><ol><li>Managing Secrets and Sensitive Data:</li></ol><ul><li>Scenario: When dealing with sensitive information that needs to be securely managed.</li><li>Use Case: Storing secrets, certificates, or private keys using Docker volumes, possibly in combination with Docker secrets.</li></ul><ol><li>Custom Storage Solutions:</li></ol><ul><li>Scenario: When integrating Docker with external storage solutions.</li><li>Use Case: Leveraging third-party volume drivers to connect Docker to external storage systems, such as network-attached storage (NAS) or cloud storage.</li></ul><p>In summary, Docker volumes are essential when you need persistent and shareable storage for containers, especially in scenarios where data needs to persist beyond the container’s lifecycle or be shared among multiple containers and hosts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0d788ec7ac3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Deployment of 2048 Game: Jenkins, SonarQube, Docker and Kubernetes Implementation]]></title>
            <link>https://blog.devops.dev/automated-deployment-of-2048-game-jenkins-sonarqube-docker-and-kubernetes-implementation-a0349ce2256b?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0349ce2256b</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[deployment-pipelines]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[2048-game]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Mon, 01 Jan 2024 10:46:32 GMT</pubDate>
            <atom:updated>2024-01-02T17:57:18.682Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6y4i5EghvVocsaGv0HnETQ.png" /></figure><p>Today, we’ll explore how to set up Continuous Integration and Continuous Deployment (CI/CD) for our 2048 Game application. We’ll create a pipeline script to deploy our application in a Docker container while leveraging SonarQube for code quality checks, OWASP Dependency Check for examining code dependencies and security vulnerabilities, and Trivy for conducting a comprehensive security scan of our Docker images. Additionally, we’ll employ Trivy to scan files for security risks. Through these tools, we’ll ensure the security of our project’s deployment.</p><p>Moreover, we’ll configure email notifications to receive alerts about our pipeline’s build stage results. Whether the build succeeds or fails, Jenkins will automatically notify us via email once the build stage is complete.<br>The exciting part is deploying our application on Kubernetes! We’ll deploy it as both a Docker container and a Kubernetes container. For Kubernetes deployment, we’ll create deployment and service manifest files.</p><p>This entire process will be demonstrated hands-on, starting from scratch. Let’s get started and try it out step by step!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*omP7YCJm9DG_NZYK" /></figure><p>First, we’ll launch two instances: one for the Main server, where we’ll deploy our entire project, and the other for the SonarQube server. The main server is our primary server. Here, we’ll set up our entire project. On the SonarQube server, we’ll run a SonarQube Docker container for using SonarQube.</p><p>We’ll deploy our application using Kubernetes orchestration. To do this, we’ll install Kubeadm and Kubectl. We’ve set up two Ubuntu 20.04 instances: one for the K8s master and the other for the K8s worker node. Additionally, we’ll install Kubectl specifically on the Jenkins machine.</p><h3>Install and Setup Jenkins:</h3><p>To start, we’ll install Jenkins by following the steps provided and then set up our Jenkins server. Let’s get started with this process!</p><pre>    sudo apt update<br>    sudo apt install fontconfig openjdk-17-jre -y<br>    curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \<br>    /usr/share/keyrings/jenkins-keyring.asc &gt; /dev/null<br>    sudo sh -c &#39;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&#39;<br>    sudo apt-get update<br>    sudo apt-get install jenkins -y<br>    sudo systemctl start jenkins<br>    sudo systemctl enable jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RFOY7tC5n1ltGR8e" /></figure><p>You can get the ec2-instance-public-ip-address from your AWS EC2 console page.</p><p>Edit the inbound traffic rule to only allow custom TCP port 8080</p><p>http://:&lt;ec2-instance-public-ip-address&gt;8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hwVrpeXnCHjWTGzZ" /></figure><p>Using this command, we’ll copy the password from the terminal and paste it here. After clicking the “Continue” button, our Jenkins server will open.</p><pre>sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D_cdQeWlH15fpjef" /></figure><p>Next, by selecting the “Install suggested plugins” option, the required default plugins will be installed automatically. Once the installation of these suggested plugins is complete, we’ll proceed to set up the User for Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iQM55368BbObYtqB" /></figure><p>After making the necessary configurations, we’ll click on the “Save and Continue” button, followed by the “Save and Finish” button. Our Jenkins setup will then be complete!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/0*cQ13oGWt6Y-DUyV_" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TPqgqWBmI_vo0zUh" /></figure><p>Run the below commands as root user to install Docker</p><pre>sudo su -<br>sudo apt update<br>sudo apt install docker.io -y<br>sudo chmod 777 /var/run/docker.sock <br>sudo usermod -aG docker $USER<br>sudo usermod -aG docker jenkins<br>sudo usermod -aG docker ubuntu<br>sudo systemctl restart docker<br># Once you have done these, its a best practice to restart Jenkins<br>sudo systemctl restart jenkins</pre><h3>Sonarqube setup:</h3><p>Install Docker for Sonarqube container on sonar-server instance</p><pre>sudo apt-get update<br>sudo apt-get install docker.io -y<br>sudo usermod -aG docker $USER<br>sudo chmod 777 /var/run/docker.sock <br>sudo docker ps<br>docker run -d --name sonar -p 9000:9000 sonarqube:lts-community</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9TNeXWHcJsSdZurU" /></figure><p>Our SonarQube Docker container is now running. We’ll attempt to access our SonarQube server. To do this, we need to enable inbound traffic on port 9000 for the SonarQube instance’s EC2 instance. The access URL will be in the format http://&lt;EC2-instance-public-IP-address&gt;:9000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6t4ehNoef2OLV5ye" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kjxQimmb6m0K6z-K" /></figure><h3>Create SonarQube Credential in Jenkins</h3><p>Once we’ve set up SonarQube, we’ll generate a SonarQube token. This token will be added to the credentials on our Jenkins server, allowing Jenkins to connect with SonarQube.</p><p>To generate the token, go to SonarQube → Administration → Security, write “Jenkins,” and then click on “Generate.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1bbLeil8eEDNsyq4" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fwvt0q8ySzbFvpsp" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*fVaomxsWmnhy7QWE" /></figure><p>We’ll set up webhooks in SonarQube for communication with Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cfdegLp2oXTvhoYb" /></figure><p>Next, navigate to Jenkins → Manage Jenkins → Manage Credentials → System → Global Credentials → Add Credentials →</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tyf-5Rrohpq0UI1v" /></figure><h3>Create DockerHub Credential in Jenkins</h3><p>To create DockerHub credentials in Jenkins, follow these steps: Jenkins → Manage Jenkins → Manage Credentials → Stored scoped to Jenkins → Global → Add Credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CwlL_ZqdTAGQHzFF" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wAOMLs1j84i83vtO" /></figure><h3>Install Trivy</h3><pre>sudo apt-get install wget apt-transport-https gnupg lsb-release -y<br>wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg &gt; /dev/null<br>echo &quot;deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main&quot; | sudo tee -a /etc/apt/sources.list.d/trivy.list<br>sudo apt-get update<br>sudo apt-get install trivy -y</pre><p>Next, we will login to Jenkins and start to configure our Pipeline in Jenkins</p><blockquote>Install Plugins like Sonarqube Scanner, Nodejs, jdk, OWASP Dependency Check, Docker , Kubernetes</blockquote><p>Goto Manage Jenkins →Plugins → Available Plugins →</p><p>Install below plugins</p><p>1→ SonarQube Scanner (Install without restart)</p><p>2 → OWASP Dependency Check</p><p>3 → Docker , Docker pipeline, Docker Cli, Docker build step,</p><p>4 → Kubernetes Related plugin</p><p>5 → Nodejs</p><p>6 → Jdk</p><p>Configure Sonar Scanner, JDK, NodeJS, OWASP check in Global Tool Configuration</p><p>Goto Manage Jenkins → Tools → jdk, nodejs, Dependency Check, Sonar scanner→ Click on Apply and Save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CZZONcgh8FXCsJwW" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gI_2C3kfTYsgSCVz" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_mJkAtGK362O_cKN" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pj7njoX8lfKOpeEP" /></figure><h3>Configure Sonar Server in System Configuration:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Iv71nYWwFr8OfcmX" /></figure><h3>Lets Create a Job , it as Real-World CI-CD project</h3><p>We’ll create a new job for our application. In the item name section, we’ll provide our project’s application name, such as ‘2048-Game.’ After selecting the pipeline option and clicking ‘OK,’ our new job will be created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BBhlsGvr6lYyJnXU" /></figure><p>If we want to describe our project, we can add its description. One tricky aspect is setting the ‘discard old build’ section to retain a record of the last two builds. This way, we can view the history of the previous two builds, preventing excessive storage consumption in our VM. This step is optional but beneficial for managing storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IplmFJLYvXPqOXO1" /></figure><p>Next, we’ll write a pipeline script. To start, we’ll create a ‘hello world’ script to test if our pipeline functions correctly. After scripting, we’ll click ‘Apply and Save’ followed by ‘Build Now’ to ensure the pipeline runs smoothly.</p><blockquote>Great! Our ‘hello world’ pipeline script is working properly.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kZlaTvFaSsccEumA" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/0*MSzZX1xDFzOWcQFy" /></figure><p>Now, we’ll move to the next step by checking out from Git and providing our project’s repository URL.</p><p>Before running any new builds, we’ll always initiate the ‘Clean Workspace’ stage to ensure our workspace is tidy and free from previous build artifacts. This step is crucial as it clears the workspace used during the build process, promoting a clean and consistent environment for subsequent builds in the pipeline.</p><p>Then, at the next stage, we’ll create a Sonarqube analysis and Quality Gate stage to analyze our project’s code for any code analysis or code smell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1widM-ycFx8Zj2F7" /></figure><p>Our pipeline script is working properly without any errors or issues. So, we’ll now verify if our project has been successfully created on the Sonarqube server. This check ensures there are no issues because if there were, the pipeline script would display error messages causing a build stage failure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WD8NY5KfuGC--Ch5" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-f6pHzfNmHpL6r_x" /></figure><p>Great news! Our project has been successfully created on the Sonarqube server, and the ‘quality gate status’ shows ‘Passed.’ This means our Sonarqube analysis and Quality Gate stage have successfully completed.</p><h3>Install Dependencies:</h3><p>This stage ensures that all necessary dependencies (Node.js modules, npm packages, or other required libraries) are present in the build environment. It helps in maintaining consistency between development, testing, and production environments.</p><p>In a React/Node.js application, this stage is crucial as it sets up the environment with the necessary dependencies required for building, testing, and running the application. By automating this stage in the CI/CD pipeline, you ensure a more reliable, efficient, and consistent development and deployment process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lDY_uVARFFECGV3E" /></figure><h3>OWASP Dependency-Check &amp; Trivy FS Scan:</h3><p>Next, we’ll perform an OWASP Dependency-Check. OWASP Dependency-Check works by identifying project dependencies and checking for any publicly known vulnerabilities. It’ll scan all dependencies of our project and generate a report. This report, named ‘dependency check report.xml,’ will be generated in our project’s workspace. We can review this XML file to see the types of issues it has identified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oIQVGhA-FagHUnN3" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/0*XhuTWebBl74Mu8ow" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*krjbMpIcsIVWQlVL" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wy60k3kvVuJo5qjJ" /></figure><p>Looks like our OWASP dependency check stage has successfully completed, and within our workspace, the dependency check report XML file has been generated. The console output provides comprehensive details about each stage of our pipeline, showcasing any failed stages, types of issues encountered, reasons for failure, and more. Specifically, we can easily locate the location of our generated XML file within the console output.</p><h3>Trivy FS Scan:</h3><p>Trivy is a vulnerability scanner designed for container images. Integrating Trivy into a CI/CD pipeline involves conducting vulnerability scans on the container images during the build stage.</p><ul><li>Scans code early for vulnerabilities, preventing insecure deployments.</li><li>Improves code quality and compliance with security standards.</li><li>Reduces attack surface and potential damage from exploits.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_oYMizMwZMccOGBA" /></figure><h3>Docker build and Push to Docker Hub:</h3><p>Moving on to Docker Build and Push to Docker Hub: We’ll build our Docker file and then push our Docker image to a DockerHub repository. Once the build stage is successful, we’ll verify if our Docker image has indeed been successfully pushed to the DockerHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PuMUXhAUzG523XP3" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hIpf75qVAOxj0gxg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ii4Vs60rL0CTjWUU" /></figure><p>Indeed, our image has been successfully pushed to DockerHub, displaying the timestamp of its last push, indicating it was pushed just 3 minutes ago.</p><h3>Trivy Docker Image Scan</h3><p>Next, let’s address Trivy Docker Image Scan. Trivy serves as an open-source vulnerability scanner specifically designed for container images. Its main focus lies in scanning container images to identify any security vulnerabilities within their OS packages and dependencies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rSSqVxssct7ieV0m" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bnUV-_B7Xx9MYCcL" /></figure><h3>Deploy to Docker Container:</h3><p>In the final stage,If all the previous stages have worked properly, we’ll deploy our Docker image into a Docker container. This will allow our application to be easily accessible from anywhere in the world.</p><pre>stage(&quot;Deploy to Docker Container&quot;){<br>            steps{<br>                sh &quot; docker run -d --name 2048-game -p 3000:3000 nahid0002/2048-game:latest &quot;<br>            }<br>        }</pre><p>Looks like our Docker image has been successfully deployed into a Docker container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d2POsghbPTL4G09R" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QphFgGUdqHtP7YwW" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yY3AfLx73BrSCUni" /></figure><p>To check if our container is properly running, we can use the ‘docker ps’ command. This command will verify if our container is indeed running. Here, we see that our container is up and running.</p><p>Now, let’s try accessing our application. Before that, it’s important to ensure that the port number of our Docker image is added as an inbound rule in the security settings. Without this, we won’t be able to access our application. In our case, the application’s port number is 3000, so we’ve added port 3000 to the inbound rule section and saved the settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kX_wxuqabWHdbzA-" /></figure><p>Next, we’ll copy our instance’s public IP address and paste it into our browser, adding the port number alongside it. Hitting ‘Enter,’ we can now see our application.</p><p>Wow! Congratulations! Finally, we’ve successfully accessed our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B33kBLupG1dopQV4" /></figure><h3>Deploy application on Kubernetes</h3><p>We’ve already deployed our application in a Docker container, and it’s successfully running. Now, we’re planning to deploy our application on Kubernetes and try accessing it. So, let’s get started.</p><p>To deploy the app on Kubernetes, we’ll install Kubeadm and Kubectl. We’ve set up two Ubuntu 20.04 instances: one for the K8s master and the other for the worker node.<br>Additionally, we’ll install Kubectl only on the Jenkins machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kXayeLLfmjhfL5uE" /></figure><p>We’ll install Kubectl on the Jenkins server to prevent any failure in the Kubernetes deployment stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZbgLpR2AnKxhPZYz" /></figure><h3>Create Credentials for connecting to Kubernetes Cluster using kubeconfig</h3><p>Execute the below command</p><pre>cd .kube/<br>sudo cat config</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aX3bJfCOUQR7iWyl" /></figure><p>Open your text editor or notepad, copy and paste the entire content and save in a file. We will upload this file.</p><p>Enter ID as K8s and choose File and upload the file and save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QXAGyD-3efW8gtaM" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MSvTKeL4vBXhcGWB" /></figure><p>Now, we’ll write a pipeline script for deploying our application.</p><pre>stage(&#39;Deploy to kubernets&#39;) {<br>            steps {<br>                script {withKubeConfig([credentialsId: &#39;k8s&#39;, serverUrl: &#39;&#39;]) {<br>                        sh (&#39;kubectl apply -f deployment.yaml&#39;)<br>                    }<br>                }<br>            }<br>        }</pre><h4>Our application is successfully deployed in a Kubernetes container.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/0*EEtR25YqFMRyjhNd" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4OvK9js1zhlbWzG2" /></figure><p>To check if our container is deployed, we’ll execute a command.</p><pre>kubectl get all<br>Kubectl get svc<br>Kubectl get deployment<br>Kubectl get pods</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1RpFfnQY9cpRyUfG" /></figure><p>Once executed, if we see the container running and displaying port number 30584, we’ll add this port number to the inbound rule of our worker node’s EC2 instance. Then, by adding this port number to the public IP address of our worker node’s instance in the browser, we should be able to access our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cZSKPcb-4dKb7c46" /></figure><h3>Wow! Congratulations, we’ve successfully accessed our application.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KjRYmGJZXLS9W2BW" /></figure><h3>Configuring mail server in Jenkins ( Gmail )</h3><p>Another great addition is configuring email notifications for our pipeline’s build stage. We want to receive notifications via email automatically from the Jenkins server, whether the build status is a success or failure. After completing the build stage, notifications will be sent to our email.</p><p>So, here’s the process:</p><p>Firstly, we’ll need to install the Email Extension Template plugin.</p><p>Next, let’s navigate to Gmail, access our profile, and manage our Google Account. Then, within the security tab, ensure that 2-step verification is enabled. Generate an app password by searching for ‘other’ in the app passwords section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tpGOSEAZ7PImLyFC" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xMeuVVuJ6_jc4mvI" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*oiQn2kF0jJDyiw2i" /></figure><p>Once the plugin is installed in Jenkins, we’ll need to access ‘Manage Jenkins’ and navigate to ‘credentials’ to add our email username and the generated password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tra7Q_dFO2yVI5Ws" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MxmfUAzE2jItpuoU" /></figure><p>In ‘Manage Jenkins’ again, under ‘configure system,’ we’ll set up the details in the ‘E-mail Notification’ section according to the provided guidelines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aN8-aRdyMYUE6iFJ" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SAEMbHX0sGnAS9Ju" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/0*pgSWMpy78uzPrJW9" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/0*a_Jk40wmu6n2lsna" /></figure><p>For verification purposes, we’ll test the email configuration to ensure that everything is properly set up.</p><p>After configuring the ‘Extended E-mail Notification’ section as indicated, we’ll test the configuration to check if our settings are working correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lm-0PP0U0s8keiaY" /></figure><p>Now, let’s test the configuration to confirm if the notifications are being sent successfully. By checking our inbox, we’ll see a test email indicating whether our email configuration is functioning properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/0*uOIIwSpHR2a3pIQr" /></figure><p>Finally, let’s script the pipeline to enable email notifications for our build stage completion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*ra5-C3F1HWeqnaiH" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/0*CoFGPM-AMVq_ZAPT" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q5jUJ0Jhp6twrvD-" /></figure><p>Once the build stage is successfully completed, we’ll check our email to confirm if we’ve received any success-related emails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/0*QelTwBO5Ysosi3px" /></figure><p>Checking our email, we can see that we’ve received a success email indicating that our configurations are working properly.</p><blockquote>In conclusion, we’ve successfully demonstrated the implementation of a CI/CD pipeline for our 2048-Game application. We’ve covered aspects from setting up Jenkins, SonarQube, Docker, Trivy, and Kubernetes to deploying our application while incorporating security measures and automated email notifications. This hands-on project provided an in-depth understanding of building, testing, and deploying applications with CI/CD practices. By following these steps, developers can ensure both the reliability and security of their deployments.</blockquote><p>Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>— Happy Learning !!!</p><h3>Let’s connect !!!</h3><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><h3><a href="https://github.com/nahidkishore">Github</a></h3><h3><a href="http://nahidkishore99@gmail.com/">Mail</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0349ce2256b" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/automated-deployment-of-2048-game-jenkins-sonarqube-docker-and-kubernetes-implementation-a0349ce2256b">Automated Deployment of 2048 Game: Jenkins, SonarQube, Docker and Kubernetes Implementation</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing AWS EKS with Terraform: Infrastructure-as-Code Implementation]]></title>
            <link>https://blog.devops.dev/efficient-aws-infrastructure-management-using-terraform-and-eks-53ad87e92ef5?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/53ad87e92ef5</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[amazon-eks]]></category>
            <category><![CDATA[eks-cluster]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Wed, 20 Dec 2023 19:20:54 GMT</pubDate>
            <atom:updated>2023-12-21T17:22:35.374Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0kQzp-KQCbMkzFOc-LReTg.png" /></figure><blockquote>In the world of AWS infrastructure orchestration, Terraform stands as a robust solution for managing resources effortlessly. Here, we’ll explore step-by-step how to set up an EKS cluster on AWS, starting with configuring AWS settings and roles, creating necessary setups like VPCs, and finally crafting an EKS cluster using Terraform. You’ll discover how Terraform simplifies this process, making AWS infrastructure management much more straightforward.</blockquote><h3>AWS Provider Configuration</h3><p>We’ll configure the provider and set the region, ensuring we add the required version for the AWS provider. Here, we’ve chosen the AWS provider and specifically mentioned the us-east-1 region.</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>}<br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}</pre><h3>IAM Role for EKS Cluster</h3><p>Here, we’ll create an IAM role for our EKS cluster, which will be assumed by the EKS service itself, allowing EKS to perform actions within our AWS account. This role will be linked to the AmazonEKSClusterPolicy.</p><pre>resource &quot;aws_iam_role&quot; &quot;eks_cluster&quot; {<br>  name = &quot;eks-cluster-role&quot;<br><br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Action = &quot;sts:AssumeRole&quot;<br>        Effect = &quot;Allow&quot;<br>        Principal = {<br>          Service = &quot;eks.amazonaws.com&quot;<br>        }<br>      }<br>    ]<br>  })<br>}<br><br>resource &quot;aws_iam_policy_attachment&quot; &quot;eks_cluster_policy&quot; {<br>  name       = &quot;eks-cluster-policy&quot;<br>  roles      = [aws_iam_role.eks_cluster.name]<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSClusterPolicy&quot;<br>}</pre><h3>Default VPC and Public Subnets:</h3><p>Next, we’ll set up the default VPC and public subnets. We’ll fetch details about the default VPC and identify its public subnets. The EKS cluster will be deployed within this default VPC.</p><pre>data &quot;aws_vpc&quot; &quot;default&quot; {<br>  default = true<br>}<br><br>data &quot;aws_subnets&quot; &quot;public&quot; {<br>  filter {<br>    name   = &quot;vpc-id&quot;<br>    values = [data.aws_vpc.default.id]<br>  }<br><br>  filter {<br>    name   = &quot;availabilityZone&quot;<br>    values = [&quot;us-east-1a&quot;, &quot;us-east-1b&quot;, &quot;us-east-1c&quot;, &quot;us-east-1d&quot;, &quot;us-east-1f&quot;]<br>  }<br>}</pre><h3>AWS EKS Cluster:</h3><p>Now, let’s create the AWS EKS cluster. This will set up an Amazon EKS cluster named ‘my_eks_cluster’ in the specified VPC and public subnets. It relies on the IAM role being connected to the cluster.</p><pre>resource &quot;aws_eks_cluster&quot; &quot;eks&quot; {<br>  name     = &quot;my-eks-cluster&quot;<br>  role_arn = aws_iam_role.eks_cluster.arn<br><br>  vpc_config {<br>    subnet_ids = data.aws_subnets.public.ids<br>  }<br>}</pre><h3>IAM Role for EKS Node Group</h3><p>Then, we’ll create an IAM role for the node group in EKS. After that, we’ll attach policies to the IAM role for the EKS node group.</p><pre>resource &quot;aws_iam_role&quot; &quot;example&quot; {<br>  name = &quot;eks-node-group-example&quot;<br><br>  assume_role_policy = jsonencode({<br>    Statement = [{<br>      Action = &quot;sts:AssumeRole&quot;<br>      Effect = &quot;Allow&quot;<br>      Principal = {<br>        Service = &quot;ec2.amazonaws.com&quot;<br>      }<br>    }]<br>    Version = &quot;2012-10-17&quot;<br>  })<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;example-AmazonEKSWorkerNodePolicy&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy&quot;<br>  role       = aws_iam_role.example.name<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;example-AmazonEKS_CNI_Policy&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy&quot;<br>  role       = aws_iam_role.example.name<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;example-AmazonEC2ContainerRegistryReadOnly&quot; {<br>  policy_arn = &quot;arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly&quot;<br>  role       = aws_iam_role.example.name<br>}</pre><h3>Create EKS Node Group</h3><p>Now we wille create an EKS node group associated with the specified EKS cluster, using the IAM role, subnets, and instance configuration</p><pre>resource &quot;aws_eks_node_group&quot; &quot;example&quot; {<br>  cluster_name    = aws_eks_cluster.eks.name<br>  node_group_name = &quot;managed-nodes&quot;<br>  node_role_arn   = aws_iam_role.example.arn<br><br>  subnet_ids = data.aws_subnets.public.ids<br>  scaling_config {<br>    desired_size = 1<br>    max_size     = 2<br>    min_size     = 1<br>  }<br>  instance_types = [&quot;t2.micro&quot;]<br><br>  depends_on = [<br>    aws_iam_role_policy_attachment.example-AmazonEKSWorkerNodePolicy,<br>    aws_iam_role_policy_attachment.example-AmazonEKS_CNI_Policy,<br>    aws_iam_role_policy_attachment.example-AmazonEC2ContainerRegistryReadOnly,<br>    aws_eks_cluster.eks<br>  ]<br>}</pre><p>Now, we’ll initialize our setup by running the ‘terraform init’ command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JK3BShE1wGeGSiuj" /></figure><p>Great, it seems like Terraform has been successfully initialized. Next, we’ll execute the ‘terraform plan’ command to review the changes that will occur in our infrastructure. It’s a good practice to run ‘terraform plan’ after ‘terraform init’ to see the infrastructure changes beforehand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4Z8E5oAbUW7AMkfR" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/0*_WiJX2clZKtkDwD3" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*ewXO2nNVKmte8QOV" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/0*JQ0nU5XSJxzuBExj" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*axAQJvdToF4DwxqC" /></figure><p>If everything looks good, we’ll proceed with the ‘terraform apply’ command. Terraform will request confirmation before implementing any changes. If everything seems accurate, type ‘yes’ and press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UOWY-eikR_PjBgK1" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X0NOdzteS_M4vFPL" /></figure><p>Looks like everything is in progress, including the IAM role, role policy, and EKS cluster creation. Let’s wait for a while to see what’s happening…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MfT7Hb3RYkiPRRz3" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OLypJml6-DG1MKS-" /></figure><p>Wow!! Congratulations, our cluster has been created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o7TaCWC6svv6E-u7" /></figure><p>Now, let’s check if the EKS cluster has been created properly. When we click on the cluster, we’ll be able to see the cluster’s details. Upon clicking, we find that within the cluster, a node group has been created and attached with an IAM role. Additionally, the instance types we provided in our code for desired capacity, maximum, and minimum size are all displaying perfectly. This means our EKS cluster has been successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*omzahPgCq_f6xdxl" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HaP9hzN0zT55fJWJ" /></figure><h3>Destroy Your Infrastructure</h3><p>Lastly, when our task is completed, we might want to destroy the resources to avoid unnecessary costs. Terraform simplifies this process with the ‘destroy’ command, which deletes the existing resources determined from the Terraform files.</p><p>To execute this, simply type ‘terraform destroy’ and hit enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YCllpdb4vrxp7h3J" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0aDZgxN3pclO22yb" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KOC_j2lber41xOsz" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b0N7vO2lYR9m3Yu3" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XAbocBy4tkgkIXkS" /></figure><blockquote>In conclusion, our journey through Terraform orchestration within the AWS environment has culminated in the successful creation of IAM roles, EKS clusters, and associated resources. The power of infrastructure-as-code, utilizing Terraform, has enabled swift resource deployment and efficient management. This hands-on experience sheds light on the ease and agility that comes with managing cloud infrastructure using robust orchestration tools like Terraform.</blockquote><p>Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>— Happy Learning !!!</p><p>Let’s connect !!!</p><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><h3><a href="https://github.com/nahidkishore">Github</a></h3><h3><a href="http://nahidkishore99@gmail.com/">Mail</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53ad87e92ef5" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/efficient-aws-infrastructure-management-using-terraform-and-eks-53ad87e92ef5">Managing AWS EKS with Terraform: Infrastructure-as-Code Implementation</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS ECS Deployment: Containerized Application with ECR and Fargate]]></title>
            <link>https://blog.devops.dev/aws-ecs-deployment-containerized-application-with-ecr-and-fargate-3ffbaac94df4?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ffbaac94df4</guid>
            <category><![CDATA[aws-ecr]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-ecs]]></category>
            <category><![CDATA[aws-fargate]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 11:38:24 GMT</pubDate>
            <atom:updated>2023-12-18T17:55:42.289Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*2m2okiYxyL7QiqGW" /></figure><blockquote>In this project, we embark on an exciting journey into the world of AWS Cloud, diving deep into various services offered by Amazon Web Services. We start by creating an EC2 instance, configuring AWS ECR, and pushing an image to the registry. Our adventure continues with the setup of an AWS ECS cluster, utilizing AWS Fargate, followed by the creation of a task definition. Finally, we learn how to expose our application and access it using the provided IP address. Each step will be detailed thoroughly, offering insights into the process and the reasons behind each action taken.</blockquote><h3>Amazon Elastic Container Registry (ECR):</h3><p>Amazon ECR is a fully managed Docker container registry that allows users to store, manage, and deploy Docker container images. It integrates seamlessly with other AWS services, such as ECS and EKS (Elastic Kubernetes Service), providing a secure and scalable solution for storing and deploying container images.</p><h3>How AWS ECR Works:</h3><p>Image Storage: ECR allows users to push, pull, and manage Docker container images securely within AWS.<br>Integration: It integrates seamlessly with ECS, EKS, and CI/CD pipelines, making it easier to manage and deploy containerized applications.<br>Security: ECR supports encryption at rest and in transit, as well as AWS IAM for access control, ensuring image security.<br>Scalability: Scales automatically to accommodate the storage needs of container images.</p><h3>Amazon Elastic Container Service (ECS):</h3><p>Amazon ECS is a highly scalable, fast, and secure container management service that supports Docker containers and allows users to easily run and scale containerized applications on AWS.</p><h3>How AWS ECS Works:</h3><p>1. ECS helps manage and orchestrate Docker containers by deploying and scaling them across clusters of EC2 instances or AWS Fargate.</p><p>2. Users define tasks in ECS task definitions, specifying container image, resources, networking, etc.</p><p>3. ECS operates within clusters, which are logical groupings of EC2 instances or Fargate resources.</p><p>4. ECS services maintain a specified number of tasks, ensuring high availability and load balancing.</p><p>First, we’ll create an EC2 instance named “Node-Todo-App”. Then, we’ll install <a href="http://docker.io/">docker.io</a> and AWS CLI on our instance.</p><pre>sudo apt install awscli<br>sudo apt install docker.io -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F5tOGK4l9GomOg0I" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0ywT79e6tAZBvyci" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nARsbYGxU9d2LbIP" /></figure><p>Let’s go to the GitHub repository and copy the source code url.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tdw52jX062mJh878" /></figure><p>Clone the repository from GitHub to the EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ehJMxjx8qbB7iyPy" /></figure><h3>Configuring image in AWS ECR</h3><p>Now, we’ll configure the Amazon Elastic Container Registry (ECR). To do this, we’ll head to the AWS Management Console, search for “ECR”, and create a new repository there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T7kMmAB4ZCuJDCDa" /></figure><p>While creating the new repository, we’ll choose the “public” option in the visibility settings. Then, we’ll select all the relevant operating systems and versions based on the OS of Fargate we intend to use. Finally, we’ll create the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*emivPXGOAkYTjGE_" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/0*bnNin5Z_ajopYOXX" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CdPY-VJOtwY5Ivoa" /></figure><p>Looks, our public repository has been successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bM2Xg_i6pNYrddqf" /></figure><h3>Pushing the image to ECR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5ftQzE5LKDfVmvn0" /></figure><p>Now, when we select our repository and click on the “View push command,” a similar interface will appear. We’ll execute these commands to push our repository, just like how we use Docker image commands to push to Docker Hub. The steps and concepts are exactly the same, only the platforms differ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/0*fHe8P7TZVIlFSgQG" /></figure><p>When we applied the first command, we encountered an error in our terminal related to AWS configuration. This error occurred because we hadn’t configured AWS properly. To fix this issue, we utilized our AWS access key ID and secret access key ID. Then we re-applied our previous commands. Let’s give it another shot and proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vyXP9WDh24Ay6W8d" /></figure><p>Additionally, we faced another type of issue: “permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock.” To resolve this type of issue, we use the following command:</p><pre>sudo usermod -aG docker $USER<br>sudo reboot</pre><p>This command grants the user permission to execute Docker commands without using sudo for every command, which can be more convenient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jxlR9eoQ8ldtJCz7" /></figure><p>Now, let’s reapply our commands to see if they’re working properly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Bk4P0lPjWk6L5KcK" /></figure><p>It seems we’ve successfully logged in, so now we’ll execute the remaining commands to push our repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*enmLIZAxqX52mrn_" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UMC6_SJhdVPdCRJW" /></figure><p>Finally, after applying the push command, we’ll check our ECR repository to see if our image has been pushed. It looks like our repository is displaying the image, indicating that the image has been successfully pushed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oU0LGK2i7pNOB-i4" /></figure><h3>Configuring AWS ECS</h3><p>Now, we’ll use this image in the ECS cluster. We’ll start by searching ‘ECS’ in the AWS console and then creating a new cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2m2okiYxyL7QiqGW" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c8HBsS8M65aNIhhe" /></figure><p>For the cluster, we’ll choose a suitable name and select AWS Fargate as our cluster type. Although we have the option to add a custom VPC and subnet for our application, for now, we’ll skip this part. Simply clicking the create button will create our cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*var1PA4GbIOs9ita" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9qzIfKWuviLE-7Jh" /></figure><h3>Reason why we are Using AWS Fargate:</h3><p>One of the major disadvantages of using AWS EC2 for an application is we have to create multiple instances in case of an application load increase that will have a cost impact.</p><p>To avoid this, we will use AWS Fargate which is a serverless technique of providing the specification of applications that will be automatically managed without spinning off any instance.</p><p>We’ll check our ECS cluster creation process in the CloudFormation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l-4CEUIkCPmtTKIk" /></figure><p>It seems our cluster is now ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4uG5DdXSpMXs2qwW" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0wgkYasoPQnKKCv4" /></figure><h3>Create a Task Definition for the cluster</h3><p>Just as we are required to run a container using an image, in the same way, we need to create a task definition for the cluster.</p><p>A Task Definition in Amazon ECS is crucial as it specifies how Docker containers run within a cluster. It defines container configurations, including Docker image, CPU, memory, networking, and storage settings. Task Definitions ensure consistent deployments, simplify scaling, and support versioning for updates. They serve as blueprints, maintaining a single source of truth for container configurations and enabling ECS Services to manage desired tasks efficiently.</p><p>Go to Task definitions → Create a new task definition</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JIE_AgLZZ_jWzwXR" /></figure><p>The task definition name must be unique</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FbFAoU6UBqH0EHze" /></figure><p>Enter the Name, Container Image URI, and Port Mapping (ensuring the exposed port matches the one in the Dockerfile used to create the image, for instance, 8000).</p><p>In the Container details section, provide the container’s name and its image URL. Additionally, in the port mapping section, input the container’s port number, aligning it with the port number specified in our Dockerfile used for image creation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2c0rK3NtjHo5fAD4" /></figure><p>Select the CPU and memory configurations based on the application load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8AGmjARYojDXtooH" /></figure><p>Keep the rest of the settings as default, then by clicking the ‘create’ button, our task will be created and deployed onto the cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8AmQEiBGH6PvjKZ8" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OoYdqPXFbktQc8Nj" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EJZN0TOBfp8V0YYp" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*92GZDzSNGNpx5LsS" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HYsqH7pNsCoD0_6C" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bkZoqBRX-xGItPnU" /></figure><h3>Expose Our Applications:</h3><p>Now, to access our application, we need to follow a few steps. First, clicking on the task ID will open an interface. Then, by clicking on the ENI ID URL, we’ll navigate to the network interface summary. After that, we’ll access the security group URL, edit the inbound rules, and add port 8000 for our application. Once saved, our task will be completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MZm0gROZ_AZviAhS" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5Q4Z_vuhab8CF-XU" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zCo0Ep5P9i9zYBky" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lLqUtgQmKXRsjvtm" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v4y7kQnMz__bWs98" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pf4e7luD6H8BkMzT" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QDr-gzzBOOnJdDbB" /></figure><p>Boooommmmm!!!!!!!!!!!!!</p><p>Finally, We’ll copy the public IP address and append the port number. After hitting enter, we’ll be able to access our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x6FDQPwE8t5t2UH_" /></figure><blockquote>Through this project, we’ve navigated through several essential AWS services, demonstrating the process of deploying applications using AWS ECS and ECR. We learned to configure AWS services, push images to the registry, create clusters, and define tasks. The use of AWS Fargate showcased the advantages of serverless deployment in managing applications efficiently without creating additional instances. Moreover, by configuring security groups, we ensured secure access to our application. This journey was an insightful experience, providing a comprehensive understanding of AWS Cloud services and their functionalities.</blockquote><p>Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>— Happy Learning !!!</p><p>Linkedin Profile: https://www.linkedin.com/in/nahid099/</p><h3>Let’s connect !!!</h3><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ffbaac94df4" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/aws-ecs-deployment-containerized-application-with-ecr-and-fargate-3ffbaac94df4">AWS ECS Deployment: Containerized Application with ECR and Fargate</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient Website Deployment with CloudFront: S3 Bucket Hosting & CDN Integration]]></title>
            <link>https://aws.plainenglish.io/efficient-website-deployment-with-cloudfront-s3-bucket-hosting-cdn-integration-609d2dde14d2?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/609d2dde14d2</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[static-websites]]></category>
            <category><![CDATA[cdn]]></category>
            <category><![CDATA[cloudfront]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Mon, 11 Dec 2023 10:32:59 GMT</pubDate>
            <atom:updated>2023-12-12T01:36:39.293Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*KkL3eTc_pHrgjqLj5sGltQ.png" /></figure><blockquote>CloudFront, a robust content delivery network (CDN) offered by Amazon Web Services (AWS), plays a pivotal role in optimizing website performance by reducing latency and efficiently delivering content to users across the globe. In this comprehensive project, we delve into understanding CloudFront’s functionality and deploying a static website hosted on an S3 bucket through CloudFront, exploring its functionalities and advantages along the way.</blockquote><h3>Table of Contents:</h3><ul><li>Understanding CDN and CloudFront</li><li>CloudFront Mechanics: How it Works</li><li>Benefits of AWS CloudFront</li><li>Setting Up CloudFront on AWS</li><li>Creating an S3 Bucket for Hosting</li><li>Enabling Static Website Hosting</li><li>Creating a CloudFront Distribution</li></ul><p>CloudFront is a content delivery network (CDN) service provided by Amazon Web Services (AWS). We can set up the cloud front ahead of the S3 bucket or EC2 instance or any load balancer that will help us prevent the request directly to the origin server.<br>To understand the cloud front better we first should know what is CDN.<br>Imagine you have a website with lots of cool content, like images, videos, and documents. When a user visits your site from a different location far away from your server, the content might take a long time to load. That’s where CDN comes to the rescue!</p><p>A CDN is like a network of servers spread across various locations worldwide. These servers store a copy of your website’s content. When a user requests your website, the content is delivered from the server closest to the user, making it super fast! It’s like having a local store for your website content everywhere in the world.</p><h3>How Does CloudFront Work?</h3><p>Let’s understand how CloudFront works with a simple example:<br>Imagine you have a website with images stored on an Amazon S3 bucket (a cloud storage service). When a user requests an image, the request goes to CloudFront first.<br>Here’s how the process flows:</p><ul><li>Step 1: CloudFront checks if it already has the requested image in its cache (storage). If it does, great! It sends the image directly to the user. If not, it proceeds to Step 2.</li><li>Step 2: CloudFront fetches the image from the S3 bucket and stores a copy in its cache for future requests. Then, it sends the image to the user.</li></ul><p>The next time someone requests the same image, CloudFront will deliver it from its cache, making it super fast and efficient!</p><h3>Benefits of CloudFront</h3><ul><li>Fast Content Delivery: CloudFront ensures your content reaches users with minimal delay, making your website lightning fast.</li><li>Global Reach: With servers in various locations worldwide, CloudFront brings your content closer to users, regardless of where they are.</li><li>Security: CloudFront provides security features like DDoS protection and SSL/TLS encryption to keep your content and users safe.</li><li>Scalability: CloudFront can handle traffic spikes effortlessly, ensuring a smooth experience for your users.</li><li>Cost-Effective: Pay only for the data transfer and requests made, making it cost-effective for businesses of all sizes.</li></ul><h3>Setting Up CloudFront on AWS</h3><p>Firstly, we’ll create an S3 bucket named “<a href="http://www.nahid-example.com/">nahid-example.com</a>”. After that, we’ve enabled the bucket versioning option. We’ve kept all the other settings as default. Finally, we hit the create bucket button and our bucket has been successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LGumDfqSRwp_ALjh" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/0*ayDctqwZu1qYDLGl" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GREDBrXQOrpu85yx" /></figure><p>Now, we’ll host a simple static website on our S3 bucket. To do that, we need to upload all the files related to our static website into the S3 bucket. So far, we’ve uploaded a simple index.html file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2ni5mAmisM_81h5H" /></figure><p>To host our static website on the S3 bucket, we first need to enable the “Static Website Hosting” option. To do this, we’ll navigate to the Properties tab, locate the “Static Website Hosting” option, and edit it to “Enable”. Then, we’ll save the settings. Once done, our static website hosting will be enabled, and an S3 object URL will automatically be created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zYU-MUV9ekTeYaoP" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vd9wLSvhxAfLFCEv" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DX8M6DxW-1FuGMaF" /></figure><p>Now, we’ll copy the S3 object URL and paste it into the browser’s search bar to see if our application can be accessed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gXh-CY-jlOKdHaJ3" /></figure><p>However, I know that it won’t be accessible because we intentionally blocked public access when creating the S3 bucket. Therefore, an “Access Denied” error will appear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GQ4CORB8mam6NFAF" /></figure><h3>Create a CloudFront Distribution</h3><p>Now will will access it using the Cloud Front where we will Set our S3 Object as the origin and create the Distribution where we have configured the OAI ( Origin Access Identity ) and will update the Bucket Policy to let access the object for the Cloud Front.</p><p>Go to the AWS Management Console and navigate to CloudFront. Then Click “Create Distribution.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U57BqCgNWyIOVhLN" /></figure><p>Currently, we need to select our origin domain, which we created in the S3 bucket. Then, in the “origin access option,” we’ll choose “legacy access identities.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/0*8zabLpVA6_Y2u6rJ" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/0*OEgIij8he4qbI-k7" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*xWoeeaMzu1ZPv1zQ" /></figure><p>For the origin access identity, if it’s not created yet, we’ll have to create one. If we don’t have an existing OAI, we’ll select the “create new OAI” option. Additionally, it’s crucial to select “Yes, update the bucket policy” in the bucket policy option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/0*xLHYf8Lt_GvIkVqA" /></figure><p>In the Web Application Firewall section, we’ve chosen “Do not enable security protections” because this setup is for learning/demo purposes. Enabling this option might incur charges to our AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*3-cc6dchjazJiyLY" /></figure><p>Finally, we’ve set the default root object as index.html so that when users send their first request, they’ll see the homepage. However, if preferred, users can set any other page as their default. We’ll leave the rest of the settings to their default values. Clicking the “Create Distribution” button will create our distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XRF7_kuxgDVFwhjt" /></figure><p>Look, the state is in the ‘deploying’ phase, which means it will take some time as CloudFront configures all the settings. Therefore, we need to wait for a while. Once the state changes to ‘deployed’, we’ll be able to access our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RxMAzeaCyTAwORF_" /></figure><p>Now that the state is ‘deployed’, we can access our application by copying the distribution domain name and pasting it into the browser. We can access the application without distributing the S3 bucket object URL in any way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kWW2CItjqUEcMxBs" /></figure><p>Great news! We’ve successfully accessed our static application hosted on the S3 bucket.</p><blockquote>In this project, we explored the nuances of Amazon CloudFront, an integral component in modern web deployment strategies. Through a step-by-step approach, we learned about its capabilities in optimizing content delivery, enhancing user experience, and bolstering security measures. By setting up a static website on an S3 bucket and leveraging CloudFront, we witnessed how it efficiently handles content distribution while significantly reducing latency. With CloudFront’s global reach, scalability, and security features, we’ve achieved a high-performing and secure web application accessible worldwide.</blockquote><p>Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>— Happy Learning !!!</p><h3>Let’s connect !!!</h3><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><h3><a href="https://github.com/nahidkishore">Github</a></h3><h3><a href="http://nahidkishore99@gmail.com/">Mail</a></h3><h3><a href="https://plainenglish.io/">PlainEnglish.io</a> 🚀</h3><p><em>Thank you for being a part of the In Plain English community! Before you go:</em></p><ul><li><em>Be sure to </em><strong><em>clap</em></strong><em> and </em><strong><em>follow</em></strong><em> the writer</em><strong>️</strong></li><li><em>Learn how you can also </em><a href="https://plainenglish.io/blog/how-to-write-for-in-plain-english"><strong><em>write for In Plain English</em></strong></a><em>️</em></li><li><em>Follow us: </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>X</em></strong></a><strong><em> | </em></strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><strong><em> | </em></strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><strong><em> | </em></strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong><em>Discord</em></strong></a><strong><em> | </em></strong><a href="https://newsletter.plainenglish.io/"><strong><em>Newsletter</em></strong></a></li><li><em>Visit our other platforms: </em><a href="https://stackademic.com/"><strong><em>Stackademic</em></strong></a><strong><em> | </em></strong><a href="https://cofeed.app/"><strong><em>CoFeed</em></strong></a><strong><em> | </em></strong><a href="https://venturemagazine.net/"><strong><em>Venture</em></strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=609d2dde14d2" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/efficient-website-deployment-with-cloudfront-s3-bucket-hosting-cdn-integration-609d2dde14d2">Efficient Website Deployment with CloudFront: S3 Bucket Hosting &amp; CDN Integration</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building AWS Infrastructure Using Infrastructure as Code (IaC)]]></title>
            <link>https://aws.plainenglish.io/building-aws-infrastructure-using-infrastructure-as-code-iac-9021037e062c?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9021037e062c</guid>
            <category><![CDATA[terra]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Fri, 08 Sep 2023 09:54:47 GMT</pubDate>
            <atom:updated>2023-09-10T12:55:48.008Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous tasks, you have learned about the basics of Terraform, its configuration file, and creating an EC2 instance using Terraform. Today, we will explore more about Terraform and create multiple resources.</p><blockquote>In this project we creating a Virtual Private Cloud (VPC) along with private and public subnets. Additionally, I will set up an Internet Gateway (IGW) to enable communication between the VPC and the internet. To host a website, I will launch an EC2 instance in the public subnet with specific configurations. By leveraging the power of automation and Infrastructure as Code, I aim to ensure a consistent and reliable environment for our application.</blockquote><blockquote>Task Overview:</blockquote><blockquote>* Create a VPC (Virtual Private Cloud) with CIDR block 10.0.0.0/16: Establishing a private network environment that encapsulates our resources and provides secure communication between them.</blockquote><blockquote>* Create a private subnet with CIDR block 10.0.1.0/24 in the above VPC: This subnet will host resources that require limited external access and enhance security.</blockquote><blockquote>* Create a public subnet with CIDR block 10.0.2.0/24 in the above VPC: The public subnet will accommodate resources that need direct communication with the internet.</blockquote><blockquote>* Create an Internet Gateway (IGW) and attach it to the VPC: Enabling internet connectivity for resources within the VPC and allowing them to access the internet.</blockquote><blockquote>* Create a route table for the public subnet and associate it with the public subnet: Configuring a route table to manage the traffic flow within the public subnet, enabling connectivity to the internet via the Internet Gateway.</blockquote><blockquote>* Launch an EC2 instance in the public subnet: Creating an EC2 instance with specific details, such as the AMI, instance type, security group settings, and user data.</blockquote><blockquote>* AMI: ami-0557a15b87f6559cf, Instance type: t2.micro, Security group: Allow SSH access from anywhere: Configuring the EC2 instance with these specifications to ensure proper functionality and secure access.</blockquote><blockquote>* User data: Use a shell script to install Apache and host a simple website: Automating the installation of Apache and the hosting of a basic website on the EC2 instance using user data.</blockquote><blockquote>* Create an Elastic IP and associate it with the EC2 instance: Assigning a static public IP address to the EC2 instance to facilitate reliable communication.</blockquote><blockquote>* Open the website URL in a browser to verify that the website is hosted successfully: After completing the deployment, validating the successful hosting of the website by accessing the URL in a web browser.</blockquote><h3>Step 1: Create a VPC (Virtual Private Cloud)</h3><p>Create a VPC (Virtual Private Cloud) with CIDR block 10.0.0.0/16</p><p>Below are the prerequisites for building any aws infrastructure is to define providers.</p><pre>terraform {<br>    required_providers {<br>      aws = {<br>        source  = &quot;hashicorp/aws&quot;<br>        version = &quot;~&gt; 4.0&quot;<br>      }<br>    }<br>  }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5O_GmZ9A4nZYkjtx" /></figure><p>Add a <a href="http://provider.tf/">provider.tf</a> and add details about AWS Region that you are using</p><pre>provider &quot;aws&quot; {<br>    region = &quot;us-east-1&quot;<br>  }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nWmcjS0638DehwDO" /></figure><p>Create a <a href="http://vpc.tf/">vpc.tf</a> file and mention the required CIDR block with the name tag of VPC.</p><pre>resource &quot;aws_vpc&quot; &quot;nahid_vpc&quot; {<br>    cidr_block       = &quot;10.0.0.0/16&quot;<br>    tags = {<br>      Name = &quot;nahid_vpc&quot;<br>    }<br>  }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pJnLMQ2fS5tbKFi0" /></figure><p>Run the terraform init command to initialize the working directory and download the required providers.</p><pre>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PoEIqISdqN7fNyUt" /></figure><p>After that, run terraform apply to create the VPC in your AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9FDO-wCiTJq4BUEN" /></figure><p>We can check in the AWS console for the new VPC created with name as “main”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cegGgiaYOpwQKW-h" /></figure><h3>Step 2: Create a private subnet</h3><p>Now create a private subnet named as <a href="http://subnet.tf/">subnet.tf</a> with CIDR block 10.0.1.0/24 in the VPC with ID aws_<a href="http://vpc.main.id/">vpc.main.id</a> and tags it with the name “private_subnet”, you can take reference of vpc resource that has been created before.</p><pre>resource &quot;aws_subnet&quot; &quot;private_subnet&quot; {<br>vpc_id = aws_vpc.main.id<br>cidr_block = &quot;10.0.1.0/24&quot;<br>availability_zone = &quot;us-east-1a&quot;<br>tags = {<br>Name = &quot;private subnet&quot;<br>}<br>}</pre><p>Run Terraform apply to create a private subnet in your AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kdXwbV7D5d4WkWok" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f5s7gPe1sYPvoSev" /></figure><p>A private Subnet is successfully created using Terraform, you can verify this in the VPC Tab of the Subnet console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OLHPcah4YPUYNiKX" /></figure><p>Step 3: Create a public subnet</p><p>Same as the public subnet, creates a private subnet with CIDR block 10.0.2.0/24 in the VPC with ID aws_<a href="http://vpc.main.id/">vpc.main.id</a>, and tags it with the name “private”.</p><pre>resource &quot;aws_subnet&quot; &quot;public_subnet&quot; {<br>vpc_id = aws_vpc.main.id<br>cidr_block = &quot;10.0.2.0/24&quot;<br>availability_zone = &quot;us-east-1a&quot;<br>tags = {<br>Name = &quot;public subnet&quot;<br>}<br>}</pre><p>Run terraform apply to create a public subnet in your AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_C18CJvp7wuftaVm" /></figure><p>Go to VPC console then go to Subnets. Check Public Subnet is created successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JkRkmR_oG57vjFQ3" /></figure><h3>Step 4: Create an Internet Gateway (IGW) and attach it to the VPC.</h3><p>Create an Internet Gateway (IGW) and attach it to the VPC.</p><p>Create a <a href="http://internetgateway.tf/">internetgateway.tf</a> file and define the internet gateway with the required configurations to attach it to VPC</p><pre>resource &quot;aws_internet_gateway&quot; &quot;gw&quot; {<br>vpc_id = aws_vpc.main.id<br>tags = {<br>Name = &quot;internet-gateway&quot;<br>}<br>}</pre><p>Execute the terraform apply command for the creation of Internet Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T1iPDcYOlvIWX1dR" /></figure><p>Go to VPC then go to Internet gateways, and check whether a new Internet gateway is created with the name ‘internet-getway’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oDNXw4u_5ImN61cC" /></figure><p>VPC is attached to the internet gateway.</p><h3>Step 5: Create a Route Table</h3><p>Now create a route table named <a href="http://routetable.tf/">routetable.tf</a> for use with a public subnet specified by the subnet_id attribute.</p><pre>resource &quot;aws_route_table&quot; &quot;route_table&quot; {<br>vpc_id = aws_vpc.main.id<br>route {<br>cidr_block = &quot;0.0.0.0/0&quot;<br>gateway_id = aws_internet_gateway.gw.id<br>}<br>tags = {<br>Name = &quot;route_table&quot;<br>}<br>}<br>resource &quot;aws_route_table_association&quot; &quot;public_subnet_association&quot; {<br>subnet_id = aws_subnet.public_subnet.id<br>route_table_id = aws_route_table.route_table.id<br>}</pre><p>In Route tables, a new route table is successfully created using terraform apply command, Now route table routes with an internet gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L8LI0Lvxs1RnFBtd" /></figure><p>We can verify the route table in the AWS console along with the public subnet which is associated in the subnet association section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*75cWL_NKwubV4Y_c" /></figure><h3>Step 6: Create a Security Group</h3><p>To connect our EC2 instance, create a <a href="http://securitygroup.tf/">securitygroup.tf</a> file where use the aws_security_group block creates a new security group that allows inbound traffic on ports 22 (SSH) and 80 (HTTP) from any source (0.0.0.0/0).</p><pre>resource &quot;aws_security_group&quot; &quot;web_server&quot; {<br>name_prefix = &quot;web-server-sg&quot;<br>vpc_id = aws_vpc.main.id<br>ingress {<br>from_port = 80<br>to_port = 80<br>protocol = &quot;tcp&quot;<br>cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>}<br>ingress {<br>from_port = 22<br>to_port = 22<br>protocol = &quot;tcp&quot;<br>cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>}<br>egress {<br>from_port = 0<br>to_port = 0<br>protocol = -1<br>cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>}<br>}</pre><p>Step 7: Create an Elastic IP and associate it with the EC2 instance.</p><p>Create an Elastic IP and associate it with the EC2 instance.</p><pre>resource &quot;aws_eip&quot; &quot;ip&quot; {<br>instance = aws_instance.server_terraform.id<br>vpc = true<br>tags = {<br>Name = &quot;elastic-ip&quot;<br>}<br>}</pre><h3>Task 8: Create user data to install Apache</h3><p>The user_data attribute specifies the script to run when the instance is launched. This script updates the package manager, installs the Apache web server, creates a basic HTML file, and restarts Apache.</p><pre>#!/bin/bash<br>sudo apt-get update -y<br>sudo apt-get install -y apache2<br>sudo systemctl start apache2<br>sudo systemctl enable apache2<br>echo &quot;&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Introduction&lt;/title&gt;<br>&lt;style&gt;<br>body {<br>background-color: #d8e2dc;<br>font-family: Arial, sans-serif;<br>color: #3c415e;<br>text-align: center;<br>padding: 50px;<br>}<br>h1 {<br>font-size: 3em;<br>margin-bottom: 20px;<br>text-shadow: 0 2px 2px rgba(0,0,0,0.1);<br>}<br>p {<br>font-size: 1.5em;<br>line-height: 1.5;<br>margin-bottom: 30px;<br>}<br>&lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;h1&gt;This is Nahidul Islam.&lt;/h1&gt;<br>&lt;p&gt;I am going to be a DevOps Pro!! InshaaAllah&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;&quot; &gt; /var/www/html/index.html<br>sudo systemctl restart apache2</pre><h3>Step 9: Launch an EC2 instance in the public subnet</h3><p>Create a new <a href="http://ec2.tf/">ec2.tf</a> file where add the details of our EC2 instance like AMI ID, instance type, key name, public subnet, security group and User Data to install Apache in our EC2 instance server.</p><p>Open the website URL in a browser to verify that the website is hosted successfully.</p><p>Now combine all the configurations to spin up the EC2 instance.</p><pre>resource &quot;aws_security_group&quot; &quot;web_server&quot; {<br>name_prefix = &quot;web-server-sg&quot;<br>vpc_id = aws_vpc.main.id<br>ingress {<br>from_port = 80<br>to_port = 80<br>protocol = &quot;tcp&quot;<br>cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>}<br>ingress {<br>from_port = 22<br>to_port = 22<br>protocol = &quot;tcp&quot;<br>cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>}<br>egress {<br>from_port = 0<br>to_port = 0<br>protocol = -1<br>cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>}<br>}<br><br>resource &quot;aws_instance&quot; &quot;server_terraform&quot; {<br>ami = &quot;ami-053b0d53c279acc90&quot;<br>instance_type = &quot;t2.micro&quot;<br>key_name = &quot;an-access-key&quot;<br>subnet_id = aws_subnet.public_subnet.id<br>security_groups = [<br>aws_security_group.web_server.id<br>]<br>user_data = filebase64(&quot;userdata.sh&quot;)<br>tags = {<br>Name = &quot;terraform_infra&quot;<br>}<br>}<br>resource &quot;aws_eip&quot; &quot;ip&quot; {<br>instance = aws_instance.server_terraform.id<br>vpc = true<br>tags = {<br>Name = &quot;elastic-ip&quot;<br>}<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kSkMzuBtf3CZGy-s" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tn7yVgx9VASKGHy8" /></figure><p>Execute the terraform apply command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5Gf-w9HvgWrfKo93" /></figure><p>Now, we can see in the AWS console for the new EC2 instance which is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vdPYr10Ec0W9RdSy" /></figure><p>We can verify the security group along with the rules created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bRMMWDgheVFOUMPG" /></figure><p>We can verify the elastic IP which is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vH2zvvceDZwIvFAL" /></figure><p>Using the Public IPv4 address, open the URL in a browser to verify that the website is hosted successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UIaD03MdzPoYVzoB" /></figure><blockquote>Through the effective utilization of Infrastructure as Code and AWS resources, I have successfully built a secure and scalable AWS infrastructure. The creation of a VPC, private and public subnets, an Internet Gateway, and an EC2 instance with a hosted website demonstrates the power of automation and DevOps practices. By following best practices and leveraging AWS services, we have established a reliable environment for our application. This project lays the foundation for future enhancements and expansions while ensuring a consistent and repeatable deployment process</blockquote><p>Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>— Happy Learning</p><p><strong>Let’s connect</strong></p><ul><li><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></li><li><a href="https://github.com/nahidkishore">Github</a></li><li><a href="http://nahidkishore99@gmail.com/">Mail</a></li></ul><h3>In Plain English</h3><p><em>Thank you for being a part of our community! Before you go:</em></p><ul><li><em>Be sure to </em><strong><em>clap</em></strong><em> and </em><strong><em>follow</em></strong><em> the writer! 👏</em></li><li><em>You can find even more content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><strong><em> 🚀</em></strong></li><li><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. 🗞️</em></li><li><em>Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><strong><em>(X</em></strong>), <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a>, <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a>, and <a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9021037e062c" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/building-aws-infrastructure-using-infrastructure-as-code-iac-9021037e062c">Building AWS Infrastructure Using Infrastructure as Code (IaC)</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shell Scripting Mastery: Exploring Conditionals, Loops, Functions, and Useful Commands with a Mini…]]></title>
            <link>https://blog.devops.dev/shell-scripting-mastery-exploring-conditionals-loops-functions-and-useful-commands-with-a-mini-eb1a662dedc2?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb1a662dedc2</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Wed, 16 Aug 2023 23:31:59 GMT</pubDate>
            <atom:updated>2023-08-17T14:36:15.840Z</atom:updated>
            <content:encoded><![CDATA[<h3>Shell Scripting Mastery: Exploring Conditionals, Loops, Functions, and Useful Commands with a Mini Project</h3><blockquote>This article covers everything you need to know about user input, conditional statements (if-else), case statements, loops (for and while), functions, and passing arguments in shell scripting.</blockquote><blockquote>We will introduce essential commands like date, whoami, uptime, disk and RAM space checks, and last login details, which will be used in our mini project. The project includes welcoming users with their usernames, displaying the current date and time, showing server uptime and the last two or three login information (based on user input), providing server utilization statistics, and presenting details about the top two or three CPU processes(based on user input).</blockquote><p>Create a file name whatever you want. But, make sure it ends with .sh. Open that file in your favorite text editor and write the first line to begin your shell script journey.</p><p>We execute .sh file and we will provide execute permission by below commands.</p><pre>Chmod 700 ./filename.sh</pre><pre>#!/bin/bash</pre><p>The #! /bin/bash line is called the shebang or hashbang, and it is used to specify the interpreter to be used for executing the script. In this case, #!/bin/bash indicates that the script should be interpreted and executed using the Bash shell.</p><p>Open your terminal and go to the directory where you created the script file. Then run the below command to execute the script</p><pre>./my_script.sh</pre><p>At this stage, you won’t see any output since we have not written anything other than the shebang line. Let’s add some fun stuff<br>You can use the echo command to print statements or messages in the terminal. For example:</p><pre>echo welcome to shell scripting</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*idfZlGDzKyMLUM2W" /></figure><p>You will see “ welcome to shell scripting ” in your terminal</p><p>You can assign values to variables in Bash using the assignment operator (=). Here is example</p><pre>name=&quot;nahid&quot;<br>echo &quot;my name is $name&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mpx59FO5wvxB6BUR" /></figure><p>Now to execute the script and look at the ouput</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mkt48IF44znJpAxQ" /></figure><h3>User input:</h3><p>To read user input in Bash, you can use the read command. It prompts you to enter a value and stores it in a variable. For example:</p><pre>echo &quot;Enter your name: &quot;<br>read name<br>echo &quot;Hello $name, nice to meet you bro! &quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ys_0xP2-FQjNZY-R" /></figure><h3>Conditional Statements:</h3><p>Bash supports various conditional statements to control the flow of your script. Here are a few examples:</p><h3>Simple If Statement:</h3><pre>name=&quot;nahid&quot;<br>if [ &quot;$name&quot; == &quot;nahid&quot; ];<br>then<br>   echo &quot;Your name is nahid&quot;<br>fi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jicExq2VXUo04VfJ" /></figure><h3>If Statement with Else:</h3><pre>name=&quot;nahid&quot;<br>if [ &quot;$name&quot; == &quot;nahid&quot; ];<br>then<br>   echo &quot;Your name is nahid&quot;<br>else<br>        echo &quot;Your name is not nahid&quot;<br>fi</pre><h3>Else If Statement:</h3><pre>name=&quot;nahid&quot;<br>if [ &quot;$name&quot; == &quot;nahid&quot; ];<br>then<br>   echo &quot;Your name is nahid&quot;<br>elif [ &quot;name&quot; == &quot;Jannat&quot;];<br>then<br>        echo &quot;Your name is Jannat&quot;<br>else<br>        echo &quot;Your name is not nahid or Janant&quot;<br>fi</pre><h3>Below is an example of comparing two numbers using -gt operator in the shell script</h3><pre>NUM1=3 <br>NUM2=5<br>if [ &quot;$NUM1&quot; -gt &quot;$NUM2&quot; ] <br>then <br>    echo &quot;$NUM1 is greater than $NUM2&quot;<br>else <br>    echo &quot;$NUM1 is less than $NUM2&quot;<br>fi</pre><p>You can use any of the following operators to do comparisons in a shell script.</p><ul><li>Equal to: == or =</li><li>Example: [ “$var1” == “$var2” ]</li><li>Checks if $var1 is equal to $var2.</li><li>Not equal to: !=</li><li>Example: [ “$var1” != “$var2” ]</li><li>Checks if $var1 is not equal to $var2.</li><li>Greater than: &gt;</li><li>Example: [ “$var1” -gt “$var2” ]</li><li>Checks if $var1 is greater than $var2.</li><li>Greater than or equal to: -ge</li><li>Example: [ “$var1” -ge “$var2” ]</li><li>Checks if $var1 is greater than or equal to $var2.</li><li>Less than: &lt;</li><li>Example: [ “$var1” -lt “$var2” ]</li><li>Checks if $var1 is less than $var2.</li><li>Less than or equal to: -le</li><li>Example: [ “$var1” -le “$var2” ]</li><li>Checks if $var1 is less than or equal to $var2.</li></ul><p>Following is the example to check whether a file exists with the given or not</p><pre>FILE=&quot;test.txt&quot;<br>if [ -e &quot;$FILE&quot; ]<br>then<br>  echo &quot;$FILE exists&quot;<br>else<br>  echo &quot;$FILE does not exist&quot;<br>fi</pre><h3>Case Statement:</h3><p>The case statement allows you to evaluate the value of a variable against multiple patterns and execute different blocks of code based on the matching pattern.</p><p>Following is the example:</p><pre>#!/bin/bash<br>echo &quot;Enter a fruit: &quot;<br>read FRUIT<br>case &quot;$FRUIT&quot; in<br>    &quot;apple&quot;)<br>        echo &quot;You selected: Apple&quot;<br>        ;;<br>    &quot;banana&quot;)<br>        echo &quot;You selected: Banana&quot;<br>        ;;<br>    &quot;orange&quot;)<br>        echo &quot;You selected: Orange&quot;<br>        ;;<br>    *)<br>        echo &quot;Invalid fruit selection&quot;<br>        ;;<br>esac</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uG8Kzt8hAIdmWrkn" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KOI5sHQu-JSAH05f" /></figure><h3>For loop</h3><p>The for loop allows you to iterate over a list of values and perform a set of actions for each value.</p><pre>#!/bin/bash<br>echo &quot;Enter your name: &quot;<br>read NAME<br>for ((i=1; i&lt;=5; i++))<br>do<br>    echo &quot;Hello, $NAME!&quot;<br>done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9w_06F25vdvUhwfF" /></figure><h3>While Loop:</h3><p>A while loop in a shell script allows you to repeatedly execute a block of code as long as a certain condition is true. Here is an example of for loop.</p><pre>#!/bin/bash<br>echo &quot;Enter your name: &quot;<br>read NAME<br>counter=1<br>while [ $counter -le 5 ]<br>do<br>    echo &quot;Hello, $NAME!&quot;<br>    counter=$((counter+1))<br>done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-NVcFnNCisNM2djd" /></figure><h3>Functions:</h3><p>In shell scripting, you can define and use functions to encapsulate a block of code that can be executed multiple times throughout your script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1a-wi7vaa1Hn6VOV" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IwBFobv-D-JJghoK" /></figure><h3>Function with parameters:</h3><pre>#!/bin/bash<br>greet() {<br>    echo &quot;Hello, I am $1 and I am $2 years old&quot;<br>}<br># Call the function and pass arguments<br>greet &quot;nahid&quot; &quot;27&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HF-w6CSDGsGO96Nr" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qMcyjy95DnEce2ec" /></figure><h3>Shell Scripting Mastery: Exploring Conditionals, Loops, Functions, and Useful Commands with a Mini Project</h3><p>In this mini project, I have written a shell script that provides the details of the server based on the below criteria.</p><ol><li>Welcoming the user with the username</li><li>Information regarding the Current date and time</li><li>Show the uptime of the server along with the last 5 login information.</li><li>Showing the server utilization depicting total and available space.</li><li>Information regarding top 5 CPU processes.</li></ol><p>You can add further instructions/commands according to your needs.</p><p>Below are Commands used in our project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*1QqyOdnAL9so-CkiAj1wXw.png" /></figure><h3>Date Command:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xjod0hjRZf3IXSTE" /></figure><h3>Last Login Command:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kr-RctbriRnfimod" /></figure><h3>Free Space Command:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LxxquhaHOv9to0OH" /></figure><h3>Top CPU processes Command:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HmUbEey-DojfxD5s" /></figure><p>Let’s write the project script in our scripting file:</p><pre>#!/bin/bash<br>echo &quot;***************************** Welcome $(whoami) ***************************&quot;<br>echo &quot;Hi! Welcome to mastering of shell scripting.&quot;<br>echo &quot;***************************************************************************&quot;<br>echo &quot;Current date : &quot; &amp;&amp; date |awk &#39;{print $3 &quot;-&quot; $2 &quot;-&quot; $6}&#39;<br>echo &quot;Current time and Day:&quot; &amp;&amp; date | awk &#39;{print $4, $5 &quot;,&quot; $1}&#39;<br>echo &quot;***************************************************************************&quot;<br>echo &quot;The uptime of the server is $(uptime)&quot;<br>echo &quot;Last login details: $(last -a | head -5)&quot;<br>echo &quot;***************************************************************************&quot;<br>echo &quot;My server Utilization:&quot;<br>echo &quot;Free space is $(df -h | xargs | awk &#39;{print $11}&#39;)&quot;<br>echo &quot;Total space is $(df -h | xargs | awk &#39;{print $9}&#39;)&quot;<br>echo &quot;***************************************************************************&quot;<br>echo &quot;Top CPU Process: $(top | head -5)&quot;<br>echo &quot;***************************************************************************&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cqfjFx3u_pYVEsxY" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h1TicjRGJ0HbE4YG" /></figure><blockquote>“Shell Scripting Mastery: Exploring Conditionals, Loops, Functions, and Useful Commands with a Mini Project” is a comprehensive guide that equips you with the skills to master shell scripting. Through practical examples and step-by-step instructions, you’ll learn about user input, various types of condition statements, loops, and functions in shell scripting.</blockquote><blockquote>The mini project included in this article demonstrates the application of these concepts. You’ll utilize useful commands like date, whoami, uptime, disk and RAM space checks, and last login details. The project covers welcoming users, displaying the current date and time, showcasing server uptime and login information, presenting server utilization, and providing insights into CPU processes based on user input.</blockquote><blockquote>By delving into the depths of shell scripting, this article empowers you to automate tasks and enhance your scripting abilities. Whether you’re a beginner or have prior experience, this guide will expand your knowledge and enable you to leverage the power of shell scripting for better automation and efficiency.</blockquote><p>Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>— Happy Learning !!!</p><h3>Let’s connect !!!</h3><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><h3><a href="https://github.com/nahidkishore">Github</a></h3><h3><a href="http://nahidkishore99@gmail.com/">Mail</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb1a662dedc2" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/shell-scripting-mastery-exploring-conditionals-loops-functions-and-useful-commands-with-a-mini-eb1a662dedc2">Shell Scripting Mastery: Exploring Conditionals, Loops, Functions, and Useful Commands with a Mini…</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Common Linux Commands: From Beginner to Pro]]></title>
            <link>https://nahidkishore99.medium.com/mastering-common-linux-commands-from-beginner-to-pro-1972aba9e6a7?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1972aba9e6a7</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[linux-commands]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 10:43:04 GMT</pubDate>
            <atom:updated>2023-08-08T10:47:29.136Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8BWR1tjc0A77gnK3" /></figure><p><em>The article begins with the basics, introducing fundamental commands for navigating the file system, managing files and directories, and working with processes. It then progresses to more advanced commands that enhance your Linux skills and enable you to perform complex tasks efficiently.</em></p><p><em>This article aims to share valuable knowledge with the community. By reading and applying the concepts discussed, readers will become more proficient in using Linux commands and be equipped to handle a variety of tasks confidently.</em></p><p><em>Whether you’re a student, professional, or simply interested in Linux, Mastering Common Linux Commands: From Beginner to Pro is an excellent resource to enhance your Linux skills and empower you to make the most of this versatile operating system.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*YRZgsXZIu2nIuo43tdaGww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*eNvyzKpsEIc5NnqmjJKomQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*evWKRFm4VTBPYgUbAxqFMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*SO9DpgyjPN3srXe-rrjpOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*9OT5JT2K5yLw8K_xD85qxQ.png" /></figure><p>Last blog, we learn some basic Linux commands and their uses. Today we will learn more about command and their uses. So, let’s learn about basic and some advanced Linux command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/0*qbVBwGPWChiwP7mN" /></figure><h3>To view what’s written in a file.</h3><p>Cat is a command through which you can review what’s written in a file.</p><p>For creating Linux Files we used different commands like</p><p>cat command: to view what is written in the file we used the cat command</p><pre>vim command<br>touch command<br>nano command</pre><p>To change the access permissions of files.</p><p>Chmod is the command used to change the access permissions of a file.</p><p>Example:<br>rwx rwx rwx<br>In that values are r=4,w=2,x=1 so 4+2+1=7 then total value is 777<br>chmod 777 permission says all permission are given like we read, write and execute</p><pre>chmod 777 test-file.txt</pre><p>The command chmod 777 test-file sets the access permissions of the file test-file to read, write, and execute for the owner, group, and others.</p><pre>chmod 600 filename</pre><p>To give read and write permissions to the owner, and no permissions to group and others</p><pre>chmod 750 filename</pre><p>To give read and execute permissions to the owner and group, and no permissions to others:</p><pre>chmod 700 filename</pre><p>To give full permissions (read, write, and execute) to the owner, and no permissions to the group and others:</p><pre>chmod 444 filename</pre><p>To remove write and execute permissions from the owner, group, and others</p><p>This permission setting is commonly used when you want to make a file read-only for everyone, preventing any modifications or execution.</p><h3>Now, let start deeply discuss file access permission.</h3><pre>chmod 755 filename</pre><p>To give read, write, and execute permissions to the owner, and read permission to group and others</p><p>This permission setting is commonly used when you want to make a file read-only for everyone, preventing any modifications or execution.</p><h3>Now, let start deeply discuss file access permission.</h3><pre>chmod 755 filename</pre><p>To give read, write, and execute permissions to the owner, and read permission to group and others</p><h3>Let’s break down the permission code:</h3><ul><li>The leftmost digit, 7, represents the permission for the owner of the file.</li><li>The middle digit, 5, represents the permission for the group that the file belongs to.</li><li>The rightmost digit, 5, represents the permission for other users (not the owner or group).</li></ul><p>Each digit in the permission code represents a combination of read (4), write (2), and execute (1) permissions.</p><h3>Here’s a breakdown of the permission codes:</h3><ul><li>7: This grants the owner of the file full permissions, which include read, write, and execute.</li><li>5: This grants the group read and execute permissions, but not write permissions.</li><li>5: This grants other users read and execute permissions, but not write permissions</li></ul><p>In summary, executing chmod 755 filename sets the file permissions as follows:</p><ul><li>The owner of the file has full control (read, write, and execute).</li><li>The group has read and execute permissions.</li><li>Other users have read and execute permissions.</li></ul><p>This permission setting is commonly used for executable files or scripts that should be readable and executable by all users, but not writable to maintain security.</p><p>To check which commands you have run till now.</p><p>history command is used to check the commands you have run till now.</p><p>To remove a directory/ Folder.</p><p>To remove a directory, we use the “rm” command. We use “rm -r” if the directory is non-empty.</p><p>Some common options that you can use with the rm command are:</p><ul><li>-f: Force removal of files without prompting for confirmation.</li><li>-r: Recursively remove directories and their contents.</li></ul><p>The rmdir command in Linux is used to remove empty directories from the file system.</p><p>rm -rf It is used to forcefully and recursively remove files and directories from the file system, including non-empty directories.</p><p>rm-rp = Remove non-empty directory including parent and subdirectory</p><p>rm-r = Removes empty directories</p><p>To create a fruits.txt file and view the content.</p><p>Add content in devops.txt (One in each line) — Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.</p><p>Show only the top three fruits from the file.</p><p>To show only the top three fruits we will use the head command. The Linux head command prints the first lines of one or more files to standard output. By default, it shows the first 10 lines.</p><p>Show only the bottom three fruits from the file.</p><p>To show only the bottom three fruits we will use the tail command. Tail is a command which prints the last few lines (10 lines by default) of a certain file.</p><p>To create another file Colors.txt and view the content.</p><p>Add content in Colors.txt (One in each line) — Red, Pink, White, Black, Blue, Orange, Purple, and Grey.</p><p>We used touch and vim commands for creating the colors.txt file</p><p>Add content in Colors.txt (One in each line) — Red, Pink, White, Black, Blue, Orange, Purple, and Grey.</p><p>To find the difference between the fruits.txt and Colors.txt files.</p><p>diff Command to find the difference between the content of two files.</p><p>Thank you for reading this blog. I hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>— Happy Learning !!!</p><h3>Let’s connect !!!</h3><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><h3><a href="https://hashnode.com/@nahid0002">HashNode</a></h3><h3><a href="https://github.com/nahidkishore">Github</a></h3><h3><a href="http://nahidkishore99@gmail.com/">Mail</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1972aba9e6a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hands-On Ansible Project: Deploying a Web App on Nginx Servers]]></title>
            <link>https://blog.devops.dev/hands-on-ansible-project-deploying-a-web-app-on-nginx-servers-f231cedba8d0?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f231cedba8d0</guid>
            <category><![CDATA[infrastructure-management]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[ansible-playbook]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 08:32:22 GMT</pubDate>
            <atom:updated>2023-08-08T09:36:06.782Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Ansible playbooks are highly advantageous, as demonstrated in our previous blog on Ansible.<br>Today, we will embark on a hands-on project, where we will explore the powerful capabilities of Ansible to deploy a web application on an Nginx server. We will set up a Master server (EC2 instance) and three other servers, all using the same key pair for secure access. By leveraging Ansible, we can easily manage and deploy our application across multiple servers, streamlining the process and ensuring consistency.</blockquote><h3>Table of Contents:</h3><ol><li>Setting up the Master Server</li></ol><ul><li>Create an EC2 instance and set up Ansible</li><li>Verify Ansible installation</li><li>Create the Ansible inventory</li></ul><ol><li>Deploying the Web App</li></ol><ul><li>Prepare the web application files</li><li>Create an Ansible playbook to install Nginx, start the service, and transfer files</li></ul><ol><li>Executing the Ansible Playbook</li></ol><ul><li>Deploy the web app to the designated server(s)</li><li>Verify successful deployment</li></ul><h3>Let’s commence this endeavor and begin the journey toward our goal.</h3><ol><li>Create a Master server (EC2 instance) and three servers with one key pair for all servers</li><li>Connect the master server with SSH and install Ansible on it using the following command:</li></ol><pre>sudo apt-add-repository ppa:ansible/ansible<br>sudo apt update<br>sudo apt install ansible -y</pre><p>Now check whether Ansible properly install or not using the following command</p><pre>cat /etc/ansible/hosts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vRaUFEwUS_pzQJwg" /></figure><p>Once the file is open, you can add the IP addresses or hostnames of the servers you want to manage. The format for adding hosts is as follows:</p><p>edit /etc/ansible/hosts file and add the public key of ansible server instances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1X_hfTppcjhMQ6ut" /></figure><p>Let’s verify the inventory that we have created.</p><pre>ansible-inventory --list -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*17bS6SpCYXInsQRr" /></figure><p>Copy the private key to the master server where Ansible is set up</p><p>The below command is to copy the private key to a remote server from the local machine folder and after that copy the private key on ssh folder of the remote server</p><pre>sudo scp -i &quot;an-access-key.pem&quot; an-access-key.pem ubuntu@ec2-18-208-153-82.compute-1.amazonaws.com:/home/ubuntu/.ssh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FVCPPyDReGE5aeGH" /></figure><p>Try ping command using Ansible to the Nodes.</p><p>To test that Ansible is able to connect to your nodes, you can use the following command:</p><pre>ansible servers -m ping</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0h9Hd58gCM_Q31w8" /></figure><p>Now we will deploy a sample webpage using the Ansible playbook.</p><p>so first we will create an index.html file</p><pre>vim index.html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u9-MUza_ZEx3RAN5" /></figure><p>Create a playbook to install, start and enable the Nginx and transfer the index.html file to the Nginx location.</p><pre>vim deploy_webapp.yml</pre><pre>-<br> name: this is a simple html project deploy using ansible<br> hosts: servers<br> become: true<br> tasks:<br>   - name: install nginx<br>     apt:<br>       name: nginx<br>       state: latest<br>- name: start nginx<br>     service:<br>       name: nginx<br>       state: started<br>   - name: Deploy webpage<br>     copy:<br>       src: index.html<br>       dest: /var/www/html</pre><p>Execute the Ansible playbook YAML file to perform the task.</p><p>To run the playbook on the prod_inv server, use the following command.</p><pre>ansible-playbook -i ansible/inventories/prod_inv deploy_webapp.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UbzkQ7OE3Bcn06r5" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7Faa9H3g4pFUAZOE" /></figure><p>Here, we have deployed a web page one server named “prod_inv”. If you want to deploy the web page on all dedicated servers, simply use the following command instead of the “prod_inv” server:</p><pre>ansible-playbook deploy_webapp.yml</pre><p>Now Check prod_inv server IP address using this command:</p><pre>ansible-inventory -i /home/ubuntu/ansible/inventories/prod_inv --list -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0dqxnTO2pTIbTYdH" /></figure><p>Here, you can find the IP address of the Ansible host: 54.85.98.171. Please wait for a moment of magic!</p><p>Now, please copy the IP address and open your browser. Hit Enter!</p><h3>Boom!! Enjoy the experience!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r4Dm907ztz69qz6k" /></figure><p>In this hands-on project, we successfully deployed a web application on an Nginx server using Ansible. By following the step-by-step guide, we created a Master server and multiple nodes with one key pair for seamless access. Ansible proved to be a valuable tool for automating the installation and configuration of Nginx on the nodes and deploying our web application. This project showcased the flexibility and efficiency of Ansible, making it an essential tool for managing infrastructure and simplifying the deployment process.</p><p>By mastering Ansible, you gain the ability to manage large-scale infrastructure and deploy applications with ease, making it a valuable skill for any DevOps engineer or system administrator. Whether you’re just starting with Ansible or looking to enhance your expertise, this project provides a practical and insightful learning experience that empowers you to tackle complex infrastructure management tasks effectively. So, roll up your sleeves, dive into the world of Ansible, and take your automation skills to new heights!</p><p>Are you ready to embark on your Ansible journey? Follow along with this project, and you’ll soon be orchestrating your own infrastructure with ease.</p><p>— — Happy Learning !!!</p><h3>Let’s connect !!!</h3><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><h3><a href="https://hashnode.com/@nahid0002">HashNode</a></h3><h3><a href="https://github.com/nahidkishore">Github</a></h3><h3><a href="http://nahidkishore99@gmail.com/">Mail</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f231cedba8d0" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/hands-on-ansible-project-deploying-a-web-app-on-nginx-servers-f231cedba8d0">Hands-On Ansible Project: Deploying a Web App on Nginx Servers🔥</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ansible: Automating Infrastructure Management and Configuration]]></title>
            <link>https://blog.devops.dev/ansible-automating-infrastructure-management-and-configuration-35049777c70?source=rss-d7ea8447cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/35049777c70</guid>
            <category><![CDATA[ansible-playbook]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[infrastructure-management]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Nahidul Islam]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 08:24:50 GMT</pubDate>
            <atom:updated>2023-08-08T09:36:12.795Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sMSfIbPO8mH299to" /></figure><h3>What is Configuration Management?</h3><ul><li>Configuration management is a discipline that focuses on managing and controlling changes to a system’s configuration. It involves identifying and documenting the system’s components, their relationships, and their attributes.</li><li>It ensures that changes to the system are properly planned, evaluated, approved, and implemented. Configuration management aims to maintain consistency, integrity, and traceability of the system’s configuration throughout its lifecycle.</li><li>It facilitates efficient troubleshooting, maintenance, and version control of software, hardware, or any other complex system. Configuration management helps prevent unauthorized changes and ensures compliance with standards and regulations.</li></ul><h3>When do we use Configuration Management instead of IaC?</h3><ul><li>Configuration Management is typically used when dealing with established systems or environments that have already been set up manually or with traditional infrastructure management approaches.</li><li>It is useful in scenarios where the primary goal is to manage and track changes to the configuration of these existing systems. In contrast, Infrastructure as Code (IaC) is employed when creating new infrastructure or when adopting a more agile and automated approach to provisioning and managing infrastructure resources.</li></ul><h3>Common Tools Used in Configuration Management</h3><ol><li>Ansible: An automation tool that enables configuration management, application deployment, and orchestration.</li><li>Puppet: An open-source configuration management tool that helps automate the provisioning, configuration, and management of systems.</li><li>Chef: A configuration management tool used for infrastructure automation and management.</li><li>Kubernetes: An open-source container orchestration platform that helps manage and automate the deployment, scaling, and operation of containerized applications.</li><li>SaltStack: A configuration management and remote execution tool that aids in managing and controlling infrastructure.</li></ol><h3>What’s this Ansible?</h3><p>Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.<br>Ansible uses playbook to describe automation jobs, and playbook uses very simple language i.e. YAML (It’s a human-readable data serialization language &amp; is commonly used for configuration files, but could be used in many applications where data is being stored)which is very easy for humans to understand, read and write. Hence the advantage is that even the IT infrastructure support guys can read and understand the playbook and debug if needed (YAML — It is in human-readable form).</p><h3>How Ansible works?</h3><p>In Ansible, there are two categories of computers: the control node and managed nodes. The control node is a computer that runs Ansible. There must be at least one control node, although a backup control node may also exist. A managed node is any device being managed by the control node.</p><p>Ansible works by connecting to nodes (clients, servers, or whatever you’re configuring) on a network, and then sending a small program called an Ansible module to that node. Ansible executes these modules over SSH and removes them when finished. The only requirement for this interaction is that your Ansible control node has login access to the managed nodes. SSH keys are the most common way to provide access, but other forms of authentication are also supported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Em9MHjKvnkSeMUV4" /></figure><h3>Exploring Ansible through Practical Hands-On Experience</h3><p>Installation of Ansible on AWS EC2 (Master Node)</p><ol><li>Create a Master server (EC2 instance) and create one key pair</li><li>Connect the master server with SSH and install Ansible on it with the following command:</li></ol><pre>sudo apt-add-repository ppa:ansible/ansible  <br>sudo apt update  <br>sudo apt install ansible -y</pre><ol><li>Now check whether Ansible properly install or not using the following command</li></ol><pre>cat /etc/ansible/hosts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DtBahv3m-Lf9gu5w" /></figure><h3>Creating Inventory</h3><p>Ansible Inventory — Ansible automates tasks on managed nodes or “hosts” in your infrastructure, using a list or group of lists known as inventory. You can pass host names at the command line, but most Ansible users create inventory files. Your inventory defines the managed nodes you automate, with groups so you can run automation tasks on multiple hosts at the same time. Once your inventory is defined, you use patterns to select the hosts or groups you want Ansible to run against.</p><p>Ansible hosts file is a configuration file that contains a list of hosts or servers that Ansible can manage. The hosts file is located at /etc/ansible/hosts on the Ansible control node, and it is used to define the inventory of hosts that Ansible can manage.</p><ol><li>To edit the hosts file, you can use any text editor of your choice</li></ol><pre>sudo nano /etc/ansible/hosts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NQDQuDQFa75ZNYnc" /></figure><p>Before that, we need to create three Ansible node servers that will be connected to the Ansible master server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wZ31Gji9Hvxu9Vsz" /></figure><p>Once the file is open, you can add the IP addresses or hostnames of the servers you want to manage. The format for adding hosts is as follows:</p><p>edit /etc/ansible/hosts file and add public key of ansible server instances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QfuUGSvZ0pBZw0yP" /></figure><p>Let’s verify the inventory that we have created.</p><pre>ansible-inventory --list -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uXRDOrA9O4AtDrzb" /></figure><p>Copy the private key to the master server where Ansible is set up</p><p>The below command is to copy private key to remote server from the local machine folder and after that copy the private key on ssh folder of the remote server.</p><pre>sudo scp -i &quot;an-access-key.pem&quot; an-access-key.pem ubuntu@ec2-18-208-153-82.compute-1.amazonaws.com:/home/ubuntu/.ssh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_0Dd2yS4DUwPNfvu" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*udk9-ZJ0HGkbWd-W" /></figure><p>To grant read and write access to the user, you can use the following command:</p><pre>chmod 600 an-access-key.pem</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z7zUmq3ZVhkw5rwx" /></figure><p>Try a ping command using Ansible to the Nodes.</p><p>To test that Ansible is able to connect to your nodes, you can use the following command:</p><pre>ansible servers -m ping</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7bWY5cmpxwPbOuLq" /></figure><p>We can see all three pings are successful which indicates servers are in active states.</p><p>Let’s verify the inventory that we have created.</p><pre>ansible-inventory --list -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kq09K_5laeUen1rX" /></figure><p>Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.</p><p>I’d love to hear from you if there are any corrections or things you’d like to add to the blogs. Your feedback is valuable and always welcome! Please feel free to share any thoughts or suggestions you have.</p><p>— Happy Learning !!!</p><h3>Let’s connect !!!</h3><h3><a href="https://www.linkedin.com/in/nahid099/">Linkedin</a></h3><h3><a href="https://hashnode.com/@nahid0002">HashNode</a></h3><h3><a href="https://github.com/nahidkishore">Github</a></h3><h3><a href="http://nahidkishore99@gmail.com/">Mail</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35049777c70" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/ansible-automating-infrastructure-management-and-configuration-35049777c70">Ansible: Automating Infrastructure Management and Configuration</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>