<?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 Pramesh Palkonda on Medium]]></title>
        <description><![CDATA[Stories by Pramesh Palkonda on Medium]]></description>
        <link>https://medium.com/@pramesh.palkonda18?source=rss-30f9cdffca49------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8j4m01E25eC0oKSV</url>
            <title>Stories by Pramesh Palkonda on Medium</title>
            <link>https://medium.com/@pramesh.palkonda18?source=rss-30f9cdffca49------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:20:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pramesh.palkonda18/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[Migrating Google Cloud Storage to Amazon S3 using AWS DataSync]]></title>
            <link>https://medium.com/@pramesh.palkonda18/migrating-google-cloud-storage-to-amazon-s3-using-aws-datasync-c9d520d8aea5?source=rss-30f9cdffca49------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9d520d8aea5</guid>
            <category><![CDATA[cloud-storage-migration]]></category>
            <category><![CDATA[aws-datasync]]></category>
            <category><![CDATA[google-cloud-storage]]></category>
            <dc:creator><![CDATA[Pramesh Palkonda]]></dc:creator>
            <pubDate>Fri, 22 Nov 2024 07:58:18 GMT</pubDate>
            <atom:updated>2024-11-22T07:58:18.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y35mbBJyDkALgS_eg_fVcQ.png" /><figcaption>AWS DataSync agent architecture</figcaption></figure><h3>AWS DataSync components and terminology</h3><p>DataSync has four components for data movement: task, locations, agent, and task execution.</p><h3>Components:</h3><ol><li><strong>Agent</strong>:</li></ol><ul><li>A virtual machine (VM) responsible for facilitating data transfers.</li><li>Deployed as an <strong>Amazon EC2 instance</strong> within an <strong>Amazon VPC</strong>.</li></ul><p><strong>2.Location</strong>:</p><ul><li>Defines the <strong>source</strong> and <strong>destination</strong> of the data migration.</li></ul><p><strong>Source Location</strong>:</p><ul><li><strong>Google Cloud Storage</strong> (GCS).</li><li>Uses the <strong>Google Storage XML API</strong> endpoint: <a href="https://storage.googleapis.com./">https://storage.googleapis.com.</a></li><li>Specifies a GCS <strong>bucket name</strong>.</li></ul><p><strong>Destination Location</strong>:</p><ul><li><strong>Amazon S3</strong> bucket.</li></ul><p><strong>3. Task</strong>:</p><ul><li>Connects one <strong>source location</strong> to one <strong>destination location</strong>.</li><li>Includes configurations such as:</li><li>Include/Exclude patterns (e.g., filter specific files or directories).</li><li><strong>Task schedules</strong> for periodic transfers.</li><li><strong>Bandwidth limits</strong> to control network usage.</li></ul><p><strong>4.Task Execution</strong>:</p><ul><li>Represents an individual run of a task.</li><li>Logs details like:</li><li>Start and end times.</li><li>Amount of data transferred (bytes written).</li><li>Execution status (e.g., success or failure).</li></ul><h4>Source overview — Google Cloud Storage bucket</h4><ul><li>The source Google Cloud Storage bucket is named demo-customer-bucket.</li><li>This bucket contains two folders: <strong>business-data</strong> and <strong>system-data</strong>.</li><li>In this use case, only the objects in the <strong>business-data</strong> folder will be transferred.</li><li>The <strong>system-data</strong> folder will be excluded from the transfer.</li><li>This demonstrates AWS DataSync’s capability to include or exclude specific folders from the source bucket.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/0*eVZchyi0KnapHMSR.png" /></figure><ul><li>Inside the <strong>business-data</strong> folder, there are six files.</li><li>The goal is to transfer the five text files and exclude the temporary file named log.tmp.</li><li>This demonstrates AWS DataSync’s capability to exclude certain objects based on a name pattern.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/0*gagUos0VNfir1ArV.png" /></figure><p><strong>Now ready to build the solution to move data from Google Cloud Storage to Amazon S3 using AWS DataSync.</strong></p><ol><li>Create an Amazon S3 bucket as the destination.</li><li>Create an IAM role to access the Amazon S3 bucket.</li><li>Set up a network for the Amazon VPC.</li><li>Deploy an Amazon EC2 DataSync agent.</li><li>Create DataSync locations.<br> . Google Cloud Storage location<br> . Amazon S3</li><li>Create and run DataSync task.<br> . Create a DataSync task — Location<br> . Create a DataSync task — Configure Settings<br> . Run the DataSync task</li><li>Verify the data migrated.</li></ol><h3>Step 1: Create an Amazon S3 bucket as the destination</h3><ul><li>Create a new Amazon S3 bucket to be used as the destination for the DataSync transfer.</li><li>After creating the bucket, navigate to the <strong>Properties</strong> tab and copy the bucket’s Amazon Resource Name (ARN).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/0*iq7_CGj2Nr3cdqR-.png" /></figure><h3>Step 2: Create an IAM role to access the Amazon S3 bucket</h3><ul><li>Create a new IAM role for AWS DataSync with a trust relationship that allows DataSync to assume the role.</li><li>Attach a policy to the role that grants DataSync the necessary permissions (s3:PutObject, s3:GetObject, s3:ListBucket) to read and write to the Amazon S3 bucket.</li></ul><h3>Step 3: Deploy an Amazon EC2 DataSync agent</h3><ul><li>Launch an Amazon EC2 instance using the latest DataSync Amazon Machine Image (AMI) into the subnet from the previous step.</li><li>Attach the security group for DataSync agents to the EC2 instance.</li><li>Once the EC2 instance is running, create a DataSync agent component.</li><li>Activate the DataSync agent to associate it with your AWS account.</li></ul><h3>Step 4: Create DataSync locations</h3><p>Create source and destination DataSync locations using the following steps.</p><h4>Google Cloud Storage location</h4><ul><li>Open the AWS DataSync console and choose <strong>Locations</strong>.</li><li>Select <strong>Create Location</strong>.</li><li>For <strong>Location Type</strong>, choose <strong>Object Storage</strong>.</li><li>For <strong>Agents</strong>, select the activated DataSync agent from the previous step.</li><li>For <strong>Server</strong>, enter storage.googleapis.com.</li><li>For <strong>Bucket Name</strong>, enter the name of the Google Cloud Storage source bucket (e.g., demo-customer-bucket), ensuring the name is case-sensitive.</li><li>For <strong>Authentication</strong>, provide the Google access key and secret key ID.</li><li>Select <strong>Create Location</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*8bmZ75kPcFaEmcIx.png" /></figure><h4>Amazon S3 location</h4><ul><li>Open the AWS DataSync console and choose <strong>Locations</strong>.</li><li>Select <strong>Create Location</strong>.</li><li>For <strong>Location Type</strong>, choose <strong>Amazon S3</strong>.</li><li>For the <strong>Amazon S3 Bucket</strong>, select destination bucket created in Step-1</li><li>For <strong>IAM Role</strong>, select the IAM role created in Step 2 to access Amazon S3.</li><li>Select <strong>Create Location</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*o76XK_vV-SSUsfOI.png" /></figure><h3>Step 5: Create and run an AWS DataSync task</h3><ul><li>In the AWS DataSync console, select <strong>Create Task</strong>.</li><li>For <strong>Source Location</strong>, choose the Google Cloud Storage location created earlier.</li><li>For <strong>Destination Location</strong>, choose the Amazon S3 location created in the previous step.</li></ul><h4>Create an AWS DataSync task: Location</h4><ul><li>Open the AWS DataSync console and choose <strong>Tasks</strong>.</li><li>Select <strong>Create Task</strong>.</li><li>For <strong>Source Location Options</strong>, select <strong>Choose an existing location</strong> and choose object-storage://storage.googleapis.com/&lt;bucket name&gt;/ from Step 5: Create DataSync locations. Then select <strong>Next</strong>.</li><li>For <strong>Destination Location Options</strong>, select <strong>Choose an existing location</strong> and choose s3://&lt;bucket name&gt;/ from Step 5: Create DataSync locations. Then select <strong>Next</strong>.</li><li>This opens the <strong>Configure Settings</strong> page.</li><li>Select <strong>Next</strong>.</li></ul><h4>Create an AWS DataSync task: Configure settings</h4><p>The next step is to configure the settings for the DataSync task.</p><ul><li>For <strong>Task Name</strong>, enter a name for the task.</li><li>For <strong>Data Transfer Configuration</strong>, select the <strong>Specific files and folders</strong> option to specify the subfolder using the include patterns.</li><li>For <strong>Transfer Mode</strong>, select <strong>Transfer only data that has changed</strong>.</li><li>Uncheck <strong>Keep deleted files</strong> (this will delete corresponding objects in Amazon S3 if deleted in the source Google Cloud Storage).</li><li>Check <strong>Overwrite files</strong> (this will overwrite objects in S3 if source and target objects differ).</li><li>For <strong>Include Patterns</strong>, enter /business-data/* to filter the objects transferred. Note that the pattern is case-sensitive.</li><li>For <strong>Exclude Patterns</strong>, select <strong>Add pattern</strong> and enter *.tmp to exclude objects with the .tmp extension.</li><li>Expand <strong>Additional Settings</strong> and uncheck <strong>Copy object tags</strong> to prevent reading tags from GCS (not supported).</li></ul><h4>Task Logging:</h4><ul><li>For <strong>Log Level</strong>, select <strong>Log all transferred objects and files</strong>.</li><li>For <strong>CloudWatch Log Group</strong>, select <strong>Autogenerate</strong> to create the appropriate policy and log group.</li><li>Select <strong>Next</strong> to review the task configuration.</li></ul><h4>Create the Task:</h4><ul><li>Select <strong>Create Task</strong> and wait for the task status to become <strong>Available</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/0*N2qiDSgKfp1F3yxb.png" /></figure><h4>Run the AWS DataSync task</h4><ul><li>Start the DataSync task to begin transferring the files.</li><li>Monitor the status of the task as it progresses through each phase.</li><li>Refer to <strong>Understanding Task Execution Status</strong> for details on the possible task statuses (phases) and their meanings.</li><li>You can also monitor the task using <strong>Amazon CloudWatch</strong> for more detailed insights.</li></ul><h3>Step 6: Verify the data migrated</h3><ul><li>Verify the migrated objects by navigating to the Amazon S3 target bucket and opening the <strong>business-data</strong> folder.</li><li>The five files should now be transferred to the Amazon S3 bucket.</li><li>Notice that the log.tmp file was not transferred because the task included an exclude filter (*.tmp), which excluded this file.</li><li>You can run the task multiple times.</li><li>Each time the task runs, AWS DataSync will detect changes between the source and destination and only transfer new or modified objects.</li><li>This allows you to transfer data that may have changed on the source location.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/0*bKJ5UsSXJQG4HZYs.png" /></figure><ul><li>DataSync also transfers the object’s custom metadata.</li><li>For example, the file file-1.txt had a custom metadata key <strong>Department</strong> with a value of <strong>Math</strong>.</li><li>This custom metadata was transferred to the Amazon S3 object’s metadata.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/0*ABLdGnB_RkoS2a5L.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9d520d8aea5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cost Optimization for AWS EKS: Leveraging Python Lambda and AWS EventBridge to Reduce Expenses by…]]></title>
            <link>https://medium.com/@pramesh.palkonda18/cost-optimization-for-aws-eks-leveraging-python-lambda-and-aws-eventbridge-to-reduce-expenses-by-3cd07e7ebd87?source=rss-30f9cdffca49------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cd07e7ebd87</guid>
            <category><![CDATA[serverless-automation]]></category>
            <category><![CDATA[aws-cost-optimization]]></category>
            <category><![CDATA[eventbridge]]></category>
            <category><![CDATA[cloud-infrastructure]]></category>
            <dc:creator><![CDATA[Pramesh Palkonda]]></dc:creator>
            <pubDate>Mon, 18 Nov 2024 11:25:59 GMT</pubDate>
            <atom:updated>2024-11-18T11:25:59.583Z</atom:updated>
            <content:encoded><![CDATA[<h4>Cost Optimization for AWS EKS: Leveraging Python Lambda and AWS EventBridge to Reduce Expenses by Automatically Stopping UAT/Testing Worker Nodes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*gzlI-UET9vJzGPJz.png" /></figure><p>Amazon Elastic Kubernetes Service (EKS) allows organizations to deploy and scale Kubernetes applications efficiently. EKS nodes can be run using EC2 instances or AWS Fargate, but this discussion will focus solely on the scale-up and scale-down processes for EKS nodes operating on EC2.</p><p>Each EKS cluster incurs a base cost of $0.10 per hour, alongside the costs for running EC2 instances and their associated storage volumes. The hourly EC2 costs vary depending on the selected instance type.</p><p>For non-production clusters, such as those used for testing, maintaining availability 24/7 might not be necessary. By implementing a process to scale down these clusters during nighttime or non-business hours, organizations can significantly reduce their EC2 instance costs.</p><p>This can be achieved using an AWS Lambda function with a Python script, triggered by AWS EventBridge, to automatically scale down EKS clusters during off-peak hours.</p><p><strong>Step-by-Step Guide to Automate EKS Node Scaling with AWS Lambda and EventBridge</strong></p><h3>Step 1: Configure an IAM Policy for EKS Cluster Permissions</h3><ol><li><strong>Navigate to IAM Policies</strong>:</li></ol><ul><li>Go to the <strong>IAM console</strong>.</li><li>In the navigation pane under <strong>Access Management</strong>, click <strong>Policies</strong>.</li></ul><p>2. <strong>Create a New Policy</strong>:</p><ul><li>Click <strong>Create policy</strong>.</li><li>Select the <strong>JSON</strong> tab and paste the following code:</li></ul><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;VisualEditor0&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;eks:ListNodegroups&quot;,<br>                &quot;eks:UpdateNodegroupConfig&quot;,<br>                &quot;eks:DescribeNodegroup&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:eks:CLUSTER_REGION:ACCOUNT_ID:cluster/CLUSTER_NAME&quot;,<br>                &quot;arn:aws:eks:CLUSTER_REGION:ACCOUNT_ID:nodegroup/CLUSTER_NAME/*/*&quot;<br>            ]<br>        }<br>    ]<br>}</pre><p>Replace the following placeholders:</p><ul><li>CLUSTER_REGION: Region of your EKS cluster (e.g., us-east-1).</li><li>ACCOUNT_ID: Your AWS account ID.</li><li>CLUSTER_NAME: Name of your EKS cluster.</li></ul><p>3. <strong>Review and Save</strong>:</p><ul><li>Click <strong>Next: Tags</strong> (optional) &gt; <strong>Next: Review</strong>.</li><li>Name the policy: <em>eks_node_group_update.</em>.</li><li>Click <strong>Create policy</strong>.</li></ul><h3><strong>Step 2: Create an IAM Role for Lambda</strong></h3><ol><li><strong>Navigate to IAM Roles</strong>:</li></ol><ul><li>In the <strong>IAM console</strong>, under <strong>Access Management</strong>, click <strong>Roles</strong>.</li></ul><p><strong>2. Create a New Role</strong>:</p><ul><li>Click <strong>Create role</strong>.</li><li>Under <strong>Trusted entity type</strong>, select <strong>AWS service</strong>.</li><li>For <strong>Common use cases</strong>, choose <strong>Lambda</strong>.</li><li>Click <strong>Next: Permissions</strong>.</li></ul><p><strong>3. Attach the Policy</strong>:</p><ul><li>Search for the policy you created,eks_node_group_update.</li><li>Select the checkbox next to the policy name.</li><li>Click <strong>Next: Tags</strong> (optional) &gt; <strong>Next: Review</strong>.</li><li>Name the role: Lambda_EKS_ScaleRole.</li><li>Click <strong>Create role</strong>.</li></ul><h3><strong>Note:</strong></h3><p>BasicExecution Role: To log the events logs into AWS Cloudwatch Log group.</p><p>LamdaSNSTopic Role: To allow lambda to interact with SNS and send notifications of ScaleUP and ScaleDown Events.</p><p>eks_node_group_update Role: To allow Lambda to update the EKS AutoScaling group config to scale down &amp; Up the worker nodes.</p><h3>Step 3: Create 2 Lambda Functions for ScaleUp and ScaleDown.</h3><h3>Step 3.1: Lambda Function for ScaleUP</h3><h3>1. Create the Function</h3><p><strong>a. Go to AWS Lambda Console</strong>:</p><ul><li>Navigate to the <a href="https://console.aws.amazon.com/lambda/">AWS Lambda service</a>.</li></ul><p><strong>b. Click “Create Function”</strong>:</p><ul><li>Choose the <strong>Author from scratch</strong> option.</li></ul><p><strong>c. Set up the Function</strong>:</p><ul><li><strong>Function name</strong>: EKS_Node_ScaleUP.</li><li><strong>Runtime</strong>: Python 3.7 (or the latest version available).</li><li><strong>Execution role</strong>:</li><li><em>Choose </em><strong><em>“Use an existing role”</em></strong><em>.</em></li><li><em>Select the IAM role created earlier (</em>Lambda_EKS_ScaleRole<em>)(with EKS permissions).</em></li></ul><p><strong>d. Click “Create Function”.</strong></p><h3>2. Add the ScaleUP Code</h3><ol><li>Once the function is created, navigate to the <strong>Code</strong> section.</li><li>Replace the default code with the following Python script:</li></ol><pre>import boto3<br>import json<br><br>def lambda_handler(event, context):<br>    print(event)<br><br>    # Initialize clients<br>    eks = boto3.client(&quot;eks&quot;)<br>    sns = boto3.client(&quot;sns&quot;)<br>    <br>    # Define variables<br>    region_name = &quot;&lt;region&gt;&quot;<br>    cluster_name = &quot;&lt;cluster_name&gt;&quot;<br>    nodegroup_names = [&quot;&lt;ng-1&gt;&quot;, &quot;&lt;ng-2&gt;&quot;]<br>    new_desiredSize = 1  #change according to your will<br>    new_minSize = 1  #change according to your will<br>    new_maxSize = 3  #change according to your will<br><br>#SNS topic to alert during scale-UP event<br>    sns_topic_arn = &quot;&lt;sns-topic-arn&gt;&quot;<br><br>    # Loop through the node groups and update their scaling configuration<br>    for nodegroup_name in nodegroup_names:<br>        response = eks.update_nodegroup_config(<br>            clusterName=cluster_name,<br>            nodegroupName=nodegroup_name,<br>            scalingConfig={<br>                &quot;desiredSize&quot;: new_desiredSize,<br>                &quot;minSize&quot;: new_minSize,<br>                &quot;maxSize&quot;: new_maxSize<br>            }<br>        )<br>        <br>        # Publish a notification to SNS<br>        sns_message = {<br>            &quot;ClusterName&quot;: cluster_name,<br>            &quot;NodeGroupName&quot;: nodegroup_name,<br>            &quot;DesiredSize&quot;: new_desiredSize,<br>            &quot;MinSize&quot;: new_minSize,<br>            &quot;MaxSize&quot;: new_maxSize,<br>            &quot;Status&quot;: &quot;Scaling update triggered&quot;<br>        }<br>        <br>        sns.publish(<br>            TopicArn=sns_topic_arn,<br>            Message=json.dumps(sns_message),<br>            Subject=&quot;EKS Node Group Scaling Update Notification&quot;<br>        )<br><br>        # Print the response<br>        print(response)</pre><p>3. Update the placeholders (&lt;region&gt;, &lt;cluster_name&gt;, &lt;ng-1&gt;, &lt;sns-topic-arn&gt;) with actual values.</p><h3>Step 3.2: Lambda Function for ScaleDown</h3><h4>1. Create the Function</h4><p><strong>a. Go to AWS Lambda Console</strong>:</p><ul><li>Navigate to the <a href="https://console.aws.amazon.com/lambda/">AWS Lambda service</a>.</li></ul><p><strong>b. Click “Create Function”</strong>:</p><ul><li>Choose the <strong>Author from scratch</strong> option.</li></ul><p><strong>c. Set up the Function</strong>:</p><ul><li><strong>Function name</strong>: EKS_Node_ScaleDown.</li><li><strong>Runtime</strong>: Python 3.7 (or the latest version available).</li><li><strong>Execution role</strong>:</li><li><em>Choose </em><strong><em>“Use an existing role”</em></strong><em>.</em></li><li><em>Select the same IAM role created earlier for the ScaleUP function.</em></li></ul><p><strong>d. Click “Create Function”</strong>.</p><h3>2. Add the ScaleDown Code</h3><ul><li>Once the function is created, go to the <strong>Code</strong> section.</li><li>Replace the default code with the following Python script:</li></ul><pre>import boto3<br>import json<br><br>def lambda_handler(event, context):<br>    print(event)<br><br>    # Initialize clients<br>    eks = boto3.client(&quot;eks&quot;)<br>    sns = boto3.client(&quot;sns&quot;)<br>    <br>    # Define variables<br>    region_name = &quot;&lt;region&gt;&quot;<br>    cluster_name = &quot;&lt;cluster_name&gt;&quot;<br>    nodegroup_names = [&quot;&lt;ng-1&gt;&quot;, &quot;&lt;ng-2&gt;&quot;]<br>    new_desiredSize = 0 <br>    new_minSize = 0 <br>    new_maxSize = 1 <br><br>#SNS topic to alert during scale-UP event<br>    sns_topic_arn = &quot;&lt;sns-topic-arn&gt;&quot;<br><br>    # Loop through the node groups and update their scaling configuration<br>    for nodegroup_name in nodegroup_names:<br>        response = eks.update_nodegroup_config(<br>            clusterName=cluster_name,<br>            nodegroupName=nodegroup_name,<br>            scalingConfig={<br>                &quot;desiredSize&quot;: new_desiredSize,<br>                &quot;minSize&quot;: new_minSize,<br>                &quot;maxSize&quot;: new_maxSize<br>            }<br>        )<br>        <br>        # Publish a notification to SNS<br>        sns_message = {<br>            &quot;ClusterName&quot;: cluster_name,<br>            &quot;NodeGroupName&quot;: nodegroup_name,<br>            &quot;DesiredSize&quot;: new_desiredSize,<br>            &quot;MinSize&quot;: new_minSize,<br>            &quot;MaxSize&quot;: new_maxSize,<br>            &quot;Status&quot;: &quot;Scaling update triggered&quot;<br>        }<br>        <br>        sns.publish(<br>            TopicArn=sns_topic_arn,<br>            Message=json.dumps(sns_message),<br>            Subject=&quot;EKS Node Group Scaling Update Notification&quot;<br>        )<br><br>        # Print the response<br>        print(response)</pre><ul><li>Update the placeholders (&lt;region&gt;, &lt;cluster_name&gt;, &lt;ng-1&gt;, &lt;sns-topic-arn&gt;) with actual values.</li></ul><h3>Step 4: Create 2 EventBridge Rule Schedules for ScaleUp and ScaleDown.</h3><ol><li>On the console, in the navigation pane, choose EventBridge.</li><li>Choose to Create Rule.</li><li>Type Rule Name <strong><em>eks_scale_down</em></strong></li><li>Type Rule Description</li><li>Choose Rule Type ` <strong><em>Schedule</em></strong></li><li>Push Button <strong><em>Continue in EventBridge Scheduler</em></strong></li><li>Next</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*KfnmulZqHy6CzYaB.png" /></figure><p>8. Schedule Pattern</p><p>9. Choose a <strong><em>Recurring Schedule</em></strong> and a <strong><em>Cron-based schedule</em></strong></p><p>10. Define your specific schedule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*D-Tf3QAdFuKJAY8_.png" /></figure><p>11. Once you have set the scheduled time, proceed by pressing the “Next” button.</p><p><strong>For the next step, we need to choose the target service for AWS EventBridge.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*mJONvFVv-d-jVVZA.png" /></figure><p>Choose AWS Lambda then select Functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*GxEUxSFctNzid7g2.png" /></figure><p>Next, Review your Rule, and Create a Schedule. Repeat Step 3 will create a rule for ScaleUP.</p><p>After you add this Up you should be able to see Eventbridge coming up in your Lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*T11-ac1n3lAZEWfE.png" /></figure><p>And after setting up the Eventbridge you should see this weird named Policy under the resource based Policy of your Lambda function which helps Eventbridge to use the Eventbridge rule in which the timings are defined to scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*xHUNyHNT09j7eo5U.png" /></figure><p>If it didn’t came up then you can create on your own and For the Lambda function to know when to get triggered and run the Python function.</p><p>Go to <strong>Configuration Tab </strong>and then Click on <strong>Permissions</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*gTAZONROVVUZj8-x.png" /></figure><p>Then click on <strong>Add Permissions </strong>under <strong>Resource Based Policy.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*UEdU6xIf4eFJVhKq.png" /></figure><p>Then follow the below picture to add up the things in place to have this policy onto your Lambda function required to be triggered by the Eventbridge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*SClFamqpQAgrP-rY.png" /></figure><h3>Workflow of the Whole Setup</h3><p>The automation setup consists of the following key components and workflow:</p><h4>1. Scheduled Execution via AWS EventBridge</h4><ul><li><strong>AWS EventBridge Scheduler</strong> triggers the Lambda functions at predefined intervals.</li><li><strong><em>ScaleUp Function</em></strong><em> is triggered at times when resources are anticipated to be needed (e.g., before peak hours).</em></li><li><strong><em>ScaleDown Function</em></strong><em> is triggered during low-demand periods (e.g., off-peak hours).</em></li><li>The scheduler ensures that the scaling actions occur automatically and without manual intervention.</li></ul><h4>2. Role of Lambda Functions</h4><ul><li><strong>Lambda Functions</strong> are responsible for scaling the EKS cluster’s managed node groups:</li><li><strong><em>ScaleDown Lambda</em></strong><em>:</em></li><li><em>Reduces the number of worker nodes to zero (minimum allowed size set to 0 and maximum to 1).</em></li><li><em>Ideal for cost savings during periods of inactivity.</em></li><li><strong><em>ScaleUp Lambda</em></strong><em>:</em></li><li><em>Increases the number of worker nodes to match the demand.</em></li><li><em>Configures node group sizes based on predefined scaling parameters in the Python script.</em></li><li>Each Lambda function uses the boto3 library to interact with:</li><li><strong><em>AWS EKS</em></strong><em>: To update node group scaling configurations.</em></li><li><strong><em>AWS SNS</em></strong><em>: To send notifications on scaling actions.</em></li></ul><h4>3. Access Control</h4><ul><li>The Lambda functions utilize an <strong>IAM Role</strong> with permissions to:</li><li><em>Access and modify the EKS cluster and its node groups.</em></li><li><em>Publish notifications to an SNS topic for logging and alerting.</em></li></ul><h4>4. Cost Optimization through Scaling</h4><ul><li>When the <strong>ScaleDown Lambda</strong> is triggered:</li><li><em>Reduces the number of worker nodes in the node group to 0.</em></li><li><em>Retains a minimal </em><em>maxSize of 1 as a safeguard (AWS does not allow a </em><em>maxSize of 0).</em></li><li><em>Saves significant costs by halting resource usage during idle periods.</em></li><li>When the <strong>ScaleUp Lambda</strong> is triggered:</li><li><em>Increases the number of worker nodes to predefined values to handle demand.</em></li><li><em>Ensures sufficient capacity during peak operations.</em></li></ul><h3>Conclusion</h3><p>This automated workflow dynamically adjusts EKS worker node groups based on the specified schedule, helping optimize cloud costs while maintaining operational efficiency.</p><h4>Benefits:</h4><ul><li><strong>Cost Savings</strong>: Nodes are scaled down to 0 during off-peak hours.</li><li><strong>Operational Efficiency</strong>: Ensures enough resources during peak demand.</li><li><strong>Automation</strong>: Eliminates manual intervention with EventBridge Scheduler.</li><li><strong>Notifications</strong>: Alerts provide visibility into scaling actions.</li></ul><p>By following this guide, you can implement a cost-effective and efficient scaling solution for your AWS EKS clusters. Feel free to share this workflow with others to help them optimize their cloud expenses.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cd07e7ebd87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying SonarQube on AWS EC2: A Comprehensive Setup Guide]]></title>
            <link>https://medium.com/@pramesh.palkonda18/deploying-sonarqube-on-aws-ec2-a-comprehensive-setup-guide-52150c2d924d?source=rss-30f9cdffca49------2</link>
            <guid isPermaLink="false">https://medium.com/p/52150c2d924d</guid>
            <dc:creator><![CDATA[Pramesh Palkonda]]></dc:creator>
            <pubDate>Wed, 15 May 2024 11:05:12 GMT</pubDate>
            <atom:updated>2024-05-15T11:05:12.854Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*2u3CYxNW7UAC5zpM" /></figure><p>This guide will walk you through installing and configuring SonarQube on an AWS EC2 instance to enhance your software development process with high-quality code.</p><p><strong>Specifications</strong></p><ul><li>Ubuntu: 22.04 / 20.04 LTS</li><li>CPU: 2 vCPU</li><li>Volume: 20 GB</li><li>RAM: 4 GB</li><li>Security Ports (provided below)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*u5MHW7ELNVV1QUCBl8xaQg.png" /></figure><p><strong>Step 1: Ubuntu EC2 Instance: Command-Line Gateway Unlocked</strong></p><ol><li>Connect to your AWS EC2 Ubuntu server using SSH.</li></ol><ul><li>Update package lists and upgrade packages:</li></ul><pre>sudo apt update<br>sudo apt upgrade -y</pre><p><strong>Step 2: Effortless Installation: Java and PostgreSQL Made Simple!</strong></p><ol><li>Install OpenJDK 17:</li></ol><pre>sudo apt install -y openjdk-17-jdk</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*DRlsh8uhpXzvToEgp1V17w.png" /></figure><p>2. Verify Java installation:</p><pre>java -version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*oGF2OQQcxZOtfV0I2TQEFg.png" /></figure><p>3. Install and configure PostgreSQL:</p><ul><li>Add the PostgreSQL repository:</li></ul><pre>sudo sh -c &#39;echo &quot;deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main&quot; /etc/apt/sources.list.d/pgdg.list&#39;</pre><ul><li>Add the PostgreSQL signing key:</li></ul><pre>wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add –</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*gFktxwPBB5pDTpx6BCQh7A.png" /></figure><ul><li>Install PostgreSQL:</li></ul><pre>sudo apt install postgresql postgresql-contrib -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*J8DOBxxWixX911IytV6hfQ.png" /></figure><ul><li>Enable PostgreSQL to start automatically on reboot:</li></ul><pre>sudo systemctl enable postgresql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*ew0-2R2XrLt9nMD0OUYJqQ.png" /></figure><ul><li>Start the database server:</li></ul><pre>sudo systemctl start postgresql</pre><ul><li>Verify the database server status:</li></ul><pre>sudo systemctl status postgresql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*fM5-ld2s_6Hhp6bHCCfwKA.png" /></figure><ul><li>Verify the PostgreSQL version:</li></ul><pre>psql –version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*hAU1_PR8U_fKll0SB6mlOg.png" /></figure><ul><li>Switch to the Postgres user account:</li></ul><pre>sudo -i -u postgres</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ZPOdueFaN2cmutKn9cIhmQ.png" /></figure><p><strong>Step 3: Database Mastery: Crafting Configurations with Elegance!</strong></p><ol><li>Create a new database user:</li></ol><pre>createuser new_user</pre><p><strong>Example:</strong> Create a user named “sona”</p><pre>createuser sona</pre><p>2. Log in to the PostgreSQL database:</p><pre>Psql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*KnJBMruEOYN9flBBSmKB3w.png" /></figure><p>3. Set a strong password for the user (replace my_password with a secure password):</p><pre>ALTER USER [Created_user_name] WITH ENCRYPTED password &#39;my_password&#39;;</pre><p><strong>Example:</strong> Set password for user “sona”</p><pre>ALTER USER sona WITH ENCRYPTED password &#39;Sona#123&#39;;</pre><p>4. Create a database named “sqube” and assign ownership to the “sona” user:</p><pre>CREATE DATABASE [database_name] OWNER [Created_user_name];</pre><p><strong>Example:</strong> Create database named “sqube” owned by user “sona”</p><pre>CREATE DATABASE sqube OWNER sona;</pre><p>5. Grant all privileges on the “sqube” database to the “sona” user:</p><pre>GRANT ALL PRIVILEGES ON DATABASE sqube to sona;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*_1rmBtULYpBN-hgQi7XBgQ.png" /></figure><p>6. Verify the creation of the database:</p><pre>\l</pre><p>7. Verify the creation of the database user:</p><pre>\du</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*UR0xZ9ogeqEXw-6HxQZCmA.png" /></figure><p>8. Exit the PostgreSQL command-line interface:</p><pre>\q</pre><p>9. Return to your non-root sudo user account:</p><pre>exit</pre><p><strong>Step 4: Empower Your Development: Downloading and Installing SonarQube</strong></p><ol><li>Install the zip utility:</li></ol><pre>sudo apt install zip -y</pre><p>2. Download the latest SonarQube distribution files from the official download page (<a href="https://www.sonarsource.com/products/sonarqube/downloads/">Download SonarQube</a>).</p><p>Here, we’ll install SonarQube 10.4 Community Edition.</p><pre>sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.4.1.88267.zip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*F1xFx36ensU5nUWPaxpyfw.png" /></figure><p>3. Unzip the downloaded file using the following command:</p><pre>sudo unzip sonarqube-10.4.1.88267.zip</pre><p>4. Move the unzipped files to the /opt/sonarqube directory using the following command:</p><pre>sudo mv sonarqube-10.4.1.88267 sonarqube<br>sudo mv sonarqube /opt/</pre><p><strong>Step 5 : Setting Up SonarQube: Adding Group and User</strong></p><ol><li>Create a dedicated user and group for SonarQube, ensuring it cannot run as the root user.</li></ol><p>For example, you can use the following commands to create a user and group named “sona”:</p><pre>sudo groupadd sona<br>sudo useradd -d /opt/sonarqube -g sona sona</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*DgmiqF7dlEOnkleLc93dfQ.png" /></figure><p>2. Grant the “sona” user access to the /opt/sonarqube directory using the following command:</p><pre>sudo chown -R sona:sona /opt/sonarqube</pre><p><strong>Step 6 : Fine-Tuning SonarQube: Configuring for Peak Performance</strong></p><ol><li>Edit the SonarQube configuration file located at /opt/sonarqube/conf/sonar.properties.</li></ol><pre>sudo nano /opt/sonarqube/conf/sonar.properties</pre><p>2. Uncomment the following lines in the SonarQube configuration file (/opt/sonarqube/conf/sonar.properties) and add the database user and password you created:</p><pre>sonar.jdbc.username=sona<br>sonar.jdbc.password=Sona#123</pre><p>3. Below these lines, add the following line to specify the JDBC URL:</p><pre>sonar.jdbc.url=jdbc:postgresql://localhost:5432/sqube</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*JRD6gz6ouPpaRtdyvlsClg.png" /></figure><p>4. Replace “sona” with your database username, “Sona#123” with your database password, and “sqube” with your database name.</p><p>5. Save and exit the sonar.properties file.</p><p>6. To edit the SonarQube script file, use the following command:</p><pre>sudo nano /opt/sonarqube/bin/linux-x86-64/sonar.sh</pre><p>7. Add the following line to the SonarQube script file (/opt/sonarqube/bin/linux-x86–64/sonar.sh) to specify the user to run SonarQube as:</p><pre>RUN_AS_USER=sona</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*s_SJuhvxWHjGCZGqGyN-2Q.png" /></figure><p>Replace “sona” with the name of the user you created earlier.</p><p>8. Save and exit the sonar.sh file.</p><p><strong>Step 7 : Streamlining SonarQube: Setting Up a systemd Service</strong></p><ol><li>To create a systemd service file for SonarQube, use the following steps:</li></ol><p>2. Create a new service file using a text editor:</p><pre>sudo nano /etc/systemd/system/sonar.service</pre><p>3. Add the following content to the file:</p><pre>[Unit]<br>Description=SonarQube service<br>After=syslog.target network.target<br>[Service]<br>Type=forking<br>ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start<br>ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop<br>User=sona<br>Group=sona<br>Restart=always<br>LimitNOFILE=65536<br>LimitNPROC=4096<br>[Install]<br>WantedBy=multi-user.target</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*dc0CjwRj2LqqPIectBIazg.png" /></figure><p>Make sure to replace “User=sona” and “Group=sona” with the appropriate values you have created for your SonarQube installation.</p><p>4. Save and close the file.</p><p>Reload the systemd sonar to apply the changes:</p><pre>sudo systemctl enable sonar</pre><p>5. Enable the SonarQube service to start at boot:</p><pre>sudo systemctl start sonar</pre><p>6. ) Now, you can start the SonarQube service using the following command:</p><pre>sudo systemctl status sonar</pre><p><strong>Step 8 : Enhancing Performance: Modifying Kernel System Limits</strong></p><p>a) To ensure SonarQube functions correctly with Elasticsearch, you’ll need to make some adjustments to the system defaults.</p><p>b) To edit the sysctl configuration file, use the following command:</p><pre>sudo nano /etc/sysctl.conf</pre><p>c) This file controls various kernel parameters.</p><p>d) Add the following lines to the sysctl configuration file (/etc/sysctl.conf):</p><pre>vm.max_map_count=262144<br>fs.file-max=65536<br>ulimit -n 65536<br>ulimit -u 4096</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*HhR8UplDbk3m5ieSrr9Adw.png" /></figure><p>e) Save and exit the sysctl configuration file.</p><p>f) To apply the changes, reboot the system using the following command:</p><pre>sudo reboot</pre><p><strong>Step 9: Exploring SonarQube: Accessing the Web Interface</strong></p><p>Access SonarQube in a web browser by entering your <strong>server’s IP </strong>address followed by port <strong>9000</strong>. For example, <a href="http://ip:9000/"><strong>http://IP:9000</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*QvkZvfxGZk9URuTT7eHkQg.png" /></figure><p>The default username and password are both “admin”. To change the password in SonarQube, follow these steps:</p><ol><li>Log in to SonarQube using the username “<strong>admin</strong>” and password “<strong>admin</strong>”.</li><li>Once logged in, SonarQube will prompt you to change your password. Enter the current password “<strong>admin</strong>” and then enter your new password twice as prompted.</li><li>Click on the “<strong>Change password</strong>” button to save your new password.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*fVSvxhp7rfWFABE74UzOhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*zQYf2nTTp3r6eaygBk0QxA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52150c2d924d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate Web Deploys: A Powerful Trio — Jenkins, Ansible, & Web Server]]></title>
            <link>https://medium.com/@pramesh.palkonda18/automate-web-deploys-a-powerful-trio-jenkins-ansible-web-server-cb7fb23d28e3?source=rss-30f9cdffca49------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb7fb23d28e3</guid>
            <dc:creator><![CDATA[Pramesh Palkonda]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 09:30:10 GMT</pubDate>
            <atom:updated>2024-05-07T09:25:35.400Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automate Web Deploys: A Powerful Trio — Jenkins, Ansible, &amp; Web Server</h3><p><strong>Here’s an explanation of Git, GitHub, Jenkins, and Ansible:</strong></p><p><strong>Git:</strong></p><ul><li>A <strong>version control system</strong> that tracks changes in computer code and other projects.</li><li>Allows you to revert to previous versions, collaborate with others, and see the history of changes.</li><li>Used locally on your computer.</li></ul><p><strong>GitHub:</strong></p><ul><li>A popular <strong>hosting platform for Git repositories</strong>.</li><li>Provides features for social coding, version control, and issue tracking.</li><li>Stores your Git repositories in the cloud, making them accessible from anywhere.</li></ul><p><strong>Jenkins:</strong></p><ul><li>An <strong>open-source automation server</strong>.</li><li>Used to automate tasks, such as building, testing, and deploying your code.</li><li>Can integrate with Git to automatically trigger builds when there are changes in the repository.</li></ul><p><strong>Ansible:</strong></p><ul><li>An <strong>IT automation tool</strong> that uses a simple language (YAML) to configure and manage software deployments.</li><li>Allows you to automate tasks like provisioning servers, configuring software, and deploying applications.</li><li>Often used in conjunction with Jenkins to automate deployments triggered by Git changes.</li></ul><p><strong>Launch a New Instances as a Developer, Jenkins, Ansible and WebServer:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*EHGW7ImeJ6vlY73Onah1yQ.png" /></figure><p><strong>Step 1: Developer Server:</strong></p><ol><li>Generate SSH keys using</li></ol><pre>ssh-keygen</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*6w0-5JVez_ZfiDQNaX3nCg.png" /></figure><p>2. Copy the public key and paste it into the GitHub Repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*5R1WCn3JCOHGToxp1k1erw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*IssnGLWc1v7J19kpE9De6Q.png" /></figure><p>3. Set a root password using <strong>passwd root</strong>.</p><pre>passwd root</pre><p>4. Enable PasswordAuthentication and PermitRootLogin by editing.</p><pre>vi /etc/ssh/sshd_config</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*RzaJJL7VyFOd2bzbrIf9lg.png" /></figure><p>5. Start the sshd service using .</p><pre>systemctl start sshd</pre><p>6. Install git packages using .</p><pre>yum install git -y</pre><p>7. Create a directory using <strong>mkdir directory-name</strong>.</p><p>8. Navigate inside the directory using <strong>cd directory-name</strong>.</p><p>9. Clone the repository using <strong>git clone </strong><a href="https://github.com/palkondagithub/NewJenkins.git."><strong>https://github.com/palkondagithub/NewJenkins.git</strong>.</a></p><p>10. Make changes to the code as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*d4ijvrpKPb4opU0887GLyQ.png" /></figure><p>11. Add the changes using.</p><pre>git add index.html</pre><p>12. Commit the changes using .</p><pre>git commit -m &quot;testcommit&quot; index.html</pre><p>13. Rename the branch to main using .</p><pre>git branch -M main</pre><p>14. Push the changes to the repository using .</p><pre>git push -u origin main</pre><p><strong>Step 2: Jenkins Server:</strong></p><ol><li>Follow the steps provided in the link: <a href="https://www.jenkins.io/doc/tutorials/tutorial-for-installing-jenkins-on-AWS/">Tutorial for installing Jenkins on AWS</a>.</li><li>Generate SSH keys using .</li></ol><pre>ssh-keygen</pre><ol><li>Establish communication between Jenkins and Ansible by running</li></ol><pre>ssh-copy-id root@172.31.47.106 (replace 172.31.47.106 with the private IP of the Ansible instance).</pre><ol><li>Set a root password using <strong>passwd root</strong>.</li><li>Enable PasswordAuthentication and PermitRootLogin by editing <strong>/etc/ssh/sshd_config</strong>.</li><li>Restart sshd service using <strong>systemctl restart sshd</strong>.</li><li>Install git using <strong>yum install git -y</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*MLNL3uC8O5h7SX9abOn9Fw.png" /></figure><p><strong>Step 3: Ansible Server:</strong></p><ol><li>Install Ansible by running</li></ol><pre>sudo amazon-linux-extras install ansible2</pre><ol><li>Edit the Ansible hosts file , add the private IP of the web server under the WEBSERVER section.</li></ol><pre>vi /etc/ansible/hosts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*oFhsQrEPgN423vhLap2i3g.png" /></figure><p>3. Generate SSH keys using</p><pre>ssh-keygen</pre><p>4. Establish communication between Ansible and the web server.</p><pre>ssh-copy-id root@172.31.40.15 (replace 172.31.40.15 with the private IP of the web server)</pre><p>5. Set a root password using</p><pre>passwd root</pre><p>6. Enable PasswordAuthentication and PermitRootLogin by editing.</p><pre>vi/etc/ssh/sshd_config</pre><p>7. Restart sshd service using <strong>systemctl restart sshd</strong>.</p><p>8. Create and navigate to the <strong>/opt/srccode</strong> directory using:</p><pre>bash<br>mkdir srccode<br>cd /opt/srccode</pre><p>9. Create a playbook file <strong>playbook.yml</strong> and add the following content:</p><pre>-hosts: all<br>tasks:<br>- copy:<br>src: /opt/index.html<br>dest: /var/www/html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*XA5ncPTloPR2tba06IDORA.png" /></figure><p><strong>Step 4: Webserver:</strong></p><ol><li>Install Apache web server.</li><li>Start and enable Apache service using:</li></ol><pre>bash<br>yum install httpd -y<br>systemctl start httpd<br>systemctl enable httpd</pre><p>3. Set a root password using <strong>passwd root</strong>.</p><p>4. Enable PasswordAuthentication and PermitRootLogin by editing</p><pre>vi /etc/ssh/sshd_config</pre><p>5. Restart sshd service using</p><pre>systemctl restart sshd</pre><p><strong>Jenkins Application Setup:</strong></p><ol><li>Go to <strong>Manage Jenkins</strong> → <strong>Manage Plugins</strong>, search for <strong>ssh</strong>, select <strong>Publish Over SSH</strong>, and save.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*MsIAHrGI6zcmhGcg-eeHPg.png" /></figure><p>2. Again go to <strong>Manage Jenkins</strong> → <strong>Configure System</strong>, add SSH Server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*njYROsG2D31JepW5ATa7CQ.png" /></figure><ul><li>Name: Jenkins Server Private IP</li><li>Username: root</li><li>Advanced → Password (use the root password created on the server)</li></ul><p>3. Add SSH Server for Ansible instance in the same way.</p><p>4. Go to project <strong>Configure</strong>, select <strong>Git</strong>.</p><p>5. Add Git repository and add the following build step and also specify the branch main:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*KC_s1MQ-Xg6CpV89V5ymqg.png" /></figure><p><strong>→ rsync -avh /var/lib/jenkins/workspace/NewJenkins/* root@172.31.47.106:/opt/* (change the private IP)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*uy_BvnAk6yz8j1ykFIDZ-A.png" /></figure><p>6. Configure SSH server in the <strong>Advanced</strong> section, select <strong>Verbose output in console</strong>, and save.</p><p>7. Check if the code is fetched on the Jenkins server.</p><p>8. Again in <strong>Configure</strong>, go to <strong>Post-build Actions</strong>, select <strong>Send build artifacts over SSH</strong>, choose Ansible, and execute the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*SljweoPJeCmdyasY_nlABA.png" /></figure><p>bash</p><p>→ <strong>ansible-playbook /srccode/playbook.yml</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*sqW2CHfrSNnt8neGFRg0xg.png" /></figure><p>9. Build the project.</p><p>10. Configure <strong>Build Triggers</strong>, select <strong>GitHub hook trigger for GITScmpolling</strong> for automation without manual intervention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*kHioLXyjfyTAya4Bs-r5ww.png" /></figure><p><strong>GitHub Webhooks Setting Steps:</strong></p><ol><li>Go to GitHub settings.</li><li>Select <strong>Webhooks</strong>, add webhook:</li></ol><ul><li>Payload URL: Jenkins URL (ip:8080)</li><li><a href="http://65.0.129.139:8080/github-webhook"><strong>http://65.0.129.139:8080/github-webhook</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*7AZiMtHQEm5xxN4SwNDTjQ.png" /></figure><p>3. For the secret, go to Jenkins → <strong>Configure</strong> → <strong>API token</strong> → Generate, then copy and paste it into secrets, and select <strong>application.json</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*jNkgbvZAJjlO8gpbZiQaMA.png" /></figure><p>4. Add webhook.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb7fb23d28e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>