<?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 An K on Medium]]></title>
        <description><![CDATA[Stories by An K on Medium]]></description>
        <link>https://medium.com/@ansukumari?source=rss-3554b102d5c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OeJNdKd9VFC-G4oklIzdBw.jpeg</url>
            <title>Stories by An K on Medium</title>
            <link>https://medium.com/@ansukumari?source=rss-3554b102d5c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:01:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ansukumari/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[4 things I’ll tell my younger self when I was starting my first tech job]]></title>
            <link>https://medium.com/geekculture/4-things-ill-tell-my-younger-self-when-i-was-starting-my-first-tech-job-432cde030cb2?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/432cde030cb2</guid>
            <category><![CDATA[freshers]]></category>
            <category><![CDATA[sofware-engineering]]></category>
            <category><![CDATA[tech-jobs]]></category>
            <category><![CDATA[faang]]></category>
            <category><![CDATA[tech-career]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Fri, 21 Jul 2023 11:16:57 GMT</pubDate>
            <atom:updated>2023-07-21T11:16:57.938Z</atom:updated>
            <content:encoded><![CDATA[<h4>FAANG or startup, where to begin?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQCzYq2ar5aPludANBNR1w.png" /><figcaption>Me working from home :P</figcaption></figure><p><em>First, a little bit about me.</em></p><p>Hi, my name is Ansu, I work as a Software Engineer in a big company. I have 4 years of experience, I graduated from a tier 3 college in Delhi, India and currently live in Amsterdam, Netherlands. I have switched 4 jobs in past 4 years and I’ve worked in big corporations and small — <em>from FAANG to startup </em>— and if I were to start all over again, <em>these are the things I’ll tell my younger self</em> who was drowning in confusion at the time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CgoKTvSYjSYGiK_N" /><figcaption>Photo by <a href="https://unsplash.com/@slidebean?utm_source=medium&amp;utm_medium=referral">Slidebean</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>1. “What should I start with” — startup or MNC?</h4><p>If you want to be good at your core job, join a startup first and then an MNC /FAANG— <em>if you wish to join one</em>— a startup will help you learn latest tech in it’s raw form, experience it first hand even on production and give you many responsibilities.</p><p>An MNC is usually very slow at adapting new technologies or giving you any major responsibilities and usually have their own wrapper around major technologies like git and AWS; so you’ll never know what the native tech looks like, you’ll only know how to work with it using your company’s portal.</p><p>However, if you want to learn to be organised with your work, learn time management, have good work-life balance, and make highly informed decisions, you should start with an MNC; <em>but not switching to multiple companies might be a mistake</em> because you will not be exposed to multiple patterns and just stuck with the ones that was thrown at you first.</p><blockquote>So, choose your preference and start with it, but don’t stick to it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CDepaVtzYcn13PsJ" /><figcaption>Photo by <a href="https://unsplash.com/@element5digital?utm_source=medium&amp;utm_medium=referral">Element5 Digital</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>2. Which is more valuable — learning new technologies or experience in ongoing ones?</h4><p>I’m a forever learner and will always root for learning more and more no matter where in your career you are. Learning is very important — <em>I’d argue more than experience</em>— no matter if you have 20 years of experience in pascal you still have very limited options today, on the other hand, even if you have only internship experience with python you can find many opportunities and enhance your skill, if not find the best job.</p><p>That being said, you won’t be considered for a Senior Software Engineer role because you studied tech for 5 more years than your peers who have 5 years of experience. <strong>No amount of learning can be good enough to replace experience, so don’t take it for granted</strong>. No matter how long you studied — <em>and this includes external courses like a python crash course or a scaler data course </em>— <strong>when you step out of a college you are a fresher </strong>and experience speaks for itself.</p><blockquote>So, learning is important and you should focus on it, just don’t think of it as a replacement for experience.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N_ItQWRx6sGjz8DI" /><figcaption>Photo by <a href="https://unsplash.com/@dan__burton?utm_source=medium&amp;utm_medium=referral">Dan Burton</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>3. Is this really your honeymoon period?</h4><p>When I joined my first corporate I was told by everyone, <em>“this is your honeymoon period, you have to work all your life anyway so enjoy this time”</em> and it’s okay to chill, don’t overindulge yourself, and if you’re joining an MNC like I did you might also feel discouraged and a lack of passion because you won’t be able to <em>“just start coding”</em> with how slow things move in terms of actual work and how many hoops you’ll have to jump to submit an actual code change.</p><p>I’m not exaggerating when I say it took us a 3 month cycle of changes, approvals and testing in multiple environments, by multiple teams, to submit changes to production that were as simple as <em>“change the value of x to x+1”</em>, BUT — <em>and it’s a big but</em> — there are so many other things you can learn in an MNC that you must know in order to advance your career and this is a great place to learn.</p><p>Try to learn the existing architecture of your current system, try to learn how the approval process works and why are there so many discussions surrounded with the smallest changes. It’ll teach you what factors are important in real life while building a product, like security is one of the top priorities of big companies building any product but when you were working on a project in college, security around it was probably the thing that got least consideration.</p><p>In fair honesty, my first job was in fintech and even a change like replacing x with x+1 — <em>if done incorrectly, or at an incorrect place, or is not atomic</em> — could lead to a production error causing losses, sometimes in millions, because I was in the commercial banking team — meaning, commercial companies like amazon and flipkart would send entire day’s transaction in one file which could be a huge transaction.</p><blockquote>So as a fresher you might not understand there are many other aspects of a product than just the code and understanding that will help you make better decisions and consequently be a better software engineer — because <strong>engineering is more than just programming</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wZhSa9ol9QS9Q2kp" /><figcaption>Photo by <a href="https://unsplash.com/@micheile?utm_source=medium&amp;utm_medium=referral">micheile henderson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>4. Money doesn’t matter, but your value does!</h4><p>Just as you start earning, the first thing you’ll hear from everyone is <em>“this shouldn’t be the time you focus on earning, your focus should be learning”</em>, and I agree, as someone who values learning greatly I don’t value money nearly enough — but (<em>I would use double t to emphasise how important this but is, but that means something else</em> :P) — there’s two things wrong with not reaching for a higher paying job —</p><p>First, and no one has ever talked about this, <strong>with high price comes high quality</strong>. When you are paid good for a job, chances are all your teammates are also paid equally well — <em>or even better </em>— which means (maybe not 100% of the time) they are really smart; and the satisfaction that comes when you collaborate with smart peers is heavenly.</p><p>As the saying goes, <strong>if you’re the smartest in the room, you’re in the wrong room</strong>.</p><p>Working with really smart people is something you’d never experience in school or even in college — <em>not on a large level at least </em>— it’s something that encourages you to work, that challenges you to think outside the box, that complements your work and probably is the best form of learning. So <strong>don’t tell me that I have to choose between either learning or earning, because I choose both</strong>.</p><p>On the contrary, working with peers who don’t understand the simplest solution can be frustrating, leads to a lot of stress — <em>and politics in corporate world is real </em>— so you might find yourself in a situation where you’re the only one concerned with the product or the feature and everyone else is just trying to impress the leadership and that, for me, brings a lot of dissatisfaction at work .</p><blockquote>So if you, <em>who once was a very enthusiastic coder</em>, are currently working in a tech job and are always frustrated, it might be time for you to switch to a smarter team.</blockquote><p>Second, if you are putting out work that is worth more than what you are being paid, that simply means your employer doesn’t value your work, your knowledge or your experience enough to compensate you correctly. If your expectations don’t align with what you receive, it translates to <em>the value of the work you are putting out is not aligned with how valuable it is being perceived</em>; <strong>you’re not just underpaid, you’re under-recognised</strong>.</p><blockquote>So, stop undervaluing yourself and surround yourself with people who value you.</blockquote><p>To sum it all up — choose the skillset you want to work on and decide the company accordingly, always have a learning mindset and seek to work with smart people who value you equally!</p><p>Hope you enjoyed the article and learned something new, feel free to share your feedback or experience or any opinion you have on any of the points in the comments and share it with your friends or juniors who are starting their journey in tech. Looking forward to hear your thoughts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=432cde030cb2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/4-things-ill-tell-my-younger-self-when-i-was-starting-my-first-tech-job-432cde030cb2">4 things I’ll tell my younger self when I was starting my first tech job</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement CI/CD pipeline on AWS EC2 server using GitHub Actions]]></title>
            <link>https://medium.com/geekculture/implement-ci-cd-pipeline-on-aws-ec2-server-using-github-actions-9a2cf2d767bf?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a2cf2d767bf</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Sat, 08 Apr 2023 15:32:09 GMT</pubDate>
            <atom:updated>2023-04-08T15:32:09.084Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Let’s say you have an EC2 instance running your application, on which you take a pull from a GitHub repo to update the application every time there’s a change.</em></p><p>That is the <strong>prerequisite</strong> for this blog, <strong>have a running server on EC2</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EC6HDIUAOa4BnGYBIovRlQ.jpeg" /><figcaption>Manual Deployment — Without CI/CD</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lAKriHEqv8AexODinciYJw.jpeg" /><figcaption>Automated Deployment — with CI/CD</figcaption></figure><p>Now, let’s change that procedure and automate it in 3 easy steps:</p><ol><li>Create AWS CodeDeploy</li><li>Create a workflow in your repo using GitHub Actions</li><li>Create a script for your CodeDeploy to start the server.</li></ol><h3>1. Create AWS CodeDeploy</h3><p><em>To setup CodeDeploy, you need 3 things — The CodeDeploy Application, The Application Deployment Group, and an IAM role that CodeDeploy can assume to access the EC2 instances.</em></p><h4>Create an application</h4><p>Navigate to the CodeDeploy Console, on the left side pane click on “<strong>Applications</strong>” under “Deploy” section and select “Create Application”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9GyN31XrvBdLSbWEoz-_A.png" /></figure><p>Then provide your application name and use “<strong>EC2/On-premises</strong>” platform.</p><h4>Create CodeDeploy IAM Role</h4><p>Head on to the IAM section and create a new role</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cWE4RV-y_QkULEQd2O8X5A.png" /></figure><p>Use “<strong>AWS Service</strong>” for trusted entity and select “<strong>CodeDeploy</strong>” from dropdown for “Use Case”.</p><p>Click next and use the attched “AWSCodeDeployRole” policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBYY2Xe0nyxRhfoVO_36rA.png" /></figure><p>Give a name to the role and save it.</p><h4>Create a Deployment Group</h4><p>Go to application you created earlier and click on “Create deployment group”.</p><p>Provide a name to your deployment group and select the role we created earlier for the service role.</p><p>You can leave the deployment type at default settings. Select “Amazon EC2 instances” for targets and use tags to identify them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*is2goW0KX4NPO3O1TQdwcw.png" /></figure><p>Select “<strong>Never</strong>” in Agent config, we will install CodeDeploy Agent on our system manually for this project.</p><p>You can select “OneAtATime” deployment setting and enable Load Balancing <strong>if you have more than one instance</strong>, otherwise uncheck the load balancing option.</p><p>Then hit the create deployment group button.</p><h3>2. Create GitHub workflow</h3><p><em>Okay, I created this workflow using my custom GitHub Actions and a python script — because i didn’t know much of yaml or GO language at the time I implemented this setup — so I’ll share the same method here because that is a tested setup. However, there’s no reason why you can’t write everything that the python file do in the workflow file itself without the hassle of creating your own action.</em></p><p>Refer <a href="https://github.com/ansukumari/ci-cd"><strong>this</strong></a> repo to add the python script and copy the github-action-script folder for a custom GitHub Action python script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_VrHLVfS11dQKqLpt7mQQ.png" /></figure><p>In the deployCode.py file, make sure the links to send notification are correctly mentioned, and replace the &lt;organization-name/repo-name&gt; text with your repo details.</p><p>Then copy the deploy workflow and choose the trigger you want in your repo. Make sure to change the <strong>application name</strong> to the CodeDeploy Application you had created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h8ckJ6Bwg4I4xHVgVhaX2Q.png" /></figure><p>Create repo secrets in your GitHub repo and your workflow script is ready!</p><h3>3. Create CodeDeploy Script</h3><p><em>Now that CodeDeploy can put your repo on your server, it also needs to be able to run a startup script. For this you need to install CodeDeploy on your EC2 instance, attach IAM role to EC2 instance that it can assume to access CodeDeploy service, and the script that CodeDeploy will use to run the install script.</em></p><h4>Create IAM Role</h4><p>Just like we did above, create a new role — Use “<strong>AWS Service</strong>” for trusted entity and select “<strong>EC2</strong>” for “Use Case”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_GgNP00TtJ7tLD-Mz-gzVg.png" /></figure><p>Click next and use the attched “AmazonEC2RoleforAWSCodeDeploy” policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2V6rMXJjbPoyW29w4poxWw.png" /></figure><p>Then, name the EC2 role and save it.</p><p>Now attach this role to your EC2 server — navigate to EC2 console, select your instance(s) and select “<strong>Modify IAM role</strong>” in the top right corner as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rf3_47_tQyW4qJFSzJgGEw.png" /></figure><p>Attach the newly created role and click on “Update IAM role”.</p><p>Once attached, <strong>restart the instance</strong> to make sure it can assume the role.</p><h4>Install CodeDeploy Agent</h4><p>Use this <a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-cli.html">doc</a> to install CodeDeploy Agent on your server depending on the type of server you are using.</p><h4>Write CodeDeploy script</h4><p>Create a file appspec.yml in the root location of your directory. This file will inform the CodeDeploy Agent of the commands you want to run during deployment. Learn more about appspec file <a href="https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file.html">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-eX2Vi4ApL5PJ-XpM9Kaw.png" /></figure><p>Refer <a href="https://github.com/ansukumari/ci-cd/"><strong>this</strong></a> repo to see all the files we need to create, the appspec.yml is present in the root directory and it’s helper scripts are present in codedeploy-scripts dir. Make sure you copy both scripts.</p><p>You can create a startup-script on the EC2 instance and trigger that script via CodeDeploy Agent using the “start_server” script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Efw2ssS16slHm_-rz6UVcA.png" /></figure><h3>Final step</h3><p>Finally, create a deployment manually in your deployment group to connect your GitHub to CodeDeploy. Once connected, it can be run using the GitHub workflow.</p><p><em>Congratulations! Your CI/CD setup is ready.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a2cf2d767bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/implement-ci-cd-pipeline-on-aws-ec2-server-using-github-actions-9a2cf2d767bf">Implement CI/CD pipeline on AWS EC2 server using GitHub Actions</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Increase volume of an EC2 instance]]></title>
            <link>https://ansukumari.medium.com/increase-volume-of-an-ec2-instance-49c006a77038?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/49c006a77038</guid>
            <category><![CDATA[growpart]]></category>
            <category><![CDATA[ec2-volume]]></category>
            <category><![CDATA[ec2-disk-full]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Thu, 23 Feb 2023 17:29:46 GMT</pubDate>
            <atom:updated>2023-02-23T17:29:46.611Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Step 1 — Increase the storage volume:</strong></h3><ol><li>Select the <strong>instance</strong> that needs the volume to be increased and click on the <strong>storage</strong> tab from instance configuration.</li><li>Click on the <strong>volume ID</strong> attached to the instance, then select the volume you need to edit and select ‘<strong>Modify volume</strong>’ from ‘Actions’ dropdown.</li><li>Once on the modify page, edit the volume size to the desired capacity then click on ‘Modify’ button.</li></ol><h3><strong>Step 2 — Increase the disk partition:</strong></h3><ol><li>SSH into the instance whose volume we just increased and run $ df -hT to check the size of the partition. It should reflect the previous volume size, to check the partition and their sizes run $ lsblk command. The disk should reflect the updated volume but the partition should reflect the previous volume as of now.</li><li>Use the growpart command to extend the partition: $ sudo growpart /dev/nvme0n1 1. Notice the 1 in the end after space which is the partition number.</li><li>Now resize the partition and root volume using the below commands.</li></ol><pre>$ sudo resize2fs /dev/nvme0n1p1<br>$ sudo resize2fs /dev/nvme1n1</pre><p><strong>NOTE: </strong>above uses NVMe EBS volumes and ext4 file system. For any further information on commands, refer this article: <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html#extend-file-system">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html#extend-file-system</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49c006a77038" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Provide EC2 server access to users]]></title>
            <link>https://ansukumari.medium.com/provide-ec2-server-access-to-users-160107f1ba6d?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/160107f1ba6d</guid>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[multi-user-access]]></category>
            <category><![CDATA[private-server]]></category>
            <category><![CDATA[ec2-access]]></category>
            <category><![CDATA[bastion]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Thu, 23 Feb 2023 15:13:03 GMT</pubDate>
            <atom:updated>2023-02-23T15:13:03.423Z</atom:updated>
            <content:encoded><![CDATA[<h3>Providing bastion server access</h3><ol><li>SSH into bastion server with ubuntu user by running the below command.</li></ol><pre>ssh -i &quot;location/of/pem/file&quot; ubuntu@&lt;bastion-public-ip&gt;</pre><p>2. Create file add_user.sh with the below content:</p><pre>#!/bin/bash<br><br># Add a new user<br>adduser --disabled-password --gecos &quot;&quot; $USERNAME<br><br># Create a home directory for new user<br>mkdir /home/$USERNAME/.ssh<br><br># Add new users key to authorized keys<br>echo &quot;$PUBLIC_KEY&quot; &gt;&gt; /home/$USERNAME/.ssh/authorized_keys<br><br># Change ownership of new users ssh directory from root to user<br>chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh<br><br># Restart the ssh daemon<br>service sshd restart</pre><p>3. Set variables USERNAME and PUBLIC_KEY and run the add_user.sh script as shown below.</p><p>USERNAME — the name of user to create on bastion<br>PUBLIC_KEY — .pub SSH key present on local system of the user, if SSH key is not present you can create one by running the ssh-keygen command on local.</p><pre>sudo USERNAME=ansu PUBLIC_KEY=&#39;ssh-rsa AAD/xxxxxxxx/hBGDjsAJc8so810= ansu@Ansus-MacBook-Pro.local&#39; sh add_user.sh</pre><h3>Giving access to private servers</h3><ol><li>SSH into bastion server with ubuntu user by running the below command.</li></ol><pre>ssh -i &quot;location/of/pem/file&quot; ubuntu@&lt;bastion-public-ip&gt;</pre><p>2. Find the user’s SSH key on bastion, whom you have to give access to, in the .ssh/id_rsa.pub file in user’s home folder.</p><pre># run the following command from user&#39;s system<br>ssh username@&lt;bastion-public-ip&gt;<br>cat ~/.ssh/id_rsa.pub</pre><p>3. SSH into the private server, for which you need to give the access, as ubuntu user using the ssh key present on bastion server.</p><pre># run on bastion server as ubuntu user<br>sudo su -<br>ssh -i &quot;location/of/pem/file&quot; ubuntu@&lt;private server&#39;s private IP&gt;</pre><p>4. Append the user’s SSH key, found in step 2, in ~/.ssh/authorized_keys file, using the below command.</p><pre># run on private server<br>echo &quot;&lt;SSH pub key&gt;&quot; &gt;&gt; .ssh/authorized_keys</pre><p>5. Finally, user can access the private server using the jump server.</p><pre># on user&#39;s local system<br>ssh &lt;bastion-public-ip&gt; # if local username is same as bastion username, no need to add username before bastion IP<br><br># on bastion as user<br>ssh ubuntu@&lt;private server&#39;s private IP&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=160107f1ba6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create production Kubernetes with AWS: A step-by-step guide]]></title>
            <link>https://medium.com/geekculture/create-production-kubernetes-with-aws-a-step-by-step-guide-d40fc30066b8?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d40fc30066b8</guid>
            <category><![CDATA[production-design]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[workflow]]></category>
            <category><![CDATA[aws-eks]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Sat, 21 Jan 2023 17:02:26 GMT</pubDate>
            <atom:updated>2023-03-13T09:30:50.649Z</atom:updated>
            <content:encoded><![CDATA[<p>We want to have the below setup where your production code is being deployed to AWS EKS (Elastic Kubernetes Service) which sits behind an internet facing AWS Network Load Balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lw5Ix0ySXoQxdTkXlTAy5w.jpeg" /></figure><h4>Prerequisites:</h4><ol><li>It is being assumed that the Github repo that stores the code is already present and is containerized, if not, we need to containerize the application to have it run on k8. Refer <a href="https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-i-introduction-e9904fbc27ac">this</a> guide to get started with Docker &amp; Kubernetes, and containerize your application.</li><li>You have your domain name configured to route to an AWS CloudFront Distribution. This is because traffic can only directly be routed to NLB using an A record and most Domain Registrars do not support a Domain Name value for A records. The AWS NLB does not provide an IP address for you to add to your A record but only gives a domain name ending at amazon.com. However, if your Registrar gives you an option to add domain name for A record value, you do not have to add the AWS CloudFront.</li><li>aws cli and eksctl are installed on your device.</li></ol><h3>Following are the steps to create the above described setup:</h3><h4>1. Create the EKS cluster</h4><ol><li>We’ll start by creating<strong> <em>two private</em></strong><em> </em><strong><em>subnets</em></strong> dedicated for EKS so we have enough IPs for our pods. Run the following command twice to create two subnets.</li></ol><pre>aws ec2 create-subnet \<br>    --vpc-id &lt;vpc-id&gt; \<br>    --cidr-block &lt;cidr&gt;/22 \<br>    --availability-zone &lt;aws-region&gt;<br><br>aws ec2 create-tags \<br>    --resources &lt;subnet-id-of-above-created-subnet&gt; \<br>    --tags Key=Name,Value=eks-private-subnet-1a Key=kubernetes.io/role/internal-elb,Value=1</pre><p>2. Create the <strong><em>cluster</em></strong> without node groups by running the below command.</p><pre>eksctl create cluster \<br>    --name load-test-eks \<br>    --region &lt;aws-region&gt; \<br>    --version 1.22 \<br>    --vpc-private-subnets &lt;subnet-id-1&gt;,&lt;subnet-id-2&gt; \<br>    --without-nodegroup</pre><p>3. Create two <strong><em>node groups</em></strong> for the EKS — on-demand and spot, by running the below command.</p><pre>aws eks create-nodegroup \<br>    --cluster-name load-test-eks \<br>    --nodegroup-name ondemand-node-group \<br>    --subnets &lt;subnet-id-1&gt; &lt;subnet-id-2&gt; \<br>    --instance-types t4g.large \<br>    --ami-type AL2_ARM_64 \<br>    --capacity-type ON_DEMAND \<br>    --node-role &lt;node-group-role-arn&gt;<br><br><br>aws eks create-nodegroup \<br>    --cluster-name load-test-eks \<br>    --nodegroup-name spot-node-group \<br>    --subnets &lt;subnet-id-1&gt; &lt;subnet-id-2&gt; \<br>    --instance-types t4g.large m6g.large m6gd.large c6g.large c6gd.large \<br>    --labels intent=apps \<br>    --taints key=spotInstance,value=True,effect=PREFER_NO_SCHEDULE \<br>    --tags k8s.io/cluster-autoscaler/node-template/taint/spotInstance=true:PreferNoSchedule,k8s.io/cluster-autoscaler/node-template/label/intent=apps \<br>    --ami-type AL2_ARM_64 \<br>    --capacity-type SPOT \<br>    --node-role &lt;node-group-role-arn&gt;</pre><h4>2. Create Network Load Balancer with nginx</h4><ol><li>Create IAM <strong><em>OIDC provider</em></strong> and attach it to your cluster.</li></ol><pre>eksctl utils associate-iam-oidc-provider \<br>  --region &lt;aws-region&gt; \<br>  --cluster &lt;cluster-name&gt; \<br>  --approve</pre><p>2. Create an <strong><em>IAM service</em></strong> account for your cluster and attach AWSLoadBalancerControllerIAMPolicy to it.</p><pre>eksctl create iamserviceaccount \<br>    --cluster=&lt;your-cluster&gt; \<br>    --namespace=kube-system \<br>    --name=aws-load-balancer-controller \<br>    --attach-policy-arn=arn:aws:iam::&lt;YOUR_AWS_ACCOUNT_ID&gt;:policy/AWSLoadBalancerControllerIAMPolicy \<br>    --override-existing-serviceaccounts \<br>    --approve</pre><p>3. Install <strong><em>Load balancer Controller</em></strong> using helm</p><pre>helm install aws-load-balancer-controller eks/aws-load-balancer-controller \<br>  -n kube-system \<br>  --set clusterName=&lt;cluster-name&gt; \<br>  --set serviceAccount.create=false \<br>  --set serviceAccount.name=aws-load-balancer-controller <br><br># Verify that the controller is installed and working properly<br>kubectl get deployment -n kube-system aws-load-balancer-controller</pre><p>4. Install <strong><em>nginx controller</em></strong> for associating multiple ingress with single LB</p><pre>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/aws/deploy.yaml<br><br># Verify that the controller is installed and working properly<br>kubectl get deployment -n ingress-nginx</pre><h4>3. Create CI/CD using Github Actions</h4><ol><li>Create an ECR repo to upload your application images after build, using the below command.</li></ol><pre>aws ecr create-repository --repository-name &lt;application-name&gt;</pre><p>Use the above repo to push your image by using the below action in your GitHub workflow.</p><pre># Configure AWS user creds<br>    - name: Configure AWS credentials<br>      uses: aws-actions/configure-aws-credentials@v1<br>      with:<br>        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>        aws-region: &lt;aws-region&gt;<br><br># Login to ECR repo <br>    - name: Login to Amazon ECR<br>      id: login-ecr<br>      uses: aws-actions/amazon-ecr-login@v1<br><br># Build the image and push to ECR<br>    - name: Build, tag, and push image to Amazon ECR<br>      id: build-image<br>      env:<br>        ECR_REPOSITORY: &lt;application-name&gt;<br>        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}<br>      run: |<br>        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .<br>        aws ecr get-login-password --region &lt;aws-region&gt; | docker login --username AWS --password-stdin $ECR_REGISTRY<br>        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG<br>        echo &quot;::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG&quot;</pre><p>2. On a linux instance, backup and delete the existing .kube/config file. Run the below command to create a kube config with details of only the latest cluster.</p><pre>aws eks --region &lt;aws-region&gt; update-kubeconfig --name &lt;cluster-name&gt;</pre><p>Your config file should look like below:</p><pre>apiVersion: v1<br>clusters:<br>- cluster:<br>    certificate-authority-data: *******************tLS0tCg==<br>    server: https://***.gr7.&lt;region&gt;.eks.amazonaws.com<br>  name: arn:aws:eks:&lt;region&gt;:***:cluster/&lt;eks-name&gt;<br>contexts:<br>- context:<br>    cluster: arn:aws:eks:&lt;region&gt;:&lt;aws account id&gt;:cluster/&lt;eks-name&gt;<br>    user: arn:aws:eks:&lt;region&gt;:&lt;aws account id&gt;:cluster/&lt;eks-name&gt;<br>  name: arn:aws:eks:&lt;region&gt;:&lt;aws account id&gt;:cluster/&lt;eks-name&gt;<br>current-context: arn:aws:eks:&lt;region&gt;:&lt;aws account id&gt;:cluster/&lt;eks-name&gt;<br>kind: Config<br>preferences: {}<br>users:<br>- name: arn:aws:eks:&lt;region&gt;:&lt;aws account id&gt;:cluster/&lt;eks-name&gt;<br>  user:<br>    exec:<br>      apiVersion: client.authentication.k8s.io/v1beta1<br>      args:<br>      - --region<br>      - &lt;region&gt;<br>      - eks<br>      - get-token<br>      - --cluster-name<br>      - &lt;eks-name&gt;<br>      command: aws</pre><p>3. Convert that file to base64 encrypted format to use in github Actions.</p><pre>base64 .kube/config &gt; base64-kube-config</pre><p>Add the base64 config file to GitHub secrets with name KUBE_CONFIG and use the below action in your Github workflow file.</p><pre># Configure AWS user creds<br>    - name: Configure AWS credentials<br>      uses: aws-actions/configure-aws-credentials@v1<br>      with:<br>        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>        aws-region: &lt;aws-region&gt;<br><br># Login to ECR repo <br>    - name: Login to Amazon ECR<br>      id: login-ecr<br>      uses: aws-actions/amazon-ecr-login@v1<br><br># Install helm repo in your cluster<br>    - name: helm deploy<br>      uses: koslib/helm-eks-action@v1.25.2<br><br>      env:<br>        KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG }}<br>      with:<br>        command: |<br>          helm upgrade &lt;release-name&gt; &lt;path-to-helm-repo&gt; \<br>            -f ./values.yaml \<br>            --install \<br>            --wait \<br>            --atomic \<br>            --timeout 5m \<br>            --namespace=default \<br>            --set image.tag=${IMAGE_TAG},host=&quot;example.com&quot;,workers=null \<br>            --version 0.2.4</pre><p>4. To let GitHub access your cluster, add the GitHub user in your cluster configmap using the below command.</p><pre># Edit the configmap<br>kubectl edit cm aws-auth -n kube-system<br><br># Add the GitHub user to this config map in the mapUsers section, like below<br>- userarn: arn:aws:iam::&lt;account-id&gt;:user/github-user<br>  username: github-user<br>  groups:<br>    - system:masters</pre><p>Final ConfigMap should look like below:</p><pre>apiVersion: v1<br>data:<br>  mapRoles: |<br>    - groups:<br>      - system:bootstrappers<br>      - system:nodes<br>      rolearn: arn:aws:iam::***:role/node-group-role<br>      username: system:node:{{EC2PrivateDNSName}}<br>  mapUsers: |<br>    - userarn: arn:aws:iam::***:user/github-user<br>      username: github-user<br>      groups:<br>        - system:masters<br>kind: ConfigMap<br>metadata:<br>  creationTimestamp: &quot;2022-09-06T14:03:38Z&quot;<br>  name: aws-auth<br>  namespace: kube-system<br>  resourceVersion: &quot;241511&quot;<br>  uid: ***</pre><p>5. Create a values.yaml file in your GitHub repo at the root directory and make sure it has all the necessary values. An example values file in shown below.</p><pre>image:<br>  repository: &lt;ecr-registry&gt;/&lt;application-name&gt;<br>  pullPolicy: Always<br><br>service:<br>  type: ClusterIP<br>  port: 80<br>  targetPort: 3000<br><br>resources: <br>  limits:<br>    cpu: 500m<br>    memory: 1Gi<br>  requests:<br>    cpu: 200m<br>    memory: 250Mi<br>    <br>autoscaling:<br>  enabled: true<br>  minReplicas: 1<br>  maxReplicas: 10<br>  targetCPUUtilizationPercentage: 80<br><br>application:<br>  name: server<br>  versionTag: &#39;v8.1.1&#39;<br><br>env: <br>  - name: ENV<br>    value: staging<br><br>workers:<br>  - name: updates<br>    minReplicas: 1<br>    maxReplicas: 5<br>    targetCPUUtilizationPercentage: 60<br>    requests:<br>      cpu: 200m<br>      memory: 250Mi<br>    limits:<br>      cpu: 500m<br>      memory: 500Mi<br>    env:<br>      - name: QUEUE_NAME<br>        value: &lt;pub-sub&gt;<br>  </pre><h4>4. Create Cluster Autoscaler</h4><ol><li>Create metrics server for HPA to calculate when your pods need scaling.</li></ol><pre>kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml</pre><p>2. Create HPA for your app to scale pods.</p><pre>kubectl autoscale deployment &lt;app-deployment-name&gt; --cpu-percent=50 --min=1 --max=10</pre><p>Make sure your applications have resources configured or the HPA will not be able to calculate the usage of your pods. The yaml file for your pod/deploy should have the below resource block.</p><pre>    resources:<br>      limits:<br>        cpu: 750m<br>        memory: 500Mi<br>      requests:<br>        cpu: 500m<br>        memory: 200Mi</pre><p>3. Create Cluster Autoscaler for scaling nodes when pods are in pending state.</p><pre># Apply CA<br>kubectl apply -f https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml<br><br># Edit CA deployment, find the line with --node-group-auto-discovery and modify &lt;YOUR CLUSTER NAME&gt; to the your cluster name<br>kubectl edit deployment cluster-autoscaler -n kube-system <br><br># Check if the cluster autoscaler pod is running successfully with the command <br>kubectl get deploy cluster-autoscaler -n kube-system</pre><p>4. Create a priority class to assign it to placeholder pods to keep extra nodes running at any given time.</p><pre>kubectl create priorityclass placeholder-priority --value=-1</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d40fc30066b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/create-production-kubernetes-with-aws-a-step-by-step-guide-d40fc30066b8">Create production Kubernetes with AWS: A step-by-step guide</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add multiple AWS creds in your CLI]]></title>
            <link>https://ansukumari.medium.com/add-multiple-aws-creds-in-your-cli-b8ebda3ae3a8?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8ebda3ae3a8</guid>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[credentials]]></category>
            <category><![CDATA[multiple]]></category>
            <category><![CDATA[profile]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 07:47:41 GMT</pubDate>
            <atom:updated>2023-02-03T06:52:13.003Z</atom:updated>
            <content:encoded><![CDATA[<p>Before adding AWS creds in your CLI, make sure you have the <a href="https://docs.aws.amazon.com/cli/latest/userguide/installing.html">AWS CLI</a> installed in your system.</p><h4>1. Configure your default AWS Credentials</h4><pre>$ aws configure<br>AWS Access Key ID [None]: &lt;YOUR_ACCESS_KEY_ID&gt;<br>AWS Secret Access Key [None]: &lt;YOUR_SECRET_ACCESS_KEY&gt;<br>Default region name [None]: &lt;YOUR_AWS_REGION&gt;<br>Default output format [None]:</pre><h4>2. Configure multiple profiles</h4><pre>$ aws configure --profile produser<br>AWS Access Key ID [None]: &lt;YOUR_ACCESS_KEY_ID&gt;<br>AWS Secret Access Key [None]: &lt;YOUR_SECRET_ACCESS_KEY&gt;<br>Default region name [None]: &lt;YOUR_AWS_REGION&gt;<br>Default output format [None]:</pre><p>You can then specify a --profile <em>profilename</em> and use the credentials and settings stored under that name. For eg:</p><pre>$ aws s3 ls --profile produser</pre><p>Or you can set AWS_PROFILE as an environment variable to temporarily set any profile as default profile.</p><pre>$ export AWS_PROFILE=&lt;YOUR_PROFILE_NAME&gt;</pre><h4>3. See all the configured profiles</h4><pre>$ cat .aws/config<br>[default]<br>region = ap-south-1<br>[profile produser]<br>region = ap-south-1</pre><p>You can also check which profile you are currently switched to with the below command.</p><pre>$ aws sts get-caller-identity</pre><h3>Check your AWS credentials</h3><p>Your AWS credentials file is located in your home directory at .aws/credentials.</p><p>You can also manually create the shared credentials at the above location instead of using the configure command. The credentials file will look like below.</p><h4>Single User</h4><pre>[default]<br>aws_access_key_id = &lt;YOUR_ACCESS_KEY_ID&gt;<br>aws_secret_access_key = &lt;YOUR_SECRET_ACCESS_KEY&gt;</pre><h4>Multiple User</h4><pre>[default]<br>aws_access_key_id = &lt;YOUR_DEFAULT_ACCESS_KEY_ID&gt;<br>aws_secret_access_key = &lt;YOUR_DEFAULT_SECRET_ACCESS_KEY&gt;</pre><pre>[test-account]<br>aws_access_key_id = &lt;YOUR_TEST_ACCESS_KEY_ID&gt;<br>aws_secret_access_key = &lt;YOUR_TEST_SECRET_ACCESS_KEY&gt;</pre><pre>[prod-account]<br>aws_access_key_id = &lt;YOUR_PROD_ACCESS_KEY_ID&gt;<br>aws_secret_access_key = &lt;YOUR_PROD_SECRET_ACCESS_KEY&gt;</pre><h3>Delete AWS Profile</h3><p>To delete any user you can simply delete its credentials from the .aws/credentials file. You would also want to delete the info stored in .aws/config file to avoid any discrepancy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8ebda3ae3a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helm 102]]></title>
            <link>https://medium.com/geekculture/helm-102-2c4af7e0c7b9?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c4af7e0c7b9</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[helm-chart]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 16:03:22 GMT</pubDate>
            <atom:updated>2022-08-08T12:49:04.857Z</atom:updated>
            <content:encoded><![CDATA[<p>Here are some steps that you can implement in your helm chart to make it more robust after you have setup your Kubernetes and created a Helm chart for your application deployment.</p><h3>Wait for the deployment to succeed before marking the workflow as complete.</h3><p>When you run a Helm deployment (deploy roll), you should make sure the deploy was successful. By default Helm, just like Kubernetes, doesn’t check that.</p><p>However, Helm offers the --wait flag that waits for the release to successfully deploy all resources.</p><blockquote>if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout</blockquote><p>This flag has had multiple issues which seems to have resolved but the below two inconveniences persist with the wait flag — more detail can be found <a href="https://github.com/helm/helm/issues/5814">here</a>:</p><ol><li>If the pod is “flapping” (it goes ready for a bit and then fails) helm might pass the workflow considering the tiny amount of time for which the replica was ready, which would be a false positive in our case and this usually happens when your application has logical errors that makes it work for a while and then it crashes.</li><li>If you only have 1 replica and you’ve specified that 1 replica can be unavailable, then the deployment is technically “ready” if 1 pod is unavailable.</li></ol><h4>Solution</h4><p>The solution to second issue is pretty easy, either have more than 1 replicas or change max unavailable config to 0. Although, setting max unavailable config to 0 will cause hinderance in performing rolling updates and so will having one replica, so the best way to resolve this would be to keep a minimum of two replicas.</p><p>For the first issue you want to make sure that helm understands exactly when the pod is ready and don’t just rely on the pod status say ‘running’. You can achieve this by adding probes to your applications. Below is a sample code, you can read further about probes in this official <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes">document</a>.</p><pre><strong>kind</strong>: Deployment<br><strong>spec</strong>:<br>  <strong>template</strong>:<br>    <strong>spec</strong>:<br>      <strong>containers</strong>:<br>        <strong>livenessProbe</strong>:<br>          <strong>httpGet</strong>:<br>            <strong>path</strong>: /health<br>            <strong>port</strong>: 9000<br>          <strong>initialDelaySeconds</strong>: 3<br>          <strong>periodSeconds</strong>: 3<br>        <strong>readinessProbe</strong>:<br>          <strong>httpGet</strong>:<br>            <strong>path</strong>: /health<br>            <strong>port</strong>: 9000<br>          <strong>initialDelaySeconds</strong>: 3<br>          <strong>periodSeconds</strong>: 3</pre><h3>Rollback automatically if the deployment fails</h3><p>Sometimes you send out bad codes that crash during deployments and your system fails, such failed states can easily be rolled back manually to a stable helm version by using the below helm rolback command. This will get your pods to working state.</p><pre>helm rollback &lt;RELEASE&gt; [REVISION] [flags]</pre><pre>For eg: helm rollback release1 13</pre><p>You can check the list of release with the history command or check the current release version with status command.</p><pre>helm status release1 -n default<br>helm history release1 -n default</pre><p>However, you might not want to do that manually every time and should integrate an automated system to gracefully rollback helm release when deployment fails. Helm offers the --atomic flag to do exactly that.</p><blockquote>if set, upgrade process rolls back changes made in case of failed upgrade. The--wait flag will be set automatically if --atomic is used</blockquote><h3>Trigger deployment with every helm upgrade/roll</h3><p>When a deployment is triggered in k8s, latest/specified image is pulled to use for pod deployment but if the latest/specified image tag is the same as the one currently running pods are using, a new roll is not triggered.</p><p>This can be confused with the function of the Always pull policy defined in the deployment as was raised in <a href="https://stackoverflow.com/questions/45905999/kubernetes-image-pull-policy-always-does-not-work">this</a> thread.</p><blockquote>Kubernetes is <strong>not</strong> watching for a new version of the image. The image pull policy specifies how to acquire the image to run the container. <em>Always</em> means it will try to pull a new version each time it&#39;s starting a container. To see the update you&#39;d need to delete the Pod (not the Deployment) - the newly created Pod will run the new image.</blockquote><blockquote>There is no direct way to have Kubernetes automatically update running containers with new images.</blockquote><p>To force roll a deployment you can restart a kubectl deployment rollout by using the below command.</p><pre>kubectl rollout restart deployment/&lt;deployment-name&gt; -n &lt;namespace&gt;</pre><p>However, helm provides a better way of resolving this by adding a random string/timestamp as annotation to your deployment so it always changes and causes the deployment to roll every time you run helm upgrade. You can refer this <a href="https://stackoverflow.com/questions/65413154/how-to-force-a-redeploy-with-helm">thread</a> or official helm <a href="https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments">documentation</a> for further understanding.</p><pre><strong>kind</strong>: Deployment<br><strong>spec</strong>:<br>  <strong>template</strong>:<br>    <strong>metadata</strong>:<br>      <strong>annotations</strong>:<br>        <strong>timestamp</strong>: {{ now | quote }}</pre><pre>[...]</pre><blockquote>Each invocation of the template function will generate a unique random string. This means that if it’s necessary to sync the random strings used by multiple resources, all relevant resources will need to be in the same template file.</blockquote><h3>Wait for a deployment to finish before running another upgrade</h3><p>If you try to run the helm upgrade command on the same Helm Chart where another deployment might be ongoing, helm will throw the below error.</p><pre>Error: UPGRADE FAILED: another operation (install/upgrade/rollback) is in progress</pre><p>You should not be running multiple upgrades on the same chart to maintain the consistency of pods but at the same time you do not want to sit around for a deployment to finish before you begin yours, sounds like a lot of unproductive minutes.</p><p>To handle this, you can add a check in your workflow for the deployment to wait until the current finishes and automatically start the new upgrade. Unfortunately, helm does not provide any command that waits for a deployment to finish; but Kubernetes does. Thus, while you cannot wait for helm rollout to finish, you can wait for specific deployments to finish which is a sub-part of the helm deploy.</p><p>The kubectl rollout status command will output if a rollout has been successfully deployed or continue to serve the updates till it does. Below are a couple examples of how the command works.</p><pre>$ kubectl rollout status deploy stage-backend </pre><pre>deployment &quot;stage-backend&quot; successfully rolled out</pre><pre>------------------</pre><pre>$ kubectl rollout status deploy stage-backend</pre><pre>Waiting for deployment &quot;stage-backend&quot; rollout to finish: 1 old replicas are pending termination...<br>Waiting for deployment &quot;stage-backend&quot; rollout to finish: 1 old replicas are pending termination...<br>Waiting for deployment &quot;stage-backend&quot; rollout to finish: 1 old replicas are pending termination...<br>Waiting for deployment &quot;stage-backend&quot; rollout to finish: 3 of 4 updated replicas are available...<br>deployment &quot;stage-backend&quot; successfully rolled out</pre><pre>--------------------</pre><pre>$ kubectl rollout status deploy stage-backend </pre><pre>Waiting for deployment &quot;stage-backend&quot; rollout to finish: 2 out of 4 new replicas have been updated...<br>error: deployment &quot;stage-backend&quot; exceeded its progress deadline</pre><p>This approach can become unreliable at times, like if you have multiple deployments under single helm chart or when code crashes and helm starts to rollback — technically the deploy roll hasn’t finished but the kubectl rollout will exit saying it failed before the rollback starts. However, it is possible to work around this caveat by creating a script that continuously polls the status of the chart deployment using the helm status sub-command.</p><pre>$ helm status release1 | grep STATUS | cut -d: -f2<br>deployed</pre><p>That being said, an easier solution to this problem would be to not let multiple instances of the upgrade job run in your CI/CD pipeline. For eg, if you use Github Actions you can use the concurrency keyword in your workflow to ensure that the upgrade workflow only runs when there is no other running and if there is it’ll send the current one to a pending state which will be executed after the previous one finishes. You can also specify concurrency at the job level. For more information, see <a href="https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idconcurrency">jobs.&lt;job_id&gt;.concurrency</a>.</p><p>You can learn more about this feature from this official Github <a href="https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency">blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c4af7e0c7b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/helm-102-2c4af7e0c7b9">Helm 102</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Kubernetes for your infra and add CI/CD using GitHub Actions — Part II (Implementation)]]></title>
            <link>https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-ii-implementation-46c628124e94?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/46c628124e94</guid>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Sun, 08 May 2022 01:03:07 GMT</pubDate>
            <atom:updated>2022-08-25T04:58:44.751Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to helm Charts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2rpl7d7LsyJ-zZ52" /><figcaption>Photo by <a href="https://unsplash.com/@goshua13?utm_source=medium&amp;utm_medium=referral">Joshua Aragon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Till now we’ve seen that we have a lot of services to offer to our customers and each service has its own application. As discussed in <a href="https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-i-introduction-e9904fbc27ac">Part I</a> of this article, 50 ASGs mean 50 different types of servers — managing which became a manual task using ec2 instances. We have 5 different types of applications and roughly 10 different types of servers running for each application — categorized as http servers and workers.</p><p>Since k8s runs only containerized applications we need to build an image for each application and manage it. To containerize the app we added <strong>Dockerfile</strong> to our app and stored it on our AWS Elastic Container Registry (ECR). We then created a k8s cluster on AWS Elastic Kubernetes Service (EKS) and connected to it from our local following <a href="https://aws.amazon.com/premiumsupport/knowledge-center/eks-cluster-connection/">this</a> guide. If you need to brush up the basics of Docker or Kubernetes, refer my previous <a href="https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-i-introduction-e9904fbc27ac">blog</a>.</p><p>To push or pull images to your AWS ECR, you need to first authorize AWS with docker using the below command. Refer <a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html">this</a> doc for further guidance.</p><pre>aws ecr get-login-password --region <strong>&lt;<em>aws-region&gt;</em></strong> | docker login --username AWS --password-stdin <strong><em>&lt;aws_account_id&gt;</em></strong>.dkr.ecr.<strong>&lt;<em>aws-region&gt;</em></strong>.amazonaws.com</pre><p>Then use the docker push/pull command as shown below.</p><pre>docker pull 11xxxxxxxxxx.dkr.ecr.ap-south-1.amazonaws.com/backend:latest</pre><p>Now that we have our k8s cluster setup it’s time to create some objects. We start with creating a deployment for our application, and we’ll use our image stored in the ECR. For this example I’m using a sample image nginx:1.14.2 so we have a working code to run.</p><pre><strong>apiVersion</strong>: apps/v1<br><strong>kind</strong>: Deployment<br><strong>metadata</strong>:<br>  <strong>labels</strong>:<br>    <strong>app</strong>: backend-server<br>  <strong>name</strong>: backend-server<br><strong>spec</strong>:<br>  <strong>replicas</strong>: 2<br>  <strong>selector</strong>:<br>    <strong>matchLabels</strong>:<br>      <strong>app</strong>: backend-server<br>  <strong>template</strong>:<br>    <strong>metadata</strong>:<br>      <strong>creationTimestamp</strong>: null<br>      <strong>labels</strong>:<br>        <strong>app</strong>: backend-server<br>    <strong>spec</strong>:<br>      <strong>containers</strong>:<br>      - <strong>env</strong>:<br>          - <strong>name</strong>: ENV<br>            <strong>value</strong>: dev<br>        <strong>image</strong>: nginx:1.14.2<br>        <strong>imagePullPolicy</strong>: Always<br>        <strong>name</strong>: backend-server<br>        <strong>ports</strong>:<br>        - <strong>containerPort</strong>: 80<br>          <strong>protocol</strong>: TCP<br>      <strong>dnsPolicy</strong>: ClusterFirst</pre><p>Creating this file and running the command $ kubectl apply -f deployment.yaml inside the cluster will spin up 2 pods running the code specified in the ECS image. You can check the logs or enter the pods using the commands mentioned in <a href="https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-i-introduction-e9904fbc27ac">Part I</a> of the article and make sure the server is functioning correctly and is accessible on localhost.</p><p>We now add the below ingress file to make the servers accessible from the outside world as well.</p><pre><strong>apiVersion</strong>: networking.k8s.io/v1<br><strong>kind</strong>: Ingress<br><strong>metadata</strong>:<br>  <strong>annotations</strong>:<br>    <strong>alb.ingress.kubernetes.io/scheme</strong>: internet-facing<br>    <strong>alb.ingress.kubernetes.io/target-type</strong>: ip<br>    <strong>kubernetes.io/ingress.class</strong>: alb<br>  <strong>finalizers</strong>:<br>  - ingress.k8s.aws/resources<br>  <strong>name</strong>: backend-server-ingress<br><strong>spec</strong>:<br>  <strong>rules</strong>:<br>  - <strong>http</strong>:<br>      <strong>paths</strong>:<br>      - <strong>backend</strong>:<br>          <strong>service</strong>:<br>            <strong>name</strong>: backend-server<br>            <strong>port</strong>:<br>              <strong>number</strong>: 3000<br>        <strong>path</strong>: /<br>        <strong>pathType</strong>: Prefix</pre><p>Applying this file will generate a url which you can curl on to reach your application form anywhere. Using the get or describe command, as discussed in previous article, will show you the url.</p><p>So we have our application up and running in minutes, but wait I need to add another application — with a different image of course, because they have different code running inside of it. I’ll create another deployment file and another ingress.. and yet another for the third project and so on.</p><p>Do I manually have to create the same files over and over just to change one attribute?</p><h4>Introducing Helm Charts…</h4><p>In most simple way, helm chart is a way to reuse your object files using variables i.e once your create all the k8s objects you need, deployment and ingress file in our case, you can use a variable instead of hardcoded values for dynamic attributes and use the same set of objects over and over again.</p><p>A Helm Chart in itself is just a folder, when you install helm, a folder is created with a few files inside it which looks something like below. For now let’s just focus on 3 things — the values file, the Chart.yaml file and the templates folder (other files are optional to keep in folder). To learn Helm in detail you can start <a href="https://helm.sh/docs/topics/charts/">here</a>.</p><pre><strong>wordpress</strong>/<br>  <strong>Chart.yaml</strong>          # A YAML file containing info about the chart<br>  <strong>LICENSE</strong>             <br>  <strong>README.md    </strong>       <br>  <strong>values.yaml   </strong>      # The default config values for this chart<br>  <strong>values.schema.json  </strong><br>  <strong>charts/  </strong>           <br>  <strong>crds/</strong>               <br>  <strong>templates/   </strong>       # All the k8s object files<br>  <strong>templates/NOTES.txt </strong></pre><p>The Chart.yaml file only has metadata, like the version and description of the helm chart.</p><p>The values.yaml file is a collection of key-value pairs written in yaml format to be used as variables in all the k8s objects. Below is the values file we will keep in our project, since we only need to change the application and image name for all our applications and rest all configurations are the same, we’ll keep just that inside this file.</p><pre><strong>image</strong>:<br>  <strong>repository</strong>: nginx:1.14.2 #link to ECS image with tag<br>  <strong>pullPolicy</strong>: Always</pre><pre><strong>application</strong>:<br>  <strong>name</strong>: backend-server</pre><p>So now our deployments.yaml and ingress.yaml file looks like below, that now sit in the template folder in the helm chart project.</p><pre><strong>apiVersion</strong>: apps/v1<br><strong>kind</strong>: Deployment<br><strong>metadata</strong>:<br>  <strong>labels</strong>:<br>    <strong>app</strong>: {{.Values.application.name}}<br>  <strong>name</strong>: {{.Values.application.name}}<br><strong>spec</strong>:<br>  <strong>replicas</strong>: 2<br>  <strong>selector</strong>:<br>    <strong>matchLabels</strong>:<br>      <strong>app</strong>: {{.Values.application.name}}<br>  <strong>template</strong>:<br>    <strong>metadata</strong>:<br>      <strong>creationTimestamp</strong>: null<br>      <strong>labels</strong>:<br>        <strong>app</strong>: {{.Values.application.name}}<br>    <strong>spec</strong>:<br>      <strong>containers</strong>:<br>      - <strong>env</strong>:<br>          - <strong>name</strong>: ENV<br>            <strong>value</strong>: dev<br>        <strong>image</strong>: {{.Values.image.repository}}<br>        <strong>imagePullPolicy</strong>: {{.Values.image.pullPolicy}}<br>        <strong>name</strong>: {{.Values.application.name}}<br>        <strong>ports</strong>:<br>        - <strong>containerPort</strong>: 80<br>          <strong>protocol</strong>: TCP<br>      <strong>dnsPolicy</strong>: ClusterFirst</pre><pre><strong>apiVersion</strong>: networking.k8s.io/v1<br><strong>kind</strong>: Ingress<br><strong>metadata</strong>:<br>  <strong>annotations</strong>:<br>    <strong>alb.ingress.kubernetes.io/scheme</strong>: internet-facing<br>    <strong>alb.ingress.kubernetes.io/target-type</strong>: ip<br>    <strong>kubernetes.io/ingress.class</strong>: alb<br>  <strong>finalizers</strong>:<br>  - ingress.k8s.aws/resources<br>  <strong>name</strong>: {{.Values.application.name}}-ingress<br><strong>spec</strong>:<br>  <strong>rules</strong>:<br>  - <strong>http</strong>:<br>      <strong>paths</strong>:<br>      - <strong>backend</strong>:<br>          <strong>service</strong>:<br>            <strong>name</strong>: {{.Values.application.name}}<br>            <strong>port</strong>:<br>              <strong>number</strong>: 3000<br>        <strong>path</strong>: /<br>        <strong>pathType</strong>: Prefix</pre><p>This is the final structure of our helm chart folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C01OMTaR6-XAfku_nBpJ5g.png" /></figure><p>You can save these files and delete all the resources currently running in your k8s cluster to test our Helm Chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nIUAmYrieeinvJxdea-u4w.png" /></figure><p>Once you have no resource in your cluster run the below commands in sequence.</p><p>helm package &lt;foler_name&gt; : move up a folder and run this command, a zip file is created at this location with the name and version specified in your Chart.yaml file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4SAW-GXGXqgCujLQ2k5TZQ.png" /></figure><p>helm install &lt;release_name&gt; &lt;zip_file_name_with_version_tag&gt; : you can use the zip file to install helm in our cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ZbvUfeC10P7vvZJOJGI1A.png" /></figure><p>That’s it, it just takes one command — helm install — to install all application objects required to run your application without any hassle. Now if you kubectl the objects, you’ll find all the configured objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HyQfkBGtxP6eQi7C-52otw.png" /></figure><p>To deploy a different application that needs all the same resource objects and different values, like different image in our case — fork this repo, change the values and install helm! Done.</p><p>That’s helm for you. One last problem we had was adding worker instances for each application i.e instances that share the same image/code but run different commands. We need a dynamic way to create deployment file for each service that can be done directly by the developer and needs minimum involvement from the DevOps team. Hence, we need to add worker config to the values file itself .. but in a loop?</p><p>This is something I had to play around to get the solution to, understanding how variables, loops and conditions inside loops work in a yaml file. Here’s the solution.</p><p>One interesting feature of a Kubernetes Object file is that you can create multiple objects inside the same file using the --- characters. For example, to create an ingress and a deployment object in one file you can write something like below.</p><pre><strong>apiVersion</strong>: apps/v1<br><strong>kind</strong>: Deployment<br><strong>metadata</strong>:<br>  <strong>labels</strong>:<br>    <strong>app</strong>: {{.Values.application.name}}<br>  <strong>name</strong>: {{.Values.application.name}}<br><strong>spec</strong>:<br>  <strong>replicas</strong>: 2<br>  <strong>selector</strong>:<br>    <strong>matchLabels</strong>:<br>      <strong>app</strong>: {{.Values.application.name}}<br>  <strong>template</strong>:<br>    <strong>metadata</strong>:<br>      <strong>creationTimestamp</strong>: null<br>      <strong>labels</strong>:<br>        <strong>app</strong>: {{.Values.application.name}}<br>    <strong>spec</strong>:<br>      <strong>containers</strong>:<br>      - <strong>env</strong>:<br>          - <strong>name</strong>: ENV<br>            <strong>value</strong>: dev<br>        <strong>image</strong>: {{.Values.image.repository}}<br>        <strong>imagePullPolicy</strong>: {{.Values.image.pullPolicy}}<br>        <strong>name</strong>: {{.Values.application.name}}<br>        <strong>ports</strong>:<br>        - <strong>containerPort</strong>: 80<br>          <strong>protocol</strong>: TCP<br>      <strong>dnsPolicy</strong>: ClusterFirst<br>---<br><strong>apiVersion</strong>: networking.k8s.io/v1<br><strong>kind</strong>: Ingress<br><strong>metadata</strong>:<br>  <strong>annotations</strong>:<br>    <strong>alb.ingress.kubernetes.io/scheme</strong>: internet-facing<br>    <strong>alb.ingress.kubernetes.io/target-type</strong>: ip<br>    <strong>kubernetes.io/ingress.class</strong>: alb<br>  <strong>finalizers</strong>:<br>  - ingress.k8s.aws/resources<br>  <strong>name</strong>: {{.Values.application.name}}-ingress<br><strong>spec</strong>:<br>  <strong>rules</strong>:<br>  - <strong>http</strong>:<br>      <strong>paths</strong>:<br>      - <strong>backend</strong>:<br>          <strong>service</strong>:<br>            <strong>name</strong>: {{.Values.application.name}}<br>            <strong>port</strong>:<br>              <strong>number</strong>: 3000<br>        <strong>path</strong>: /<br>        <strong>pathType</strong>: Prefix</pre><p>Convenient, isn’t it? Here’s how I used this feature to dynamically create deployment files.</p><p>I added the below code to the values.yaml file:</p><pre>workers:<br>  - name: update<br>    replicas: 1<br>    command: [&quot;export QUEUE_NAME=updates-queue &amp;&amp; node worker.js&quot;]<br>  - name: cron-events<br>    replicas: 1<br>    command: [&quot;export QUEUE_NAME=cron-events &amp;&amp; node worker.js&quot;]</pre><p>so the complete file looks like below.</p><pre><strong>image</strong>:<br>  <strong>repository</strong>: nginx:1.14.2 #link to ECS image with tag<br>  <strong>pullPolicy</strong>: Always</pre><pre><strong>application</strong>:<br>  <strong>name</strong>: backend-server</pre><pre><strong>workers</strong>:<br>  - <strong>name</strong>: update<br>    <strong>replicas</strong>: 1<br>    <strong>command</strong>: [&quot;export QUEUE_NAME=updates-queue &amp;&amp; node worker.js&quot;]<br>  - <strong>name</strong>: cron-events<br>    <strong>replicas</strong>: 1<br>    <strong>command</strong>: [&quot;export QUEUE_NAME=cron-events &amp;&amp; node worker.js&quot;]</pre><pre># NOTE: the worker commands won&#39;t run with this values file because we have provided nginx image and nodejs is not installed on the container that is being spin up. This is just an example code to refer.</pre><p>and I created a new deployment file for workers, workersDeployment.yaml, that looks like this.</p><pre>{{- range $worker := .Values.workers }}<br>{{- with $worker }}<br><strong>apiVersion</strong>: apps/v1<br><strong>kind</strong>: Deployment<br><strong>metadata</strong>:<br>  <strong>labels</strong>:<br>    <strong>app</strong>: {{.name}}<br>  <strong>name</strong>: {{.name}}<br><strong>spec</strong>:<br>  <strong>replicas</strong>: {{ .replicas }}<br>  <strong>selector</strong>:<br>    <strong>matchLabels</strong>:<br>      <strong>app</strong>: {{.name}}<br>  <strong>template</strong>:<br>    <strong>metadata</strong>:<br>      <strong>creationTimestamp</strong>: null<br>      <strong>labels</strong>:<br>        <strong>app</strong>: {{.name}}<br>    <strong>spec</strong>:<br>      <strong>containers</strong>:<br>      - <strong>env</strong>:<br>          - <strong>name</strong>: NODE_ENV<br>            <strong>value</strong>: staging<br>        <strong>image</strong>: {{$.Values.image.repository}}<br>        <strong>imagePullPolicy</strong>: {{$.Values.image.pullPolicy}}<br>        <strong>name</strong>: {{.name}}<br>        <strong>command</strong>: [&quot;/bin/sh&quot;,&quot;-c&quot;]<br>        <strong>args</strong>: {{.command}}<br>        <strong>ports</strong>:<br>        - <strong>containerPort</strong>: {{$.Values.service.targetPort}}<br>          <strong>protocol</strong>: TCP<br>        <strong>resources</strong>: {}<br>        <strong>terminationMessagePath</strong>: /dev/termination-log<br>        <strong>terminationMessagePolicy</strong>: File<br>      <strong>dnsPolicy</strong>: ClusterFirst<br>---<br>{{- end }}<br>{{- end }}</pre><p>{{- range $worker := .Values.workers}}</p><p>range keyword is an iterator, it is how you run a loop in a yaml file like the for keyword in languages like python, java or c++ . The above line is similar to writing for worker in .Values.workers in python.</p><p>{{- with $worker }}</p><blockquote>The next control structure to look at is the with action. This controls variable scoping. Recall that . is a reference to <em>the current scope</em>. So .Values tells the template to find the Values object in the current scope.</blockquote><p>We have defined workers in the values file as a list of maps, for each of the list element we set the current scope to that element so we can then use the . followed by the keyname of the map to refer to its keyvalues.</p><p>{{.name}}</p><p>Which brings us to this. . is the current element of the workers list and .&lt;keyname&gt; will populate the value of element key. It is similar to writing worker[name] in python.</p><p>{{$.Values.image.repository}}</p><p>Now that we’ve changed the current scope, notice that we have to use $ in front of the Values variable to access the values.yaml file to make the compiler understand that we need to access a global/parent variable rather than a local worker variable.</p><p>{{end}}</p><p>end is simply the keyword to end a scope like we use curly braces } to end scopes in some languages like c++ and java.</p><p><em>To learn more on variables and scopes in helm you can refer </em><a href="https://helm.sh/docs/chart_template_guide/control_structures/"><em>this</em></a><em> official doc.</em></p><p>When helm install is run with this file in repo, it creates multiple deployment files with names as provided in the workers list present in values file and spins respective pods for each deployment.</p><p>So we have our servers ready with just one command — no hassle, but wait do we have pull the code, build an image, push it to ECR registry, package helm again and then install it again everytime I make the most minor change in my code? Sounds like a lot of labor again but I think we’ve solved this problem, time to make some tweaks in our GitHub Actions workflow to manage CI/CD for k8s.</p><p>Let’s solve this and build a testing environment for each branch that we create in our GitHub repo for every individual developer to test their code in prod-identical yet isolated environment for Component Testing before merging it to the staging branch for Integration Testing — yet another advantage of using k8s — in the next article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46c628124e94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-ii-implementation-46c628124e94">Setup Kubernetes for your infra and add CI/CD using GitHub Actions — Part II (Implementation)</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Kubernetes for your infra and add CI/CD using GitHub Actions — Part I (Introduction)]]></title>
            <link>https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-i-introduction-e9904fbc27ac?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9904fbc27ac</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[orchestration]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Tue, 03 May 2022 12:02:58 GMT</pubDate>
            <atom:updated>2022-08-25T04:54:57.985Z</atom:updated>
            <content:encoded><![CDATA[<h3>Beginners guide to Docker and Kubernetes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v7BNkz3kcPkvJjc4" /><figcaption>Photo by <a href="https://unsplash.com/@towfiqu999999?utm_source=medium&amp;utm_medium=referral">Towfiqu barbhuiya</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Earlier we had solved the problem of CI/CD and scaling with AWS CodeDeploy, GitHub Actions and AWS Auto Scaling Groups (ASG). This works well as long as you have a couple of services to manage, as your services grow so do your servers and managing a huge number of ASGs need a better orchestration than simply creating a new ASG every time you need to add a new service for your users.</p><p>Before we start, I’d recommend you visit my previous blog on how we solved the scaling issue <a href="https://ansukumari.medium.com/auto-deploy-and-auto-scale-servers-using-aws-codedeploy-and-github-actions-cb85edb3da4e">here</a> so you can compare what’s changing and why.</p><p>In a nutshell, we placed instances behind an ASG to scale automatically in case of traffic surge, then we ran AWS CodeDeploy in GitHub Actions Workflow to deploy code pushed on GitHub automatically to all instances behind the ASG.</p><p>With time we kept on adding new services and consequently new ASGs for each service with different type of instance running different code in each ASG. We now have over 50 ASGs and managing these is a hell of a task.</p><h4>ENTER KUBERNETES..</h4><p>To understand how we have setup Kubernetes we need to understand the components it is built on. I’ll explain little about each of them below, feel free to skip to <a href="https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-ii-implementation-46c628124e94">Part II</a> where I talk about how we used these components to solve the above problem with code examples, if you already know how these components work.</p><h3>Docker, docker images and containers</h3><p>Docker is simply a way to containerize your application. When you write an application on your local machine, you can transfer the code to the internet to let other people use it but that doesn’t guarantee that it’ll work exactly how it worked on your machine or even work at all. This is because your application might have dependencies like modules, frameworks, databases etc, which might not get satisfied in other user’s machine.</p><p>To solve this we can put your application inside a container that not only contains your code but all its dependencies and the specified version of all the modules. This is called <strong>containerization</strong>. If we use a docker container it is called <strong>Dockerization</strong>.</p><p>In order to dockerize your app you need to add a file in your repository called <strong>Dockerfile (</strong>this file cannot be named anything else, the D should be in capital and rest in small without any extension<strong>) </strong>which, when run, builds a sharable image of your application. This image can be pushed to a registry online and shared with anyone to run in their system inside a container. Below is an example <strong>Dockerfile </strong>for a node application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d9050695653398e447135358914e38e/href">https://medium.com/media/7d9050695653398e447135358914e38e/href</a></iframe><p>A <strong>container</strong> is a lightweight environment that separates your application from other applications in the system. Conceptually it is similar to Virtual Machines but unlike virtual machines it does not have a guest OS on top of the machine OS, hence more lightweight and manageable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*hezOFEFv08IkqkQLlqvqYg.png" /></figure><h3>How to run applications on Docker</h3><p>Docker has a few components/objects that you’d need to run your applications and below are the frequently used commands associated with them:</p><h4>a. images —</h4><p>An image is the template of your application packaged in a file that, when executed, runs your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*pIOhRXLedob9f6oKTcSJHg.jpeg" /></figure><p>$ docker run &lt;image_id/image_name&gt;: You can use this command to create a running instance of your image. If the image exists on your local, docker will use that else it will pull the image from the DockerHub registry during the execution of the same command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CmVLp4Udi0Q6-WlcRBrdbA.png" /></figure><p>$ docker images: list all the images that exist in your local machine with this command.</p><p>$ docker rmi &lt;image_id/image_name&gt;: to delete an image from your local.</p><h4>b. containers —</h4><p>A container is simply all the isolated applications that is being run in your Docker.</p><p>$ docker ps : to list all the containers that are currently running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UXvAYkHlew2XA4-Qd_RiUA.png" /></figure><p>$ docker ps --all : to list all the containers in various states, ie. running, exited, completed etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8yuefwXgIbIWqMJDRlSdg.png" /></figure><p>$ docker container start/stop/kill &lt;container_id/container_name&gt; : to start a container that is listed but currently not running, to stop a running container, to kill a container without allowing the processes to finish respectively.</p><p><strong><em>NOTE</em></strong><em>: when writing container or image id you don’t have to write the complete hash, just using the unique initial letters works.</em></p><p>$ docker exec -it &lt;container_id/container_name&gt; bash : to enter your container application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n6pvBAIEl4JKIclbng8SKA.png" /></figure><p>$ docker rm &lt;container_id/container_name&gt; : to delete a container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rFizDcz7bnlN7YMTqWGi9w.png" /></figure><h3>Kubernetes</h3><p>AKA k8s, the best resource I found to get acquainted with k8s is the official hands on tutorial and <a href="https://kubernetes.io/docs/tutorials/kubernetes-basics/">here</a> is the link to it. For this blog though, I’ll give you a brief introduction to k8s and its objects that we need to be familiar with, with respect to our system, to setup and work with our infra on k8s.</p><p>Kubernetes is a way to manage all the containers and its associated images and other resources.</p><blockquote>Kubernetes provides you with a framework to run distributed systems resiliently. It takes care of scaling and failover for your application, provides deployment patterns, and more. For example, Kubernetes can easily manage a canary deployment for your system.</blockquote><h4>Kubernetes Cluster</h4><p>A k8s cluster is an ecosystem which comprises of <strong>highly available cluster of computers that are connected to work as a single unit</strong> that run your applications and services binding your application.</p><p>Below are some commands to see and switch cluster/context:</p><p>$ kubectl config get-clusters : to list all the clusters configured in your system</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*hd1MKD11RIREAnK5ScwJLA.png" /></figure><p>$ kubectl config get-contexts : to list all contexts configured in your system. A cluster with an authenticated user form a context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbbqUx4K5lT6eQ0rEJ-2Aw.png" /></figure><p>$ kubectl config current-context : to check which context are you currently working on, any changes you make would be applied to this context.</p><p>$ kubectl config use-context &lt;context_name&gt; : to switch contexts.</p><h4>Node</h4><p>It is the underlying physical or virtual machine that runs your application. A bunch of these nodes form the k8s cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*-oSJoLH3hY--IKXem3ZqLQ.png" /></figure><h4>Pod</h4><p>A pod is an abstraction that runs a containerized application. Ideally, one pod only runs one container although you can specify k8s to run multiple containers in a single pod but it is only recommended for very tightly coupled applications. Multiple pods run on a single node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lixji6vxS0DIFa1q7gpUUQ.png" /></figure><p><strong><em>Common commands you need to know when working with pods:</em></strong></p><p>$ kubectl get po : to list all the pods present in the default namespace in the current context.</p><p>$ kubectl exec -it &lt;pod_name&gt; -- bash : to get inside the pod</p><p>$ kubectl logs -f &lt;pod_name&gt; : to get console logs of the pod</p><h4>Deployment</h4><p>A k8s deployment is one of k8s objects written in yaml format and contains all specifications for your application pod management, for example, the number of replicas your application should have, the image your application pod should use, any environment variable that needs to be set in your pod containers etc. Below is a sample deployment file.</p><pre><strong>apiVersion</strong>: apps/v1<br><strong>kind</strong>: Deployment<br><strong>metadata</strong>:<br>  <strong>name</strong>: nginx-deployment<br>  <strong>labels</strong>:<br>    <strong>app</strong>: nginx<br><strong>spec</strong>:<br>  <strong>replicas</strong>: 3<br>  <strong>selector</strong>:<br>    <strong>matchLabels</strong>:<br>      <strong>app</strong>: nginx<br>  <strong>template</strong>:<br>    <strong>metadata</strong>:<br>      <strong>labels</strong>:<br>        <strong>app</strong>: nginx<br>    <strong>spec</strong>:<br>      <strong>containers</strong>:<br>      - <strong>name</strong>: nginx<br>        <strong>image</strong>: nginx:1.14.2<br>        <strong>ports</strong>:<br>        - <strong>containerPort</strong>: 80</pre><p>You can either use the kubectl create command to create a default deployment providing image in the command or write a yaml file of <em>kind</em> deployment, as shown above, and run the kubectl apply command to create that deployment.</p><p>To create a default deployment, run the below command:</p><pre>$ kubectl create deployment &lt;deployment_name&gt; --image=&lt;image_name/image_id&gt;</pre><pre><strong>Eg: </strong><br>kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1</pre><p>To create a deployment using the above deployment file, run the below command:</p><pre>$ kubectl apply -f &lt;path_to_deployment_yaml_file&gt;</pre><pre><strong>Eg:</strong><br>kubectl apply -f <a href="https://k8s.io/examples/controllers/nginx-deployment.yaml">https://k8s.io/examples/controllers/nginx-deployment.yaml</a></pre><p><strong>Deployment</strong> is one of the most used objects, to learn more about it you can refer <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">this</a> official doc.</p><h4>Ingress</h4><p>k8s ingress is an object to allow users from outside your cluster to access your applications and services. It majorly provides routing rules typically via HTTP/HTTPS and also acts a Load Balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NfZ0lku-b0t-Xa3UIiW1Jg.png" /></figure><p>Below is a sample ingress yaml file.</p><pre><strong>apiVersion</strong>: networking.k8s.io/v1<br><strong>kind</strong>: Ingress<br><strong>metadata</strong>:<br>  <strong>name</strong>: minimal-ingress<br>  <strong>annotations</strong>:<br>    <strong>nginx.ingress.kubernetes.io/rewrite-target</strong>: /<br><strong>spec</strong>:<br>  <strong>ingressClassName</strong>: nginx-example<br>  <strong>rules</strong>:<br>  - <strong>http</strong>:<br>      <strong>paths</strong>:<br>      - <strong>path</strong>: /testpath<br>        <strong>pathType</strong>: Prefix<br>        <strong>backend</strong>:<br>          <strong>service</strong>:<br>            <strong>name</strong>: test<br>            <strong>port</strong>:<br>              <strong>number</strong>: 80</pre><p>You can create an ingress file similar to deployment file with either the kubectl create command or kubectl apply command with a yaml file path.</p><h4>Other objects and common commands</h4><p>k8s has a lot of objects and it is not feasible to remember commands for each one of them, thus it follows a common pattern which is useful in most cases.</p><p><strong><em>Some of the k8s objects are:</em></strong></p><ul><li>Deployments</li><li>Pods</li><li>Services</li><li>Namespaces</li><li>Ingress</li><li>ReplicaSets</li><li>ConfigMaps</li><li>DaemonSets</li><li>Horizontal Pod Autoscaler (HPA)</li><li>etc</li></ul><p><strong><em>Common commands to use with above objects:</em></strong></p><p>$ kubectl get &lt;object_type&gt;: to list all objects of same category. For example to list all pods that are running or to see all the deployments there is in the current context you can use kubectl get pods or kubectl get deployments respectively.</p><p>Most objects also have a shorthand to use with command for example:</p><pre><strong>pods</strong>: kubectl get pods/po</pre><pre><strong>deployments</strong>: kubectl get deployments/deploy</pre><pre><strong>services</strong>: kubectl get services/svc</pre><pre><strong>namespaces</strong>: kubectl get namespaces/ns</pre><pre><strong>HPA</strong>: kubectl get horizontalpodautoscaler/hpa</pre><pre><strong>ConfigMaps</strong>: kubectl get configmaps/cm</pre><pre><strong>DaemonSets</strong>: kubectl get daemonsets/ds</pre><pre><strong>Ingress</strong>: kubectl get ingress/ing</pre><p>$ kubectl edit &lt;object_type&gt; &lt;object_name&gt; : to edit any object on the fly you can use this command, this opens the yml file in vi editor where you can use i command to insert changes and esc + :wq! to save those changes.</p><p>$ kubectl describe &lt;object_type&gt; &lt;object_name&gt; : to get the detailed description/configuration of the object.</p><p>$ kubectl get &lt;object_type&gt; &lt;object_name&gt; -o yaml : to see the configurations of the object as a yaml file.</p><p>$ kubectl delete &lt;object_type&gt; &lt;object_name&gt; : to delete any object and it’s dependencies. For example, if you delete a deployment, any pod that the deployment was supposed to run/create will also get deleted.</p><p>$ &lt;any_of_above_command&gt; -n &lt;namespace_name&gt; : by default if you use any of the above commands it will only work for the default namespace, to use the command in different namespaces you can use the -n flag. For instance, $ kubectl get po -n test .</p><p>This concludes our introduction to pre-requisites, now let’s talk about how are we solving the initial problem using k8s in the next part linked <a href="https://medium.com/@ansukumari/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-ii-implementation-46c628124e94">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9904fbc27ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/setup-kubernetes-for-your-infra-and-add-ci-cd-using-github-actions-part-i-introduction-e9904fbc27ac">Setup Kubernetes for your infra and add CI/CD using GitHub Actions — Part I (Introduction)</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I interviewed them; and they disappointed — 4 mistakes to avoid in a coding technical interview]]></title>
            <link>https://interviewnoodle.com/i-interviewed-them-and-they-disappointed-4-mistakes-to-avoid-in-a-coding-technical-interview-eaefac7de960?source=rss-3554b102d5c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaefac7de960</guid>
            <category><![CDATA[faang-interview-prep]]></category>
            <category><![CDATA[technical]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[An K]]></dc:creator>
            <pubDate>Fri, 28 Jan 2022 08:26:07 GMT</pubDate>
            <atom:updated>2022-02-03T10:07:29.675Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>I interviewed them; and they disappointed — 4 mistakes to avoid in a coding technical interview</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bm6n0NVWRrENJF7F" /><figcaption>Photo by <a href="https://unsplash.com/@heykellybrito?utm_source=medium&amp;utm_medium=referral">J. Kelly Brito</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Being someone with 2–3 years of experience in technical firms as a software engineer, I’ve given a lot of technical interviews and it is for sure unavoidable. However, the tables turned recently when I was given the opportunity to take interviews of potential candidates and most managed to disappoint me pretty well. Below are a few things you can steer clear of when giving your next interview.</p><h3>1. Not able to explain your past projects or your contribution to them.</h3><p>This is a huge no-no, this is probably the first thing I’ll ask or anyone will ask and will build the base of your profile on. Confidence speaks volumes here; if you played a vital role in your project but you’re “not able to explain it well” that is also a problem in itself, it says you don’t have proper communication skills and won’t be very efficient when working with a team.</p><h3>2. Not knowing the basics (specially if you dare enough to put that on your resume)</h3><p>What is a set? What is BST? And you said you’re good with data structures? What is OOP? “It’s a way of programming” — that’s all you’ve got?</p><p>This is pretty self-explanatory and it should not be reiterated, a technical interviewer assumes that you know the basics of programming and things you were taught in college. For instance, if your resume says you’ve completed a B Tech degree it is expected of you to answer OOPs, data structure and algorithm related questions. Even if you never did any practical projects, you should have the theoretical background of coding practices.</p><h3>3. Not able to structure your thoughts</h3><p>Honestly, it is not as important as the above two, specially if you are a fresher; I believe thought structure comes with experience, but if you are able to show you have a streamlined thought process it gives a great impression.</p><p>Thought process can be judged by your approach to a solution, you might think that providing an optimized solution right away will impress the interviewer (I know I used to) but it’s more impressive to learn that you started from scratch — a brute force approach — and built your way up to the optimized solution giving an impression that we can always keep improvising.</p><h3>4. And last, not able to solve the given problem —even to some extent.</h3><p>If you’re appearing for a technical round you should expect one problem question regardless of whether you’ve put algorithms on your resume or not. So if you’re out of touch with problem solving — PREPARE!</p><p>Depending on the role you’re applying for, the interviewer might expect you to solve all parts of the question in the most optimized way or simply present you with questions in increasing level of difficulty just to see your level of problem solving. In any case, a basic grasp on pattern based problem solving is a good start.</p><p>These were the pointers for a tech round. If you have 2–3 years of experience you might also want to prepare for the system design round, which is a slightly different game — so stay tuned for that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaefac7de960" width="1" height="1" alt=""><hr><p><a href="https://interviewnoodle.com/i-interviewed-them-and-they-disappointed-4-mistakes-to-avoid-in-a-coding-technical-interview-eaefac7de960">I interviewed them; and they disappointed — 4 mistakes to avoid in a coding technical interview</a> was originally published in <a href="https://interviewnoodle.com/">InterviewNoodle</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>