<?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 Pavan Kumar Srinivasulu on Medium]]></title>
        <description><![CDATA[Stories by Pavan Kumar Srinivasulu on Medium]]></description>
        <link>https://medium.com/@pavankumarrs099?source=rss-368d364cdd19------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-7vzkoksE6VQy01lX8Wx1w.jpeg</url>
            <title>Stories by Pavan Kumar Srinivasulu on Medium</title>
            <link>https://medium.com/@pavankumarrs099?source=rss-368d364cdd19------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:17:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pavankumarrs099/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automating EC2 Deployments with AWS CodePipeline and GitHub Integration]]></title>
            <link>https://medium.com/@pavankumarrs099/automating-ec2-deployments-with-aws-codepipeline-and-github-integration-d4e31d08ff31?source=rss-368d364cdd19------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4e31d08ff31</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Pavan Kumar Srinivasulu]]></dc:creator>
            <pubDate>Sun, 04 May 2025 08:53:12 GMT</pubDate>
            <atom:updated>2025-06-27T02:12:17.261Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*kmzByxGilDDpADfLP2AMpQ.png" /></figure><p>Setting up an automated CI/CD pipeline is an essential step for any developer looking to streamline code deployment. In this blog post, I’ll walk you through how I successfully created a CodePipeline in AWS to deploy changes pushed to a GitHub repository directly to an EC2 instance using AWS CodeDeploy.</p><h3>Overview</h3><p>We will automate the process of:</p><ul><li>Monitoring a GitHub repo for code changes</li><li>Deploying code to an EC2 instance using CodeDeploy</li><li>Running the application/script automatically</li></ul><p>This setup eliminates manual deployments and ensures consistency across environments.</p><h3>Flow Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NroVvBUOKZ8eww6AYDsFVw.png" /></figure><h3>IAM Setup</h3><h4>1. Attach IAM Policies to User</h4><p>Navigate to IAM → Users → Select Your User → Add Permissions:</p><ul><li><strong>AWSCodePipelineFullAccess</strong></li><li><strong>AWSCodeCommitFullAccess</strong></li></ul><h4>2. Create IAM Roles</h4><p><strong>For EC2:</strong></p><ul><li>Go to IAM → Roles → Create Role</li><li>Select <strong>EC2</strong>, attach <strong>AmazonS3FullAccess</strong></li><li>Name:ec2-s3-codedeploy-test (name as you wish)</li></ul><p><strong>For CodeDeploy:</strong></p><ul><li>IAM → Roles → Create Role</li><li>Select <strong>CodeDeploy</strong>, use default permissions that already exists</li><li>Name: code-deploy-role-test (name as you wish)</li></ul><h4>3. Custom Policy for EC2</h4><p>Create a custom policy (from AWS docs) and attach it to the EC2 IAM role.</p><ul><li>Name it ec2-code-deploy-policy-test (name as you wish)</li><li>Add this JSON :</li></ul><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Action&quot;: [<br>                &quot;s3:Get*&quot;,<br>                &quot;s3:List*&quot;<br>            ],<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Resource&quot;: &quot;*&quot;<br>        }<br>    ]<br>}</pre><p>To restrict for certain S3 bucket in order to secure things, follow the document <a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-create-iam-instance-profile.html#getting-started-create-iam-instance-profile-console">here</a></p><h3>Launching the EC2 Instance</h3><ul><li>Go to EC2 → Launch Instance</li><li>Select Amazon Linux (anything you wish)</li><li>Name itec2-codedeploy-test (name as you wish)</li><li>Attach the role: ec2-s3-codedeploy-test (created above)</li><li>Use a security group that allows SSH</li><li>Add this <strong>User Data</strong> (installs CodeDeploy agent):</li></ul><pre>#!/bin/bash<br>sudo yum -y update<br>sudo yum -y install ruby<br>sudo yum install wget<br>cd /home/ec2-user<br>wget https://aws-codedeploy-us-west-2.s3.amazonaws.com/latest/install<br>chmod +x ./install<br>sudo ./install auto</pre><p>Note: Use the correct region bucket from <a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/resource-kit.html#resource-kit-bucket-names">AWS resource kit buckets</a>.</p><h3>CodeDeploy Setup</h3><h4>1. Create Application</h4><ul><li>CodeDeploy → Applications → Create Application</li><li>Name: code-deploy-test (name as you wish)</li><li>Compute type: EC2/On-Premises</li></ul><h4>2. Create Deployment Group</h4><ul><li>Inside the application, click “Create Deployment Group”</li><li>Name: code-deployment-group-test (name as you wish)</li><li>Select <strong>In-place</strong> deployment</li><li>Disable Load Balancer</li><li>Use EC2 tag key-value pair (<strong><em>should match EC2 instance</em></strong>)</li></ul><h3>CodePipeline Setup</h3><h4>1. Create a Pipeline</h4><ul><li>CodePipeline → Create Pipeline</li><li>Name: code-pipeline-testing (name as you wish)</li><li>Select <strong>New service role</strong></li></ul><h4>2. Source Stage</h4><ul><li>Provider: GitHub (via OAuth App)</li><li>Connect your GitHub account</li><li>A prompt will pop up and confirm the connection.</li><li>Once the GitHub is authenticated here, select the Repository name and branch name you want to trigger.</li></ul><h4>3. Skip Build Stage</h4><ul><li>We don’t need build for this use case.</li></ul><h4>4. Deploy Stage</h4><ul><li>Provider: AWS CodeDeploy</li><li>Region: Your EC2 region</li><li>Application: code-deploy-test (created above)</li><li>Deployment Group: code-deployment-group-test (created above)</li></ul><h3>Project Structure on GitHub</h3><p>Ensure your GitHub repo has these at the root:</p><pre>/<br>├── appspec.yml<br>├── run_script.sh<br>└── EmailSend.py</pre><p>I’ve developed a sample Python script named EmailSend.py that sends email notifications to a specified recipient using the AWS SES (Simple Email Service). The recipient details are defined within the script itself. The script is as below. You have to install boto3 and configuire AWS credentials on the EC2 instance before running this script. This script is juts an example, it can be your hosted application or your product too.</p><p>References: <a href="https://aws.amazon.com/ses/">SES documentation</a> | <a href="https://boto3.amazonaws.com/v1/documentation/api/1.37.0/reference/services/ses.html">Boto3 SES Documentation</a></p><pre>import boto3<br>from datetime import datetime<br><br># Initialize the SES client<br>ses = boto3.client(&#39;ses&#39;, region_name=&#39;us-east-1&#39;)<br><br># Sender and receiver emails (both must be verified in SES if in sandbox)<br>sender_email = &quot;&lt;add sender email here&gt;&quot;<br>recipient_email = &quot;&lt;add recipient email here&gt;&quot; <br><br># Current datetime<br>now = datetime.now()<br><br># Email subject and body<br>subject = &#39;University | Your attendance report as on {}&#39;.format(now)<br>body_text = (<br>    &quot;Hello!\n\n&quot;<br>    &quot;This is to let you know that your attendance is 86% as on {}.\n\n&quot;<br>    &quot;Thanks,\nSanta Clara University&quot;.format(now.strftime(&#39;%Y-%m-%d&#39;))<br>)<br><br># Send the email<br>response = ses.send_email(<br>    Source=sender_email,<br>    Destination={<br>        &#39;ToAddresses&#39;: [<br>            recipient_email,<br>        ],<br>    },<br>    Message={<br>        &#39;Subject&#39;: {<br>            &#39;Data&#39;: subject,<br>        },<br>        &#39;Body&#39;: {<br>            &#39;Text&#39;: {<br>                &#39;Data&#39;: body_text,<br>            },<br>        }<br>    }<br>)<br><br><br>print(&quot;Email sent to {0}! Message ID:{1}&quot;.format(recipient_email, response[&#39;MessageId&#39;]))</pre><p>Return to CodePipeline and click <strong>“Release change”</strong>.</p><p><strong>appspec.yml</strong> (for CodeDeploy):</p><pre>version: 0.0<br>os: linux<br>files:<br>  - source: /<br>    destination: /home/ec2-user/EmailApp<br>hooks:<br>  AfterInstall:<br>    - location: run_script.sh<br>      timeout: 300<br>      runas: ec2-user</pre><p><strong>run_script.sh</strong>:</p><pre>#!/bin/bash<br>cd /home/ec2-user/EmailApp<br>python3 EmailSend.py &gt; output.txt 2&gt;&amp;1</pre><p>Make sure run_script.sh is executable:</p><pre>chmod +x run_script.sh</pre><p>Now, each and everytime you make some changes and push the code onto Github, the codepipeline is automatically triggered and is copied to the EC2 instance.</p><pre>git add run_script.sh<br>git commit -m &quot;Make it executable&quot;<br>git push</pre><h3>Output, CodeDeploy success</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*w1EGBW9-v-TAwn_aVEYHbQ.png" /></figure><h3>Troubleshooting &amp; Tips</h3><p>🔴<strong>Rollback in CodeDeploy?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*lNvNQgTasQv8m9acf2IklQ.png" /></figure><p>CodeDeploy reverted rollback = The actual deployment due to an issue during or after install.</p><p>This typically happens when:</p><ul><li>A <strong>lifecycle hook</strong> (e.g., AfterInstall) <strong>fails</strong> (e.g., run_script.sh crashes)</li><li>The deployment <strong>completed</strong>, but something <strong>inside the app</strong> caused CodeDeploy to <strong>auto-rollback</strong> to the previous version</li><li>You have <strong>automatic rollback enabled</strong> (which is default)</li><li>Check the logs: /opt/codedeploy-agent/deployment-root/deployment-logs/</li></ul><p>🔴<strong>Script not found?</strong></p><p>Ensure relative paths and correct file names in appspec.yml</p><p>🔴<strong>Permission issues?</strong> Update IAM roles (especially for GetApplicationRevision)</p><p>🔴<strong>Latest Action execution message error</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CU69KLPZfhWBfg1qV6huYw.png" /></figure><p>Fix: Add missing permissions to CodePipeline IAM Role</p><p>Step 1:</p><ol><li>Go to<strong> AWS Console → IAM → Roles</strong></li><li>Search for: AWSCodePipelineServiceRole-us-east-1-code-pipeline-test</li><li>Click on the role</li></ol><p>Step 2:</p><p>Attach Inline Policy for CodeDeploy Access</p><p>Click <strong>“Add permissions” → “Create inline policy”</strong>, then:</p><ol><li>Choose <strong>Service</strong>: CodeDeploy</li><li>Actions: check if these are present, else add them:</li></ol><ul><li>GetApplication</li><li>GetApplicationRevision</li><li>RegisterApplicationRevision</li><li>CreateDeployment</li><li>GetDeployment</li><li>GetDeploymentConfig</li></ul><p>3. Resources: Choose <strong>All resources</strong> (or specify your app ARN)</p><p>4. Click <strong>Next → Review → Name it </strong><strong>AllowCodeDeployAccess → Create policy</strong></p><p>Step 3:</p><p>Retry the Pipeline:</p><p>Return to CodePipeline and click <strong>“Release change”</strong>.</p><p>🔴<strong>Tag mismatch?</strong> The deploymentgroup EC2 tag must match instance</p><h3>Success!</h3><p>Once all components are set up correctly, pushing a change to GitHub will:</p><ul><li>Trigger CodePipeline</li><li>Deploy the app to EC2 via CodeDeploy</li><li>Run the script automatically</li></ul><p>No manual intervention. Just code, push, and deploy.</p><h3>Conclusion</h3><p>This setup forms a solid CI/CD foundation using AWS and GitHub. It’s scalable, automatable, and highly customizable. Whether you’re deploying scripts, web apps, or services — this pipeline can grow with you.</p><p>Happy deploying!!!</p><p>Thanks for reading!</p><p>Pavan Kumar Srinivasulu | <a href="https://www.linkedin.com/in/p4v4n/">LinkedIn</a> | Email: pavankumarrs099@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4e31d08ff31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring GitHub Repository Access with Shell Script in DevOps Workflows]]></title>
            <link>https://medium.com/@pavankumarrs099/monitoring-github-repository-access-with-shell-script-in-devops-workflows-b8966bade03c?source=rss-368d364cdd19------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8966bade03c</guid>
            <category><![CDATA[shell-script]]></category>
            <category><![CDATA[site-reliability-engineer]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Pavan Kumar Srinivasulu]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 01:20:26 GMT</pubDate>
            <atom:updated>2025-04-21T01:23:50.063Z</atom:updated>
            <content:encoded><![CDATA[<p>How a simple Bash script can enhance visibility, security, and collaboration in modern DevOps pipelines</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ly5XNqlTJSygYwJBpkN8XQ.png" /></figure><h3>Introduction</h3><p>In any software development environment, especially in fast-moving DevOps teams , <strong>knowing who has access to your codebase is critical</strong>. Whether it’s open-source collaboration, internal microservices, or infrastructure-as-code, you need clear visibility over your GitHub repositories’ access control.</p><p>This article introduces a simple but powerful <strong>shell script</strong> that queries GitHub’s API to list all users with <strong>read access</strong> to a given repository. We’ll walk through how it’s built, how to set it up on an Amazon Linux machine, and why it matters.</p><h3>The Use Case: Why Should You Care?</h3><p>Let’s imagine you’re a DevOps engineer managing multiple GitHub repositories across teams. You’re responsible for:</p><ul><li>Ensuring only authorized users have access</li><li>Auditing contributor access as part of compliance checks</li><li>Automating reporting on repo-level permissions</li></ul><p>In a scenario where there are many users, <strong>manual verification isn’t scalable</strong>. Instead, we automate the audit process using GitHub APIs + shell scripting.</p><h3>What This Script Does</h3><ul><li>Accepts a GitHub repo_owner and repo_name as command-line arguments</li><li>Authenticates via a GitHub personal access token</li><li>Calls the GitHub API to list all <strong>collaborators with at least read access</strong></li><li>Outputs them in a clean, readable format</li></ul><pre>#!/bin/bash<br><br># Exit on error<br>set -e<br><br># GitHub API base URL<br>API_URL=&quot;https://api.github.com&quot;<br><br># Check for required arguments<br>if [ $# -ne 2 ]; then<br>    echo &quot;Usage: $0 &lt;repo_owner&gt; &lt;repo_name&gt;&quot;<br>    exit 1<br>fi<br><br># GitHub username and token must be set in environment<br>if [[ -z &quot;$username&quot; || -z &quot;$token&quot; ]]; then<br>    echo &quot;Error: Please export your GitHub username and token:&quot;<br>    echo &quot;  export username=your_username&quot;<br>    echo &quot;  export token=your_token&quot;<br>    exit 1<br>fi<br><br>REPO_OWNER=$1<br>REPO_NAME=$2<br><br># Function to make a GET request to the GitHub API<br>function github_api_get {<br>    local endpoint=&quot;$1&quot;<br>    curl -s -u &quot;${username}:${token}&quot; &quot;${API_URL}/${endpoint}&quot;<br>}<br><br># Function to list users with read access to the repository<br>function list_users_with_read_access {<br>    local endpoint=&quot;repos/${REPO_OWNER}/${REPO_NAME}/collaborators&quot;<br><br>    echo &quot;Listing users with read access to ${REPO_OWNER}/${REPO_NAME}...&quot;<br><br>    collaborators=$(github_api_get &quot;$endpoint&quot; | jq -r &#39;.[] | select(.permissions.pull == true) | .login&#39;)<br><br>    if [[ -z &quot;$collaborators&quot; ]]; then<br>        echo &quot;No users with read access found for ${REPO_OWNER}/${REPO_NAME}.&quot;<br>    else<br>        echo &quot;Users with read access:&quot;<br>        echo &quot;$collaborators&quot;<br>    fi<br>}<br><br># Run the function<br>list_users_with_read_access</pre><h3>Script Breakdown</h3><pre>#!/bin/bash<br>set -e</pre><p>We start by telling the script to <strong>exit immediately on any error</strong>, ensuring robust execution.</p><pre>if [ $# -ne 2 ]; then<br>    echo &quot;Usage: $0 &lt;repo_owner&gt; &lt;repo_name&gt;&quot;<br>    exit 1<br>fi</pre><p>This ensures the user provides both required inputs, repository owner and repository name.</p><pre>if [[ -z &quot;$username&quot; || -z &quot;$token&quot; ]]; then<br>    echo &quot;Error: Please export your GitHub username and token:&quot;<br>    echo &quot;  export username=your_username&quot;<br>    echo &quot;  export token=your_token&quot;<br>    exit 1<br>fi</pre><p>We <strong>validate credentials</strong> from environment variables, which is safer than hardcoding.</p><pre>function github_api_get {<br>    local endpoint=&quot;$1&quot;<br>    curl -s -u &quot;${username}:${token}&quot; &quot;${API_URL}/${endpoint}&quot;<br>}</pre><p>Reusable function to hit any GitHub API endpoint using curl.</p><pre>function list_users_with_read_access {<br>    local endpoint=&quot;repos/${REPO_OWNER}/${REPO_NAME}/collaborators&quot;<br>    collaborators=$(github_api_get &quot;$endpoint&quot; | jq -r &#39;.[] | select(.permissions.pull == true) | .login&#39;)<br>    ...<br>}</pre><p>Uses the GitHub REST API to list <strong>collaborators</strong>, filters them by permissions.pull == true using jq, and prints only those with read access.</p><h3>How to Run This Script</h3><ol><li><strong>Set your GitHub credentials</strong> (use a personal access token with repo scope):</li></ol><pre>export username=YOUR-USERNAME-HERE<br>export token=YOUR-PERSONAL-TOKEN-HERE</pre><p><strong>2. Run the script with owner and repo</strong>:</p><pre>./list_contributors.sh YOUR-OWNER-NAME-HERE YOUR-REPO-NAME-HERE</pre><p>Output:</p><pre>Listing users with read access to octocat/Hello-World...<br>Users with read access:<br>abc<br>xyz<br>pqr</pre><p>Additionally you can easily schedule this script via <strong>cron</strong>, <strong>GitHub Actions</strong>, or integrate it with <strong>CloudWatch</strong> for alerting on access changes and automatically update a file with the list of users for the time set in cron.</p><p>Links to refer:</p><p><a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens">To create a GitHub API Token</a></p><p><a href="https://docs.github.com/en/rest?apiVersion=2022-11-28">GitHub REST API Documentation</a></p><p>Thanks for reading!</p><p>— Pavan Kumar Srinivasulu</p><p><a href="https://www.linkedin.com/in/p4v4n/">https://www.linkedin.com/in/p4v4n/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8966bade03c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Static to Dynamic: Automating ConfigMap to Deployment Sync in Kubernetes using a Go-Based…]]></title>
            <link>https://medium.com/@pavankumarrs099/from-static-to-dynamic-automating-configmap-to-deployment-sync-in-kubernetes-using-a-go-based-fbcffcdc295c?source=rss-368d364cdd19------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbcffcdc295c</guid>
            <category><![CDATA[configmap]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[environment-variables]]></category>
            <dc:creator><![CDATA[Pavan Kumar Srinivasulu]]></dc:creator>
            <pubDate>Tue, 15 Apr 2025 08:57:07 GMT</pubDate>
            <atom:updated>2025-04-15T08:57:54.522Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Static to Dynamic: Automating ConfigMap to Deployment Sync in Kubernetes using a Go-Based Operator</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_OdbwkDzTS0QG6_qctwruQ.png" /></figure><p>In modern cloud-native environments, teams often deploy microservices to Kubernetes clusters where configuration is passed through environment variables. These environment variables usually live in ConfigMaps or Secrets and are baked into pod templates during deployment. However, changing them usually requires a manual rollout restart, causing unnecessary toil and risk.</p><p>In this article, I share a real-world implementation of a Kubernetes-native automation solution where I created a custom operator in Go. This operator watches a ConfigMap and dynamically updates the environment variables of a running Deployment, making the updates live without requiring any manual pod restarts or image rebuilds. This approach is especially beneficial for teams practicing GitOps, looking to minimize manual configuration drift, and improve rollout efficiency.</p><h3>Article Overview</h3><p>The goal is to build a two-part system:</p><ol><li><strong>Go HTTP Server</strong>: A lightweight HTTP service deployed in Kubernetes that prints its environment variables at runtime.</li><li><strong>Go-Based Operator</strong>: A controller that watches a Kubernetes ConfigMap and dynamically patches environment variables into a live Deployment.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fsUaZwpdG48TD-Eec4zHMw.png" /></figure><p>This setup simulates real-world use cases where dynamic config changes need to be reflected immediately, such as updating feature flags, toggling logging levels, or adjusting service-specific settings.</p><h3>Architecture Overview</h3><ul><li><strong>ConfigMap</strong>: Holds deployment-specific environment variables in JSON format.</li><li><strong>Operator Pod</strong>: Written in Go using client-go. Watches the ConfigMap for changes</li><li><strong>Target Deployment (go-http)</strong>: A simple web server that shows current env vars.</li><li><strong>Service</strong>: Exposes the pod so you can query it via browser.</li></ul><p><strong>The flow:</strong></p><ol><li>ConfigMap is updated</li><li>Operator detects the change</li><li>It fetches the Deployment and patches its pod template with new env vars</li><li>Kubernetes rolls out a new pod with updated configuration</li></ol><h3>Directory Structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*Wl0B-LI-t-en6ULyOA6Adg.jpeg" /></figure><h3>Pre requisites</h3><p>This project is using a Windows Powershell.</p><p>Install Go — <a href="https://go.dev/dl/">https://go.dev/dl/</a> , run as administrator</p><pre>go version</pre><p>Install chocolatey to install kubectl — <a href="https://chocolatey.org/install">https://chocolatey.org/install</a>, make sure you run this command on power shell running powershell as administrator.</p><p>To install kubectl -</p><pre>choco install kubernetes-cli<br>kubectl version --client</pre><p>Install Docker desktop. Go to settings inside Docker desktop and allow kubernetes to run.</p><pre>docker version</pre><p>Install Minikube — <a href="https://minikube.sigs.k8s.io/docs/start/?arch=%2Fwindows%2Fx86-64%2Fstable%2F.exe+download">https://minikube.sigs.k8s.io/docs/start/?arch=%2Fwindows%2Fx86-64%2Fstable%2F.exe+download</a></p><pre>minikube version<br>minikube start --driver=docker</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*0Kw7jl9xXNKj_DrO.png" /></figure><h3>Build and Deploy the Go HTTP Server in Kubernetes</h3><p>Make sure you are inside <strong>go-http-server</strong> directory.</p><h4>Build Docker image:</h4><p>Make sure Minikube uses your local Docker image:</p><p>Dockerfile</p><pre>FROM golang:1.24<br><br>WORKDIR /app<br>COPY . .<br><br>RUN go build -o app .<br><br>CMD [&quot;./app&quot;]</pre><p>deployment.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: go-http<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: go-http<br>  template:<br>    metadata:<br>      labels:<br>        app: go-http<br>    spec:<br>      containers:<br>      - name: go-http<br>        image: go-http-env<br>        imagePullPolicy: Never<br>        ports:<br>        - containerPort: 8080<br>        env:<br>        - name: INITIAL_ENV<br>          value: &quot;hello&quot;<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: go-http<br>spec:<br>  selector:<br>    app: go-http<br>  ports:<br>    - protocol: TCP<br>      port: 80<br>      targetPort: 8080</pre><p>main.go</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;net/http&quot;<br> &quot;os&quot;<br>)<br><br>func handler(w http.ResponseWriter, r *http.Request) {<br> for _, e := range os.Environ() {<br>  fmt.Fprintf(w, &quot;%s\n&quot;, e)<br> }<br>}<br><br>func main() {<br> http.HandleFunc(&quot;/&quot;, handler)<br> fmt.Println(&quot;Listening on :8080&quot;)<br> http.ListenAndServe(&quot;:8080&quot;, nil)<br>}</pre><h4>Commands to build docker image</h4><pre>minikube docker-env</pre><pre>&amp; minikube -p minikube docker-env | Invoke-Expression  //Run this command to ensure you&#39;re inside Minikube&#39;s Docker context:</pre><pre>docker build -t go-http-env .</pre><h3>Deploy to Kubernetes using configmap.yaml</h3><pre>kubectl apply -f deployment.yaml</pre><pre>kubectl get pods</pre><pre>minikube service go-http --url</pre><p>Now try pasting the URL on to the browser, you must see set of predefined Environment Variable.</p><h3>Building a Kubernetes Operator in Go</h3><p>Make sure you are inside <strong>operator </strong>directory.</p><p>Dockerfile</p><pre># Build stage<br>FROM golang:1.24 AS builder<br><br>WORKDIR /app<br>COPY . .<br><br># Build the Go binary for Linux explicitly<br>RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o operator .<br><br># Final stage<br>FROM alpine:latest<br>RUN apk --no-cache add ca-certificates<br><br>WORKDIR /root/<br>COPY --from=builder /app/operator .<br><br>CMD [&quot;./operator&quot;]</pre><p>deployment.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: env-operator<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: env-operator<br>  template:<br>    metadata:<br>      labels:<br>        app: env-operator<br>    spec:<br>      serviceAccountName: default<br>      containers:<br>      - name: operator<br>        image: env-operator<br>        imagePullPolicy: Never</pre><p>main.go</p><pre>package main<br><br>import (<br> &quot;context&quot;<br> &quot;encoding/json&quot;<br> &quot;fmt&quot;<br> &quot;time&quot;<br>    metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;<br> &quot;k8s.io/client-go/kubernetes&quot;<br> &quot;k8s.io/client-go/rest&quot;<br> v1 &quot;k8s.io/api/core/v1&quot;<br>)<br><br>type EnvVar struct {<br> Name  string `json:&quot;name&quot;`<br> Value string `json:&quot;value&quot;`<br>}<br><br>func main() {<br> // Load in-cluster configuration<br> config, err := rest.InClusterConfig()<br> if err != nil {<br>  fmt.Println(&quot;Failed to load in-cluster config:&quot;, err)<br>  return<br> }<br><br> // Create Kubernetes clientset<br> clientset, err := kubernetes.NewForConfig(config)<br> if err != nil {<br>  fmt.Println(&quot;Failed to create clientset:&quot;, err)<br>  return<br> }<br><br> fmt.Println(&quot;Operator started successfully. Watching ConfigMap &#39;environment&#39;...&quot;)<br><br> // Continuous sync loop<br> for {<br>  err := syncEnvConfig(clientset)<br>  if err != nil {<br>   fmt.Println(&quot;Sync error:&quot;, err)<br>  }<br>  time.Sleep(10 * time.Second)<br> }<br>}<br><br>func syncEnvConfig(clientset *kubernetes.Clientset) error {<br> // to get the ConfigMap named &quot;environment&quot; from the default namespace<br> cm, err := clientset.CoreV1().ConfigMaps(&quot;default&quot;).Get(context.TODO(), &quot;environment&quot;, metav1.GetOptions{})<br> if err != nil {<br>  return fmt.Errorf(&quot;could not read configmap: %v&quot;, err)<br> }<br><br> // Iterate over each key in the configmap<br> for deployName, raw := range cm.Data {<br>  var envs []EnvVar<br>  if err := json.Unmarshal([]byte(raw), &amp;envs); err != nil {<br>   fmt.Printf(&quot;Failed to parse JSON for &#39;%s&#39;: %v\n&quot;, deployName, err)<br>   continue<br>  }<br><br>  // Get the Deployment matching the key<br>  deploy, err := clientset.AppsV1().Deployments(&quot;default&quot;).Get(context.TODO(), deployName, metav1.GetOptions{})<br>  if err != nil {<br>   fmt.Printf(&quot;Deployment &#39;%s&#39; not found: %v\n&quot;, deployName, err)<br>   continue<br>  }<br><br>  // Update env vars in first container<br>  container := &amp;deploy.Spec.Template.Spec.Containers[0]<br>  for _, newEnv := range envs {<br>   found := false<br>   for i, existing := range container.Env {<br>    if existing.Name == newEnv.Name {<br>     container.Env[i].Value = newEnv.Value<br>     found = true<br>     break<br>    }<br>   }<br>   if !found {<br>    container.Env = append(container.Env, v1.EnvVar{Name: newEnv.Name, Value: newEnv.Value})<br>   }<br>  }<br><br>  // Apply the updated deployment<br>  _, err = clientset.AppsV1().Deployments(&quot;default&quot;).Update(context.TODO(), deploy, metav1.UpdateOptions{})<br>  if err != nil {<br>   fmt.Printf(&quot;Failed to update deployment &#39;%s&#39;: %v\n&quot;, deployName, err)<br>  } else {<br>   fmt.Printf(&quot;Updated deployment: %s\n&quot;, deployName)<br>  }<br> }<br> return nil<br>}</pre><p>rbac.yaml</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br>kind: Role<br>metadata:<br>  namespace: default<br>  name: configmap-reader<br>rules:<br>- apiGroups: [&quot;&quot;]<br>  resources: [&quot;configmaps&quot;]<br>  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;, &quot;update&quot;]<br>- apiGroups: [&quot;apps&quot;]<br>  resources: [&quot;deployments&quot;]<br>  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;, &quot;update&quot;]<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: RoleBinding<br>metadata:<br>  name: read-configmap-binding<br>  namespace: default<br>subjects:<br>- kind: ServiceAccount<br>  name: default<br>  namespace: default<br>roleRef:<br>  kind: Role<br>  name: configmap-reader<br>  apiGroup: rbac.authorization.k8s.io</pre><h4>Initialise Go Module</h4><pre>go mod init operator</pre><h4>Install Kubernetes go client</h4><pre>go get k8s.io/client-go@v0.26.3<br>go get k8s.io/apimachinery@v0.26.3</pre><p>The above installation might take some time, give it some time.</p><pre>go mod tidy</pre><p>This will create required dependencies (especially for client-go)</p><h4>Make sure it’s the minikube docker</h4><pre>&amp; minikube -p minikube docker-env | Invoke-Expression</pre><pre>docker build -t env-operator .</pre><pre>kubectl apply -f deployment.yaml</pre><h4>Apply configmap.yaml and rbac.yaml</h4><pre>kubectl apply -f configmap.yaml<br> <br>kubectl apply -f rbac.yaml</pre><h4>Check for pods status</h4><pre>kubectl get pods</pre><h4>See the dynamic changes in configmap.yaml reflecting on the URL</h4><pre>minikube service go-http --url</pre><p>Open the URL in browser and see the actual env variables.</p><p>You can also see it on the console using,</p><pre>kubectl exec -it deploy/go-http -- printenv</pre><p>Now dynamically edit the config file,</p><pre>kubectl edit configmap environment //edit, save and quit</pre><p>Now open the url in browser, each and every time you change/edit the variables in configmap, it changes dynamically on browser as well.</p><h3>Errors Encountered &amp; Fixes</h3><ul><li><strong>ErrImagePull</strong>: Fixed by setting imagePullPolicy: Never and building in Minikube.</li><li><strong>RBAC Denied</strong>: Gave permissions via Role and RoleBinding.</li><li><strong>ConfigMap change not detected</strong>: Solved by editing in-cluster with kubectl edit instead of applying same unchanged file.</li><li><strong>Git push conflict</strong>: Fixed via git pull --rebase.</li></ul><h3>Conclusion</h3><p>This project demonstrates how to:</p><ul><li>Build an HTTP microservice</li><li>Write a real Kubernetes operator using Go and client-go</li><li>Use RBAC to control access to cluster resources</li><li>Implement a dynamic ConfigMap-to-Deployment sync mechanism</li></ul><p>It’s a foundational automation that many teams can build on to power internal tools, reliability pipelines, and zero-downtime config management.</p><p>Feel free to explore the code, raise issues, or fork the project on GitHub: <a href="https://github.com/P4v4n5/k8sAutomationUsingGo.git">https://github.com/P4v4n5/k8sAutomationUsingGo.git</a></p><p>Thanks for reading!</p><p>— Pavan Kumar Srinivasulu</p><p><a href="https://www.linkedin.com/in/p4v4n/">https://www.linkedin.com/in/p4v4n/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbcffcdc295c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Guide: Installing Docker Desktop, WSL - Ubuntu, and Deploying Apps with Kubernetes and…]]></title>
            <link>https://medium.com/@pavankumarrs099/step-by-step-guide-installing-docker-desktop-wsl-ubuntu-and-deploying-apps-with-kubernetes-and-7fefddca32fb?source=rss-368d364cdd19------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fefddca32fb</guid>
            <dc:creator><![CDATA[Pavan Kumar Srinivasulu]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 04:27:30 GMT</pubDate>
            <atom:updated>2024-11-25T04:50:07.360Z</atom:updated>
            <content:encoded><![CDATA[<h3>Step-by-Step Guide: Installing Docker Desktop, WSL - Ubuntu, and Deploying Apps with Kubernetes and Helm</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzT7VED31e4DyLmEU5A80A.png" /></figure><p>If you’re considering setting up a local development environment for developing, building, and deploying your applications, you’re in the right place. This is a great way to start the Kubernetes development on your Windows machine. The following guide provides a simple approach to running and deploying applications locally without using any cloud platforms.</p><p>Below is a step-by-step guide on how to install Docker Desktop on Windows, configure Ubuntu on WSL, enable Kubernetes in Docker Desktop, and deploy a simple Python application using Helm.</p><p>By the end of this guide, you will have a powerful local development environment that can containerize applications with Docker, deploy them on Kubernetes, and manage the deployments efficiently with Helm.</p><h4><strong>Prerequisites:</strong></h4><ul><li>Windows 10/11 (ensure you’re on a version that supports WSL 2)</li><li>Basic knowledge of Docker, WSL, and Kubernetes</li><li>Administrator access on Windows</li><li>Docker Hub account (optional, if you plan to push your image)</li></ul><h4>STEP 1: Installing WSL</h4><p>WSL allows running a full fledged Linux distribution or application on Windows. To make use of it, make sure that the WSL is enabled in your Windows features or to check if WSL is installed, you can run the below command onthe Windows PowerShell:</p><pre>wsl --version</pre><p>Now that you have WSL, navigate to the Windows AppStore search for “Ubuntu”, and install the latest one among various other distributions, it should be available free for you to install. After installing Ubuntu, its terminal will launch automatically, prompting you to set a username and password. Provide the requested credentials to complete the initial setup of your Ubuntu WSL environment. That is it!! you now have an Ubuntu distribution inside Windows!</p><h4><strong>STEP 2: Installing Docker Desktop</strong></h4><p>It’s a straight forward approach, just navigate to the browser search for “Download Docker desktop” and then download and install your respective Windows version.</p><p>Now, you have to enable WSL and Kubernetes on the Docker desktop. To Enable WSL, navigate to settings → Resources → WSL integrations → then select your WSL, Ex: Ubuntu-22.04</p><p>Next, navigate to Resources → Builds → Kubernetes → then enable it. It takes some time for a WSL to integrate with Kubernetes and Docker Desktop.</p><p>Then, to check if this is working properly, bring up your WSL and run the below commands.</p><pre>docker ps //to list running docker containers<br>kubectl get ns // to list all namespace in a cluster</pre><h4>STEP 3: Deploy the script using Kubernetes and Helm</h4><p>Let the directory structure be as follows, you can name it as per your requirements:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*zeoX963wubUZ_WhbQwu3Pg.png" /></figure><p>STEP 3.1: Create your python script and save it inside a directory, in this case, PythonDockersK8s/</p><p>STEP 3.2: Create a Dockerfile in PythonDockersK8s/ as follows;</p><pre># Dockerfile<br>FROM python:3.9-slim<br><br>WORKDIR /app<br>COPY python_test.py /app/python_test.py<br><br>CMD [&quot;python&quot;, &quot;python_test.py&quot;]</pre><ul><li><strong>FROM python:3.9-slim</strong>: Use a lightweight Python image.</li><li><strong>WORKDIR /app</strong>: Set the working directory.</li><li><strong>COPY python_test.py</strong>: Copy your script to the container.</li><li><strong>CMD</strong>: Command to run the script.</li></ul><p>STEP 3.3: Build the Docker image. Navigate to PythonDockersK8s/ and build the Docker image using following command:</p><pre>docker build python_test .<br>docker run python_test // to test the image is present or not</pre><p>STEP 3.4: Push the Docker Image onto your Docker Hub</p><pre>docker login // login to your docker hub account<br>docker tag python_test &lt;your-dockerhub-username&gt;/python_test:latest<br>docker push &lt;your-dockerhub-username&gt;/python_test:latest</pre><p>STEP 3.5: Create Helm Chart</p><p>Initialize the chart: Navigate to PythonDockersK8s/ and execute the following command:</p><pre>helm create helm-chart</pre><p>Edit chart.yaml as per your requirements: Update all the metadata inside PythonDockersK8s/helm-chart/chart.yaml or you can rewrite the whole as below:</p><pre>apiVersion: v2<br>name: python_test<br>description: A Helm chart to run a test Python script as a CronJob<br>version: 1.0.0</pre><p>Edit values.yaml as per your requirements: Navigate to PythonDockersK8s/helm-chart/values.yaml, it’s better to rewrite as below with your requirements:</p><pre>image:<br>  repository: &lt;your-docker-username&gt;/python_test<br>  tag: &quot;latest&quot;<br>schedule: &quot;0 8 * * *&quot;  # Cron schedule for 8 AM daily</pre><p>Add cronjob: Naviagte to PythonDockersK8s/helm-chart/templates/cronjob.yaml and rewrite as below per your requirements, it is ok to keep the below values as well:</p><pre>apiVersion: batch/v1<br>kind: CronJob<br>metadata:<br>  name: {{ .Release.Name }}<br>spec:<br>  schedule: {{ .Values.schedule }}<br>  jobTemplate:<br>    spec:<br>      template:<br>        spec:<br>          containers:<br>          - name: python-script<br>            image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag }}&quot;<br>            imagePullPolicy: IfNotPresent<br>            resources:<br>              limits:<br>                memory: &quot;128Mi&quot;<br>                cpu: &quot;500m&quot;<br>              requests:<br>                memory: &quot;64Mi&quot;<br>                cpu: &quot;250m&quot;<br>          restartPolicy: OnFailure</pre><p>STEP 3.6: Deploy with Helm</p><p>Navigate to PythonDockersK8s/helm-chart and execute the following commands:</p><pre>helm package .<br>helm install python-test //install helm chart in your Kubernetes cluster<br>kubectl get cronjobs // to check if the cronjob is created or not<br>kubectl get pods<br>kubectl logs &lt;pod_name&gt; // to debug</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*-v2PI7ZLC3iH1nBRbv3M-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*ltPRwaOGPteHSy48MKAjJA.png" /></figure><p>Make sure your container is up and running on your Docker Desktop, also once again check you have an active helm-chart. Once this is all done, your script will automatically execute at the scheduled time. If your Python application is interactive, such as a script that generates and sends a report or an email, you should receive the output (e.g., an email) around the specified time. This happens because the CronJob triggers your script at the designated schedule, ensuring it runs to produce the intended output.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fefddca32fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>