<?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"><channel><title><![CDATA[Suraj's Odyssey]]></title><description><![CDATA[Hi, I'm Suraj. I write about DevOps, Cloud, MLOps, AIOps, FinOps, and Cloud Native technologies with hands-on tutorials, debugging guides, and production insights.]]></description><link>https://blog.surajdev.tech</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1721930575568/6a7c26dd-849f-4e33-bec0-b9886a88faaf.png</url><title>Suraj&apos;s Odyssey</title><link>https://blog.surajdev.tech</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 23:11:21 GMT</lastBuildDate><atom:link href="https://blog.surajdev.tech/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Antigravity Login Issue on MacBook & How I Finally Fixed It (After Hours of Trying)]]></title><description><![CDATA[The Problem
If you're reading this, you're probably stuck in the same nightmare I was: Antigravity shows "Authentication Required Please sign in" no matter what you do. You've reinstalled it. You've c]]></description><link>https://blog.surajdev.tech/antigravity-login-issue-on-macbook-how-i-finally-fixed-it-after-hours-of-trying</link><guid isPermaLink="true">https://blog.surajdev.tech/antigravity-login-issue-on-macbook-how-i-finally-fixed-it-after-hours-of-trying</guid><category><![CDATA[Google Antigravity]]></category><category><![CDATA[macOS]]></category><category><![CDATA[debugging]]></category><category><![CDATA[Google AI]]></category><category><![CDATA[devtools]]></category><category><![CDATA[Productivity]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Tue, 24 Mar 2026 16:51:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/63f0aa570e63a77a616fd5ab/b7f0b56e-007a-4336-90e9-5842f06de4c5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>The Problem</strong></h2>
<p>If you're reading this, you're probably stuck in the same nightmare I was: Antigravity shows <strong>"Authentication Required Please sign in"</strong> no matter what you do. You've reinstalled it. You've cleared the browser cache. You've restarted your MacBook. Nothing works.</p>
<img src="https://cdn.hashnode.com/uploads/covers/63f0aa570e63a77a616fd5ab/c2f42a03-6a43-41a6-855d-0e5820562c61.png" alt="" style="display:block;margin:0 auto" />

<p>Here's the complete story of what happened, every fix I tried, and what finally resolved it.</p>
<p><strong>The symptoms were confusing and contradictory:</strong></p>
<ul>
<li><p>Antigravity's <strong>Settings page showed my Google account</strong>, so it knew I was logged in</p>
</li>
<li><p>But the <strong>main/Agent view kept showing "Sign In"</strong></p>
</li>
<li><p>Clicking "Sign In" would open Google auth in the browser, I'd complete it successfully, but Antigravity would <strong>loop right back</strong> to "Authentication Required"</p>
</li>
<li><p>I couldn't even <strong>sign out</strong>, there was no sign-out option because the app was in a broken half-authenticated state</p>
</li>
</ul>
<h2><strong>What I Already Tried (That Didn't Work)</strong></h2>
<p>Before finding the real fix, I tried everything the internet suggested:</p>
<ul>
<li><p>❌ Restarted the MacBook</p>
</li>
<li><p>❌ Cleared browser cache and cookies</p>
</li>
<li><p>❌ Deleted Antigravity and reinstalled it</p>
</li>
<li><p>❌ Deleted <code>~/Library/Application Support/Antigravity/Session Storage</code></p>
</li>
<li><p>❌ Deleted <code>~/Library/Application Support/Antigravity/Local Storage</code></p>
</li>
<li><p>❌ Deleted <code>auth-tokens</code>, <code>Cookies</code> folders</p>
</li>
<li><p>❌ Deleted <code>~/.gemini/antigravity</code></p>
</li>
<li><p>❌ Used <code>Ctrl+Shift+P</code> → <code>Antigravity: Reset Onboarding</code></p>
</li>
<li><p>❌ Applied the BigInt patch to <code>main.js</code></p>
</li>
<li><p>❌ Switched default browser from Brave to Safari</p>
</li>
</ul>
<p><strong>None of it worked.</strong> Here's why, I was missing the actual root cause every single time.</p>
<h2><strong>The Root Cause: macOS Keychain</strong></h2>
<p>Here's what nobody tells you:</p>
<p>When Antigravity first authenticates, it stores an encrypted token in <strong>macOS Keychain</strong> under the name <strong>"Antigravity Safe Storage"</strong>. This is completely separate from the app's files in <code>~/Library/Application Support/</code>.</p>
<p>When you <strong>uninstall</strong> Antigravity, the app files are removed, but the Keychain entry <strong>stays behind</strong>. When you reinstall and try to log in again, Antigravity finds this old, expired, corrupted token in Keychain and tries to use it. It fails silently. No error message. Just "Authentication Required" forever.</p>
<p><strong>This is why:</strong></p>
<ul>
<li><p>Other macOS user profiles on the same Mac worked fine (each profile has its own Keychain)</p>
</li>
<li><p>Reinstalling never helped (Keychain survives uninstalls)</p>
</li>
<li><p>Clearing Library folders never helped (Keychain is stored separately)</p>
</li>
</ul>
<h2><strong>The Fix</strong></h2>
<h3><strong>Step 1: Kill Antigravity completely</strong></h3>
<pre><code class="language-plaintext">pkill -f Antigravity
</code></pre>
<h3><strong>Step 2: Delete all app data</strong></h3>
<pre><code class="language-plaintext">rm -rf ~/Library/Application\ Support/Antigravity/
rm -rf ~/.gemini/antigravity
rm -rf ~/Library/Caches/Antigravity/
rm -rf ~/Library/Logs/Antigravity/
</code></pre>
<h3><strong>Step 3: Delete the Keychain entry (THE KEY STEP)</strong></h3>
<pre><code class="language-shell">security delete-generic-password -l "Antigravity Safe Storage"
</code></pre>
<p><strong>You should see:</strong></p>
<pre><code class="language-shell">password has been deleted.
</code></pre>
<p>Alternatively, do it via UI:</p>
<ol>
<li><p>Open <strong>Keychain Access</strong> (Spotlight → search "Keychain Access")</p>
</li>
<li><p>Search for <code>antigravity</code></p>
</li>
<li><p>Right-click <strong>"Antigravity Safe Storage"</strong> → Delete</p>
</li>
<li><p>Enter your Mac login password when prompted → click <strong>Always Allow</strong></p>
</li>
</ol>
<h3><strong>Step 4: Set Safari as default browser temporarily</strong></h3>
<ul>
<li><p>Apple menu → <strong>System Settings</strong> → <strong>Desktop &amp; Dock</strong> → <strong>Default web browser</strong> → <strong>Safari</strong></p>
<blockquote>
<p><strong>Why Safari? If you use Brave, its aggressive "Auto-redirect tracking URLs" feature intercepts the OAuth callback URL and silently kills the token handoff back to the app.</strong></p>
</blockquote>
</li>
</ul>
<h3><strong>Step 5: Sign in</strong></h3>
<ol>
<li><p>Open Antigravity</p>
</li>
<li><p>Click <strong>Sign In</strong></p>
</li>
<li><p>Complete Google auth in Safari</p>
</li>
<li><p>✅ Done, switch back to Brave after</p>
</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/63f0aa570e63a77a616fd5ab/0b6e85d7-5ff0-4b03-9be3-70d0dc5b9094.png" alt="" style="display:block;margin:0 auto" />

<h3><strong>Bonus: Why Brave Browser Made It Worse</strong></h3>
<p>Even after fixing the Keychain issue, if you use Brave as your default browser, you may still face the auth loop. Brave's Shields intercept OAuth redirect URLs as "tracking URLs" and kill the token handoff. The fix is simple, use Safari (or any non-Brave browser) as your default browser just for the sign-in step.</p>
<h2><strong>Conclusion</strong></h2>
<table>
<thead>
<tr>
<th><strong>What I tried</strong></th>
<th><strong>Why it failed</strong></th>
</tr>
</thead>
<tbody><tr>
<td>Reinstalling Antigravity</td>
<td>Keychain token survives uninstalls</td>
</tr>
<tr>
<td>Clearing Library folders</td>
<td>Keychain is stored separately</td>
</tr>
<tr>
<td>BigInt patch</td>
<td>Different issue entirely</td>
</tr>
<tr>
<td>Browser cache clear</td>
<td>OAuth token lives in Keychain, not browser</td>
</tr>
<tr>
<td><strong>Deleting Keychain entry</strong></td>
<td>✅ This was the actual fix</td>
</tr>
</tbody></table>
<p>The corrupted Keychain entry in my case was dated <strong>November 21, 2025</strong>. A 4-month-old stale token that had been silently blocking every login attempt since then.</p>
<p>If you're stuck on this issue, go straight to the Keychain step. It'll save you hours.</p>
]]></content:encoded></item><item><title><![CDATA[How I Contributed to the CNCF Kubernetes Conformance Program]]></title><description><![CDATA[Submitting Kubernetes v1.34 conformance results for Kubespray.
Every Kubernetes distribution needs to prove it behaves like Kubernetes. That proof comes through the CNCF Kubernetes Conformance Program, a standardized set of 424 end-to-end tests that ...]]></description><link>https://blog.surajdev.tech/how-i-contributed-to-the-cncf-kubernetes-conformance-program</link><guid isPermaLink="true">https://blog.surajdev.tech/how-i-contributed-to-the-cncf-kubernetes-conformance-program</guid><category><![CDATA[Kubernetes]]></category><category><![CDATA[kubespray]]></category><category><![CDATA[Conformance Testing]]></category><category><![CDATA[vagrant]]></category><category><![CDATA[vagrantfile]]></category><category><![CDATA[CNCF]]></category><category><![CDATA[Open Source]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Thu, 12 Feb 2026 19:40:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1770925104424/1f2af145-33b7-4c90-bb21-3a93d436df47.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Submitting Kubernetes v1.34 conformance results for Kubespray.</em></p>
<p>Every Kubernetes distribution needs to prove it behaves like Kubernetes. That proof comes through the <strong>CNCF Kubernetes Conformance Program</strong>, a standardized set of 424 end-to-end tests that verify a distribution implements the Kubernetes API correctly. If it passes, it earns the <strong>"Certified Kubernetes"</strong> badge.</p>
<p>This is the story of how I picked up a <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/issues/12932">GitHub issue</a>, ran into DNS nightmares, broke my cluster twice, learned a ton about Linux internals, and ultimately got my <a target="_blank" href="https://github.com/cncf/k8s-conformance/pull/4078">PR merged</a> into the official CNCF conformance repository.</p>
<h2 id="heading-what-is-kubespray">What is Kubespray?</h2>
<p><a target="_blank" href="https://github.com/kubernetes-sigs/kubespray">Kubespray</a> is an <strong>Ansible-based tool</strong> for deploying production-ready Kubernetes clusters. It's part of the official <a target="_blank" href="https://github.com/kubernetes-sigs">kubernetes-sigs</a> organization and supports deployment across <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_providers/aws.md"><strong>AWS,</strong></a> <strong>GCE,</strong> <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_providers/azure.md"><strong>Azure,</strong></a> <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_providers/azure.md"><strong>Ope</strong></a><a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_controllers/openstack.md"><strong>nStack,</strong></a> <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_controllers/openstack.md"><strong>vSphere</strong></a><a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_controllers/vsphere.md"><strong>,</strong></a> <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_controllers/vsphere.md"><strong>Equin</strong></a><a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/docs/cloud_providers/equinix-metal.md"><strong>ix Metal (bare metal)</strong></a><strong>, Oracle Cloud Infrastructure (Experimental), or Baremetal</strong></p>
<p>Think of it as "Infrastructure as Code for Kubernetes", you define your cluster configuration, and Kubespray handles the 50+ steps needed to get a production-grade Kubernetes cluster running. For a deeper dive, check the <a target="_blank" href="https://kubespray.io">official documentation</a>.</p>
<h2 id="heading-what-is-conformance-testing">What is Conformance Testing?</h2>
<p>The CNCF runs the <a target="_blank" href="https://github.com/cncf/k8s-conformance">Kubernetes Software Conformance Certification</a> program. Every time a new Kubernetes version is released, distributions like Kubespray need to submit proof that they can deploy a conformant cluster.</p>
<p><strong>The submission requires four files:</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>File</td><td>Purpose</td></tr>
</thead>
<tbody>
<tr>
<td><a target="_blank" href="k8s-conformance/v1.34/kubespray/PRODUCT.yaml">PRODUCT.yaml</a></td><td>Product metadata (vendor, name, version, URLs)</td></tr>
<tr>
<td><a target="_blank" href="http://README.md">README.md</a></td><td>Step-by-step instructions to reproduce the test</td></tr>
<tr>
<td><a target="_blank" href="k8s-conformance/v1.30/kubespray/e2e.log">e2e.log</a></td><td>Raw test output log</td></tr>
<tr>
<td><a target="_blank" href="k8s-conformance/v1.34/kubespray/junit_01.xml">junit_01.xml</a></td><td>Machine-readable test results</td></tr>
</tbody>
</table>
</div><p>The testing tool is <a target="_blank" href="https://sonobuoy.io/"><strong>Sonobuoy</strong></a><strong>,</strong> it runs 424 end-to-end tests inside your cluster in <code>certified-conformance</code> mode.</p>
<h2 id="heading-the-issue-k8s-conformance-test-for-v134">The Issue: K8s Conformance Test for v1.34</h2>
<p>I found <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/issues/12932">issue #12932</a> on the kubespray repo, they needed someone to run the conformance tests for Kubernetes v1.34 using Kubespray v2.30.0 and submit the results to the CNCF.</p>
<p>The task seemed straightforward:</p>
<ol>
<li><p>Spin up a 3-node Kubernetes cluster using Kubespray</p>
</li>
<li><p>Run Sonobuoy conformance tests</p>
</li>
<li><p>Collect results and submit a PR</p>
</li>
</ol>
<p>How hard could it be? <em>Spoiler: very.</em></p>
<h2 id="heading-my-setup">My Setup</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Component</td><td>Details</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Host Machine</strong></td><td>MacBook Pro M1 Pro (Apple Silicon / ARM64)</td></tr>
<tr>
<td><strong>Hypervisor</strong></td><td>VMware Fusion</td></tr>
<tr>
<td><strong>VM Provisioning</strong></td><td>Vagrant</td></tr>
<tr>
<td><strong>OS (Guest VMs)</strong></td><td>Ubuntu 24.04 LTS ARM64</td></tr>
<tr>
<td><strong>Kubernetes</strong></td><td>v1.34.3 (via Kubespray v2.30.0)</td></tr>
<tr>
<td><strong>CNI</strong></td><td>Calico (required for ARM6, <a target="_blank" href="https://kubespray.io/#/docs/advanced/arch">Flannel doesn't support ARM64</a>)</td></tr>
<tr>
<td><strong>Cluster</strong></td><td>3 nodes (2 control-plane, 1 worker)</td></tr>
</tbody>
</table>
</div><h3 id="heading-why-vagrant">Why Vagrant?</h3>
<p><a target="_blank" href="https://www.vagrantup.com/">Vagrant</a> is a tool for building and managing virtual machine environments. It reads a <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/Vagrantfile">Vagrantfile</a> and provisions VMs automatically. Kubespray includes a <a target="_blank" href="https://github.com/kubernetes-sigs/kubespray/blob/master/Vagrantfile">Vagrantfile</a> that integrates with its Ansible playbooks, so <code>vagrant up</code> creates VMs, configures networking, and runs Kubespray to deploy Kubernetes. All in one command.</p>
<p>For conformance testing, this is ideal because it ensures <strong>reproducibility</strong>, anyone can follow the same steps to recreate the exact environment.</p>
<h3 id="heading-why-calico-instead-of-flannel">Why Calico Instead of Flannel?</h3>
<p>This is an ARM64-specific gotcha. According to the <a target="_blank" href="https://kubespray.io/#/docs/advanced/arch">Kubespray architecture docs</a>, Flannel <strong>does not support ARM64</strong>. Calico is the recommended CNI for ARM64 clusters.</p>
<h2 id="heading-the-journey-what-actually-happened">The Journey: What Actually Happened</h2>
<h3 id="heading-phase-1-getting-the-cluster-up">Phase 1: Getting the Cluster Up</h3>
<p>Setting up the Vagrant configuration was straightforward:</p>
<pre><code class="lang-ruby">$instance_name_prefix = <span class="hljs-string">"kube"</span>
$vm_cpus = <span class="hljs-number">2</span>
$vm_memory = <span class="hljs-number">4096</span>
$num_instances = <span class="hljs-number">3</span>
$os = <span class="hljs-string">"ubuntu2404"</span>
$subnet = <span class="hljs-string">"10.2.20"</span>
$inventory = <span class="hljs-string">"inventory/k8s-conformance"</span>
$network_plugin = <span class="hljs-string">"calico"</span>
</code></pre>
<p>Running <code>vagrant up</code> kicked off the Ansible playbook, and after about 20 minutes, I had a 3-node Kubernetes cluster. So far, so good.</p>
<pre><code class="lang-bash">$ kubectl get nodes
NAME     STATUS   ROLES           AGE   VERSION
kube-1   Ready    control-plane   10m   v1.34.3
kube-2   Ready    control-plane   10m   v1.34.3
kube-3   Ready    &lt;none&gt;          10m   v1.34.3
</code></pre>
<h3 id="heading-phase-2-the-first-sonobuoy-run-dns-failures">Phase 2: The First Sonobuoy Run — DNS Failures</h3>
<p>I downloaded Sonobuoy v0.57.2 (ARM64 binary) and started the conformance tests:</p>
<pre><code class="lang-bash">./sonobuoy run --mode=certified-conformance \
    --sonobuoy-image=sonobuoy/sonobuoy:v0.57 \
    --systemd-logs-image=sonobuoy/systemd-logs-arm64:v0.4 \
    --<span class="hljs-built_in">wait</span>
</code></pre>
<p>~2 hours later, the results came back:</p>
<pre><code class="lang-bash">Passed: 0, Failed: 0, Remaining: 424
</code></pre>
<p>Wait, <strong>0 passed AND 0 failed?</strong> That means the e2e plugin crashed before running any tests. Digging into the logs, I found the culprit:</p>
<pre><code class="lang-bash">[sig-network] DNS should provide DNS <span class="hljs-keyword">for</span> the cluster
FAILED [602.517 seconds]

Unable to <span class="hljs-built_in">read</span> from pod dns-test-...: the server could not find the requested resource
</code></pre>
<p>The test pods were being created but <strong>immediately disappearing</strong>. The DNS test couldn't find its own pods.</p>
<h3 id="heading-phase-3-the-rabbit-hole-systemd-resolved">Phase 3: The Rabbit Hole — systemd-resolved</h3>
<p>Here's where it got interesting. Ubuntu 24.04 uses <code>systemd-resolved</code> for DNS resolution. This service creates a stub resolver at <code>127.0.0.53</code> and manages <code>/etc/resolv.conf(file:///etc/resolv.conf)</code> as a symlink to <code>/run/systemd/resolve/stub-resolv.conf</code>.</p>
<p><strong>The problem:</strong> CoreDNS inside the cluster was trying to use <code>127.0.0.53</code> as an upstream DNS server, but that address is <strong>only valid inside the host</strong>, not inside containers. Every container DNS lookup was timing out.</p>
<p><strong>The fix:</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment"># Disable systemd-resolved</span>
sudo systemctl stop systemd-resolved
sudo systemctl <span class="hljs-built_in">disable</span> systemd-resolved

<span class="hljs-comment"># Replace with direct DNS servers</span>
sudo rm -f /etc/resolv.conf
<span class="hljs-built_in">echo</span> -e <span class="hljs-string">'nameserver 8.8.8.8\nnameserver 8.8.4.4'</span> | sudo tee /etc/resolv.conf
</code></pre>
<p>I applied this on all three nodes. DNS test looked good now:</p>
<pre><code class="lang-bash">$ kubectl run dnstest --image=busybox:1.28 --rm -it --restart=Never -- nslookup google.com
Name:      google.com
Address 1: 142.250.192.206
✅
</code></pre>
<h3 id="heading-phase-4-the-second-sonobuoy-run-still-failing">Phase 4: The Second Sonobuoy Run — Still Failing</h3>
<p>Ran Sonobuoy again. Another 2+ hours. Same result:</p>
<pre><code class="lang-bash">Passed: 0, Failed: 0, Remaining: 424
</code></pre>
<p>The cluster was showing signs of instability, controller restarts, unhealthy probes, context deadline exceeded errors. Something deeper was wrong.</p>
<h3 id="heading-phase-5-the-reboot-that-broke-everything">Phase 5: The Reboot That Broke Everything</h3>
<p>I rebooted all three nodes to clear the instability. After rebooting, the cluster was <strong>completely dead</strong>:</p>
<pre><code class="lang-bash">The connection to the server 127.0.0.1:6443 was refused
</code></pre>
<p>The API server wasn't starting. No containers were running. Checking the kubelet logs revealed the smoking gun:</p>
<pre><code class="lang-bash">E0203 18:15:08.841453 dns.go:285] <span class="hljs-string">"Could not open resolv conf file."</span>
err=<span class="hljs-string">"open /run/systemd/resolve/resolv.conf: no such file or directory"</span>

E0203 18:15:08.841474 kuberuntime_sandbox.go:44]
<span class="hljs-string">"Failed to generate sandbox config for pod"</span>
err=<span class="hljs-string">"open /run/systemd/resolve/resolv.conf: no such file or directory"</span>
</code></pre>
<p><strong>Our DNS fix broke the kubelet!</strong></p>
<p>When we disabled <code>systemd-resolved</code> and deleted its files, we also removed <code>/run/systemd/resolve/resolv.conf</code>. But the kubelet was configured to read DNS settings from that exact file path. Without it, <strong>kubelet couldn't create any pod sandboxes</strong> — which means no static pods, which means no API server, which means a dead cluster.</p>
<h3 id="heading-phase-6-the-real-fix-the-symlink">Phase 6: The Real Fix — The Symlink</h3>
<p>The solution was elegant: create the directory and symlink it back to our static resolv.conf:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Create the directory kubelet expects</span>
sudo mkdir -p /run/systemd/resolve

<span class="hljs-comment"># Symlink to our static resolv.conf with real DNS servers</span>
sudo ln -sf /etc/resolv.conf /run/systemd/resolve/resolv.conf

<span class="hljs-comment"># Restart kubelet</span>
sudo systemctl restart kubelet
</code></pre>
<p>Applied this to all three nodes. Within 30 seconds:</p>
<pre><code class="lang-bash">$ kubectl get nodes
NAME     STATUS   ROLES           AGE   VERSION
kube-1   Ready    control-plane   26h   v1.34.3
kube-2   Ready    control-plane   26h   v1.34.3
kube-3   Ready    &lt;none&gt;          25h   v1.34.3
</code></pre>
<p><strong>The cluster was back!</strong></p>
<h3 id="heading-phase-7-the-final-run-424424">Phase 7: The Final Run — 424/424 ✅</h3>
<p>Third time's the charm. With the DNS properly configured and the kubelet symlink in place, I ran Sonobuoy one last time:</p>
<pre><code class="lang-bash">./sonobuoy run --mode=certified-conformance \
    --sonobuoy-image=sonobuoy/sonobuoy:v0.57 \
    --systemd-logs-image=sonobuoy/systemd-logs-arm64:v0.4 \
    --<span class="hljs-built_in">wait</span>
</code></pre>
<p>~1 hour 42 minutes later:</p>
<pre><code class="lang-bash">Ran 424 of 7137 Specs <span class="hljs-keyword">in</span> 6112.853 seconds
SUCCESS! -- 424 Passed | 0 Failed | 0 Pending | 6713 Skipped
PASS
</code></pre>
<p><strong>ALL 424 TESTS PASSED.</strong> 🎉</p>
<h2 id="heading-the-pr-submission">The PR Submission</h2>
<h3 id="heading-the-commit-squashing-lesson">The Commit Squashing Lesson</h3>
<p>The CNCF conformance repo has strict CI checks. One of them: <strong>exactly one commit per submission</strong>. My branch had accumulated multiple commits during the debugging process. The conformance bot flagged it:</p>
<pre><code class="lang-bash">[FAIL] it appears that there is not exactly one commit.
Please rebase and squash with git rebase -i HEAD
</code></pre>
<p>The fix:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Reset to the base commit (keeping all changes staged)</span>
git reset --soft &lt;base-commit-hash&gt;

<span class="hljs-comment"># Create a single commit with DCO sign-off</span>
git commit -s -m <span class="hljs-string">"Conformance results for v1.34/kubespray"</span>

<span class="hljs-comment"># Force push to update the PR</span>
git push --force-with-lease origin conformance/v1.34-kubespray
</code></pre>
<h3 id="heading-dco-sign-off">DCO Sign-Off</h3>
<p>The CNCF requires a <a target="_blank" href="https://developercertificate.org/">Developer Certificate of Origin (DCO)</a> sign-off on every commit. This is done with the <code>-s</code> flag in <code>git commit</code>, which adds:</p>
<pre><code class="lang-bash">Signed-off-by: Your Name &lt;your-email@example.com&gt;
</code></pre>
<h3 id="heading-the-result">The Result</h3>
<p>After squashing into a single signed commit, the bot confirmed:</p>
<pre><code class="lang-bash">All requirements (15) have passed <span class="hljs-keyword">for</span> the submission!
</code></pre>
<p>On <strong>February 10, 2026</strong>, <a target="_blank" href="https://github.com/taylorwaggoner">Taylor Waggoner</a> (CNCF staff) merged the PR with:</p>
<blockquote>
<p><strong>"You are now Certified Kubernetes 🎉"</strong></p>
</blockquote>
<p><a target="_blank" href="https://github.com/cncf/k8s-conformance/pull/4078"><strong>PR #4078</strong></a> <strong>— Merged.</strong></p>
<h2 id="heading-what-i-learned">What I Learned</h2>
<h3 id="heading-technical-skills">Technical Skills</h3>
<ul>
<li><p><strong>Linux DNS internals</strong>: How <code>systemd-resolved</code> works, the difference between stub resolvers (<code>127.0.0.53</code>) and direct DNS, and the resolution chain</p>
</li>
<li><p><strong>Kubernetes node architecture</strong>: How kubelet starts static pods (API server, scheduler, controller-manager) using manifest files in <code>/etc/kubernetes/manifests/</code></p>
</li>
<li><p><strong>Container networking</strong>: How CoreDNS resolves cluster DNS and how host DNS configuration affects pod DNS resolution</p>
</li>
<li><p><strong>Sonobuoy &amp; e2e testing</strong>: Running conformance tests, interpreting results, understanding the difference between test failures and infrastructure failures</p>
</li>
<li><p><strong>ARM64 considerations</strong>: Not all CNI plugins support ARM64, Sonobuoy needs architecture-specific images, and some configurations behave differently on ARM</p>
</li>
</ul>
<h3 id="heading-open-source-best-practices">Open Source Best Practices</h3>
<ul>
<li><p><strong>Read existing submissions first</strong>: Looking at <a target="_blank" href="https://github.com/cncf/k8s-conformance/tree/master/v1.30/kubespray">previous conformance PRs</a> saved me hours</p>
</li>
<li><p><strong>Follow CI requirements precisely</strong>: Single commit, DCO sign-off, correct directory structure, and automation enforces these strictly</p>
</li>
<li><p><strong>Document everything</strong>: The README should contain reproducible steps so anyone can verify your results</p>
</li>
<li><p><strong>Be patient with debugging</strong>: What seemed like a DNS issue turned out to be a kubelet configuration dependency. Layer by layer, the picture became clear</p>
</li>
</ul>
<h3 id="heading-the-debugging-mindset">The Debugging Mindset</h3>
<p>The biggest lesson was <strong>systematic troubleshooting</strong>. When the tests failed:</p>
<ol>
<li><p><strong>Read the actual logs</strong>, not just the summary</p>
</li>
<li><p><strong>Check each component</strong> independently (kubelet → containerd → API server → pods)</p>
</li>
<li><p><strong>Understand the dependency chain</strong> (kubelet needs DNS config → DNS config path is hardcoded → removing systemd-resolved removed that path)</p>
</li>
<li><p><strong>Test incrementally</strong> (verify DNS works before running full test suite)</p>
</li>
</ol>
<h2 id="heading-the-complete-dns-fix">The Complete DNS Fix</h2>
<p>For anyone running Kubespray conformance tests on Ubuntu 24.04 (or any OS with <code>systemd-resolved</code>), here's the complete fix that works:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># On each node (kube-1, kube-2, kube-3):</span>

<span class="hljs-comment"># 1. Disable systemd-resolved</span>
sudo systemctl stop systemd-resolved
sudo systemctl <span class="hljs-built_in">disable</span> systemd-resolved

<span class="hljs-comment"># 2. Set up direct DNS</span>
sudo rm -f /etc/resolv.conf
<span class="hljs-built_in">echo</span> -e <span class="hljs-string">'nameserver 8.8.8.8\nnameserver 8.8.4.4'</span> | sudo tee /etc/resolv.conf

<span class="hljs-comment"># 3. Create the symlink kubelet expects (THIS IS THE KEY STEP)</span>
sudo mkdir -p /run/systemd/resolve
sudo ln -sf /etc/resolv.conf /run/systemd/resolve/resolv.conf

<span class="hljs-comment"># 4. Restart services</span>
sudo systemctl restart containerd kubelet
</code></pre>
<p><strong>Wait 2-3 minutes</strong> for the cluster to stabilize before running Sonobuoy.</p>
<h2 id="heading-resources">Resources</h2>
<ul>
<li><p><a target="_blank" href="https://kubespray.io">Kubespray Documentation</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/cncf/k8s-conformance/blob/master/instructions.md">CNCF Conformance Instructions</a></p>
</li>
<li><p><a target="_blank" href="https://sonobuoy.io/docs">Sonobuoy Documentation</a></p>
</li>
</ul>
<p><em>If you're working on a conformance submission and hit DNS issues on Ubuntu/Fedora, the symlink fix above might save you a few hours. Happy testing!</em></p>
]]></content:encoded></item><item><title><![CDATA[Fix Wrong Authors Commits the Safe Way Using Git Rebase]]></title><description><![CDATA[Introduction
Ever committed code with the wrong Git author? Whether you're juggling personal and work accounts or just forgot to configure your identity in a new project, this happens to the best of us. The good news? You can fix it safely and in thi...]]></description><link>https://blog.surajdev.tech/fix-wrong-authors-commits-the-safe-way-using-git-rebase</link><guid isPermaLink="true">https://blog.surajdev.tech/fix-wrong-authors-commits-the-safe-way-using-git-rebase</guid><category><![CDATA[Git]]></category><category><![CDATA[git rebase]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[Gitcommands]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Sun, 21 Sep 2025 17:28:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1757877525408/79519833-0efb-4a79-973c-d6fabac9128f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>Ever committed code with the wrong Git author? Whether you're juggling personal and work accounts or just forgot to configure your identity in a new project, this happens to the best of us. The good news? <strong>You can fix it safely</strong> and in this guide, we'll do it the smart way using a Docker sandbox plus real GitHub practice.</p>
<h2 id="heading-what-youll-learn">What You'll Learn</h2>
<ul>
<li><p><strong>Git rebase fundamentals</strong> (interactive mode explained simply)</p>
</li>
<li><p><strong>Three real-world scenarios</strong> for fixing wrong authors</p>
</li>
<li><p><strong>Safe Docker lab environment</strong> (no risk to your actual Git setup)</p>
</li>
<li><p><strong>Hands-on GitHub practice</strong> (see the fixes in action)</p>
</li>
</ul>
<h2 id="heading-why-this-approach-works">Why This Approach Works</h2>
<p><strong>Docker Container:</strong> Keeps your global Git config safe while you experiment<br /><strong>Real GitHub Repo:</strong> See the actual before/after results in GitHub's UI<br /><strong>Progressive Scenarios:</strong> From simple local fixes to complex merged commits</p>
<p>We'll simulate this common mistake:</p>
<ul>
<li><p><strong>Global user (wrong)</strong> → <code>surajdeveloper &lt;surajdeveloper@example.com&gt;</code> → You have made commit with this</p>
</li>
<li><p><strong>Repo user (correct)</strong> → <code>surajdevops &lt;surajdevops@example.com&gt;</code> → But you should have made the commit with this.</p>
</li>
</ul>
<h2 id="heading-git-rebase-the-foundation">Git Rebase : The Foundation</h2>
<p>Before diving into <strong>fixes</strong>, let's understand <strong>why we use Git rebase</strong> for <strong>author corrections</strong>.</p>
<h3 id="heading-what-is-git-rebase">What is Git Rebase?</h3>
<p>Takes your commits and replays them on top of another branch, creating a <strong>straight line history</strong>.</p>
<pre><code class="lang-bash">git rebase main
</code></pre>
<p><strong>What it does:</strong></p>
<ul>
<li><p>Moves your commits to the tip of main branch</p>
</li>
<li><p>Creates <strong>new commit IDs</strong> (rewrites history)</p>
</li>
<li><p>Makes history look like you worked on the latest code all along</p>
</li>
</ul>
<h2 id="heading-what-is-git-merge">What is Git Merge?</h2>
<p><strong>Git Merge</strong> = Combines two branches by creating a <strong>merge commit</strong> that joins them together.</p>
<pre><code class="lang-bash">git merge feature
</code></pre>
<p><strong>What it does:</strong></p>
<ul>
<li><p>Keeps <strong>original commits unchanged</strong></p>
</li>
<li><p>Creates one new "merge commit"</p>
</li>
<li><p>Preserves the branching structure</p>
</li>
</ul>
<h2 id="heading-when-to-use">When to Use?</h2>
<ul>
<li><p><strong>Merge:</strong> When working with others on the same branch</p>
</li>
<li><p><strong>Rebase:</strong> When cleaning up your local commits before opening a PR</p>
</li>
</ul>
<p><strong>Golden Rule:</strong> Never rebase shared branches!</p>
<h2 id="heading-why-use-interactive-rebase-for-fixes">Why Use Interactive Rebase for Fixes?</h2>
<p>If you only need to fix the <strong>latest commit</strong>, you can use:</p>
<pre><code class="lang-bash">git commit --amend --author=<span class="hljs-string">"Correct Name &lt;correct@email.com&gt;"</span>
</code></pre>
<p>But if the wrong author is <strong>buried in the middle</strong> of history, you need to:</p>
<ol>
<li><p><strong>Stop at that specific commit</strong></p>
</li>
<li><p><strong>Fix the author information</strong></p>
</li>
<li><p><strong>Replay the remaining commits</strong></p>
</li>
</ol>
<p>That's exactly what <code>git rebase -i</code> (interactive rebase) does!</p>
<h2 id="heading-rebase-vs-merge-quick-comparison">Rebase vs Merge: Quick Comparison</h2>
<ul>
<li><p><strong>Merge</strong> = Combines two branches while preserving original commit history</p>
</li>
<li><p><strong>Rebase</strong> = Replays commits on a new base, rewriting history for a clean linear timeline</p>
</li>
</ul>
<h3 id="heading-interactive-rebase-what-happens-under-the-hood">Interactive Rebase: What Happens Under the Hood</h3>
<p>When you run <code>git rebase -i HEAD~3</code>, here's the journey:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758043872419/7805a4db-a7af-4a13-8e46-4d0dabd5b3c0.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-visual-before-amp-after-actual-git-output">Visual: Before &amp; After (Actual Git Output)</h3>
<p><strong>Before (wrong author on commits):</strong></p>
<pre><code class="lang-bash">$ git <span class="hljs-built_in">log</span> --oneline --graph --pretty=format:<span class="hljs-string">'%h - %an &lt;%ae&gt; - %s'</span>
* 9a3f8d2 - surajdeveloper &lt;surajdeveloper@example.com&gt; - Add gitignore
* 7b2c4e1 - surajdeveloper &lt;surajdeveloper@example.com&gt; - Add main application file
* 5d1a3b9 - surajdevops &lt;surajdevops@example.com&gt; - Initial commit
</code></pre>
<p>Notice commits <code>9a3f8d2</code> and <code>7b2c4e1</code> have the <strong>wrong author</strong> (surajdeveloper).</p>
<p><strong>During interactive rebase:</strong></p>
<pre><code class="lang-bash">$ git rebase -i HEAD~3
<span class="hljs-comment"># Editor opens showing:</span>
pick 5d1a3b9 Initial commit
pick 7b2c4e1 Add main application file  
pick 9a3f8d2 Add gitignore

<span class="hljs-comment"># You change it to:</span>
pick 5d1a3b9 Initial commit
edit 7b2c4e1 Add main application file  <span class="hljs-comment"># &lt;- mark as edit</span>
edit 9a3f8d2 Add gitignore              <span class="hljs-comment"># &lt;- mark as edit</span>
</code></pre>
<p><strong>After fixing with rebase + amend:</strong></p>
<pre><code class="lang-bash">$ git <span class="hljs-built_in">log</span> --oneline --graph --pretty=format:<span class="hljs-string">'%h - %an &lt;%ae&gt; - %s'</span>
* 2f8a9c5 - surajdevops &lt;surajdevops@example.com&gt; - Add gitignore
* 4e7b3d1 - surajdevops &lt;surajdevops@example.com&gt; - Add main application file
* 5d1a3b9 - surajdevops &lt;surajdevops@example.com&gt; - Initial commit
</code></pre>
<p>✅ All commits now show the <strong>correct author</strong> (surajdevops)!<br />⚠️ Note: The commit hashes changed (9a3f8d2 → 2f8a9c5) because we rewrote history.</p>
<h2 id="heading-setting-up-your-docker-git-lab-lets-do-it-hands-on">🐳 Setting Up Your Docker Git Lab: Let's do it hands-on</h2>
<p>Let's create a completely isolated environment for safe experimentation.</p>
<h3 id="heading-build-amp-run-the-lab-with-the-docker-image-and-clone-the-github-repo">Build &amp; Run the Lab with the Docker image and clone the GitHub repo:</h3>
<p><strong>Image:</strong> <a target="_blank" href="https://hub.docker.com/r/surajkumar00/git-rebase-lab">https://hub.docker.com/r/surajkumar00/git-rebase-lab</a><br /><strong>GitHub repo:</strong> <a target="_blank" href="https://github.com/Suraj-kumar00/learn-git">https://github.com/Suraj-kumar00/learn-git</a></p>
<h3 id="heading-run-interactive-container">Run interactive container</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Run interactive container</span>
docker run -it --rm surajkumar00/git-rebase-lab

git <span class="hljs-built_in">clone</span> https://github.com/Suraj-kumar00/learn-git.git
<span class="hljs-built_in">cd</span> learn-git
</code></pre>
<p>You're now inside a clean Ubuntu container and GitHub repo with Git ready to go!</p>
<h2 id="heading-lab-exercise-creating-the-problem">Lab Exercise: Creating the Problem</h2>
<p>Let's simulate the real-world scenario where you accidentally use the wrong Git identity.</p>
<h3 id="heading-step-0-create-a-feature-branch">Step 0: Create a feature branch</h3>
<pre><code class="lang-bash">git checkout -b feature

<span class="hljs-comment"># Check the branch</span>
git branch
</code></pre>
<h3 id="heading-step-1-set-wrong-global-identity">Step 1: Set Wrong Global Identity</h3>
<p>Inside the Docker container:</p>
<pre><code class="lang-bash">git config --global user.name <span class="hljs-string">"surajdeveloper"</span>
git config --global user.email <span class="hljs-string">"surajdeveloper@example.com"</span>

<span class="hljs-comment"># Verify it's set</span>
git config --global --list
<span class="hljs-comment"># or</span>
git config --list
</code></pre>
<h3 id="heading-step-2-lets-make-some-commits">Step 2: Let's make some Commits</h3>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">"console.log('Hello World');"</span> &gt; app.js
git add app.js
git commit -m <span class="hljs-string">"Add main javascript application file"</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"print('Hello World')"</span> &gt; main.py
git add main.py
git commit -m <span class="hljs-string">"Add main python application file"</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"node_modules/"</span> &gt; .gitignore
git add .gitignore
git commit -m <span class="hljs-string">"Add gitignore"</span>
</code></pre>
<h3 id="heading-step-3-check-the-damage">Step 3: Check the Damage</h3>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span>

<span class="hljs-comment"># or </span>

git <span class="hljs-built_in">log</span> --oneline

<span class="hljs-comment"># or</span>

git <span class="hljs-built_in">log</span> --pretty=format:<span class="hljs-string">"%h %an &lt;%ae&gt; %s"</span>
</code></pre>
<p>Output shows all commits have the wrong author:</p>
<pre><code class="lang-bash">a1b2c3d surajdeveloper &lt;surajdeveloper@example.com&gt; Add gitignore
b4c5d6e surajdeveloper &lt;surajdeveloper@example.com&gt; Add main python application file  
c7d8e9f surajdeveloper &lt;surajdeveloper@example.com&gt; Add main javascript application file
</code></pre>
<h3 id="heading-step-4-set-correct-repo-level-identity">Step 4: Set Correct Repo-Level Identity</h3>
<pre><code class="lang-bash">git config user.name <span class="hljs-string">"surajdevops"</span>
git config user.email <span class="hljs-string">"surajdevops@example.com"</span>

<span class="hljs-comment"># Verify repo config overrides global</span>
git config user.name
git config user.email
</code></pre>
<p>New commits will now use the correct author, but what about the existing ones?</p>
<h2 id="heading-scenario-1-fix-local-commits-before-push">Scenario 1: Fix Local Commits (Before Push)</h2>
<p>This is the <strong>safest scenario</strong> — commits exist only on your local machine.</p>
<h3 id="heading-interactive-rebase-in-action">Interactive Rebase in Action</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Start interactive rebase for last 3 commits</span>
git rebase -i HEAD~3
</code></pre>
<p>This opens your editor with something like:</p>
<pre><code class="lang-bash">pick c7d8e9f Add main javascript application file
pick b4c5d6e Add main python application file
pick a1b2c3d Add gitignore

<span class="hljs-comment"># Commands:</span>
<span class="hljs-comment"># p, pick &lt;commit&gt; = use commit</span>
<span class="hljs-comment"># e, edit &lt;commit&gt; = use commit, but stop for amending</span>
<span class="hljs-comment"># r, reword &lt;commit&gt; = use commit, but edit the commit message</span>
</code></pre>
<h3 id="heading-mark-commits-for-editing">Mark Commits for Editing</h3>
<p>Change <code>pick</code> to <code>edit</code> for commits you want to fix:</p>
<pre><code class="lang-bash">edit c7d8e9f Add main javascript application file
edit b4c5d6e Add main python application file
edit a1b2c3d Add gitignore
</code></pre>
<p>Save and exit (in vim: <code>esc</code> <code>shift+:</code> press <code>x</code>)</p>
<h3 id="heading-fix-each-commit">Fix Each Commit</h3>
<p>Git will stop at each commit marked for editing:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># When Git pauses at first commit</span>
git commit --amend --author=<span class="hljs-string">"surajdevops &lt;surajdevops@example.com&gt;"</span> --no-edit

<span class="hljs-comment"># Continue to next commit</span>
git rebase --<span class="hljs-built_in">continue</span>

<span class="hljs-comment"># Repeat for each commit Git stops at</span>
</code></pre>
<h3 id="heading-verify-the-fix">Verify the Fix</h3>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span> --pretty=format:<span class="hljs-string">"%h %an &lt;%ae&gt; %s"</span>
</code></pre>
<p>Now all commits show the correct author! ✅</p>
<h2 id="heading-scenario-11-fix-initial-commit-including-root">Scenario 1.1: Fix Initial Commit (Including Root)</h2>
<p><strong>Special case:</strong> What if the <strong>initial commit</strong> also has the wrong author? Regular <code>HEAD~N</code> won't include the root commit.</p>
<h3 id="heading-the-problem-initial-commit-has-wrong-author">The Problem: Initial Commit Has Wrong Author</h3>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span> --pretty=format:<span class="hljs-string">"%h %an &lt;%ae&gt; %s"</span>
</code></pre>
<p>Output shows:</p>
<pre><code class="lang-bash">a1b2c3d surajdeveloper &lt;surajdeveloper@example.com&gt; Add gitignore
b4c5d6e surajdeveloper &lt;surajdeveloper@example.com&gt; Add main python application file  
c7d8e9f surajdeveloper &lt;surajdeveloper@example.com&gt; Add main javascript application file
d8e9f0g surajdeveloper &lt;surajdeveloper@example.com&gt; Initial commit  ← WRONG!
</code></pre>
<h3 id="heading-the-solution-use-root-flag">The Solution: Use <code>--root</code> Flag</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Include the initial commit in interactive rebase</span>
git rebase -i --root
</code></pre>
<p>This opens the editor with <strong>ALL commits</strong> including the root:</p>
<pre><code class="lang-bash">pick d8e9f0g Initial commit          ← Root commit included!
pick c7d8e9f Add main javascript application file
pick b4c5d6e Add main python application file
pick a1b2c3d Add gitignore
</code></pre>
<h3 id="heading-mark-commits-including-root-for-editing">Mark Commits (Including Root) for Editing</h3>
<pre><code class="lang-bash">edit d8e9f0g Initial commit          ← Fix the root!
edit c7d8e9f Add main javascript application file
edit b4c5d6e Add main python application file
edit a1b2c3d Add gitignore
</code></pre>
<h3 id="heading-fix-each-commit-same-process">Fix Each Commit (Same Process)</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Git stops at root commit first</span>
git commit --amend --author=<span class="hljs-string">"surajdevops &lt;surajdevops@example.com&gt;"</span> --no-edit
git rebase --<span class="hljs-built_in">continue</span>

<span class="hljs-comment"># Continue for each subsequent commit...</span>
</code></pre>
<h3 id="heading-why-root-is-essential">Why <code>--root</code> is Essential</h3>
<ul>
<li><p><strong>Regular rebase</strong> (<code>HEAD~4</code>) excludes the initial commit</p>
</li>
<li><p><strong>Root rebase</strong> (<code>--root</code>) includes <strong>everything</strong> from the beginning</p>
</li>
<li><p>This is the <strong>only way</strong> to edit the initial commit's author</p>
</li>
</ul>
<h2 id="heading-scenario-2-wrong-author-already-pushed-branch-not-merged">Scenario 2: Wrong Author Already Pushed (Branch Not Merged)</h2>
<p>If you've already pushed the commits to a feature branch (but not merged to main), you can still fix them.</p>
<h3 id="heading-setup-push-to-remote-branch">Setup: Push to Remote Branch</h3>
<p>First, let's simulate this scenario:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Create a feature branch (if not already on one)</span>
git checkout -b feature/user-auth

<span class="hljs-comment"># Push to remote (if you have access to push)</span>
git push -u origin feature/user-auth
</code></pre>
<h3 id="heading-fix-and-force-push">Fix and Force Push</h3>
<p>After fixing the commits locally (using the same rebase process above):</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Force push the corrected history</span>
git push origin feature/user-auth --force
</code></pre>
<p><strong>⚠️ Important Warnings:</strong></p>
<ul>
<li><p>Only force push if <strong>you own the branch</strong></p>
</li>
<li><p><strong>Coordinate with your team</strong> before rewriting pushed history</p>
</li>
<li><p>Never force push to <code>main</code> or <code>master</code> without team agreement</p>
</li>
</ul>
<h2 id="heading-scenario-3-wrong-author-already-merged-to-main">Scenario 3: Wrong Author Already Merged to Main</h2>
<p>This is the <strong>most complex scenario</strong>. Once commits are merged into the main branch, rewriting history becomes dangerous.</p>
<h3 id="heading-option-1-accept-and-document-recommended">Option 1: Accept and Document (✅ Recommended)</h3>
<p><strong>Best practice</strong> → Don't rewrite main branch history. Instead, add documentation:</p>
<pre><code class="lang-bash">git commit --allow-empty -m <span class="hljs-string">"docs: commits abc123-def456 were authored by surajdevops, not surajdeveloper"</span>
</code></pre>
<h3 id="heading-option-2-rewrite-main-dangerous">Option 2: Rewrite Main (⚠️ Dangerous)</h3>
<p>Only do this if:</p>
<ul>
<li><p>Your <strong>entire team agrees</strong></p>
</li>
<li><p>You can coordinate a <strong>synchronized reset</strong> for all team members</p>
</li>
<li><p>The repository is <strong>not public</strong> or widely used</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment"># Fix commits using rebase</span>
git rebase -i HEAD~5  <span class="hljs-comment"># Adjust number as needed</span>

<span class="hljs-comment"># Force push main (DANGEROUS!)</span>
git push origin main --force

<span class="hljs-comment"># All team members must then:</span>
<span class="hljs-comment"># git fetch origin</span>
<span class="hljs-comment"># git reset --hard origin/main</span>
</code></pre>
<h2 id="heading-advanced-tips-amp-best-practices">Advanced Tips &amp; Best Practices</h2>
<p>For this you can read my this blog <a target="_blank" href="https://surajk00.hashnode.dev/managing-multiple-githubgit-accounts-on-one-machine-personal-work"><strong>Managing Multiple GitHub/Git Accounts on One Machine (Personal + Work)</strong></a></p>
<h3 id="heading-prevent-future-mistakes">Prevent Future Mistakes</h3>
<ol>
<li><strong>Set repo-specific config</strong> immediately in new projects:</li>
</ol>
<pre><code class="lang-bash"><span class="hljs-comment"># Right after git clone or git init</span>
git config user.name <span class="hljs-string">"Your Correct Name"</span>
git config user.email <span class="hljs-string">"your.correct@email.com"</span>
</code></pre>
<ol start="2">
<li><strong>Create Git aliases</strong> for quick identity switching:</li>
</ol>
<pre><code class="lang-bash"><span class="hljs-comment"># Add to ~/.gitconfig</span>
git config --global alias.work <span class="hljs-string">'config user.email "work@company.com"'</span>
git config --global alias.personal <span class="hljs-string">'config user.email "personal@gmail.com"'</span>

<span class="hljs-comment"># Usage: git work or git personal</span>
</code></pre>
<h3 id="heading-when-not-to-rewrite-history">When NOT to Rewrite History</h3>
<p>Never rewrite history when:</p>
<ul>
<li><p>❌ Commits already merged to main/master</p>
</li>
<li><p>❌ Public repositories with external contributors</p>
</li>
<li><p>❌ Other team members have based work on your commits</p>
</li>
<li><p>❌ CI/CD systems have already processed the commits</p>
</li>
<li><p>❌ The commits have been tagged for a release</p>
</li>
</ul>
<h3 id="heading-quick-reference-rebase-commands">Quick Reference: Rebase Commands</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Fix last commit only</span>
git commit --amend --author=<span class="hljs-string">"Name &lt;email&gt;"</span>

<span class="hljs-comment"># Fix multiple recent commits</span>
git rebase -i HEAD~N  <span class="hljs-comment"># N = number of commits</span>

<span class="hljs-comment"># Fix commits including the initial commit</span>
git rebase -i --root

<span class="hljs-comment"># Fix commits after specific commit</span>
git rebase -i abc123^  <span class="hljs-comment"># abc123 = commit hash</span>

<span class="hljs-comment"># Abort rebase if something goes wrong</span>
git rebase --abort

<span class="hljs-comment"># Skip a problematic commit during rebase</span>
git rebase --skip
</code></pre>
<h2 id="heading-complete-setup-commands-summary">Complete Setup Commands Summary</h2>
<pre><code class="lang-bash"><span class="hljs-comment"># 1. Run the Docker lab</span>
docker run -it --rm surajkumar00/git-rebase-lab

<span class="hljs-comment"># 2. Clone the practice repo</span>
git <span class="hljs-built_in">clone</span> https://github.com/Suraj-kumar00/learn-git.git
<span class="hljs-built_in">cd</span> learn-git

<span class="hljs-comment"># 3. Create feature branch</span>
git checkout -b feature

<span class="hljs-comment"># 4. Set wrong identity and create commits</span>
git config --global user.name <span class="hljs-string">"surajdeveloper"</span>
git config --global user.email <span class="hljs-string">"surajdeveloper@example.com"</span>

<span class="hljs-comment"># 5. Make commits (will have wrong author)</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"console.log('Hello World');"</span> &gt; app.js &amp;&amp; git add app.js &amp;&amp; git commit -m <span class="hljs-string">"Add main javascript application file"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"print('Hello World')"</span> &gt; main.py &amp;&amp; git add main.py &amp;&amp; git commit -m <span class="hljs-string">"Add main python application file"</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"node_modules/"</span> &gt; .gitignore &amp;&amp; git add .gitignore &amp;&amp; git commit -m <span class="hljs-string">"Add gitignore"</span>

<span class="hljs-comment"># 6. Set correct identity</span>
git config user.name <span class="hljs-string">"surajdevops"</span>
git config user.email <span class="hljs-string">"surajdevops@example.com"</span>

<span class="hljs-comment"># 7. Fix the commits</span>

<span class="hljs-comment"># or git rebase -i --root for initial commit</span>
git rebase -i HEAD~3 

<span class="hljs-comment"># Change 'pick' to 'edit', then for each commit:</span>
git commit --amend --author=<span class="hljs-string">"surajdevops &lt;surajdevops@example.com&gt;"</span> --no-edit
git rebase --<span class="hljs-built_in">continue</span>

<span class="hljs-comment"># 8. Verify the fix</span>
git <span class="hljs-built_in">log</span> --pretty=format:<span class="hljs-string">"%h %an &lt;%ae&gt; %s"</span>
</code></pre>
<h2 id="heading-your-next-steps">Your Next Steps</h2>
<ol>
<li><p><strong>Configure proper Git identities</strong> in all your current projects to prevent future mistakes</p>
</li>
<li><p><strong>Share this guide</strong> with your team to prevent future author mix-ups</p>
</li>
</ol>
<p><strong><mark>Remember</mark></strong>: Git is powerful, but with great power comes great responsibility hehe. Always practice in safe environments before applying these techniques to important repositories!</p>
<h2 id="heading-happy-rebasing"><strong>Happy rebasing!</strong></h2>
<p>Found this helpful? Star the practice repo and share with your team! Questions or improvements? Open an issue on the above GitHub repo.</p>
]]></content:encoded></item><item><title><![CDATA[Why NGINX Still Powers the Modern Web in 2025: Part 1]]></title><description><![CDATA[Introduction
NGINX has revolutionized modern web infrastructure, becoming the backbone of high-performance applications worldwide. In this part 1 you'll learn about NGINX fundamentals configurations, theoretical knowledge with real-time scenario exam...]]></description><link>https://blog.surajdev.tech/why-nginx-still-powers-the-modern-web-in-2025-part-1</link><guid isPermaLink="true">https://blog.surajdev.tech/why-nginx-still-powers-the-modern-web-in-2025-part-1</guid><category><![CDATA[nginx]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Docker]]></category><category><![CDATA[Nginx configuration guide]]></category><category><![CDATA[Nginx installation tutorial]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Fri, 22 Aug 2025 07:54:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1755849009468/b84d5dc8-8e40-476d-aa65-f730dcabd813.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>NGINX has revolutionized modern web infrastructure, becoming the backbone of high-performance applications worldwide. In this part 1 you'll learn about NGINX fundamentals configurations, theoretical knowledge with real-time scenario examples.</p>
<p>Originally developed by <strong>Igor Sysoev</strong> in <strong>2004</strong>, NGINX was created to solve the infamous <strong>C10K problem</strong> and has since evolved into one of the most powerful and widely adopted web servers in the world.</p>
<h2 id="heading-what-is-forward-proxy-and-reverse-proxy">What is Forward Proxy and Reverse Proxy?</h2>
<p>Understanding proxy servers is fundamental to grasping NGINX's core functionality, as it excels primarily as a reverse proxy server.</p>
<h3 id="heading-forward-proxy">Forward Proxy:</h3>
<p>A forward proxy acts as an intermediary between <strong>clients</strong> and the <strong>internet</strong>, <strong>sitting on the client side</strong> of the <strong>network</strong>.</p>
<p><strong>Key Characteristics:</strong></p>
<ul>
<li><p>Acts on behalf of the <strong>client</strong></p>
</li>
<li><p>Sits between <strong>client</strong> and the <strong>public internet</strong></p>
</li>
<li><p>Forwards client requests to servers</p>
</li>
<li><p>Server doesn't know which specific client made the request</p>
</li>
<li><p>Primarily serves client needs</p>
</li>
</ul>
<p><strong>Real-World Example:</strong> Corporate networks use forward proxies to:</p>
<ul>
<li><p>Filter employee internet access</p>
</li>
<li><p>Block <strong>social media</strong> and <strong>non-work websites</strong></p>
</li>
<li><p>Cache frequently accessed content to save bandwidth</p>
</li>
<li><p>Provide anonymity for internal users</p>
</li>
<li><p>Monitor and log internet usage</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755758883138/029caeb6-4b08-4d87-83f2-c1a5edd7d877.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-reverse-proxy">Reverse Proxy:</h3>
<p>A reverse proxy sits between <strong>clients</strong> and <strong>backend servers</strong>, <strong>acting on behalf of the server infrastructure</strong>.</p>
<p><strong>Key Characteristics:</strong></p>
<ul>
<li><p>Acts on behalf of the <strong>server</strong></p>
</li>
<li><p>Sits between <strong>internet clients</strong> and <strong>backend servers</strong></p>
</li>
<li><p>Hides server implementation details from clients</p>
</li>
<li><p>Distributes incoming requests across multiple backend servers</p>
</li>
<li><p>Provides additional services like <strong>SSL termination</strong>, <strong>caching</strong>, and <strong>load balancing</strong></p>
</li>
</ul>
<p><strong>Real-World Example:</strong> Netflix, Amazon, and Google use reverse proxies to:</p>
<ul>
<li><p>Distribute user requests across thousands of servers worldwide</p>
</li>
<li><p>Cache popular content closer to users</p>
</li>
<li><p>Terminate SSL connections at the edge</p>
</li>
<li><p>Provide DDoS protection and security filtering</p>
</li>
<li><p>Ensure high availability and fault tolerance</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755841561604/29b7a8fc-a57e-4f8e-aed0-5579d856fd89.png" alt class="image--center mx-auto" /></p>
<details><summary>What is DMZ?</summary><div data-type="detailsContent">A DMZ (Demilitarized Zone) is <strong><mark>a physical or logical subnetwork that adds an extra layer of security to an organization's network by isolating publicly accessible services, such as web or email servers, from the main internal network</mark></strong>.</div></details>

<h2 id="heading-understanding-nginx-architecture-amp-use-cases">Understanding NGINX: Architecture &amp; Use Cases</h2>
<h3 id="heading-what-is-nginx">What is NGINX?</h3>
<p>NGINX (pronounced "<strong>engine-x</strong>") is a widely used <strong>open-source</strong> tool that does much more than just <strong>serve web pages</strong>. Known for its <strong>speed</strong> and <strong>reliability</strong>, it also works as a <strong>reverse proxy</strong>, <strong>load balancer</strong>, and <strong>caching server</strong>. Whether you're <strong>streaming medi</strong>a, handling <strong>email protocols like SMTP or IMAP, or routing HTTP and TCP traffic</strong>, NGINX is built to handle it all with efficiency.</p>
<p><strong>Core Capabilities:</strong></p>
<ul>
<li><p><strong>Web Server</strong>: Serving static and dynamic content with minimal resource usage</p>
</li>
<li><p><strong>Reverse Proxy</strong>: Forwarding client requests to backend application servers</p>
</li>
<li><p><strong>Load Balancer</strong>: Distributing incoming traffic across multiple backend servers</p>
</li>
<li><p><strong>HTTP Cache</strong>: Storing frequently requested content to reduce backend load</p>
</li>
<li><p><strong>SSL/TLS Termination</strong>: Handling encryption/decryption at the network edge</p>
</li>
<li><p><strong>Mail Proxy</strong>: Managing SMTP, POP3, and IMAP protocol connections</p>
</li>
<li><p><strong>Stream Proxy</strong>: Handling TCP and UDP traffic for various applications</p>
</li>
</ul>
<h3 id="heading-what-problem-it-solves">What problem it solves?</h3>
<p>NGINX was specifically designed to solve the <strong>C10K problem</strong> - the challenge of handling 10,000 (or more) concurrent client connections on a web server efficiently.</p>
<p><strong>The Traditional Problem:</strong> Before NGINX, traditional web servers like Apache used a process-per-connection or thread-per-connection model:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755834780343/ba1261f6-610f-401e-a146-c568c94f12e9.png" alt class="image--center mx-auto" /></p>
<p>This approach became unsustainable as:</p>
<ul>
<li><p>Each connection consumed significant memory (<strong>8-12MB per process</strong>)</p>
</li>
<li><p>Context switching between processes became expensive</p>
</li>
<li><p>System resources were quickly exhausted</p>
</li>
<li><p>Performance degraded dramatically under high load</p>
</li>
</ul>
<p><strong>NGINX's Solution:</strong> NGINX was built to solve this problem using an asynchronous, event-driven model, making it lightweight and able to handle tens of thousands of connections simultaneously efficiently and reliably.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755834893764/d6f50d29-31be-4c63-a3a2-4a7ea58b578a.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-why-nginx-became-essential">Why NGINX Became Essential:</h3>
<p>The traditional web servers like <strong>Apache</strong> used a <strong>process-per-connection model</strong>, which became inefficient as web traffic grew exponentially. Each connection required a separate process or thread, consuming significant memory and CPU resources. NGINX's innovative approach changed this paradigm entirely.</p>
<h2 id="heading-nginx-architecture-the-process-model"><strong>NGINX Architecture: The Process Model</strong></h2>
<p>NGINX uses an <strong>event-driven, asynchronous architecture</strong> that sets it apart from traditional web servers and consists of <strong>several components</strong> such as**:**</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755833045389/f6005ce3-cd1e-449b-9a7c-26c1012d5f40.png" alt="infographic-Inside-NGINX_process-model" class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Master process</strong> – Controls the main NGINX instance. It manages configuration, and is responsible for starting, stopping, and supervising the worker processes.</p>
</li>
<li><p><strong>Worker processes</strong> – Handle all the actual work: managing client connections, serving static content, proxying requests, load balancing, and SSL/TLS termination.</p>
</li>
<li><p><strong>Cache loader</strong> – Runs at startup to load cache metadata from disk into memory, making cached content immediately available after NGINX boots.</p>
</li>
<li><p><strong>Cache manager</strong> – Runs in the background at intervals to check the cache directory, remove expired data, and ensure disk usage stays within limits.</p>
</li>
<li><p><strong>Shared memory</strong> – Provides inter-process communication and storage for shared state, such as cache indexes, rate limiting counters, and load-balancing information.</p>
</li>
</ol>
<h3 id="heading-why-this-architecture-matters">Why This Architecture Matters:</h3>
<ul>
<li><p><strong>Memory Efficiency</strong>: One worker can handle thousands of connections with minimal memory overhead</p>
</li>
<li><p><strong>CPU Efficiency</strong>: No context switching between processes for each request</p>
</li>
<li><p><strong>Scalability</strong>: Performance degrades gracefully under high load</p>
</li>
<li><p><strong>Stability</strong>: If a worker crashes, the master spawns a new one without affecting other connections</p>
</li>
<li><p><strong>Resource Optimization</strong>: Efficient use of system resources leads to better overall performance</p>
</li>
</ul>
<h2 id="heading-core-use-cases">Core Use Cases</h2>
<p><strong>NGINX's versatility makes it suitable for numerous deployment scenarios:</strong></p>
<p>1. <strong>Web Server:</strong> Serving static content (<strong>HTML</strong>, <strong>CSS</strong>, <strong>JS</strong>, <strong>images</strong>) with minimal overhead</p>
<p>2. <strong>Reverse Proxy:</strong> Forwarding requests to backend applications</p>
<h2 id="heading-nginx-alternatives">NGINX Alternatives</h2>
<p>While NGINX is widely used, a few alternatives are worth knowing:</p>
<ol>
<li><p><strong>Apache HTTP Server</strong> – A long-standing web server with strong legacy support and a rich module ecosystem, but less efficient under heavy load compared to NGINX.</p>
</li>
<li><p><strong>HAProxy</strong> – Specializes in high-performance load balancing and traffic distribution. Great for reliability, but not designed to serve static content.</p>
</li>
<li><p><strong>Traefik</strong> – A modern, cloud-native reverse proxy with built-in support for containers, service discovery, and automatic SSL management.</p>
</li>
<li><p><strong>Cloudflare (as a Service)</strong> – A managed CDN and security platform offering DDoS protection, WAF, and global content delivery but relies on a third-party provider.</p>
</li>
</ol>
<h1 id="heading-setting-up-nginx-with-docker-hands-on">Setting Up Nginx with Docker: Hands-On</h1>
<h1 id="heading-prerequisites">Prerequisites</h1>
<p>Before we begin, ensure you have Docker installed on your system. You can download it from <a target="_blank" href="https://docker.com/">Docker's official website</a>.</p>
<h2 id="heading-step-1-setting-up-the-docker-container">Step 1: Setting Up the Docker Container</h2>
<p>Let's start by creating and running an Ubuntu container with Nginx:</p>
<pre><code class="lang-bash">docker run -it --name nginx-docker -p 8080:80 ubuntu
</code></pre>
<p><strong>Command Breakdown:</strong></p>
<ul>
<li><p><code>-name nginx-docker</code> → Assigns a custom name to your container</p>
</li>
<li><p><code>p 8080:80</code> → Maps your host machine's port 8080 to the container's port 80</p>
</li>
<li><p><code>it ubuntu</code> → Creates an interactive terminal session with Ubuntu</p>
</li>
</ul>
<p>This command will download the Ubuntu image (if not already present) and start an interactive container session.</p>
<h2 id="heading-step-2-installing-nginx-and-essential-tools">Step 2: Installing Nginx and Essential Tools</h2>
<p>Once inside the container, update the package list and install Nginx:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Update package repositories</span>
apt update

<span class="hljs-comment"># Install Nginx web server</span>
apt install nginx -y

<span class="hljs-comment"># Install vim text editor (useful for editing config files)</span>
apt install vim -y
</code></pre>
<p>After running the <code>apt install vim -y</code> command first choose number <code>5</code> which is Asia and then choose <code>44</code> It’s Kolkata, we are choosing these to install IST timezone while installing the <code>vim</code> tool.</p>
<p><strong>Pro Tip:</strong> Always run <code>apt update</code> first to ensure you're installing the latest versions of packages.</p>
<h2 id="heading-step-3-verify-nginx-installation">Step 3: Verify Nginx Installation</h2>
<p>Check if Nginx was installed successfully:</p>
<pre><code class="lang-bash">nginx -v
or 
nginx -V
</code></pre>
<p>You should see output similar to: <code>nginx version: nginx/1.18.0 (Ubuntu)</code></p>
<h2 id="heading-step-4-understanding-nginx-directory-structure">Step 4: Understanding Nginx Directory Structure</h2>
<p>After installation, all Nginx files are stored in <code>/etc/nginx</code>. Let's explore this directory:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /etc/nginx
ls -la
</code></pre>
<p>You'll see a structure like this:</p>
<pre><code class="lang-bash">drwxr-xr-x 8 root root 4096 Aug 19 13:38 ./
drwxr-xr-x 1 root root 4096 Aug 19 13:36 ../
drwxr-xr-x 2 root root 4096 May 27 10:28 conf.d/
-rw-r--r-- 1 root root 1125 Dec  1  2023 fastcgi.conf
-rw-r--r-- 1 root root 1055 Dec  1  2023 fastcgi_params
-rw-r--r-- 1 root root 5465 Dec  1  2023 mime.types
drwxr-xr-x 2 root root 4096 May 27 10:28 modules-available/
drwxr-xr-x 2 root root 4096 May 27 10:28 modules-enabled/
-rw-r--r-- 1 root root 1446 Aug 19 13:37 nginx.conf
-rw-r--r-- 1 root root  636 Dec  1  2023 scgi_params
drwxr-xr-x 2 root root 4096 Aug 19 13:24 sites-available/
drwxr-xr-x 2 root root 4096 Aug 19 13:24 sites-enabled/
drwxr-xr-x 2 root root 4096 Aug 19 13:24 snippets/
</code></pre>
<p><strong>Key Files and Directories:</strong></p>
<ul>
<li><p><code>nginx.conf</code> → Main configuration file (most important!)</p>
</li>
<li><p><code>sites-available/</code> → Contains individual site configurations</p>
</li>
<li><p><code>sites-enabled/</code> → Contains symlinks to active site configurations</p>
</li>
<li><p><code>conf.d/</code> → Additional configuration files</p>
</li>
</ul>
<h2 id="heading-step-5-managing-nginx-service">Step 5: Managing Nginx Service</h2>
<h3 id="heading-starting-nginx">Starting Nginx</h3>
<p>To start the Nginx service:</p>
<pre><code class="lang-bash">service nginx start
</code></pre>
<p><strong>When to use:</strong> After installation or when Nginx has been stopped.</p>
<h3 id="heading-checking-nginx-status">Checking Nginx Status</h3>
<p>To verify Nginx is running:</p>
<pre><code class="lang-bash">service nginx status
</code></pre>
<p>Alternative method to check running processes:</p>
<pre><code class="lang-bash">ps aux | grep nginx
</code></pre>
<p>You should see output showing:</p>
<ul>
<li><p><code>nginx: master process</code> (main Nginx process)</p>
</li>
<li><p><code>nginx: worker process</code> (handles actual requests)</p>
</li>
</ul>
<h3 id="heading-stopping-nginx">Stopping Nginx</h3>
<p>When you need to stop Nginx:</p>
<pre><code class="lang-bash">service nginx stop
</code></pre>
<p><strong>When to use:</strong> During maintenance, troubleshooting, or when shutting down your server.</p>
<h2 id="heading-step-6-testing-your-nginx-installation">Step 6: Testing Your Nginx Installation</h2>
<p>Since we mapped port 80 to 8080, open your web browser and navigate to:</p>
<pre><code class="lang-bash">http://localhost:8080
</code></pre>
<p>You should see the default <strong>Nginx Welcome Page</strong>!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755848302018/5d22aa2b-1ec0-4b4e-978b-162d6269f485.png" alt class="image--center mx-auto" /></p>
<p><strong>Important Note:</strong> Nginx runs on port 80 by default, but since we're using Docker, we've mapped container port 80 to host port 8080. Make sure no other service is using port 8080 on your host machine.</p>
<h2 id="heading-step-7-creating-a-custom-configuration">Step 7: Creating a Custom Configuration</h2>
<p>Now let's customize Nginx with our own configuration.</p>
<h3 id="heading-backup-the-original-configuration">Backup the Original Configuration</h3>
<p>Always backup before making changes:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /etc/nginx
mv nginx.conf nginx-backup.conf
</code></pre>
<h3 id="heading-create-new-configuration-file">Create New Configuration File</h3>
<p>You can either create an empty file first or directly edit:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Option 1: Create empty file then edit</span>
touch nginx.conf
vim nginx.conf

<span class="hljs-comment"># Option 2: Directly create and edit</span>
vim nginx.conf
</code></pre>
<h3 id="heading-add-custom-configuration">Add Custom Configuration</h3>
<p>Insert the following content into your new <code>nginx.conf</code>:</p>
<pre><code class="lang-bash">events {
    worker_connections 1024;
}

http {
    server {
        listen 80;
        server_name _;

        location / {
            <span class="hljs-built_in">return</span> 200 <span class="hljs-string">"Hello from Nginx Custom Configuration via Docker\\n"</span>;
            add_header Content-Type text/plain;
        }
    }
}
</code></pre>
<p><strong>How to exit the vim editor</strong>: After pasting this, press <code>esc</code> and then <code>shift + :</code> and the press <code>x</code> and press <code>enter</code></p>
<p><strong>Configuration Breakdown:</strong></p>
<ul>
<li><p><code>events</code> → Defines connection processing parameters</p>
</li>
<li><p><code>worker_connections 1024</code> → Maximum connections per worker process</p>
</li>
<li><p><code>http</code> → Main HTTP context</p>
</li>
<li><p><code>listen 80</code> → Port Nginx listens on</p>
</li>
<li><p><code>server_name _</code> → Catch-all server name</p>
</li>
<li><p><code>location /</code> → Handles all requests to root path</p>
</li>
<li><p><code>return 200</code> → Returns HTTP 200 status with custom message</p>
</li>
</ul>
<h2 id="heading-step-8-testing-and-reloading-configuration">Step 8: Testing and Reloading Configuration</h2>
<h3 id="heading-test-configuration-syntax">Test Configuration Syntax</h3>
<p>Before applying changes, always test the configuration:</p>
<pre><code class="lang-bash">nginx -t
</code></pre>
<p>You should see something like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755848514054/54789bc6-2393-4845-9ee8-647c8e18bf79.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-reload-configuration">Reload Configuration</h3>
<p>If the test passes, reload Nginx to apply changes:</p>
<pre><code class="lang-bash">nginx -s reload
</code></pre>
<p><strong>Why reload instead of restart?</strong></p>
<ul>
<li><p><code>reload</code> → Applies new configuration without dropping existing connections</p>
</li>
<li><p><code>restart</code> → Stops and starts Nginx, dropping all connections</p>
</li>
</ul>
<h3 id="heading-verify-your-changes">Verify Your Changes</h3>
<p>Visit <code>http://localhost:8080</code> again. You should now see your custom message: "Hello from Nginx Custom Configuration via Docker"</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755848609659/858902e8-40e1-4fed-b124-8d7e80655fd7.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-common-commands-summary">Common Commands Summary</h2>
<p>Here's a quick reference of essential Nginx commands:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Service management</span>
service nginx start     <span class="hljs-comment"># Start Nginx</span>
service nginx stop      <span class="hljs-comment"># Stop Nginx</span>
service nginx status    <span class="hljs-comment"># Check status</span>
service nginx restart   <span class="hljs-comment"># Full restart</span>

<span class="hljs-comment"># Configuration management</span>
nginx -t               <span class="hljs-comment"># Test configuration</span>
nginx -s reload        <span class="hljs-comment"># Reload configuration</span>
nginx -s stop          <span class="hljs-comment"># Graceful stop</span>
nginx -s quit          <span class="hljs-comment"># Graceful shutdown</span>

<span class="hljs-comment"># Information</span>
nginx -v              <span class="hljs-comment"># Show version</span>
nginx -V              <span class="hljs-comment"># Show version and compile options</span>
</code></pre>
<h2 id="heading-in-the-next-parts-of-this-nignx-blogs-well-learn">In the next parts of this nignx blogs we’ll learn:</h2>
<p>Now that you have a basic Nginx setup running, you can explore:</p>
<ul>
<li><p>Serving static files</p>
</li>
<li><p>Setting up reverse proxy</p>
</li>
<li><p>SSL/TLS configuration</p>
</li>
<li><p>Load balancing</p>
</li>
<li><p>Custom error pages</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You've successfully set up <strong>Nginx in a Docker container</strong>, learned how to manage the service, and created your <strong>first custom configuration</strong>. This foundation will serve you well as you continue your journey with <strong>web servers</strong> and <strong>containerization</strong>.</p>
<p><strong>Remember</strong>: Always test your configurations before applying them, and keep backups of working configurations. Happy learning!</p>
<h3 id="heading-thanks-for-reading">Thanks for reading…</h3>
]]></content:encoded></item><item><title><![CDATA[Git Cherry-Pick Saved My Messed-Up Branch — Here’s How You Can Too!]]></title><description><![CDATA[Introduction
A practical, real-world guide to understanding and applying Git cherry-pick with actual developer mistakes and fixes.

What is git cherry-pick?
git cherry-pick lets you selectively apply commits from one branch to another — like copying ...]]></description><link>https://blog.surajdev.tech/git-cherry-pick-saved-my-messed-up-branch-heres-how-you-can-too</link><guid isPermaLink="true">https://blog.surajdev.tech/git-cherry-pick-saved-my-messed-up-branch-heres-how-you-can-too</guid><category><![CDATA[Git]]></category><category><![CDATA[cherry-pick]]></category><category><![CDATA[Gitcommands]]></category><category><![CDATA[gitadvanced]]></category><category><![CDATA[git advance]]></category><category><![CDATA[Git Commands]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Sun, 29 Jun 2025 07:24:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1751306636299/462802b2-aebe-4142-8fe1-1bdbd1afd0d9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>A practical, real-world guide to understanding and applying Git <strong>cherry-pick</strong> with actual developer mistakes and fixes.</p>
<p><img src="https://media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExcDZvaDQ0bWxtc3g0ZjBnaXJwdTNjdnc1MXE1MGFkdGJub2tzanhkMSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/VrTtTArIazPiB6kbFm/giphy.gif" alt class="image--center mx-auto" /></p>
<h2 id="heading-what-is-git-cherry-pick"><strong>What is</strong> <code>git cherry-pick</code>?</h2>
<p><code>git cherry-pick</code> lets you <strong>selectively</strong> apply commits from <strong>one branch to another</strong> — like copying specific code changes <strong>without merging entire branches</strong>.</p>
<h2 id="heading-now-lets-understand-a-quick-comparison-cherry-pick-vs-merge-vs-rebase"><strong>Now let’s understand a quick comparison</strong> <code>cherry-pick</code> <strong>vs</strong> <code>merge</code> vs <code>rebase</code></h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command</td><td>What it Does</td><td>When to Use</td></tr>
</thead>
<tbody>
<tr>
<td><code>git cherry-pick</code></td><td>Apply specific commits to current branch</td><td>You want <em>only</em> certain commits, not the full branch</td></tr>
<tr>
<td><code>git merge</code></td><td>Combine entire branch history into current branch</td><td>You want to bring all commits and preserve history</td></tr>
<tr>
<td><code>git rebase</code></td><td>Move/Replay commits onto another base branch</td><td>You want a clean, linear history, avoid merge commits</td></tr>
</tbody>
</table>
</div><p><strong>TL;DR:</strong></p>
<ul>
<li><p>Use <code>cherry-pick</code> for precision, specific commits only</p>
</li>
<li><p>Use <code>merge</code> to combine full branch history</p>
</li>
<li><p>Use <code>rebase</code> to clean history and avoid unnecessary merges</p>
</li>
</ul>
<h2 id="heading-why-you-might-need-cherry-pick"><strong>Why You Might Need</strong> <code>cherry-pick</code></h2>
<ol>
<li><p>You committed on the wrong branch (happens more than we admit)</p>
</li>
<li><p>You need a bug fix from one branch to another</p>
</li>
<li><p>You want to copy only certain commits, not merge everything</p>
</li>
<li><p>You made changes, reverted them locally, but commits got mixed up</p>
</li>
</ol>
<h2 id="heading-my-real-time-scenario-how-i-discovered-cherry-pick"><strong>My Real-Time Scenario: How I Discovered</strong> <code>cherry-pick</code></h2>
<p>Let me share how I personally ran into this:</p>
<blockquote>
<p>I made some changes in a branch (let's call it <code>branch A</code>) but accidentally reverted the commits locally, leaving them in the unstaged area. Later, I re-committed those changes — but this time, I was working on <code>branch B</code>, where I only wanted my latest changes, not the leftover ones from <code>branch A.</code></p>
</blockquote>
<p>I pushed the branch to GitHub, went to open the PR, and BOOM — I saw two commits:</p>
<ul>
<li><p>One commit with my intended change for <code>branch B</code></p>
</li>
<li><p>But another unintended commit sneakily came from <strong>branch A</strong></p>
</li>
</ul>
<p>Total mess, right? But no worries — I fixed this cleanly using <code>git cherry-pick</code>.</p>
<p>I removed the wrong commit from <code>branch B</code>, stayed on <code>branch A</code>, cherry-picked only the commit I actually needed onto <code>branch B</code>, and pushed it again. Clean history, problem solved.</p>
<h2 id="heading-step-by-step-practical-guide-to-git-cherry-pick"><strong>Step-by-Step Practical Guide to</strong> <code>git cherry-pick</code></h2>
<h3 id="heading-1-view-commit-history-with-git-log"><strong>1. View Commit History with</strong> <code>git log</code></h3>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span> --oneline --graph --all
</code></pre>
<p>✅ This shows a simple, visual commit history across all branches.</p>
<p><strong>Tip:</strong> If you're working on a shared repository with your team and didn't create your own branch yet, you can check history of a specific branch like:</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span> &lt;branch-name&gt; --oneline --graph --all
</code></pre>
<p><strong>Example:</strong></p>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span> main --oneline --graph --all
</code></pre>
<p>✅ Use this to find the commit hash (<code>abc123</code>) you want to cherry-pick.</p>
<p>✅ Copy that hash — you'll need it in the next step.</p>
<h3 id="heading-2-switch-to-your-target-branch"><strong>2. Switch to Your Target Branch</strong></h3>
<p>Before you apply the commit, make sure you're on the correct branch:</p>
<pre><code class="lang-bash">git status
</code></pre>
<p>This shows your current branch.</p>
<p>If unsure, list all branches:</p>
<pre><code class="lang-bash">git branch
</code></pre>
<p>Switch to your target branch:</p>
<pre><code class="lang-bash">git checkout &lt;your-branch-name&gt;
</code></pre>
<p><strong>Example:</strong></p>
<pre><code class="lang-bash">git checkout feature/login
</code></pre>
<h3 id="heading-3-cherry-pick-the-commit"><strong>3. Cherry-Pick the Commit</strong></h3>
<pre><code class="lang-bash">git cherry-pick &lt;commit-hash&gt;
</code></pre>
<p>✅ This applies only the specific commit to your current branch, without merging the entire source branch or bringing unrelated changes.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-bash">git cherry-pick abcd1234
</code></pre>
<p>If the commit applies cleanly, you're done. If there's a conflict, Git will pause and you resolve it manually.</p>
<h2 id="heading-cherry-pick-multiple-commits"><strong>Cherry-Pick Multiple Commits</strong></h2>
<p>One by one:</p>
<pre><code class="lang-bash">git cherry-pick &lt;commit1&gt; &lt;commit2&gt;
</code></pre>
<p>Range of commits:</p>
<pre><code class="lang-bash">git cherry-pick commitA^..commitB
</code></pre>
<h2 id="heading-handling-conflicts-during-cherry-pick"><strong>Handling Conflicts During Cherry-Pick</strong></h2>
<p>Conflict? No stress. Git pauses:</p>
<pre><code class="lang-bash">CONFLICT (content): Merge conflict <span class="hljs-keyword">in</span> file.js
</code></pre>
<p>Resolve it:</p>
<pre><code class="lang-bash">git add .
git cherry-pick --<span class="hljs-built_in">continue</span>
</code></pre>
<p>Or abort:</p>
<pre><code class="lang-bash">git cherry-pick --abort
</code></pre>
<h2 id="heading-you-can-also-follow-this-short-youtube-video-if-you-want">You can also follow this short youtube video if you want:</h2>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=i657Bg_HAWI">https://www.youtube.com/watch?v=i657Bg_HAWI</a></div>
<p> </p>
<h2 id="heading-final-thoughts"><strong>Final Thoughts</strong></h2>
<p>Mistakes happen — commits go to the wrong place, branches get mixed up.</p>
<p><code>git cherry-pick</code> is the clean, targeted way to:</p>
<p>✅ Move specific commits</p>
<p>✅ Fix accidental commits</p>
<p>✅ Avoid messy merges</p>
<p>Once you try it practically, you’ll use it confidently — like I did when I accidentally messed up branches.</p>
<h3 id="heading-thanks-for-reading-guys">Thanks for reading guys…</h3>
]]></content:encoded></item><item><title><![CDATA[Managing Multiple GitHub/Git Accounts on One Machine (Personal + Work)]]></title><description><![CDATA[As developers and DevOps engineers, it's common to contribute to both personal and professional projects. However, using two GitHub accounts on a single machine can lead to identity conflicts, unverified commits, or accidentally pushing to the wrong ...]]></description><link>https://blog.surajdev.tech/managing-multiple-githubgit-accounts-on-one-machine-personal-work</link><guid isPermaLink="true">https://blog.surajdev.tech/managing-multiple-githubgit-accounts-on-one-machine-personal-work</guid><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><category><![CDATA[ssh-keygen]]></category><category><![CDATA[Manage Multiple GitHub Accounts Using SSH]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Tue, 17 Jun 2025 09:18:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1750145148128/e722ac43-2b94-4f4d-a7d7-68f6b9944a2d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As developers and DevOps engineers, it's common to contribute to both personal and professional projects. However, using <strong>two GitHub accounts</strong> on a <strong>single machine</strong> can lead to <code>identity conflicts</code>, <code>unverified commits</code>, or <code>accidentally pushing to the wrong repository</code>.</p>
<p>In this guide I’ll walks you through setting up two GitHub accounts <strong>securely</strong>, <strong>cleanly</strong>, and with <strong>verified SSH-signed commits</strong> all on a single machine.</p>
<h2 id="heading-objectives">Objectives</h2>
<ol>
<li><p>Work with both <strong>personal and work GitHub repositories</strong> (public &amp; private).</p>
</li>
<li><p>Use <strong>two separate GitHub accounts</strong> on one machine.</p>
</li>
<li><p>Ensure <strong>verified commits</strong> via SSH commit signing.</p>
</li>
<li><p>Maintain a <strong>scalable, secure, and professional Git setup</strong>.</p>
</li>
</ol>
<h2 id="heading-step-1-generate-separate-ssh-keys">Step 1: Generate Separate SSH Keys</h2>
<p>Create separate SSH key pairs for each GitHub account:</p>
<p>You can name these according to your preferences while generating the SSH keys</p>
<ul>
<li><p><code>for-personal</code></p>
</li>
<li><p><code>for-work</code></p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-comment"># Personal Key</span>
ssh-keygen -t ed25519 -C <span class="hljs-string">"you.email@gmail.com"</span> -f ~/.ssh/for-personal

<span class="hljs-comment"># Work Key</span>
ssh-keygen -t ed25519 -C <span class="hljs-string">"you.workemail@gmail.com"</span> -f ~/.ssh/for-work
</code></pre>
<blockquote>
<p>Do <strong>not</strong> overwrite the default <code>id_ed25519</code>. Keeping keys separate ensures flexibility and security.</p>
</blockquote>
<h2 id="heading-step-2-add-keys-to-ssh-agent">Step 2: Add Keys to SSH Agent</h2>
<pre><code class="lang-bash"><span class="hljs-comment"># View loaded keys</span>
ssh-add -l

<span class="hljs-comment"># Add new keys</span>
ssh-add ~/.ssh/for-personal
ssh-add ~/.ssh/for-work

<span class="hljs-comment"># Remove all existing keys (optional reset)</span>
ssh-add -D
</code></pre>
<h2 id="heading-step-3-configure-ssh-config-file">Step 3: Configure SSH <code>config</code> File</h2>
<p>Create or edit your SSH config file:</p>
<pre><code class="lang-bash">touch ~/.ssh/config
</code></pre>
<p>Add the following content:</p>
<pre><code class="lang-ini"><span class="hljs-comment"># Global settings</span>
Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentitiesOnly yes
  ServerAliveInterval 60
  ServerAliveCountMax 3

<span class="hljs-comment"># Personal GitHub</span>
Host personal.github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/for-personal

<span class="hljs-comment"># Work GitHub</span>
Host work.github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/for-work
</code></pre>
<h2 id="heading-step-4-add-public-keys-to-github">Step 4: Add Public Keys to GitHub</h2>
<p>Upload the corresponding <code>.pub</code> files to each account:</p>
<ul>
<li><p><code>~/.ssh/for-personal.pub</code> → Personal GitHub</p>
</li>
<li><p><code>~/.ssh/for-work.pub</code> → Work GitHub</p>
</li>
</ul>
<blockquote>
<p>GitHub → <strong>Settings → SSH and GPG Keys → New SSH Key</strong></p>
</blockquote>
<h2 id="heading-step-5-clone-repositories-using-ssh-host-aliases">Step 5: Clone Repositories Using SSH Host Aliases</h2>
<pre><code class="lang-bash"><span class="hljs-comment"># Clone personal repo</span>
git <span class="hljs-built_in">clone</span> git@personal.github.com:your-username/my-repo.git

<span class="hljs-comment"># Clone work repo</span>
git <span class="hljs-built_in">clone</span> git@work.github.com:my-org/work-repo.git
</code></pre>
<h2 id="heading-step-6-configure-git-identity-per-repository">Step 6: Configure Git Identity per Repository</h2>
<p>Set identity locally inside each project to avoid global conflicts:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Inside Personal Repo</span>
<span class="hljs-built_in">cd</span> ~/PersonalRepo

git config user.name <span class="hljs-string">"your name"</span>
git config user.email <span class="hljs-string">"your email"</span>

<span class="hljs-comment"># Inside Work Repo</span>
<span class="hljs-built_in">cd</span> ~/WorkRepo

git config user.name <span class="hljs-string">"your name"</span>
git config user.email <span class="hljs-string">"your work email"</span>
</code></pre>
<h2 id="heading-step-7-enable-verified-commits-with-ssh-signing">Step 7: Enable Verified Commits with SSH Signing</h2>
<p>GitHub supports <strong>SSH-based commit signing</strong>, separate from SSH authentication.</p>
<h3 id="heading-generate-signing-keys">Generate Signing Keys</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Personal Signing Key</span>
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_signing_personal -C <span class="hljs-string">"signing-personal"</span>

<span class="hljs-comment"># Work Signing Key</span>
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_signing_work -C <span class="hljs-string">"signing-work"</span>
</code></pre>
<h3 id="heading-add-signing-keys-to-github">Add Signing Keys to GitHub</h3>
<p>Go to <strong>GitHub → Settings → SSH and GPG Keys → New Signing Key</strong> and paste the contents of each <code>.pub</code> file.</p>
<h2 id="heading-step-8-configure-git-to-use-signing-keys">Step 8: Configure Git to Use Signing Keys</h2>
<p>Set up commit signing in each repo:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Personal Repo</span>
<span class="hljs-built_in">cd</span> ~/PersonalRepo

git config commit.gpgsign <span class="hljs-literal">true</span>
git config gpg.format ssh
git config user.signingkey ~/.ssh/id_ed25519_signing_personal.pub

<span class="hljs-comment"># Work Repo</span>
<span class="hljs-built_in">cd</span> ~/WorkRepo

git config commit.gpgsign <span class="hljs-literal">true</span>
git config gpg.format ssh
git config user.signingkey ~/.ssh/id_ed25519_signing_work.pub
</code></pre>
<h2 id="heading-pre-commit-workflow-start-ssh-agent-and-test-connections">Pre-Commit Workflow: Start SSH Agent and Test Connections</h2>
<p>Before making commits in any repository, ensure your SSH agent is running and keys are loaded:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Ensure SSH agent is running and keys are loaded</span>
<span class="hljs-built_in">eval</span> <span class="hljs-string">"<span class="hljs-subst">$(ssh-agent -s)</span>"</span>
ssh-add ~/.ssh/personal_github
ssh-add ~/.ssh/work_github

<span class="hljs-comment"># Test connections to verify which account will be used</span>
ssh -T git@personal.github.com
<span class="hljs-comment"># or</span>
ssh -T git@work.github.com

<span class="hljs-comment"># Now proceed with your git operations</span>
git add .
git commit -m <span class="hljs-string">"Your commit message"</span>
git push origin main
</code></pre>
<blockquote>
<p>Successful messages like <code>Hi broh! You've successfully authenticated</code> confirm proper setup.</p>
</blockquote>
<hr />
<p><strong>Note:</strong> This step is particularly important after system restarts or when opening new terminal sessions, as the SSH agent may not be running or may not have your keys loaded.</p>
<h2 id="heading-final-result">Final Result</h2>
<ul>
<li><p><strong>Secure and clean GitHub SSH setup</strong> for both accounts.</p>
</li>
<li><p><strong>Verified commits</strong> using SSH signing keys.</p>
</li>
<li><p><strong>Separate identities</strong> per project.</p>
</li>
</ul>
<h3 id="heading-bonus-tip">Bonus Tip</h3>
<p>To view signed commits:</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">log</span> --show-signature
</code></pre>
<h2 id="heading-the-end-thanks-for-reading">The end! - Thanks for reading…</h2>
]]></content:encoded></item><item><title><![CDATA[You Need To Learn Docker Right Now : Part 2]]></title><description><![CDATA[Introduction
Docker is a powerful containerization platform that streamlines application development, deployment, and scaling of containerized applications. In this blog I’ll covers important Docker concepts like networking, Volumes, writing compose ...]]></description><link>https://blog.surajdev.tech/you-need-to-learn-docker-right-now-part-2</link><guid isPermaLink="true">https://blog.surajdev.tech/you-need-to-learn-docker-right-now-part-2</guid><category><![CDATA[Docker]]></category><category><![CDATA[Docker compose]]></category><category><![CDATA[docker-network]]></category><category><![CDATA[docker-volume]]></category><category><![CDATA[advanced docker]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Thu, 29 May 2025 07:18:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1747894413623/42703d4f-b25f-49bb-8e8d-4231f135c8b8.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>Docker is a powerful <strong>containerization</strong> platform that streamlines <strong>application development</strong>, <strong>deployment</strong>, and <strong>scaling</strong> of containerized applications. In this blog I’ll covers important Docker concepts like <strong>networking, Volumes, writing compose file in docker, difference in Docker and Kubernetes, Multi-Stage build in dockerfile</strong> with practical insights for developers and DevOps engineers.</p>
<h1 id="heading-docker-networking">Docker Networking</h1>
<p>Docker Networking enables communication between <strong>containers</strong>, the <strong>Docker host</strong>, and the <strong>external world</strong>. When a container is running, it is attached to a <strong>virtual network</strong>. This network determines how the <strong>container can talk to other containers</strong>, <strong>services</strong>, or the <strong>internet</strong>. Docker uses <strong>network drivers</strong> to abstract different networking strategies. Understanding these drivers helps optimize <strong>performance</strong>, <strong>security</strong>, and communication within your containerized environments.</p>
<h3 id="heading-docker-provides-three-primary-network-drivers-but-there-are-more-according-to-the-usecases">Docker provides three primary network drivers but there are more according to the usecases:</h3>
<h2 id="heading-bridge-default-driver">Bridge (Default Driver)</h2>
<p>If you're running containers on a single host and want them to talk to each other, <strong>Bridge</strong> is your go-to.</p>
<p><strong>How it works:</strong> Creates an internal network and assigns IP addresses to containers.</p>
<p><strong>Use case:</strong><br />You’re running a Node.js API and a MongoDB container on your laptop. Both need to talk to each other. Use the default bridge network.</p>
<p><strong>Practical Example:</strong></p>
<pre><code class="lang-bash">docker network create --driver bridge my_bridge
docker run -d --name db --network my_bridge mongo
docker run -d --name api --network my_bridge node-app
</code></pre>
<blockquote>
<p><code>api</code> can now connect to MongoDB using <code>mongodb://db:27017</code>.</p>
</blockquote>
<p><strong>So see which containers are connected with the same network on bridge driver use this command:</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment"># To see the detailed information on one or more networks</span>
docker network inspect bridge
</code></pre>
<h2 id="heading-host">Host</h2>
<p>Remove network isolation between the container and the Docker host, and use the host's networking directly.</p>
<p><strong>How it works:</strong></p>
<ul>
<li><p>The container shares the host’s network stack — it has no separate IP.</p>
</li>
<li><p>Ports on the container are directly exposed on the host.</p>
</li>
</ul>
<p><strong>Use case:</strong><br />Running an Nginx container on port 80 without port mapping, for better performance.</p>
<p><strong>Practical Example:</strong></p>
<pre><code class="lang-bash">docker run --rm --network host nginx
</code></pre>
<blockquote>
<p>Nginx is now accessible directly at <a target="_blank" href="http://localhost"><code>http://localhost</code></a> without needing <code>-p 80:80</code>.</p>
</blockquote>
<p>The flag <code>--rm</code> means:</p>
<blockquote>
<p><strong>Automatically remove the container when it exits.</strong></p>
</blockquote>
<h2 id="heading-none">None</h2>
<p>You want a container <strong>completely cut off</strong> from all networks? Use this.</p>
<p><strong>How it works:</strong></p>
<ul>
<li><p>No network interface is created.</p>
</li>
<li><p>Only useful for extreme isolation or containers communicating via files/mounted volumes only.</p>
</li>
</ul>
<p><strong>Use case:</strong><br />Highly secure containers for background data processing with no need for communication.</p>
<p><strong>Practical Example:</strong></p>
<pre><code class="lang-bash">docker run --network none your_image
</code></pre>
<hr />
<blockquote>
<p><strong>Want to learn more network drivers you can follow the official</strong> <strong>documentation</strong> <strong>of docker itself.</strong></p>
<p>Link: <a target="_blank" href="https://docs.docker.com/engine/network/drivers/">https://docs.docker.com/engine/network/drivers</a></p>
</blockquote>
<hr />
<h2 id="heading-difference-between-bridge-and-host-network">Difference Between Bridge and Host Network</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748492731119/f2e68053-e574-4245-9fbb-8a7343505385.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-how-to-create-custom-networks-in-docker">How To Create Custom Networks In Docker</h2>
<p>When you use Docker, containers by default get attached to the <code>bridge</code> network unless you specify otherwise. But for more control, better architecture, and easier service-to-service communication, <strong>custom networks</strong> are the way to go.</p>
<p><strong>Practical Example:</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment"># Step 1: Create a custom network</span>
docker network create my_custom_net

<span class="hljs-comment"># Step 2: Run Redis container on that network</span>
docker run -d --name redis --network my_custom_net redis

<span class="hljs-comment"># Step 3: Run backend app on the same network</span>
docker run -d --name backend --network my_custom_net myapp
</code></pre>
<p>Now the <code>backend</code> container can reach the <code>redis</code> container using:</p>
<pre><code class="lang-bash">redis:6379
</code></pre>
<blockquote>
<p>No need to figure out IP addresses. Docker’s DNS handles the resolution automatically.</p>
</blockquote>
<h3 id="heading-benefits-of-creating-your-own-network">Benefits of creating your own network</h3>
<ul>
<li><p>Automatic container name resolution</p>
</li>
<li><p>Better network isolation</p>
</li>
<li><p>Cleaner communication between services</p>
</li>
</ul>
<h1 id="heading-docker-volumes">Docker Volumes</h1>
<p>By default, <strong>Docker containers are ephemeral</strong> — meaning, when a container is deleted, all the data inside it is also lost. This is a big problem for things like:</p>
<ul>
<li><p>Databases (e.g., PostgreSQL, MongoDB)</p>
</li>
<li><p>Log files</p>
</li>
<li><p>User-generated content (uploads, configs)</p>
</li>
</ul>
<p>To solve this, Docker provides <strong>volumes</strong>, which are persistent storage locations managed by Docker.</p>
<h3 id="heading-how-to-use-docker-volumes">How to Use Docker Volumes</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Step 1: Create a Docker volume</span>
docker volume create my_data

<span class="hljs-comment"># Step 2: Mount the volume into a container</span>
docker run -v my_data:/data my_image
</code></pre>
<p>This mounts the <code>my_data</code> volume into the container’s <code>/data</code> directory.</p>
<h3 id="heading-benefits-of-docker-volumes">Benefits of Docker Volumes</h3>
<ul>
<li><p><strong>Persistence</strong><br />  Data remains intact even if the container is removed, restarted, or recreated.</p>
</li>
<li><p><strong>Managed by Docker</strong><br />  Volumes live outside the container filesystem and are managed in a secure and efficient way by Docker.</p>
</li>
<li><p><strong>Decouples Data from Containers</strong><br />  You can attach the same volume to different containers (great for backup jobs, logs, etc.)</p>
</li>
<li><p><strong>Supports Named Volumes and Bind Mounts</strong></p>
<ul>
<li><p>Named volumes: managed by Docker (<code>my_data</code>)</p>
</li>
<li><p>Bind mounts: link to a host path (<code>/home/user/data:/data</code>)</p>
</li>
</ul>
</li>
</ul>
<h1 id="heading-efficient-caching-in-layers">Efficient Caching in Layers</h1>
<p>Every command in your <code>Dockerfile</code> creates a <strong>layer</strong>. These layers are cached and reused by Docker to avoid rebuilding the entire image every time — this is known as <strong>layer caching</strong>.</p>
<p>A well-structured <code>Dockerfile</code> improves build time significantly. Why? Because Docker will <strong>reuse unchanged layers</strong> from cache instead of rebuilding them.</p>
<h4 id="heading-youll-much-understand-via-this-example">You’ll much understand Via this example:</h4>
<p>Here we have the sample dockerfile and below I have given you a diagram in which you can see arranging the layers carefully can save the time everytime you build your <code>dockerfile</code> but in the first build it takes time much longer then the rebuild you do further.</p>
<pre><code class="lang-dockerfile"><span class="hljs-comment"># Build dependencies using lightweight Node.js base image</span>
<span class="hljs-keyword">FROM</span> node:<span class="hljs-number">18</span>-alpine

<span class="hljs-comment"># Set the working directory inside the container</span>
<span class="hljs-keyword">WORKDIR</span><span class="bash"> /app</span>

<span class="hljs-comment"># Only copy dependency descriptor files (changes infrequently)</span>
<span class="hljs-keyword">COPY</span><span class="bash"> package*.json ./</span>

<span class="hljs-comment"># Install only production dependencies (skips devDependencies)</span>
<span class="hljs-keyword">RUN</span><span class="bash"> npm ci --only=production</span>

<span class="hljs-comment"># Copy the rest of the application source code (changes frequently)</span>
<span class="hljs-keyword">COPY</span><span class="bash"> . .</span>

<span class="hljs-comment"># Define the command to run the app</span>
<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"npm"</span>, <span class="hljs-string">"start"</span>]</span>
</code></pre>
<p>When you build a Docker image, each line in your Dockerfile creates a <strong>layer</strong>. Docker tries to reuse (cache) these layers in future builds to <strong>save time</strong> — especially when files or steps haven’t changed.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748495776120/e4c7a000-038b-4f9d-ad75-7e50c9f2a1ab.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-benefits-of-efficient-layer-caching">Benefits of Efficient Layer Caching</h3>
<ul>
<li><p><strong>Faster builds</strong> — Only changed layers are rebuilt.</p>
</li>
<li><p><strong>Smaller image layers</strong> — Cached intelligently.</p>
</li>
<li><p><strong>Repeatable builds</strong> — Fewer surprises and cleaner CI/CD.</p>
</li>
</ul>
<h1 id="heading-docker-multi-stage-builds">Docker Multi-Stage Builds</h1>
<p>Multi-stage builds allow you to <strong>use multiple</strong> <code>FROM</code> instructions in one Dockerfile. This helps you separate the <strong>build environment</strong> (where dependencies and tools are needed) from the <strong>production image</strong> (where only final code/artifacts go).</p>
<p>This results in:</p>
<ul>
<li><p>Smaller images 📦</p>
</li>
<li><p>More secure builds 🔐</p>
</li>
<li><p>Faster CI/CD deployment ⚡</p>
</li>
</ul>
<p><strong>So here I’m showing you one of my project’s multi-stage build</strong> <code>Dockerfile</code></p>
<pre><code class="lang-dockerfile"><span class="hljs-comment"># Stage 1: Builder with full Node.js environment</span>
<span class="hljs-keyword">FROM</span> node:<span class="hljs-number">18</span>-alpine AS builder

<span class="hljs-keyword">WORKDIR</span><span class="bash"> /app</span>

<span class="hljs-comment"># Copy package files first for optimal caching</span>
<span class="hljs-keyword">COPY</span><span class="bash"> package.json package-lock.json ./</span>

<span class="hljs-comment"># Install all dependencies (including devDependencies)</span>
<span class="hljs-keyword">RUN</span><span class="bash"> npm ci --no-audit --prefer-offline</span>

<span class="hljs-comment"># Copy source files</span>
<span class="hljs-keyword">COPY</span><span class="bash"> . .</span>

<span class="hljs-comment"># Build the application</span>
<span class="hljs-keyword">RUN</span><span class="bash"> npm run build</span>

<span class="hljs-comment"># Stage 2: Production image</span>
<span class="hljs-keyword">FROM</span> node:<span class="hljs-number">18</span>-alpine

<span class="hljs-keyword">WORKDIR</span><span class="bash"> /app</span>

<span class="hljs-comment"># Copy built assets and dependencies</span>
<span class="hljs-keyword">COPY</span><span class="bash"> --from=builder /app/.next ./.next</span>
<span class="hljs-keyword">COPY</span><span class="bash"> --from=builder /app/public ./public</span>
<span class="hljs-keyword">COPY</span><span class="bash"> --from=builder /app/node_modules ./node_modules</span>
<span class="hljs-keyword">COPY</span><span class="bash"> --from=builder /app/package.json ./package.json</span>

<span class="hljs-comment"># expose the port</span>
<span class="hljs-keyword">EXPOSE</span> <span class="hljs-number">3000</span>

<span class="hljs-comment"># Start the application</span>
<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"npm"</span>, <span class="hljs-string">"start"</span>]</span>
</code></pre>
<h2 id="heading-best-practices-to-write-a-good-multi-stage-dockerfile">Best practices to write a good multi-stage dockerfile</h2>
<ul>
<li><p>Use small base images like <code>node:18-alpine</code> or <code>nginx:alpine</code>.</p>
</li>
<li><p>Name your stages (<code>AS builder</code>) for readability.</p>
</li>
<li><p>Avoid copying unnecessary files (use <code>.dockerignore</code>).</p>
</li>
<li><p>Keep the final image minimal (no build tools, dev dependencies).</p>
</li>
<li><p>Use multi-stage even for simple projects to keep the image lean and clean.</p>
</li>
</ul>
<h1 id="heading-docker-compose">Docker Compose</h1>
<p>Docker Compose is a tool used to <strong>define and run multi-container Docker applications</strong> using a YAML file (<code>docker-compose.yml</code> or <code>compose.yml</code> or <code>docker-compose.yaml</code>). You describe the services, their images/build context, ports, environment variables, volumes, and networks — all in one place.</p>
<h3 id="heading-understanding-with-architecture-diagram">Understanding with Architecture diagram:</h3>
<p>Consider an application split into a <strong>frontend web</strong> application and a <strong>backend service</strong>.</p>
<p>The frontend is configured at runtime with an HTTP configuration file managed by infrastructure, providing an external domain name, and an HTTPS server certificate injected by the platform's secured secret store.</p>
<p>The <strong>backend</strong> stores data in a <strong>persistent volume.</strong></p>
<p>Both services communicate with each other on an isolated <strong>back-tier network</strong>, while the frontend is also connected to a <strong>front-tier network</strong> and <strong>exposes port 443 for external usage</strong>.</p>
<p><img src="https://docs.docker.com/compose/images/compose-application.webp" alt="Compose application example" /></p>
<h3 id="heading-this-is-how-you-write-a-docker-composeyml-file">This is how you write a <code>docker-compose.yml</code> file:</h3>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">'3.8'</span>  <span class="hljs-comment"># Specify Compose file version for compatibility</span>

<span class="hljs-attr">services:</span>
  <span class="hljs-attr">frontend:</span>
    <span class="hljs-attr">image:</span> <span class="hljs-string">example/webapp</span>                    <span class="hljs-comment"># Frontend web application image</span>
    <span class="hljs-attr">ports:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">"443:8043"</span>                          <span class="hljs-comment"># Map host port 443 to container port 8043 for HTTPS access</span>
    <span class="hljs-attr">networks:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">front-tier</span>                         <span class="hljs-comment"># Connect to front-tier network (public-facing)</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">back-tier</span>                          <span class="hljs-comment"># Connect to back-tier network to talk to backend securely</span>
    <span class="hljs-attr">configs:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">source:</span> <span class="hljs-string">httpd-config</span>               <span class="hljs-comment"># Use external Apache HTTPD config</span>
        <span class="hljs-attr">target:</span> <span class="hljs-string">/etc/httpd/conf/httpd.conf</span>
    <span class="hljs-attr">secrets:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">server-certificate</span>                 <span class="hljs-comment"># Use external TLS/SSL certificate secret</span>

  <span class="hljs-attr">backend:</span>
    <span class="hljs-attr">image:</span> <span class="hljs-string">example/database</span>                 <span class="hljs-comment"># Backend database service image</span>
    <span class="hljs-attr">volumes:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">db-data:/etc/data</span>                   <span class="hljs-comment"># Persist database data in a named volume</span>
    <span class="hljs-attr">networks:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">back-tier</span>                         <span class="hljs-comment"># Only expose backend internally on back-tier network</span>

<span class="hljs-attr">volumes:</span>
  <span class="hljs-attr">db-data:</span>
    <span class="hljs-attr">driver:</span> <span class="hljs-string">flocker</span>                        <span class="hljs-comment"># Volume driver for data persistence</span>
    <span class="hljs-attr">driver_opts:</span>
      <span class="hljs-attr">size:</span> <span class="hljs-string">"10GiB"</span>                       <span class="hljs-comment"># Allocate 10GB storage for DB data volume</span>

<span class="hljs-attr">configs:</span>
  <span class="hljs-attr">httpd-config:</span>
    <span class="hljs-attr">external:</span> <span class="hljs-literal">true</span>                        <span class="hljs-comment"># Reference an externally created config</span>

<span class="hljs-attr">secrets:</span>
  <span class="hljs-attr">server-certificate:</span>
    <span class="hljs-attr">external:</span> <span class="hljs-literal">true</span>                       <span class="hljs-comment"># Reference an externally managed secret (TLS cert)</span>

<span class="hljs-attr">networks:</span>
  <span class="hljs-attr">front-tier:</span> {}                         <span class="hljs-comment"># Define front-tier network (default bridge network)</span>
  <span class="hljs-attr">back-tier:</span> {}                          <span class="hljs-comment"># Define back-tier network (default bridge network)</span>
</code></pre>
<h3 id="heading-key-commands"><strong><mark>Key commands</mark></strong></h3>
<p>To start all the services defined in your <code>compose.yaml</code> or <code>docker-compose.yml</code> file:</p>
<pre><code class="lang-bash">docker compose up
</code></pre>
<p>To run the services in the background:</p>
<pre><code class="lang-bash">docker compose up -d
</code></pre>
<p>To rebuild Docker images and start containers:</p>
<pre><code class="lang-bash">docker compose up --build
</code></pre>
<p>To run the services in the background:</p>
<pre><code class="lang-bash">docker compose up --build -d
</code></pre>
<p>To stop and remove the running services:</p>
<pre><code class="lang-bash">docker compose down
</code></pre>
<p>If you want to monitor the output of your running containers and debug issues, you can view the logs with:</p>
<pre><code class="lang-bash">docker compose logs
</code></pre>
<p>To list all the services along with their current status:</p>
<pre><code class="lang-bash">docker compose ps
<span class="hljs-comment"># or</span>
docker ps
</code></pre>
<p>To list all the services along with stopped/exited:</p>
<pre><code class="lang-bash">docker compose ps -a
<span class="hljs-comment"># or</span>
docker ps -a
</code></pre>
<p>To watch the docker services current status continuously:</p>
<pre><code class="lang-bash">watch docker ps
</code></pre>
<p>To access shell inside a running container:</p>
<pre><code class="lang-bash">docker compose <span class="hljs-built_in">exec</span> -it &lt;container-id or container-name&gt; sh
<span class="hljs-comment"># or</span>
docker compose <span class="hljs-built_in">exec</span> -it &lt;container-id or container-name&gt; bash
</code></pre>
<h1 id="heading-docker-swarm">Docker Swarm</h1>
<p>Docker Swarm is Docker’s built-in clustering and orchestration tool. It allows you to <strong>combine multiple Docker hosts (nodes) into a single cluster</strong> called a <code>swarm</code>, making it easier to deploy and manage containerized applications at scale.</p>
<h4 id="heading-how-it-works">How it works:</h4>
<ul>
<li><p><strong>Cluster Setup:</strong> You start by initializing a swarm on one machine, which becomes the manager node.</p>
</li>
<li><p><strong>Node Management:</strong> Other Docker hosts can join this swarm as worker nodes.</p>
</li>
<li><p><strong>Service Deployment:</strong> You deploy your application as a <em>service</em> instead of individual containers.</p>
</li>
<li><p><strong>Scaling:</strong> You specify how many replicas (instances) of a service you want, and Swarm handles scheduling those across available nodes.</p>
</li>
<li><p><strong>Load Balancing:</strong> Swarm automatically distributes incoming requests among service replicas, balancing load and improving availability.</p>
</li>
</ul>
<h4 id="heading-steps-to-do-to-work-with-swarm">Steps to do to work with swarm:</h4>
<pre><code class="lang-bash">docker swarm init
</code></pre>
<p>after initializing you’ll see this message:</p>
<pre><code class="lang-bash">Swarm initialized: current node (7ns53yw3fvsy1bvoma6tkyf8v) is now a manager.

To add a worker to this swarm, run the following <span class="hljs-built_in">command</span>:

    docker swarm join --token SWMTKN-1-5r4ya9ic9x3rducjym1i4dxgg01rtydnmtuh9bq2k2khllnyt4-0jbi2g5s5kzon0drl65pux8jc 192.168.65.3:2377

To add a manager to this swarm, run <span class="hljs-string">'docker swarm join-token manager'</span> and follow the instructions.
</code></pre>
<ul>
<li><p>Initializes the current Docker host as a swarm manager node.</p>
</li>
<li><p>This sets up the cluster control plane.</p>
</li>
</ul>
<pre><code class="lang-bash">docker service create --replicas 3 --name web nginx
</code></pre>
<p>After running above command you’ll this:</p>
<pre><code class="lang-bash">tzgrg9wjm0xunznt04zti2qd4
overall progress: 3 out of 3 tasks 
1/3: running   [==================================================&gt;] 
2/3: running   [==================================================&gt;] 
3/3: running   [==================================================&gt;] 
verify: Service tzgrg9wjm0xunznt04zti2qd4 converged
</code></pre>
<ul>
<li><p>Creates a new service named <code>web</code> using the <code>nginx</code> image.</p>
</li>
<li><p>Runs <strong>3 replicas</strong> of the <code>nginx</code> container distributed across the swarm nodes.</p>
</li>
<li><p>Swarm automatically schedules these replicas on different nodes (if available) and manages their lifecycle.</p>
</li>
</ul>
<pre><code class="lang-bash">docker ps
</code></pre>
<p>After running the dcoker ps command you’ll these logs:</p>
<pre><code class="lang-bash">CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES
2069f48eecbd   nginx:latest   <span class="hljs-string">"/docker-entrypoint.…"</span>   16 seconds ago   Up 15 seconds   80/tcp    web.3.m3mtwuonvph1krfn0uvxe325r
9d52e9929221   nginx:latest   <span class="hljs-string">"/docker-entrypoint.…"</span>   16 seconds ago   Up 15 seconds   80/tcp    web.2.5xzbt400wks7f7j55lqxi5ahe
4066263b7592   nginx:latest   <span class="hljs-string">"/docker-entrypoint.…"</span>   16 seconds ago   Up 15 seconds   80/tcp    web.1.tv76fhg177h0zyo3zvf74gaii
</code></pre>
<h4 id="heading-why-use-docker-swarm">Why use Docker Swarm?</h4>
<ul>
<li><p><strong>Simple to set up</strong>: Native Docker CLI commands manage the cluster.</p>
</li>
<li><p><strong>Built-in load balancing and scaling</strong>.</p>
</li>
<li><p><strong>High availability</strong>: Services automatically recover from node failures.</p>
</li>
<li><p><strong>Declarative service model</strong>: Define how many replicas and Docker manages the rest.</p>
</li>
</ul>
<h2 id="heading-to-clean-up-everything-youve-done-with-docker-swarm-you-need-to">To clean up everything you've done with <strong>Docker Swarm</strong>, you need to:</h2>
<h3 id="heading-1-remove-services">1. <strong>Remove Services</strong></h3>
<p>First, remove any running services you created in the swarm:</p>
<pre><code class="lang-bash">docker service ls                 <span class="hljs-comment"># List all services</span>
docker service rm &lt;service-name&gt; <span class="hljs-comment"># Remove each service</span>
</code></pre>
<h3 id="heading-2-remove-the-swarm-leave-the-cluster">2. <strong>Remove the Swarm (Leave the Cluster)</strong></h3>
<p>If you're on a <strong>worker node</strong>, leave the swarm with:</p>
<pre><code class="lang-bash">docker swarm leave
</code></pre>
<p>If you're on the <strong>manager node</strong>, force it to leave (and dissolve the swarm):</p>
<pre><code class="lang-bash">docker swarm leave --force
</code></pre>
<h1 id="heading-docker-vs-kubernetes">Docker Vs Kubernetes</h1>
<h3 id="heading-docker"><strong>Docker</strong>:</h3>
<p>Docker operates at the individual container level on a single operating system host. You must manually <strong>manage each hos</strong>t and <strong>setting up networks</strong>, <strong>security policies</strong>, and <strong>storage</strong> for multiple related containers can be <strong>complex</strong>.</p>
<h3 id="heading-kubernetes"><strong>Kubernetes</strong>:</h3>
<p>Kubernetes operates at the <strong>cluster level</strong>. It manages multiple containerized applications across <strong>multiple hosts</strong>, providing automation for tasks like <strong>load balancing</strong>, <strong>scaling</strong>, and <strong>ensuring the desired state of applications</strong>.</p>
<p>In short, Docker focuses on containerization and running containers on individual hosts, while Kubernetes specializes in managing and orchestrating containers at scale across a cluster of hosts.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Docker</strong></td><td><strong>Kubernetes</strong></td></tr>
</thead>
<tbody>
<tr>
<td>🔸 A containerization platform.</td><td>🔸 A container orchestration system.</td></tr>
<tr>
<td>🔸 Packages applications and dependencies into containers.</td><td>🔸 Manages containerized applications at scale.</td></tr>
<tr>
<td>🔸 Ensures portability across environments.</td><td>🔸 Handles deployment, scaling, and networking.</td></tr>
<tr>
<td>🔸 Runs containers on a single host.</td><td>🔸 Distributes workloads across multiple nodes.</td></tr>
<tr>
<td>🔸 Used in CI/CD pipelines for deployment automation.</td><td>🔸 Optimized for microservices and cloud-native applications.</td></tr>
</tbody>
</table>
</div><h3 id="heading-with-this-diagram-youll-understand-what-we-have-talked-above">With this diagram you’ll understand what we have talked above.</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748492423997/5db528fc-6b3f-487d-9280-e9addad31585.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-wrapping-up-with-demo">Wrapping up with Demo:</h1>
<p>If you want to try out yourself this demo you can use this project:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://github.com/Suraj-kumar00/DevOps-URL2QR">https://github.com/Suraj-kumar00/DevOps-URL2QR</a></div>
<p> </p>
<p>So, now let’s do it practically what we have learned so far. In the above repository i have give you the <code>Dockerfile</code> for <strong>frontend</strong> and the <strong>backend.</strong></p>
<p>And you also have the <code>docker-compose.yml</code> file in this repo.</p>
<p>So now you just have to do these steps in order to spin up the frontend and the backend containers simultaneously.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">'3.8'</span>

<span class="hljs-attr">services:</span>
  <span class="hljs-attr">frontend:</span>                                    <span class="hljs-comment"># This is frontend service</span>
    <span class="hljs-attr">build:</span> <span class="hljs-string">./front-end-nextjs</span>                  <span class="hljs-comment"># Build from Dockerfile in this directory</span>
    <span class="hljs-attr">working_dir:</span> <span class="hljs-string">/app</span>                          <span class="hljs-comment"># Set working directory inside container</span>
    <span class="hljs-attr">command:</span> <span class="hljs-string">sh</span> <span class="hljs-string">-c</span> <span class="hljs-string">"npm run build &amp;&amp; npm start"</span> <span class="hljs-comment"># Build once container starts, then run app</span>
    <span class="hljs-attr">ports:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">"3000:3000"</span>                            <span class="hljs-comment"># Expose frontend on port 3000</span>
    <span class="hljs-attr">volumes:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">./front-end-nextjs:/app</span>               <span class="hljs-comment"># Mount local code for dev hot-reload</span>
    <span class="hljs-attr">environment:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">NODE_ENV=production</span>                   <span class="hljs-comment"># Env variable for production setup</span>
    <span class="hljs-attr">depends_on:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">backend</span>                               <span class="hljs-comment"># Ensure backend starts first</span>
    <span class="hljs-attr">networks:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">app_network</span>                           <span class="hljs-comment"># Join the shared network</span>

  <span class="hljs-attr">backend:</span>                                    <span class="hljs-comment"># This is backend service</span>
    <span class="hljs-attr">build:</span> <span class="hljs-string">./backend</span>                          <span class="hljs-comment"># Build backend service from its Dockerfile</span>
    <span class="hljs-attr">ports:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">"8000:8000"</span>                           <span class="hljs-comment"># Expose backend API on port 8000</span>
    <span class="hljs-attr">env_file:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">./backend/.env</span>                        <span class="hljs-comment"># Load sensitive config like DB URL, secrets</span>
    <span class="hljs-attr">volumes:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">./backend:/usr/src/app</span>                <span class="hljs-comment"># Mount backend code for live updates (dev)</span>
    <span class="hljs-attr">environment:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">FASTAPI_ENV=production</span>                <span class="hljs-comment"># Custom variable for backend environment</span>
    <span class="hljs-attr">networks:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">app_network</span>                           <span class="hljs-comment"># Same network to talk with frontend</span>

<span class="hljs-attr">networks:</span>
  <span class="hljs-attr">app_network:</span>
    <span class="hljs-attr">driver:</span> <span class="hljs-string">bridge</span>                            <span class="hljs-comment"># Default bridge network for isolated common</span>
</code></pre>
<p>To build and start the services in our above compose file:</p>
<pre><code class="lang-bash">docker compose up
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748501323848/4502b9b7-6f37-4a26-816d-c5645032590a.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-bash">CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                    NAMES
0a771b5eaf4c   devops-url2qr-frontend   <span class="hljs-string">"docker-entrypoint.s…"</span>   21 minutes ago   Up 21 minutes   0.0.0.0:3002-&gt;3000/tcp   devops-url2qr-frontend-1
d379bafbbd41   devops-url2qr-backend    <span class="hljs-string">"uvicorn main:app --…"</span>   23 minutes ago   Up 21 minutes   0.0.0.0:8000-&gt;8000/tcp   devops-url2qr-backend-1
</code></pre>
<p>And after successful build and run the service you can access them, for this application we are running you can find the:</p>
<p><strong>Fronetend Running on:</strong></p>
<p><a target="_blank" href="http://localhost:3000">http://localhost:3000</a></p>
<p><strong>Backend Running on:</strong></p>
<p><a target="_blank" href="http://localhost:3000">http://localhost:8000</a></p>
<h1 id="heading-dockerhub">DockerHub:</h1>
<p><strong>Docker Hub</strong> is a <strong>cloud-based repository</strong> where you can <strong>store, share, and manage Docker container images</strong>.</p>
<p><a target="_blank" href="https://hub.docker.com/">Official Website</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1748502549174/42fb1fb9-d729-4985-bcb4-3a4b73d12eb2.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-this-is-the-workflow-if-you-want-to-push-your-docker-image-to-dockerhub">This is the workflow if you want to push your docker image to DockerHub:</h3>
<pre><code class="lang-bash"><span class="hljs-comment"># Login to Docker Hub</span>
docker login

<span class="hljs-comment"># Tag your image</span>
docker tag myapp:latest username/myapp:1.0

<span class="hljs-comment"># Push it to Docker Hub</span>
docker push username/myapp:1.0

<span class="hljs-comment"># Pull it from Docker Hub (any machine)</span>
docker pull username/myapp:1.0
</code></pre>
<p>If you're working in production or need tighter access control, you might consider <strong>private registries</strong> like:</p>
<ul>
<li><p><strong>AWS Elastic Container Registry (ECR),</strong></p>
</li>
<li><p><strong>Azure Container Registry (ACR)</strong></p>
</li>
<li><p><strong>Google Container Registry (GCR)</strong></p>
</li>
<li><p><strong>GitHub Container Registry</strong></p>
</li>
<li><p><strong>GitLab Container Registry</strong></p>
</li>
<li><p><strong>Harbor</strong></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Automating The Deployment Spring Boot Deployment with AWS CodePipeline and Elastic Beanstalk]]></title><description><![CDATA[In this comprehensive guide, I’ll walk through setting up a complete CI/CD pipeline using AWS CodePipeline to deploy a Spring Boot application to Elastic Beanstalk. Here's what we'll cover:
Tools Used




ToolRole



CodeCommitGit repository for sour...]]></description><link>https://blog.surajdev.tech/automating-the-deployment-spring-boot-deployment-with-aws-codepipeline-and-elastic-beanstalk</link><guid isPermaLink="true">https://blog.surajdev.tech/automating-the-deployment-spring-boot-deployment-with-aws-codepipeline-and-elastic-beanstalk</guid><category><![CDATA[AWS]]></category><category><![CDATA[aws-codepipline]]></category><category><![CDATA[CodePipeline]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[Elastic Beanstalk]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Sat, 03 May 2025 18:30:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1746213061803/aff531d7-34f9-4775-b805-8ccd2337e5d8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this comprehensive guide, I’ll walk through setting up a complete CI/CD pipeline using AWS CodePipeline to deploy a Spring Boot application to Elastic Beanstalk. Here's what we'll cover:</p>
<h3 id="heading-tools-used">Tools Used</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Tool</td><td>Role</td></tr>
</thead>
<tbody>
<tr>
<td><strong>CodeCommit</strong></td><td>Git repository for source code</td></tr>
<tr>
<td><strong>CodeBuild</strong></td><td>Builds the Spring Boot app and outputs the <code>.jar</code></td></tr>
<tr>
<td><strong>CodePipeline</strong></td><td>Orchestrates source → build → deploy stages</td></tr>
<tr>
<td><strong>Elastic Beanstalk</strong></td><td>Deployment environment</td></tr>
</tbody>
</table>
</div><h2 id="heading-lets-understand-the-architecture-diagram">Let’s understand the architecture diagram</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210057789/d3df0b18-f310-4ad5-86a7-4d4582185b3e.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Source (GitHub Repository)</strong></p>
<ul>
<li><p>The pipeline starts when a <strong>code change is pushed</strong> (commit) to your GitHub repository.</p>
</li>
<li><p>This event <strong>triggers the pipeline</strong> automatically — no manual deployment needed.</p>
</li>
</ul>
</li>
<li><p><strong>Build Phase (CodePipeline + CodeBuild)</strong></p>
<ul>
<li><p><strong>AWS CodePipeline</strong> detects the commit and <strong>initiates the CI/CD process</strong>.</p>
</li>
<li><p>It hands over the code to <strong>AWS CodeBuild</strong>, which:</p>
<ul>
<li><p><strong>Builds the project</strong> (compiles the Spring Boot application).</p>
</li>
<li><p><strong>Runs tests</strong> (unit/integration).</p>
</li>
<li><p><strong>Returns the build status</strong> (success or failure) back to CodePipeline.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Deploy Phase (Elastic Beanstalk)</strong></p>
<ul>
<li><p>If the build is successful, CodePipeline proceeds to the <strong>Deploy</strong> stage.</p>
</li>
<li><p>It <strong>deploys the built Spring Boot application</strong> to <strong>AWS Elastic Beanstalk</strong>, a managed environment that handles infrastructure, load balancing, scaling, and app hosting.</p>
</li>
</ul>
</li>
</ol>
<h1 id="heading-step-by-step-follow-up">Step-by-Step Follow-up:</h1>
<h2 id="heading-step-1-repository-setup">Step 1: Repository Setup</h2>
<p>First, create a GitHub repository for your Spring Boot project. This will serve as our source code repository.</p>
<p>GitHub Repository: <a target="_blank" href="https://github.com/Suraj-kumar00/aws-springboot-ecommerce">https://github.com/Suraj-kumar00/aws-springboot-ecommerce</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210428999/9e19cfa0-8600-47fc-acc2-a12e0b714f50.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-step-2-elastic-beanstalk-configuration">Step 2: Elastic Beanstalk Configuration</h2>
<p>Create your Elastic Beanstalk environment with these configurations:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210502553/bc5ebd72-c6d4-474d-a3a6-9ab65e6ad0c3.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Give it the <strong>Application name</strong> And the <strong>Domain Name</strong> and also check the availability.</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210556695/f0adb98d-25ba-4138-b509-84f0f002a7fb.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Select Java 17 as the platform</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210573609/941ead8c-fc9a-4ce9-953d-1b55d119ff68.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Upload your initial .jar file and set version to 1</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210618029/6fa4afdf-4834-4f05-95be-37f613429fbe.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Configure service access settings:</p>
<ul>
<li><p>Set up service role</p>
</li>
<li><p>Configure EC2 key pair</p>
</li>
<li><p>Set up AWS Elastic Beanstalk profile</p>
</li>
</ul>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210737377/0bd2a7a0-b2f5-4677-9c1c-bdaaa865ca5f.png" alt class="image--center mx-auto" /></p>
<ul>
<li>In initial case there’s no EC2 instance profile so just click on the view permission details and create the role according to that in AWS IAM Role .</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210804843/b5ba02f1-b68e-4125-8297-a28be6468be0.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-step-3-database-configuration">Step 3: Database Configuration</h2>
<p>Choose the:</p>
<ul>
<li><p>VPC ( In my case I’m choosing default)</p>
</li>
<li><p>Choose Instance subnets</p>
</li>
<li><p>Choose Database subnets</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210878259/fdf642a3-2bca-4c47-820a-96227acd7026.png" alt class="image--center mx-auto" /></p>
<p>For the database setup:</p>
<ul>
<li><p>Enable the RDS database integration</p>
</li>
<li><p>Configure database username</p>
</li>
<li><p>Set secure database password</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746210902138/124ed956-9008-4f25-b7fb-512180c6edc4.png" alt class="image--center mx-auto" /></p>
<p>After that just click on next.</p>
<ul>
<li>Now in this step just choose the Security Group and we can edit it lated in the EC2 security group inbound rule for opening the custom ports:</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211073643/e35b15c7-9c10-4e3c-899b-360a948de513.png" alt class="image--center mx-auto" /></p>
<p>Other then that leave all the settings defalut and go to the next step.</p>
<ul>
<li>Now choose the system as Basic:</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211123767/7c179416-fb98-461c-8421-25220eef83b6.png" alt class="image--center mx-auto" /></p>
<ul>
<li>And leave all the setting as it is but change the <code>ENVIRONMENT VARIABLES</code> :</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211211038/09f149ba-f96a-4584-bb59-84752ca9e84b.png" alt class="image--center mx-auto" /></p>
<p>After that click on the next step.</p>
<p>At the last step just review all the configuration and <strong>submit</strong> it.</p>
<h2 id="heading-step-4-pipeline-setup">Step 4: Pipeline Setup</h2>
<p>Create your AWS CodePipeline:</p>
<ul>
<li>Navigate to AWS CodePipeline and create a new pipeline</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211342070/f7dcd00b-4795-4e8e-91de-032c87108ec9.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Now chose the Custom build pipeline</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211479040/0e4fa49a-f8c4-43da-91a5-546a6273326a.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Now give the pipeline a name and leave all the setting default and click on the next.</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211597079/c728461c-e0f2-4b1d-beb5-05a5a692a72c.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Now Select the provider which <strong>GitHub</strong> in my case using OAuth.</p>
<p>  After Authenticating chose the <code>Repository name and the branch</code> and click on next.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211625024/87c8bf51-1027-4325-a695-c31af7dafb74.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Now select the <code>Other build providers</code> and create a new project:</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211651756/a477877d-fb8e-4642-ae5c-5689a8479705.png" alt class="image--center mx-auto" /></p>
<p>Give the project name:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211697306/3544d53b-73d8-47b7-abdf-9bd66584043e.png" alt class="image--center mx-auto" /></p>
<p>After that chose the <code>buildspec.yml</code> options and click on the <strong>create code pipeline.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211810285/94e346ee-19d9-4741-a340-b9b07ab6da9f.png" alt class="image--center mx-auto" /></p>
<ul>
<li>After that choose it will redirect you to the same page and just click on the next step:</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211862356/81e26f85-744f-468d-a054-2ec85b7743f4.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Now the in the test stage choose the provder <strong>AWS CodeBuild and the project name and continute:</strong></li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211912816/92537d15-af8f-408b-a779-0dac9d362a3f.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Now in the deploy stage choose the provider as <code>AWS Elastic Beanstalk</code> ,</p>
<p>  Region, Application Name and the Environment Name.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211943547/3be47134-b8b1-4869-b620-a4cfbc115d6b.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-essential-configuration-files">Essential Configuration Files</h3>
<p>Add this <code>buildspec.yml</code> to your project root:</p>
<p>You should change the <code>.jar</code> because you name could be different.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-number">0.2</span>
<span class="hljs-attr">phases:</span>
  <span class="hljs-attr">install:</span>
    <span class="hljs-attr">runtime-versions:</span>
      <span class="hljs-attr">java:</span> <span class="hljs-string">corretto17</span>
  <span class="hljs-attr">pre_build:</span>
    <span class="hljs-attr">commands:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">echo</span> <span class="hljs-string">Build</span> <span class="hljs-string">started</span> <span class="hljs-string">on</span> <span class="hljs-string">`date`</span>
  <span class="hljs-attr">build:</span>
    <span class="hljs-attr">commands:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">mvn</span> <span class="hljs-string">clean</span> <span class="hljs-string">install</span>
<span class="hljs-attr">artifacts:</span>
  <span class="hljs-attr">files:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">target/Shopping_Cart-0.0.1-SNAPSHOT.jar</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">Procfile</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">.ebextensions/**/*</span>
  <span class="hljs-attr">discard-paths:</span> <span class="hljs-literal">no</span>
</code></pre>
<h2 id="heading-5-pipeline-execution-flow-diagram">5. Pipeline Execution Flow Diagram</h2>
<p>This is the execution result of the AWS Code Pipeline <code>Taking the source, Building it and Deploying the new verion of the application to AWS Elastic Beanstalk</code> .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746211991366/17050a28-cba3-4edf-84ec-891674f377d6.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-6-result">6. Result:</h2>
<p><strong>The Application was deploy on this URL:</strong> <a target="_blank" href="http://aws-springboot-ecommerce.ap-south-1.elasticbeanstalk.com/">http://aws-springboot-ecommerce.ap-south-1.elasticbeanstalk.com/</a> (This will not work now as I deleted the steup)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746212068466/7d7b760b-206c-4240-9470-e35f1b4094a1.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746212116114/558468d8-81f9-43c8-a154-758b662e6bd8.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746212083821/3abfbf67-a0e6-4721-85bd-a8b918e58093.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-7-common-challenges-and-solutions">7. Common Challenges and Solutions</h2>
<p><strong>Database Connection Issues:</strong></p>
<ul>
<li><p><code>Problem</code>: Build failures due to communication link issues</p>
</li>
<li><p><code>Solution</code>: Implement H2 in-memory database for testing</p>
</li>
</ul>
<p><strong>JAR File Naming:</strong></p>
<ul>
<li><p><code>Problem</code>: Deployment failures due to JAR file mismatches</p>
</li>
<li><p><code>Solution</code>: Maintain consistent artifactId naming across configurations</p>
</li>
</ul>
<h2 id="heading-best-practices">Best Practices</h2>
<p><strong>Key practices to follow:</strong></p>
<ul>
<li><p>Separate test and production configurations</p>
</li>
<li><p>Use environment variables for sensitive data</p>
</li>
<li><p>Implement proper proxy configuration</p>
</li>
<li><p>Add post-deployment hooks</p>
</li>
<li><p>Maintain consistent artifact naming</p>
</li>
<li><p>Implement proper error handling and logging</p>
</li>
</ul>
<h3 id="heading-thanks-for-reading-see-you-in-the-next-one">Thanks for reading - See you in the next one!</h3>
]]></content:encoded></item><item><title><![CDATA[Deploying SpringBoot Application on AWS EC2: A Comprehensive Guide]]></title><description><![CDATA[Introduction
This guide outlines the process of deploying a SpringBoot application on AWS EC2 with GitHub Actions for automated deployment. The setup includes Docker containers and proper security configurations.
Prerequisites

AWS Account

GitHub Re...]]></description><link>https://blog.surajdev.tech/deploying-springboot-application-on-aws-ec2-a-comprehensive-guide</link><guid isPermaLink="true">https://blog.surajdev.tech/deploying-springboot-application-on-aws-ec2-a-comprehensive-guide</guid><category><![CDATA[ec2]]></category><category><![CDATA[EC2 instance]]></category><category><![CDATA[AWS]]></category><category><![CDATA[Devops]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[github-actions]]></category><category><![CDATA[Devops articles]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Fri, 02 May 2025 18:03:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1746208572384/6a1eab76-7781-4a3b-9dfa-d2df2e69085f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>This guide outlines the process of deploying a SpringBoot application on AWS EC2 with GitHub Actions for automated deployment. The setup includes Docker containers and proper security configurations.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li><p>AWS Account</p>
</li>
<li><p>GitHub Repository</p>
</li>
<li><p>Basic knowledge of Docker and AWS services</p>
</li>
<li><p>SpringBoot application ready for deployment</p>
</li>
</ul>
<p>NOTE: While working on this project I have made the repository private, so remember</p>
<ul>
<li><p>If your <strong>repo is private</strong>, then you <strong>must configure SSH or PAT</strong> on EC2 to interact with it.</p>
</li>
<li><p>If your <strong>repo is public</strong>, <strong>no key setup is needed</strong> to clone it.</p>
</li>
</ul>
<p>But for your reference if you want the application I’m making it public</p>
<p>Here is the Repository</p>
<p><a target="_blank" href="https://github.com/Suraj-kumar00/scm-springboot-application-devops">https://github.com/Suraj-kumar00/scm-springboot-application-devops</a></p>
<h2 id="heading-first-lets-understand-the-architecture-diagram">First let’s understand the architecture Diagram</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746206255347/e9aac1e0-947f-4d5c-8266-acc2661a5a7e.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-architecture-overview"><strong>Architecture Overview</strong></h3>
<ol>
<li><p><strong>User</strong> accesses the app via a web browser using the <strong>HTTP.</strong></p>
</li>
<li><p>The request hits <strong>Nginx</strong> running on the <strong>EC2 instance</strong>, which listens on port 80.</p>
</li>
<li><p><strong>Nginx</strong> acts as a <strong>reverse proxy</strong> and forwards the request to the <strong>Spring Boot application</strong> running inside a Docker container on port 8081.</p>
</li>
<li><p>The <strong>Spring Boot app</strong> processes the request and, if needed, communicates with the <strong>MySQL database</strong> (also running in a Docker container on the same EC2 instance).</p>
</li>
<li><p>The response is sent back through the same path:<br /> <code>MySQL → Spring Boot → Nginx → User's browser.</code></p>
</li>
<li><p><strong>GitHub Actions</strong> is used to automatically deploy updates to the EC2 instance by SSHing in and running the necessary Docker commands (e.g., <code>docker-compose up</code>).</p>
</li>
</ol>
<h2 id="heading-step-1-launch-ec2-instance">Step 1: Launch EC2 Instance</h2>
<p>Begin by setting up your EC2 instance with these specifications:</p>
<ul>
<li><p>Choose Ubuntu as the operating system</p>
</li>
<li><p>Select t2.medium instance type</p>
</li>
<li><p>Create and download a new key pair for SSH access</p>
</li>
<li><p>Configure security group with the following ports:</p>
</li>
<li><p><code>TCP 22 (SSH)</code></p>
</li>
<li><p><code>TCP 80 (HTTP for Nginx)</code></p>
</li>
<li><p><code>TCP 443 (HTTPS)</code></p>
</li>
<li><p><code>TCP 8081 (Spring Boot via Docker)</code></p>
</li>
<li><p><code>TCP 3000 (phpMyAdmin)</code></p>
</li>
<li><p>Set EBS volume size (20GB recommended for free tier)</p>
</li>
</ul>
<h2 id="heading-step-2-configure-elastic-ip">Step 2: Configure Elastic IP</h2>
<ol>
<li><p>Navigate to Elastic IP section in AWS Console</p>
</li>
<li><p>Allocate new Elastic IP address</p>
</li>
<li><p>Associate it with your EC2 instance</p>
</li>
<li><p>Note down the Elastic IP for future use</p>
</li>
</ol>
<h2 id="heading-step-3-ssh-into-ec2-instance">Step 3: SSH Into EC2 Instance</h2>
<pre><code class="lang-bash">ssh -i <span class="hljs-string">"your-key.pem"</span> ubuntu@your-elastic-ip
</code></pre>
<h2 id="heading-step-4-install-docker-and-docker-compose">Step 4: Install Docker and Docker Compose</h2>
<p>Create and execute this installation script:</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Install Docker</span>
sudo apt update
sudo apt install docker.io -y
sudo systemctl <span class="hljs-built_in">enable</span> docker
sudo usermod -aG docker <span class="hljs-variable">$USER</span>

<span class="hljs-comment"># Install Docker Compose</span>
sudo curl -L <span class="hljs-string">"&lt;https://github.com/docker/compose/releases/latest/download/docker-compose-$&gt;(uname -s)-<span class="hljs-subst">$(uname -m)</span>"</span> \\
  -o /usr/<span class="hljs-built_in">local</span>/bin/docker-compose
sudo chmod +x /usr/<span class="hljs-built_in">local</span>/bin/docker-compose
</code></pre>
<h2 id="heading-step-5-set-up-ssh-for-github">Step 5: Set Up SSH for GitHub</h2>
<ol>
<li>Generate SSH key on EC2:</li>
</ol>
<pre><code class="lang-bash">ssh-keygen -t rsa -b 4096 -C <span class="hljs-string">"ec2-rsa-key"</span>
</code></pre>
<ol>
<li>Add the public key to GitHub:</li>
</ol>
<ul>
<li><p>Copy the content of ~/.ssh/id_<a target="_blank" href="http://rsa.pub">rsa.pub</a></p>
</li>
<li><p>Add it to GitHub under Settings &gt; SSH and GPG Keys</p>
</li>
</ul>
<h2 id="heading-step-6-clone-and-deploy-application">Step 6: Clone and Deploy Application</h2>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> git@github.com:your-username/your-repo.git
<span class="hljs-built_in">cd</span> your-repo
docker-compose up --build -d
</code></pre>
<h2 id="heading-step-7-configure-nginx-as-reverse-proxy">Step 7: Configure Nginx as Reverse Proxy</h2>
<p>Install and configure Nginx:</p>
<pre><code class="lang-bash">sudo apt install nginx -y
sudo nano /etc/nginx/sites-available/default
</code></pre>
<p>Add this configuration:</p>
<pre><code class="lang-yaml"><span class="hljs-string">server</span> {
    <span class="hljs-string">listen</span> <span class="hljs-number">80</span><span class="hljs-string">;</span>
    <span class="hljs-string">server_name</span> <span class="hljs-string">your-elastic-ip;</span>

    <span class="hljs-string">location</span> <span class="hljs-string">/</span> {
        <span class="hljs-string">proxy_pass</span> <span class="hljs-string">&lt;http://localhost:8081&gt;;</span>
        <span class="hljs-string">proxy_set_header</span> <span class="hljs-string">Host</span> <span class="hljs-string">$host;</span>
        <span class="hljs-string">proxy_set_header</span> <span class="hljs-string">X-Real-IP</span> <span class="hljs-string">$remote_addr;</span>
    }
}
</code></pre>
<p>Restart Nginx:</p>
<pre><code class="lang-bash">sudo systemctl restart nginx
</code></pre>
<h2 id="heading-step-8-set-up-github-actions">Step 8: Set Up GitHub Actions</h2>
<p>Create .github/workflows/deploy.yml in your repository:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">name:</span> <span class="hljs-string">Deploy</span> <span class="hljs-string">to</span> <span class="hljs-string">EC2</span>

<span class="hljs-attr">on:</span>
  <span class="hljs-attr">push:</span>
    <span class="hljs-attr">branches:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">main</span>
  <span class="hljs-attr">workflow_dispatch:</span>

<span class="hljs-attr">jobs:</span>
  <span class="hljs-attr">deploy:</span>
    <span class="hljs-attr">runs-on:</span> <span class="hljs-string">ubuntu-latest</span>
    <span class="hljs-attr">steps:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Setup</span> <span class="hljs-string">SSH</span> <span class="hljs-string">Key</span>
        <span class="hljs-attr">run:</span> <span class="hljs-string">|
          echo "${{ secrets.EC2_SSH_PRIVATE_KEY }}" &gt; key.pem
          chmod 600 key.pem
</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Deploy</span> <span class="hljs-string">via</span> <span class="hljs-string">SSH</span>
        <span class="hljs-attr">run:</span> <span class="hljs-string">|
          ssh -o StrictHostKeyChecking=no -i key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} &lt;&lt; 'EOF'
            cd /home/ubuntu/your-repo
            git pull origin main
            docker-compose down
            docker-compose build --no-cache
            docker-compose up -d
          EOF</span>
</code></pre>
<h2 id="heading-step-9-configure-auto-restart-on-reboot">Step 9: Configure Auto-restart on Reboot</h2>
<p>Set up a cron job:</p>
<pre><code class="lang-bash">crontab -e
<span class="hljs-comment"># Add this line:</span>
@reboot <span class="hljs-built_in">cd</span> /home/ubuntu/your-repo &amp;&amp; docker-compose up --build -d
</code></pre>
<h3 id="heading-result">Result!!</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1746208822375/f64033b3-c27b-4da1-ae7e-25d865ee4d2e.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-common-challenges-and-solutions">Common Challenges and Solutions</h2>
<ul>
<li><p>Permission Issues</p>
<ul>
<li><p>Docker permission denied: Run <code>sudo usermod -aG docker $USER</code></p>
</li>
<li><p>SSH key issues: Verify proper key permissions (<code>chmod 600</code>)</p>
</li>
</ul>
</li>
<li><p>Networking Issues</p>
<ul>
<li><p><code>502 Bad Gateway</code>: Check if Spring Boot container is running</p>
</li>
<li><p>Connection refused: Verify security group settings</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-best-practices">Best Practices</h2>
<ul>
<li><p>Always use environment variables for sensitive data</p>
</li>
<li><p>Regularly backup your application data</p>
</li>
<li><p>Monitor application logs and performance</p>
</li>
<li><p>Keep Docker images updated with security patches</p>
</li>
<li><p>Use proper version tagging for Docker images</p>
</li>
</ul>
<h2 id="heading-thanks-for-reading-see-you-in-the-next-one">Thanks for reading - see you in the next one!</h2>
]]></content:encoded></item><item><title><![CDATA[The Complete YAML Course for DevOps]]></title><description><![CDATA[What is YAML?
YAML is a human-friendly data serialization language that's used across all programming languages.

It’s not a programming language, it’s a data format.

It’s similar to JSON and XML.

You can only store data, not run commands.


YAML F...]]></description><link>https://blog.surajdev.tech/the-complete-yaml-course-for-devops</link><guid isPermaLink="true">https://blog.surajdev.tech/the-complete-yaml-course-for-devops</guid><category><![CDATA[YAML]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[Devops]]></category><category><![CDATA[YAML, JSON,DEVOPS]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Tue, 22 Apr 2025 06:32:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721474244365/42cfae62-e4fb-40ee-aec8-23066053fc65.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-yaml">What is YAML?</h2>
<p>YAML is a <strong>human-friendly data serialization language</strong> that's used across all programming languages.</p>
<ul>
<li><p>It’s <strong>not a programming language</strong>, it’s a <strong>data format</strong>.</p>
</li>
<li><p>It’s similar to <strong>JSON</strong> and <strong>XML</strong>.</p>
</li>
<li><p>You can only <strong>store data</strong>, not run commands.</p>
</li>
</ul>
<h3 id="heading-yaml-full-form"><strong>YAML FULL FORM:</strong></h3>
<ul>
<li><p>Previously: <strong>"Yet Another Markup Language"</strong></p>
</li>
<li><p>Now: <strong>"YAML Ain't Markup Language"</strong></p>
</li>
</ul>
<h3 id="heading-but-why-this-change">But Why This Change?</h3>
<p>Markup languages like HTML are designed to store documents. But YAML? It can do more than just that — it can store <strong>structured data</strong>, like objects. That’s why it’s called “YAML Ain’t Markup Language” now — to clarify that it’s <strong>not limited to markup</strong>.</p>
<h2 id="heading-data-serialization"><strong>Data Serialization:</strong></h2>
<ul>
<li><p><strong>Serialization</strong> is the process of converting a data object—a combination of code and data represented within a region of data storage—into a series of bytes that saves the state of the object in an easily transmittable form. In this serialized form, the data can be delivered to another data store (such as an <a target="_blank" href="https://hazelcast.com/products/in-memory-computing-platform/"><strong>in-memory computing platform</strong></a>), application, or some other destination.</p>
</li>
<li><p><strong>In simple words, <mark>data serialization is the process of converting an object into a stream of bytes to save or transmit it more easily.</mark></strong></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707145533597/052cc338-16a4-48a2-8b91-40b714b5d95a.webp" alt="Data serialization is the process of converting an object into a stream of bytes to more easily save or transmit it." /></p>
<ul>
<li>The reverse of this process is called <strong>De-Serialization</strong></li>
</ul>
<h2 id="heading-data-serialization-languages">Data Serialization languages:</h2>
<ul>
<li><p>YAML</p>
</li>
<li><p>JSON</p>
</li>
<li><p>XML</p>
</li>
</ul>
<h2 id="heading-where-yaml-is-used">Where YAML Is Used?</h2>
<ul>
<li><p>Kubernetes config files (<code>*.yaml</code>)</p>
</li>
<li><p>Docker Compose</p>
</li>
<li><p>GitHub Actions workflows</p>
</li>
<li><p>CI/CD pipelines</p>
</li>
<li><p>Logs, caching systems, etc.</p>
</li>
</ul>
<h2 id="heading-benefits-of-yaml">Benefits of YAML:</h2>
<ul>
<li><p>Simple &amp; easy to read</p>
</li>
<li><p>Clean syntax (but indentation matters!)</p>
</li>
<li><p>Converts easily to JSON, XML</p>
</li>
<li><p>Language-agnostic (used in most stacks)</p>
</li>
<li><p>Can represent complex data structures</p>
</li>
<li><p>Parsing YAML is easy using various tools/parsers</p>
</li>
</ul>
<h2 id="heading-creating-a-yaml-file">Creating a YAML File</h2>
<p>YAML uses <strong>key-value pairs</strong> and <strong>lists</strong>. Think of it like <strong>dictionaries in Python</strong> or <strong>HashMaps in Java</strong>.</p>
<p>Also:</p>
<ul>
<li><p>YAML is <strong>case-sensitive</strong></p>
</li>
<li><p><strong>Indentation is mandatory</strong></p>
</li>
</ul>
<h3 id="heading-strings-and-multiline-texts">Strings and Multiline Texts</h3>
<pre><code class="lang-yaml"><span class="hljs-attr">myself:</span> <span class="hljs-string">Suraj</span> <span class="hljs-string">kumar</span>
<span class="hljs-attr">fruit:</span> <span class="hljs-string">"Apple"</span>
<span class="hljs-attr">job:</span> <span class="hljs-string">'DevOps'</span>

<span class="hljs-attr">bio:</span> <span class="hljs-string">|
  Hey there my name is Suraj and currently learning YAML
  I am a very enthusiastic about learning new things.
</span>
<span class="hljs-attr">message:</span> <span class="hljs-string">&gt;
  this will
  all be 
  in one single line
</span>
<span class="hljs-comment"># Same as:</span>
<span class="hljs-attr">message:</span> <span class="hljs-type">!!str</span> <span class="hljs-string">this</span> <span class="hljs-string">will</span> <span class="hljs-string">all</span> <span class="hljs-string">be</span> <span class="hljs-string">in</span> <span class="hljs-string">one</span> <span class="hljs-string">single</span> <span class="hljs-string">line</span>
</code></pre>
<p><code>|</code> → preserves newlines<br /><code>&gt;</code> → converts into a single line (removes newlines)</p>
<h2 id="heading-numbers-and-booleans">Numbers and Booleans</h2>
<p>In YAML, you can represent all types of numbers — integers, floats, binary, hex, exponential — and even booleans with chill syntax.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">number:</span> <span class="hljs-number">6549864</span>          <span class="hljs-comment"># Integer</span>
<span class="hljs-attr">marks:</span> <span class="hljs-number">45.12</span>             <span class="hljs-comment"># Float</span>

<span class="hljs-attr">booleanValue:</span> <span class="hljs-type">!!bool</span> <span class="hljs-literal">No</span>  <span class="hljs-comment"># Boolean → false</span>
<span class="hljs-comment"># Valid false: no, n, false, False</span>
<span class="hljs-comment"># Valid true: yes, y, true, True</span>

<span class="hljs-attr">zero:</span> <span class="hljs-type">!!int</span> <span class="hljs-number">0</span>
<span class="hljs-attr">positiveNum:</span> <span class="hljs-type">!!int</span> <span class="hljs-number">55</span>
<span class="hljs-attr">negativeNum:</span> <span class="hljs-type">!!int</span> <span class="hljs-number">-55</span>
<span class="hljs-attr">binaryNum:</span> <span class="hljs-type">!!int</span> <span class="hljs-string">0b11001</span>     <span class="hljs-comment"># Binary</span>
<span class="hljs-attr">octalNum:</span> <span class="hljs-type">!!int</span> <span class="hljs-number">0123</span>         <span class="hljs-comment"># Octal</span>
<span class="hljs-attr">hexa:</span> <span class="hljs-type">!!int</span> <span class="hljs-number">0x45</span>             <span class="hljs-comment"># Hexadecimal</span>
<span class="hljs-attr">commaValue:</span> <span class="hljs-type">!!int</span> <span class="hljs-string">+540_000</span>  <span class="hljs-comment"># 540000 (underscores allowed)</span>

<span class="hljs-attr">exponential_numbers:</span> <span class="hljs-number">5.125E56</span> <span class="hljs-comment"># Exponential float</span>

<span class="hljs-attr">marks:</span> <span class="hljs-type">!!float</span> <span class="hljs-number">57.98</span>
<span class="hljs-attr">infinite:</span> <span class="hljs-type">!!float</span> <span class="hljs-string">.inf</span>        <span class="hljs-comment"># Infinity</span>
<span class="hljs-attr">not_a_num:</span> <span class="hljs-string">.nan</span>               <span class="hljs-comment"># Not a number</span>
</code></pre>
<p>🧠 YAML even understands underscores in large numbers and scientific notation!</p>
<h2 id="heading-null-values">Null Values</h2>
<p>YAML supports nulls (empty/missing values) using <code>null</code>, <code>Null</code>, <code>~</code>, or just leaving it blank.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">surname:</span> <span class="hljs-type">!!null</span> <span class="hljs-literal">Null</span>  <span class="hljs-comment"># null key with null value</span>
<span class="hljs-string">~:</span> <span class="hljs-string">This</span> <span class="hljs-string">is</span> <span class="hljs-string">a</span> <span class="hljs-literal">null</span> <span class="hljs-string">key</span>  <span class="hljs-comment"># Null key with a value</span>
</code></pre>
<p>🔥 You can use nulls to mark something intentionally empty.</p>
<h2 id="heading-dates-and-time">Dates and Time</h2>
<p>Dates and timestamps are built-in. You can write simple dates or full timestamps (with or without timezone).</p>
<pre><code class="lang-yaml"><span class="hljs-attr">date:</span> <span class="hljs-type">!!timestamp</span> <span class="hljs-number">2024-2</span><span class="hljs-number">-4</span>
<span class="hljs-attr">India time:</span> <span class="hljs-number">2024-2</span><span class="hljs-string">-4T02:59:43.10</span> <span class="hljs-string">+5:30</span>
<span class="hljs-attr">no_time_zone:</span> <span class="hljs-number">2024-2</span><span class="hljs-string">-4T02:59:43.10</span>
</code></pre>
<p>✅ YAML can auto-parse this as date/time objects in most languages.</p>
<h2 id="heading-sequence-datatype-lists">Sequence Datatype (Lists)</h2>
<p>Lists in YAML are written with dashes <code>-</code> or inline with square brackets <code>[]</code>.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">student:</span> <span class="hljs-type">!!seq</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">marks</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">name</span> 
 <span class="hljs-bullet">-</span> <span class="hljs-string">roll_no</span>

<span class="hljs-comment"># Same as:</span>
<span class="hljs-attr">student:</span> [<span class="hljs-string">marks</span>, <span class="hljs-string">name</span>, <span class="hljs-string">roll_no</span>]

<span class="hljs-comment"># Sparse list → Some values can be left empty</span>
<span class="hljs-attr">sparse_seq:</span> 
 <span class="hljs-bullet">-</span> <span class="hljs-string">hey</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">how</span> 
 <span class="hljs-bullet">-</span> 
 <span class="hljs-bullet">-</span> <span class="hljs-literal">Null</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">sup</span>
</code></pre>
<p>🚀 Great for defining arrays or ordered values.</p>
<h2 id="heading-nested-sequences">Nested Sequences</h2>
<p>YAML also supports nested lists (lists inside lists):</p>
<pre><code class="lang-yaml"><span class="hljs-bullet">-</span> 
 <span class="hljs-bullet">-</span> <span class="hljs-string">mango</span> 
 <span class="hljs-bullet">-</span> <span class="hljs-string">apple</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">banana</span>
<span class="hljs-bullet">-</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">marks</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">roll_no</span>
 <span class="hljs-bullet">-</span> <span class="hljs-string">date</span>
</code></pre>
<p>It’s like having arrays inside arrays 📦</p>
<h2 id="heading-mapping-keyvalue-or-dictionary">Mapping (Key:Value) or Dictionary</h2>
<p>Basic dictionary in YAML is just <code>key: value</code>. You can also nest them or use inline format.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">name:</span> <span class="hljs-string">Suraj</span> <span class="hljs-string">kumar</span>
<span class="hljs-attr">role:</span> 
   <span class="hljs-attr">age:</span> <span class="hljs-number">21</span>
   <span class="hljs-attr">job:</span> <span class="hljs-string">student</span>

<span class="hljs-comment"># Inline version:</span>
<span class="hljs-attr">role:</span> {<span class="hljs-attr">age:</span> <span class="hljs-number">21</span>, <span class="hljs-attr">job:</span> <span class="hljs-string">student</span>}
</code></pre>
<p>💡 Use this for configs, JSON-style data, etc.</p>
<h2 id="heading-pairs-duplicate-keys-allowed">!!pairs (Duplicate keys allowed)</h2>
<p>When you wanna allow <strong>duplicate keys</strong>, use <code>!!pairs</code>.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">pair_example:</span> <span class="hljs-type">!!pairs</span>
 <span class="hljs-bullet">-</span> <span class="hljs-attr">job:</span> <span class="hljs-string">student</span>
 <span class="hljs-bullet">-</span> <span class="hljs-attr">job:</span> <span class="hljs-string">teacher</span>

<span class="hljs-comment"># Same as:</span>
<span class="hljs-attr">pair_example:</span> <span class="hljs-type">!!pairs</span> [<span class="hljs-attr">job:</span> <span class="hljs-string">student</span>, <span class="hljs-attr">job:</span> <span class="hljs-string">teacher</span>]
</code></pre>
<p>🧩 This is useful for APIs that accept repeated fields.</p>
<h2 id="heading-set-unique-values-only">!!set (Unique values only)</h2>
<p>If you want a <strong>set of unique keys</strong>, use <code>!!set</code>:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">names:</span> <span class="hljs-type">!!set</span>
 <span class="hljs-string">?</span> <span class="hljs-string">suraj</span>
 <span class="hljs-string">?</span> <span class="hljs-string">mohit</span>
 <span class="hljs-string">?</span> <span class="hljs-string">mahesh</span>
</code></pre>
<p>Each key in a set is unique and holds a null/empty value by default.</p>
<h2 id="heading-omap-ordered-dictionary">!!omap (Ordered dictionary)</h2>
<p>When the <strong>order of key-value pairs matters</strong>, go for <code>!!omap</code>:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">people:</span> <span class="hljs-type">!!omap</span>
 <span class="hljs-bullet">-</span> <span class="hljs-attr">Suraj:</span>
     <span class="hljs-attr">name:</span> <span class="hljs-string">Suraj</span> <span class="hljs-string">kumar</span>
     <span class="hljs-attr">age:</span> <span class="hljs-number">21</span>
     <span class="hljs-attr">height:</span> <span class="hljs-number">678</span>
 <span class="hljs-bullet">-</span> <span class="hljs-attr">Mohit:</span>
     <span class="hljs-attr">name:</span> <span class="hljs-string">Mohit</span> <span class="hljs-string">joping</span>
     <span class="hljs-attr">age:</span> <span class="hljs-number">22</span>
     <span class="hljs-attr">height:</span> <span class="hljs-number">768</span>
</code></pre>
<p>🎯 Super helpful when ordering is important (like user rankings, configs, etc.)</p>
<h2 id="heading-reusing-properties-with-anchors-amp-and">Reusing Properties with Anchors (&amp; and *)</h2>
<p>You can <strong>reuse data</strong> using anchors (<code>&amp;</code>) and aliases (<code>*</code>):</p>
<pre><code class="lang-yaml"><span class="hljs-attr">liking:</span> <span class="hljs-meta">&amp;likes</span>
  <span class="hljs-attr">fav_fruit:</span> <span class="hljs-string">apple</span>
  <span class="hljs-attr">dislikes:</span> <span class="hljs-string">grapes</span>

<span class="hljs-attr">person1:</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">Suraj</span> <span class="hljs-string">kumar</span>
  <span class="hljs-string">&lt;&lt;:</span> <span class="hljs-meta">*likes</span>

<span class="hljs-attr">person2:</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">Mohit</span> <span class="hljs-string">joping</span>
  <span class="hljs-string">&lt;&lt;:</span> <span class="hljs-meta">*likes</span>
  <span class="hljs-attr">dislikes:</span> <span class="hljs-string">berries</span>
</code></pre>
<p>So basically:</p>
<ul>
<li><p><code>&amp;likes</code> defines a reusable block.</p>
</li>
<li><p><code>*likes</code> pulls that block wherever you want.</p>
</li>
<li><p><code>&lt;&lt;: *likes</code> merges it into another object.</p>
</li>
</ul>
<p>🙌 This avoids repetition in large configs.</p>
<h2 id="heading-storing-data-in-xml-extensible-markup-language">Storing Data in XML (Extensible Markup Language)</h2>
<p>XML is a markup language used to <strong>store and transport data</strong>. It looks like HTML but is designed for <strong>data, not UI</strong>.</p>
<pre><code class="lang-xml"><span class="hljs-meta">&lt;?XML version="1.0" encoding="UTF-8"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">College</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"GITM"</span> <span class="hljs-attr">principal</span>=<span class="hljs-string">"Someone"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Students</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">Student</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">rollno</span>&gt;</span>9<span class="hljs-tag">&lt;/<span class="hljs-name">rollno</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>"Suraj"<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">marks</span>&gt;</span>80<span class="hljs-tag">&lt;/<span class="hljs-name">marks</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">Student</span>&gt;</span>       
    <span class="hljs-tag">&lt;/<span class="hljs-name">Students</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">College</span>&gt;</span>
</code></pre>
<p><strong>Explanation:</strong></p>
<ul>
<li><p><code>&lt;?XML ... ?&gt;</code> → This is the declaration. It tells the parser this is an XML doc.</p>
</li>
<li><p><code>&lt;College&gt;</code> is the root element. It has attributes like <code>name</code> and <code>principal</code>.</p>
</li>
<li><p>Inside, we nest <code>&lt;Students&gt;</code>, and inside that, a <code>&lt;Student&gt;</code> with info.</p>
</li>
<li><p>XML is strict with opening/closing tags and proper nesting.</p>
</li>
</ul>
<p>✅ Used in many legacy systems, APIs, config files, and document storage.</p>
<h2 id="heading-storing-data-in-json-javascript-object-notation">Storing Data in JSON (JavaScript Object Notation)</h2>
<p>JSON is the <strong>go-to format for modern APIs and apps</strong> — lightweight, easy to read/write, and works across all programming languages.</p>
<pre><code class="lang-json">{  
   <span class="hljs-attr">"College"</span>: [ 
       {
          <span class="hljs-attr">"name"</span>: <span class="hljs-string">"GITM"</span>,
          <span class="hljs-attr">"principle"</span>: <span class="hljs-string">"Someone"</span>,
          <span class="hljs-attr">"Students"</span>: [
                 {
                    <span class="hljs-attr">"rollno"</span>: <span class="hljs-number">2</span>,
                    <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Suraj kuamr"</span>,
                    <span class="hljs-attr">"marks"</span>: <span class="hljs-number">78</span>
                  }
            ]
        }
     ]
}
</code></pre>
<p><strong>Explanation:</strong></p>
<ul>
<li><p>JSON uses <code>{}</code> for objects (like dictionaries) and <code>[]</code> for arrays (lists).</p>
</li>
<li><p>Everything is in <code>key: value</code> pairs.</p>
</li>
<li><p>Strings must be in <strong>double quotes</strong> (<code>" "</code>).</p>
</li>
<li><p>Commas are required between fields (unlike YAML).</p>
</li>
</ul>
<p>🔥 JSON is everywhere — web apps, APIs, config files, databases, you name it.</p>
<h2 id="heading-yaml-devops-tools">YAML DevOps tools</h2>
<p><strong>Blog:</strong><a target="_blank" href="https://itnext.io/how-to-validate-kubernetes-yaml-files-9a17b9a30f08"><strong>How to validate Kubernetes YAML files</strong></a></p>
<p>Here are some tools used to <strong>validate and manage YAML configs</strong> in the DevOps world:</p>
<h3 id="heading-1-datreehttpswwwdatreeio">1. <a target="_blank" href="https://www.datree.io/">Datree</a></h3>
<p>Used to <strong>validate Kubernetes YAML</strong> files and catch misconfigurations.</p>
<h3 id="heading-2-monoklehttpsmonokleio-desktohttpswwwdatreeiophttpsmonokleio-idhttpsmonokleioehttpswwwdatreeio">2. <a target="_blank" href="https://monokle.io/">Monokle</a> <a target="_blank" href="https://www.datree.io/">Deskto</a><a target="_blank" href="https://monokle.io/">p</a> <a target="_blank" href="https://monokle.io/">ID</a><a target="_blank" href="https://www.datree.io/">E</a></h3>
<p>A dedicated IDE for managing Kubernetes YAMLs with preview and validation.</p>
<h3 id="heading-3-lens-idehttpsk8slensdev">3. <a target="_blank" href="https://k8slens.dev/">Lens IDE</a></h3>
<p>Kubernetes IDE to manage clusters and YAML configs visually.</p>
<blockquote>
<p>This YAML learning I documented from kunal kushwaha's DevOps course. This is easy isn't it. So this is for today I'll be come with the next blog of DevOps practices soon.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[You Need to Learn Docker Right Now! (Part 1)]]></title><description><![CDATA[Let’s Understand the Problem

Let's say a developer is working on a project and has set up all the required dependencies and configurations. Everything works fine. However, when a team collaborates on the same project across different operating syste...]]></description><link>https://blog.surajdev.tech/you-need-to-learn-docker-right-now-part-1</link><guid isPermaLink="true">https://blog.surajdev.tech/you-need-to-learn-docker-right-now-part-1</guid><category><![CDATA[Docker]]></category><category><![CDATA[containers]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[containerization]]></category><category><![CDATA[docker images]]></category><category><![CDATA[Dockerfile]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Mon, 24 Mar 2025 11:54:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1742816527898/40144e4c-25a1-4eec-b5e0-e0e135d41f66.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-lets-understand-the-problem">Let’s Understand the Problem</h1>
<p><img src="https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExN3hwdXloY2p6ejV1cGx5aGFvc25iajVtMDRnODdrczc0MGRlcTg4NiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/2XflxzkboOpH5iG9LH2/giphy.gif" alt class="image--center mx-auto" /></p>
<p>Let's say a developer is working on a project and has set up all the required dependencies and configurations. Everything works fine. However, when a team collaborates on the same project across different operating systems, they may have different dependencies and setups, making it a hassle to configure the environment repeatedly.</p>
<p>For example, if a tool is built for Windows, it won’t run on macOS or Linux, making setup even more difficult. Managing multiple environments and ensuring consistency becomes a challenge.</p>
<p>Docker solves this problem by creating a standardized, portable environment that works the same across all systems, eliminating compatibility issues and simplifying setup.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742579619351/c62e692c-10b7-4921-a569-20d2f2be5b35.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-before-docker"><strong>Before Docker:</strong></h2>
<ul>
<li><p>Each application required a <strong>dedicated server</strong>.</p>
</li>
<li><p>Running multiple applications on the same server was difficult due to conflicts between <strong>dependencies and configurations</strong>.</p>
</li>
<li><p>Companies had to invest in more <strong>servers</strong> and <strong>powerful CPUs</strong>, leading to <strong>high costs</strong> and <strong>inefficient resource utilization</strong>.</p>
</li>
<li><p>This approach was not <strong>scalable</strong>, <strong>cost-effective</strong>, or <strong>environmentally friendly</strong>.</p>
</li>
</ul>
<h2 id="heading-who-solved-this-problem"><strong>Who Solved This Problem?</strong></h2>
<ul>
<li><p><strong>Virtual Machines (VMs)</strong> provided a solution by allowing multiple applications to run on the same physical server.</p>
</li>
<li><p>This was an improvement but still had limitations.</p>
</li>
</ul>
<h2 id="heading-problems-with-virtual-machines"><strong>Problems with Virtual Machines:</strong></h2>
<ul>
<li><p>Each VM required its own full operating system, consuming significant resources.</p>
</li>
<li><p>Managing dependencies across different environments was still complex.</p>
</li>
<li><p>“Works on my machine” issues persisted, making development and deployment inconsistent.</p>
</li>
</ul>
<h2 id="heading-then-containers-came-into-the-picture"><strong>Then Containers Came into the Picture</strong></h2>
<ul>
<li><p>Containers allow applications to run <strong>without needing multiple OS installations</strong>.</p>
</li>
<li><p>Docker <strong>simplified</strong> containerization, making it easier to build, share, and deploy applications.</p>
</li>
<li><p>Containers are <strong>lightweight, fast, and portable</strong> across environments.</p>
</li>
<li><p><strong>Better resource utilization</strong>, run more apps on the same hardware.</p>
</li>
<li><p><strong>Quick to build, destroy, and deploy</strong>, ideal for cloud scaling.</p>
</li>
<li><p><strong>Standardized workflow</strong> from development to production.</p>
</li>
</ul>
<h2 id="heading-difference-between-virtual-machine-amp-containers">Difference between Virtual Machine &amp; Containers</h2>
<h3 id="heading-1-virtual-machines-vms"><strong>1. Virtual Machines (VMs)</strong></h3>
<ul>
<li><p>Each VM runs on a <strong>Hypervisor</strong>, which allows multiple VMs to share the same physical infrastructure.</p>
</li>
<li><p>Every VM has its own <strong>Guest OS</strong>, making it <strong>heavyweight</strong> since each OS requires its own resources (RAM, CPU, Storage).</p>
</li>
<li><p>Applications inside VMs come with their own dependencies (Bins/Libs), which can lead to duplication of resources.</p>
</li>
<li><p><strong>Overhead:</strong> Since each VM has a separate OS, it consumes more CPU and memory, making it less efficient for running multiple applications.</p>
</li>
</ul>
<h3 id="heading-2-containers"><strong>2. Containers</strong></h3>
<ul>
<li><p>Containers share the same <strong>Host OS</strong> but are managed by a <strong>Container Engine</strong> (e.g., Docker, CRI-O, etc.), eliminating the need for separate Guest OS instances.</p>
</li>
<li><p>Each container has its own dependencies (Bins/Libs) but shares the OS kernel with other containers, making them <strong>lightweight</strong> and efficient.</p>
</li>
<li><p><strong>Faster startup and lower overhead</strong> compared to VMs since containers don’t require a full OS boot.</p>
</li>
<li><p>Ideal for <strong>microservices</strong> and scalable applications since they consume fewer resources and can be deployed rapidly.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742579982282/32342cb5-697c-43b8-9529-85a9376dfcc6.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-key-differences-in-short"><strong>Key differences in short:</strong></h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Virtual Machines (VMs)</td><td>Containers</td></tr>
</thead>
<tbody>
<tr>
<td><strong>OS Overhead</strong></td><td>Each VM has a full Guest OS</td><td>Share the same Host OS</td></tr>
<tr>
<td><strong>Startup Time</strong></td><td>Slower (OS boot required)</td><td>Faster (lightweight)</td></tr>
<tr>
<td><strong>Resource Usage</strong></td><td>Heavy (CPU &amp; RAM overhead)</td><td>Efficient &amp; lightweight</td></tr>
<tr>
<td><strong>Scalability</strong></td><td>Harder to scale due to overhead</td><td>Easily scalable</td></tr>
<tr>
<td><strong>Isolation</strong></td><td>Stronger (Separate OS per VM)</td><td>Process-level isolation</td></tr>
<tr>
<td><strong>Performance</strong></td><td>Slower due to OS duplication</td><td>Faster &amp; optimized</td></tr>
</tbody>
</table>
</div><h1 id="heading-what-is-docker">What is Docker?</h1>
<p>Docker is a <strong>containerization platform</strong> that simplifies the process of building, shipping, and running applications in isolated environments called <strong>containers</strong>. Under the hood, Docker utilizes Linux namespaces and cgroups to create lightweight, portable containers. Initially, Docker used LXC (Linux Containers), but later switched to its own container runtime called <code>containerd</code></p>
<h3 id="heading-according-to-dockers-official-site"><strong>According to Docker’s official site:</strong></h3>
<blockquote>
<p><em><mark>Docker is an open platform for developing, shipping, and running applications. It allows developers to package software into standardized units called containers, which include everything needed to run: libraries, system tools, code, and runtime.</mark></em></p>
</blockquote>
<h1 id="heading-why-docker"><strong>Why Docker?</strong></h1>
<ul>
<li><p><strong>Manages Containers Easily</strong> – It provides tooling to handle containers efficiently.</p>
</li>
<li><p><strong>Simplifies Deployment</strong> – Packages an app and its dependencies into a single unit (<strong>Docker container</strong>).</p>
</li>
<li><p><strong>Build Once, Run Anywhere</strong> – Ensures consistency across development, testing, and production.</p>
</li>
<li><p><strong>Fast &amp; Lightweight</strong> – Containers are quick to create, destroy, and scale.</p>
</li>
</ul>
<h1 id="heading-installation-of-docker">Installation of Docker</h1>
<p>I have listed the official website to install the <strong>Docker Engine</strong> and <strong>Docker Desktop</strong> for up to date installation steps.</p>
<h3 id="heading-official-documentation-for-installationcheck-according-to-your-device">Official Documentation for Installation(Check according to your device)</h3>
<p>Website: <a target="_blank" href="https://docs.docker.com/desktop/setup/install/linux/"><strong>Install Docker Desktop</strong></a></p>
<p>Website: <a target="_blank" href="https://docs.docker.com/engine/install/"><strong>Install Docker Engine</strong></a></p>
<h2 id="heading-docker-daemon"><strong>Docker Daemon:</strong></h2>
<p>The Docker Daemon (<code>dockerd</code>) is the core engine that runs in the background. It listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. The daemon handles all the container operations like starting, stopping, and scaling containers, as well as pulling and creating images.</p>
<h2 id="heading-docker-desktop"><strong>Docker Desktop:</strong></h2>
<p>Docker Desktop is an application for MacOS and Windows that provides a GUI for managing Docker environments. It includes Docker Engine, Docker CLI client, Docker Compose, Kubernetes, and a graphical user interface that allows users to manage containers, images, and other Docker resources visually. Docker Desktop simplifies the process of setting up and using Docker on your local machine.</p>
<h1 id="heading-how-docker-works">How Docker Works?</h1>
<p>Docker follows a simple process to create, distribute, and run containers. Here’s how it works step by step:</p>
<h4 id="heading-docker-architecture">Docker Architecture</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742805548930/7a53d163-8a17-43ca-bfe4-a0071525ef47.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-1-docker-client"><strong>1. Docker Client</strong></h3>
<p>The developer interacts with Docker using commands like:</p>
<ul>
<li><p><code>docker build</code> → Creates a <strong>Docker Image</strong> from a <strong>Dockerfile</strong>.</p>
</li>
<li><p><code>docker pull</code> → Downloads an existing image from the <strong>Docker Registry</strong> (like Docker Hub).</p>
</li>
<li><p><code>docker run</code> → Creates and starts a container from an image.</p>
</li>
</ul>
<h3 id="heading-2-docker-daemon"><strong>2. Docker Daemon</strong></h3>
<ul>
<li><p>The <strong>Docker Daemon</strong> runs in the background and manages everything, including images, containers, networks, and storage.</p>
</li>
<li><p>It processes the client commands and does the actual work of building, pulling, and running containers.</p>
</li>
</ul>
<h3 id="heading-3-docker-host"><strong>3. Docker Host</strong></h3>
<ul>
<li><p>The <strong>Docker Host</strong> is where containers run.</p>
</li>
<li><p>It holds two key components:</p>
<ul>
<li><p><strong>Images:</strong> Pre-built packages that contain applications and dependencies (e.g., Ubuntu, Nginx).</p>
</li>
<li><p><strong>Containers:</strong> Running instances of Docker images that execute applications.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-4-docker-registry"><strong>4. Docker Registry</strong></h3>
<ul>
<li><p>This is a storage location for Docker images like you store you code on GitHub.</p>
</li>
<li><p>Common registries include <strong>Docker Hub, Google Artifact Registry,Azure container registry, Amazon Elastic Container Registry (ECR), GitHub Conainer registry(GCR) and private registries</strong>.</p>
</li>
<li><p>Images can be <strong>pulled</strong> (<code>docker pull</code>) from here or <strong>pushed</strong> (<code>docker push</code>) to share with others.</p>
</li>
</ul>
<h3 id="heading-process-flow"><strong>Process Flow</strong></h3>
<p><strong>Step 1:</strong> You <strong>build</strong> an image using <code>docker build</code> .</p>
<p><strong>Step 2:</strong> If the image isn’t available locally, Docker <strong>pulls</strong> it from the registry using <code>docker pull</code>.</p>
<p><strong>Step 3:</strong> You <strong>run</strong> a container using <code>docker run</code>, which creates an instance from the image.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742582298994/5af1e740-5183-48c2-8894-a039b1d096f7.gif" alt class="image--center mx-auto" /></p>
<h1 id="heading-what-is-a-dockerfile">What is a Dockerfile?</h1>
<p>A <strong>Dockerfile</strong> is a script containing a set of instructions to build a <strong>Docker Image</strong>. It defines the base OS, dependencies, and commands required to set up an environment.</p>
<h2 id="heading-docker-image">Docker Image</h2>
<p>A <strong>Docker Image</strong> is a lightweight, standalone, and executable software package that includes everything needed to run an application: <strong>code, runtime, system tools, libraries, and dependencies</strong>. A docker image is built in <strong>layers</strong>, where each instruction in the <code>Dockerfile</code> creates a new <strong>layer</strong>. These layers stack on top of each other to form the final image.</p>
<ol>
<li><p><code>FROM</code> → Base image layer (e.g., Ubuntu, Node.js, or Alpine).</p>
</li>
<li><p><code>WORKDIR</code> → Sets the working directory inside the container.</p>
</li>
<li><p><code>COPY</code> → Copies files from the host to the container.</p>
</li>
<li><p><code>RUN</code> → Executes commands inside the image (e.g., installing dependencies).</p>
</li>
<li><p><code>EXPOSE</code> → Declares which ports the container will use.</p>
</li>
<li><p><code>CMD</code> / <code>ENTRYPOINT</code> → Defines the default command when the container starts.</p>
</li>
</ol>
<p>Each layer is <strong>immutable</strong>—once created, it doesn’t change. Instead, new layers are added when modifications are made.</p>
<ul>
<li><p><strong>Images are immutable</strong> (cannot be changed).</p>
</li>
<li><p><strong>Stored locally or on Docker Hub</strong> for sharing.</p>
</li>
</ul>
<h2 id="heading-writing-your-first-dockerfile">Writing your first Dockerfile:</h2>
<pre><code class="lang-dockerfile"><span class="hljs-keyword">FROM</span> ubuntu:latest  

<span class="hljs-keyword">WORKDIR</span><span class="bash"> /app  </span>

<span class="hljs-keyword">COPY</span><span class="bash"> package.json package-lock.json ./  </span>

<span class="hljs-keyword">COPY</span><span class="bash"> . .  </span>

<span class="hljs-keyword">EXPOSE</span> <span class="hljs-number">3000</span>  

<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"npm"</span>, <span class="hljs-string">"start"</span>]</span>
</code></pre>
<h2 id="heading-docker-layer-caching"><strong>Docker Layer Caching</strong></h2>
<p>Docker optimizes image builds by <strong>caching layers</strong>. If a layer hasn’t changed, Docker reuses the cached version instead of rebuilding it.</p>
<h3 id="heading-how-caching-works"><strong>How caching works:</strong></h3>
<ul>
<li><p>Docker runs through the <code>Dockerfile</code> line by line.</p>
</li>
<li><p>If a layer hasn’t changed, it is pulled from cache.</p>
</li>
<li><p>If a layer <strong>changes</strong>, all layers <strong>after it</strong> must be rebuilt.</p>
</li>
</ul>
<h2 id="heading-containers">Containers</h2>
<p>A <strong>Docker Container</strong> is a running instance of an image. It provides a lightweight and isolated environment to run applications.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742807071757/10a717ae-3701-436a-b63a-e35243013278.jpeg" alt class="image--center mx-auto" /></p>
<ul>
<li><p><strong>Ephemeral</strong> (data is lost when deleted unless using volumes).</p>
</li>
<li><p><strong>Multiple containers can be created from the same image.</strong></p>
</li>
</ul>
<h1 id="heading-recap-with-demo-dockerizing-a-nodejs-application">Recap with Demo: Dockerizing a Nodejs application</h1>
<p>Remember above we have written our first <strong>Dockerfile</strong> we will be using that.</p>
<p>Now for the practice at your own you can use this github repository, here you will find the nodejs applicaiton code okay: <a target="_blank" href="https://github.com/piyushgarg-dev/nodejs-docker-example"><strong>Nodejs Application Code</strong></a></p>
<p><code>Dockerfile</code></p>
<h3 id="heading-step-1-writing-the-dockerfile"><strong>Step 1: Writing the Dockerfile</strong></h3>
<pre><code class="lang-dockerfile"><span class="hljs-comment"># Use the latest Ubuntu image as the base</span>
<span class="hljs-keyword">FROM</span> ubuntu:latest

<span class="hljs-comment"># Set the working directory inside the container</span>
<span class="hljs-keyword">WORKDIR</span><span class="bash"> /app</span>

<span class="hljs-comment"># Copy package files first (helps with caching layers efficiently)</span>
<span class="hljs-keyword">COPY</span><span class="bash"> package.json package-lock.json ./</span>

<span class="hljs-comment"># Install dependencies</span>
<span class="hljs-keyword">RUN</span><span class="bash"> apt update &amp;&amp; apt install -y nodejs npm &amp;&amp; npm install</span>

<span class="hljs-comment"># Copy all remaining project files</span>
<span class="hljs-keyword">COPY</span><span class="bash"> . .</span>

<span class="hljs-comment"># Expose port 3000 to allow external access to the application</span>
<span class="hljs-keyword">EXPOSE</span> <span class="hljs-number">3000</span>

<span class="hljs-comment"># Start the application using npm</span>
<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"npm"</span>, <span class="hljs-string">"start"</span>]</span>
</code></pre>
<h3 id="heading-step-2-build-the-docker-image"><strong>Step 2: Build the Docker Image</strong></h3>
<p>Now, let's <strong>build the image</strong> using the Dockerfile:</p>
<pre><code class="lang-bash">docker build -t mynodeapp .
</code></pre>
<ul>
<li><p><code>t mynodeapp</code> → Gives the name <strong>mynodeapp</strong> to the image.</p>
</li>
<li><p><code>.</code> → Refers to the current directory where the Dockerfile is located.</p>
</li>
</ul>
<h3 id="heading-step-3-run-the-container"><strong>Step 3: Run the Container</strong></h3>
<p>Once the image is built, we can <strong>start a container</strong> from it:</p>
<pre><code class="lang-bash">docker run -d -p 3000:3000 --name mynodejscontainer mynodeapp
</code></pre>
<ul>
<li><p><code>d</code> → Runs the container in <strong>detached mode</strong> (in the background).</p>
</li>
<li><p><code>p 3000:3000</code> → Maps port <strong>3000 of the container</strong> to port <strong>3000 of the host</strong>.</p>
</li>
<li><p><code>-name mynodejscontainer</code> → Names the running container <strong>mynodejscontainer</strong>.</p>
</li>
<li><p><code>mynodeapp</code> → Uses the <strong>mynodeapp</strong> image to create the container.</p>
</li>
</ul>
<h3 id="heading-step-4-verify-the-running-container"><strong>Step 4: Verify the Running Container</strong></h3>
<p>To check if the container is running:</p>
<pre><code class="lang-bash">docker ps

CONTAINER ID   IMAGE       COMMAND        STATUS        PORTS                  NAMES
abcdef123456   mynodeapp   <span class="hljs-string">"npm start"</span>    Up 5 minutes  0.0.0.0:3000-&gt;3000/tcp  mynodejscontainer
</code></pre>
<h3 id="heading-step-5-view-logs-of-the-application"><strong>Step 5: View Logs of the Application</strong></h3>
<p>To check logs and ensure the app is running properly:</p>
<pre><code class="lang-bash">docker logs -f mycontainer

&gt; mynodeapp@1.0.0 start /
&gt; node server.js
Server is running on port 3000...
</code></pre>
<h3 id="heading-step-6-access-the-application"><strong>Step 6: Access the Application</strong></h3>
<p>Now, open your browser and go to:</p>
<pre><code class="lang-bash">http://localhost:3000
</code></pre>
<p>Now, we have successfully dockerized our <strong>Node.js application</strong> running inside a <strong>Docker container</strong>!</p>
<h3 id="heading-this-is-the-flow-form-writing-a-dockerfile-building-the-image-out-of-it-and-running-the-container-of-the-image">This is the flow form writing a dockerfile, building the image out of it and running the container of the image.</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742810913025/12b667c4-0dab-420e-b09c-6efc73327c96.gif" alt class="image--center mx-auto" /></p>
<h1 id="heading-basic-docker-commands"><strong>Basic Docker Commands</strong></h1>
<h4 id="heading-run-a-container-interactively"><strong>Run a container interactively</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Runs an Ubuntu container in interactive mode (-it)</span>
docker run -it ubuntu

<span class="hljs-comment"># Run the container using port you have exposed in dockerfile, for example -p (publish)</span>
docker run -it -p hostPort:containerPort &lt;name-of-the-image&gt;
</code></pre>
<h4 id="heading-list-all-running-containers"><strong>List all running containers</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Shows currently running container</span>
docker container ls

<span class="hljs-comment"># or </span>
docker ps
</code></pre>
<h4 id="heading-list-all-containers-including-stopped-ones"><strong>List all containers (including stopped ones)</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Lists all containers, including stopped ones</span>
docker container ls -a
</code></pre>
<h4 id="heading-stop-a-running-container"><strong>Stop a running container</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Stops a running container using its container ID</span>
docker container stop [container_id]
</code></pre>
<h4 id="heading-remove-all-stopped-containers-unused-volumes-and-networks"><strong>Remove all stopped containers, unused volumes, and networks</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Cleans up unused containers, networks, and images</span>
docker system prune
</code></pre>
<p><strong>Exec into the running container</strong></p>
<pre><code class="lang-bash">docker <span class="hljs-built_in">exec</span> -it &lt;name-of-your-container&gt; bash
</code></pre>
<h4 id="heading-inspect-running-processes-in-a-container"><strong>Inspect running processes in a container</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Lists all running processes inside the container after you exec into the container</span>
ps -ef
</code></pre>
<h2 id="heading-image-amp-container-management"><strong>Image &amp; Container Management</strong></h2>
<h4 id="heading-list-all-docker-images"><strong>List all Docker images</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Shows all locally available Docker images</span>
docker images
</code></pre>
<h4 id="heading-pull-an-image-from-docker-hub"><strong>Pull an image from Docker Hub</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Downloads the latest Nginx image</span>
docker pull nginx
</code></pre>
<h4 id="heading-remove-an-image"><strong>Remove an image</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Deletes the specified Docker image</span>
docker rmi nginx
</code></pre>
<h4 id="heading-start-a-stopped-container"><strong>Start a stopped container</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Restarts a stopped container</span>
docker start [container_id]

<span class="hljs-comment"># Or you can use the name of the container as well</span>
docker start &lt;name-of-the-conatiner&gt;
</code></pre>
<h4 id="heading-restart-a-container"><strong>Restart a container</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Stops and starts a container again</span>
docker restart [container_id]

<span class="hljs-comment"># Or you can use the name of the container as well</span>
docker restart &lt;name-of-the-conatiner&gt;
</code></pre>
<h4 id="heading-delete-a-container"><strong>Delete a container</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Removes a stopped container permanently</span>
docker rm [container_id]

<span class="hljs-comment"># Or you can use the name of the container as well</span>
docker rm &lt;name-of-the-conatiner&gt;
</code></pre>
<h2 id="heading-container-logs-amp-inspection"><strong>Container Logs &amp; Inspection</strong></h2>
<h4 id="heading-view-container-logs"><strong>View container logs</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Shows logs of a specific container</span>
docker logs [container_id]

<span class="hljs-comment"># Or you can use the name of the container as well</span>
docker logs &lt;name-of-the-conatiner&gt;
</code></pre>
<h4 id="heading-check-container-details"><strong>Check container details</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Displays detailed information about a container</span>
docker inspect [container_id]

<span class="hljs-comment"># Or you can use the name of the container as well</span>
docker inspect &lt;name-of-the-conatiner&gt;
</code></pre>
<h4 id="heading-monitor-real-time-container-stats"><strong>Monitor real-time container stats</strong></h4>
<pre><code class="lang-bash"><span class="hljs-comment"># Shows real-time CPU, memory, and network stats of containers</span>
docker stats
</code></pre>
<h2 id="heading-ill-be-covering-these-advanced-and-important-topics-in-next-blog">I’ll be covering these advanced and Important topics in next blog</h2>
<ol>
<li><p>Docker Compose</p>
</li>
<li><p>Docker Networking</p>
</li>
<li><p>Docker Volumes</p>
</li>
<li><p>Docker Swarm</p>
</li>
<li><p>Docker Vs Kubernetes</p>
</li>
</ol>
<h1 id="heading-the-end">The End!</h1>
<blockquote>
<p>I hope you enjoyed this blog and have learned about docker today. See you in the next one.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Building a Secure, Fast & Scalable Static Website on AWS - MindfulCloud]]></title><description><![CDATA[Introduction
The Problem It Solves
Anyone can host a static website on AWS, but that’s not enough in today's landscape. The real challenge is building a secure, fast, and scalable website that efficiently uses AWS resources.

Security Risks: Hackers ...]]></description><link>https://blog.surajdev.tech/building-a-secure-fast-and-scalable-static-website-on-aws-mindfulcloud</link><guid isPermaLink="true">https://blog.surajdev.tech/building-a-secure-fast-and-scalable-static-website-on-aws-mindfulcloud</guid><category><![CDATA[Cloud]]></category><category><![CDATA[AWS]]></category><category><![CDATA[S3]]></category><category><![CDATA[Static Website]]></category><category><![CDATA[#CloudWatch]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Cloud Computing]]></category><category><![CDATA[cloudfront]]></category><category><![CDATA[route53]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Fri, 14 Mar 2025 08:14:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1741690271119/3cff04ce-bed2-4f4c-8e44-1f656cc57e12.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<h3 id="heading-the-problem-it-solves">The Problem It Solves</h3>
<p>Anyone can host a static website on AWS, but that’s not enough in today's landscape. The real challenge is building a <strong>secure, fast, and scalable</strong> website that efficiently uses AWS resources.</p>
<ul>
<li><p><strong>Security Risks:</strong> Hackers are everywhere, and a simple HTML file won’t stop them.</p>
</li>
<li><p><strong>Performance Issues:</strong> Users expect lightning-fast websites. Anything over a second and they bounce.</p>
</li>
<li><p><strong>Cost Management:</strong> Resources need to be allocated smartly to avoid unnecessary spending.</p>
</li>
</ul>
<p>This blog walks you through building a <strong>highly secure, performance-optimized</strong> static website leveraging AWS services.</p>
<h2 id="heading-how-i-built-it">How I Built It</h2>
<p>The AWS services used:</p>
<ul>
<li><p><strong>AWS S3:</strong> Foundation for static site storage.</p>
</li>
<li><p><strong>CloudFront:</strong> Distributes content worldwide for ultra-fast loading.</p>
</li>
<li><p><strong>Certificate Manager:</strong> Manages HTTPS encryption.</p>
</li>
<li><p><strong>AWS WAF:</strong> Protects against cyber threats like DDoS, XSS, and SQL Injection.</p>
</li>
<li><p><strong>CloudWatch:</strong> Monitors traffic, security, and performance with alerts.</p>
</li>
<li><p><strong>AWS Route 53:</strong> Manages the custom domain.</p>
</li>
</ul>
<h3 id="heading-this-is-the-architecture-for-hosting-a-static-website">This is the architecture for Hosting a Static Website</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741934848757/2969583a-46b5-430e-bcd3-d14dbf221c56.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-understanding-the-architecture-the-complete-flow">Understanding the Architecture: The Complete Flow</h2>
<p>1️⃣ <strong>User Request (Entry Point)</strong></p>
<ul>
<li><p>A user visits <strong>https://mindfulcloud.devsuraj.me</strong>.</p>
</li>
<li><p>The request is sent to <strong>Amazon Route 53</strong>, which maps the domain to CloudFront.</p>
</li>
</ul>
<p>2️⃣ <strong>Route 53 → CloudFront</strong></p>
<ul>
<li><p>Route 53 forwards the request to <strong>Amazon CloudFront (CDN)</strong>.</p>
</li>
<li><p>CloudFront serves cached content to it’s edge locations near to the users for lower latency.</p>
</li>
</ul>
<p>3️⃣ <strong>Security Layer</strong></p>
<ul>
<li><p><strong>AWS WAF</strong> protects against:</p>
<ul>
<li><p>SQL Injection</p>
</li>
<li><p>Cross-site Scripting (XSS)</p>
</li>
<li><p>DDoS attacks</p>
</li>
</ul>
</li>
<li><p><strong>AWS ACM (AWS Certificate Manager)</strong> enables <strong>SSL/TLS encryption</strong>.</p>
</li>
</ul>
<p>4️⃣ <strong>Fetching Content from S3</strong></p>
<ul>
<li><p>If CloudFront doesn’t have the content cached, it fetches it from <strong>Amazon S3</strong>.</p>
</li>
<li><p>S3 acts as the <strong>origin server</strong> for static assets like HTML, CSS, JavaScript, and images.</p>
</li>
</ul>
<p>5️⃣ <strong>Monitoring &amp; Logging</strong></p>
<ul>
<li><p><strong>AWS CloudWatch</strong> tracks:</p>
<ul>
<li><p>CloudFront request logs, cache hit ratio, and performance metrics.</p>
</li>
<li><p>S3 storage access patterns.</p>
</li>
</ul>
</li>
<li><p>Alerts notify about security threats or traffic spikes.</p>
</li>
</ul>
<h1 id="heading-implementation">Implementation</h1>
<h2 id="heading-step-1-setting-up-an-s3-bucket-for-static-website-hosting">Step 1: Setting Up an S3 Bucket for Static Website Hosting</h2>
<ol>
<li><p>Go to <strong>AWS Console</strong> <strong>S3</strong> service and <strong>Create Bucket</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936179420/26c98294-5be0-40e6-a00b-17a1318a7e16.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enter a <strong>unique bucket name</strong> (e.g., <a target="_blank" href="http://mindfulcloud.devsuraj.me">mindfulcloud.devsuraj.me</a>).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936242843/b601fcb5-87b9-47b4-b03b-3fb0e131fa24.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Choose <strong>public or private access</strong> (public if hosting static content).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936256012/8fe9f031-300d-40ac-bad3-792614dd8dd8.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enable <strong>static website hosting</strong> under <strong>Properties</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936336105/dbfb2316-af77-460a-8ad1-494357b9bc45.png" alt class="image--center mx-auto" /></p>
<p> <strong>Scroll down below and enter the Index document and save it.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936385873/3c0484e4-301a-41b2-ab2d-0de76b8fe891.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Upload your static website files (HTML, CSS, JS).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936454088/96581c85-06a4-46ad-86ad-680ff196fee8.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h2 id="heading-step-2-configuring-aws-acm-ssl-certificate-for-https">Step 2: Configuring AWS ACM (SSL Certificate) for HTTPS</h2>
<ol>
<li><p>Go to <strong>AWS Certificate Manager (ACM)</strong> → <strong>Request a Certificate</strong>.</p>
<p> You should create the certificate in the N.Verginia otherwise you’ll not be able to see it when you select the certificate in the cloudfront.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936507905/19de7840-f895-4a78-a5d5-12c236f5d88a.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Choose <strong>Public Certificate</strong> → <strong>Enter domain name</strong> (e.g., <a target="_blank" href="http://mindfulcloud.devsuraj.me">mindfulcloud.devsuraj.me</a>).</p>
<p> In my case I have my root domain which <code>devsuraj.me</code> so I want subdomain to attach it and above I have mentioned.</p>
</li>
<li><p>Choose <strong>DNS validation</strong> (faster &amp; recommended).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936582041/0da2c569-93a1-4b58-9a45-c182062ba4de.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>ACM provides <strong>CNAME records</strong>; add them to your <strong>Namecheap DNS settings</strong>.</p>
<p> Copy the CNAME name and CNAME value.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936692597/44ae53ce-e35b-419b-9b6c-3f358e64e166.png" alt class="image--center mx-auto" /></p>
<p> <strong>Add it to the DNS service provide you have in my case I have Namecheap:</strong></p>
<ol>
<li><p>After login to you namecheap to <strong>domain list and click on manage and go to the advanced DNS.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936855801/da52e500-2fdd-489d-8436-251d9ba35198.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936932660/167695bc-5ee3-439e-beb5-5cac5824a937.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now create new record</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741936988454/bad3a968-4ef7-45ba-804c-df0894df790c.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enter the CNAME and The Value</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937059909/bde2292c-bff5-497d-94f5-c83776ef660a.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
</li>
<li><p>Now you’re done with ACM, wait for validation (may take a few minutes to hours).</p>
</li>
</ol>
<h2 id="heading-step-3-setting-up-a-route-53-hosted-zone">Step 3: Setting Up a Route 53 Hosted Zone</h2>
<ol>
<li><p>Go to <strong>AWS Route 53</strong> → <strong>Create Hosted Zone</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937278726/1d5f3848-1535-462d-b7af-6bc4324ee223.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enter your subdomain (e.g., <a target="_blank" href="http://mindfulcloud.devsuraj.me">mindfulcloud.devsuraj.me</a>).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937316935/9c49f832-2900-448d-bb07-0b54122cc50d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Copy the provided <strong>NS (Name Server) records</strong> and update them in <strong>Namecheap’s DNS settings</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937364181/f080c810-24bd-4c61-8a6b-64af039e2e78.png" alt class="image--center mx-auto" /></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937411428/3d461340-949d-4f9d-87bd-06b810537e9b.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Create an <strong>A record</strong> (alias) pointing to <strong>CloudFront Distribution</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937481808/12063eed-8512-4c9e-a3da-d31119e9e58c.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h2 id="heading-step-4-setting-up-cloudfront-for-cdn-amp-caching">Step 4: Setting Up CloudFront for CDN &amp; Caching</h2>
<ol>
<li><p>Go to <strong>AWS CloudFront</strong> → <strong>Create Distribution</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937620661/752f1322-52e6-4f3e-a303-d0418b57b5d1.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Set <strong>Origin Domain</strong> as your S3 bucket.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937675982/8cb2b5fd-978d-49b8-b517-571343f8da8a.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enable <strong>HTTPS</strong> using your ACM certificate.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937719854/634b15b3-7601-47c5-a0fa-6c8b79f93978.png" alt class="image--center mx-auto" /></p>
<p> <strong>Select you ACM certificate:</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741938040610/2a2272de-dbcd-479b-a822-c9e363d9855b.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Configure <strong>default root object</strong> (index.html).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741937830674/8f3b498f-e483-4ab5-8294-5f8e75701377.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Deploy the distribution and note the <strong>CloudFront URL</strong>.</p>
</li>
<li><p>After creating the distribution it you’ll give you the bucket policy to you just copy that and paste it in the bucket you created:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939790925/b5326d2b-a8d7-4ad9-b594-4f5292812bfb.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h2 id="heading-step-5-connecting-namecheap-domain-to-aws"><strong>Step 5: Connecting Namecheap Domain to AWS</strong></h2>
<h4 id="heading-1-go-to-namecheap-dns-settings"><strong>1️⃣ Go to Namecheap DNS Settings</strong></h4>
<ul>
<li>Log in to <strong>Namecheap</strong> → <strong>Domain List</strong> → <strong>Manage</strong> your domain → <strong>Advanced DNS</strong>.</li>
</ul>
<h4 id="heading-2-verify-ns-records-are-correct-as-we-did-this-in-step-3"><strong>2️⃣ Verify NS Records are correct( as we did this in step 3)</strong></h4>
<ul>
<li>Ensure <strong>Nameservers</strong> are set to <strong>Custom DNS</strong> with Route 53 NS records.</li>
</ul>
<h4 id="heading-3-save-amp-wait-for-propagation"><strong>3️⃣ Save &amp; Wait for Propagation</strong></h4>
<ul>
<li><p>Click <strong>Save Changes</strong> → Wait <strong>a few minutes to 24 hours</strong>.</p>
</li>
<li><p>Open <a target="_blank" href="https://mindfulcloud.devsuraj.me"><code>https://yourdomain.com</code></a> in a browser to confirm it works.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741934637323/c090c826-03be-457a-9f71-e0d40b2ba74c.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-step-6-enhancing-security-with-aws-waf">Step 6: Enhancing Security with AWS WAF</h2>
<ol>
<li><p>Go to <strong>AWS WAF</strong> → <strong>Create WebACL</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741938495635/3272157f-05b8-47eb-b042-cb3cfcc11be9.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Attach it to <strong>CloudFront Distribution</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741938621461/470152fc-19ac-4371-a586-c38b1f331875.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Add security rules:</p>
<ul>
<li><p><strong>Block common threats</strong> (DDoS, SQL Injection, XSS attacks).</p>
</li>
<li><p><strong>Rate limiting</strong> for excessive requests.</p>
</li>
<li><p><strong>Geo-restriction</strong> to block traffic from unwanted locations.</p>
</li>
</ul>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741938708441/68e33ba9-c921-45eb-9b21-ecdffefaec7d.png" alt class="image--center mx-auto" /></p>
<ol start="4">
<li><p>Enable <strong>AWS WAF logging</strong> to monitor security threats.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741938751012/ac9b3e8e-a90b-4e98-9aaa-6ee7513e790a.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h2 id="heading-step-7-enabling-cloudwatch-monitoring-amp-logging">Step 7: Enabling CloudWatch Monitoring &amp; Logging</h2>
<ol>
<li><p><strong>Enable CloudFront Logging</strong>:</p>
<ul>
<li><p>Go to <strong>CloudFront</strong> → <strong>Enable Standard Logging</strong>.</p>
</li>
<li><p>Choose an <strong>S3 bucket</strong> to store logs.</p>
</li>
</ul>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939080782/1676e8f4-5f32-4192-9f77-3ef76aeacaec.png" alt class="image--center mx-auto" /></p>
<ol start="2">
<li><p><strong>Create CloudWatch Dashboards</strong>:</p>
<ul>
<li><p>Monitor <strong>requests, latency, cache hit ratio</strong>.</p>
</li>
<li><p>Set up <strong>CloudWatch alarms</strong> for security events.</p>
</li>
</ul>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939126900/0f60cb5f-56ee-49ac-9ce8-42fcad14767b.png" alt class="image--center mx-auto" /></p>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939166984/efa1da91-d747-4af2-a9bb-bd888926ae61.png" alt class="image--center mx-auto" /></p>
<ol start="3">
<li><p><strong>Set Up Alerts</strong>:</p>
<ul>
<li><p>Use <strong>AWS SNS (Simple Notification Service)</strong> to receive alerts via email/SMS.</p>
</li>
<li><p>Example: Alert if <strong>CloudFront request count exceeds a threshold</strong>.</p>
</li>
</ul>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939196683/643c1916-5063-418b-9990-eb3761999501.png" alt class="image--center mx-auto" /></p>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939225941/7f112d6e-e9bc-4bfe-ab88-206268bc90fb.png" alt class="image--center mx-auto" /></p>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939245897/0c15274a-ad3b-4827-bfd4-2b20dbf754e2.png" alt class="image--center mx-auto" /></p>
<p>    <strong>Select The SNS topic or create one:</strong></p>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939277290/73c9ca7e-f59c-438e-adc4-90d9316c0572.png" alt class="image--center mx-auto" /></p>
<ol start="4">
<li>And just complete the step 3 and step 4 in creating the alarm and you’re good go.</li>
</ol>
<h2 id="heading-step-8-implementing-reliability-amp-disaster-recovery">Step 8: Implementing Reliability &amp; Disaster Recovery</h2>
<ol>
<li><p><strong>Enable S3 Versioning</strong>:</p>
<ul>
<li><p>Go to <strong>S3</strong> → <strong>Properties</strong> → <strong>Enable Versioning</strong>.</p>
</li>
<li><p>This helps rollback in case of accidental file deletion.</p>
</li>
</ul>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939409370/487fa00a-b0a4-4805-8740-5496212985fb.png" alt class="image--center mx-auto" /></p>
<ol start="2">
<li><p><strong>Enable Cross-Region Replication</strong>:</p>
<ul>
<li><p>Go to <strong>S3</strong> → <strong>Replication Rules</strong> → <strong>Set up a backup region</strong>.</p>
</li>
<li><p>Choose a different AWS region for redundancy.</p>
</li>
</ul>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939858163/7583db07-78b4-430b-a8c9-63abfdf88141.png" alt class="image--center mx-auto" /></p>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741939832570/14ef29f7-bbb5-4f2f-8b2e-210b2defa017.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-send-the-requests-to-your-website-to-check-the-performance-waf-security-and-other-metrics"><strong>Send the requests to your website to check the performance, WAF security and other metrics.</strong></h2>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

URL=<span class="hljs-string">"your website url"</span>
REQUESTS=<span class="hljs-string">''</span> <span class="hljs-comment"># include the number of requrests you want to send  </span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"Starting load test on <span class="hljs-variable">$URL</span> with <span class="hljs-variable">$REQUESTS</span> requests..."</span>

<span class="hljs-keyword">for</span> ((i=1; i&lt;=REQUESTS; i++))
<span class="hljs-keyword">do</span>
  curl -s -o /dev/null -w <span class="hljs-string">"Request <span class="hljs-variable">$i</span>: HTTP %{http_code}\n"</span> <span class="hljs-variable">$URL</span> &amp;
<span class="hljs-keyword">done</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"Load test initiated!"</span>
</code></pre>
<h3 id="heading-how-to-run"><strong>How to Run</strong></h3>
<ol>
<li><p>Save this script as <code>simple_load_</code><a target="_blank" href="http://test.sh"><code>test.sh</code></a>.</p>
</li>
<li><p>Give it execution permission:</p>
</li>
</ol>
<pre><code class="lang-bash">chmod +x simple_load_test.sh
</code></pre>
<ol start="3">
<li>Run it:</li>
</ol>
<pre><code class="lang-bash">./simple_load_test.sh
</code></pre>
<h2 id="heading-the-end">The end!!!</h2>
<h3 id="heading-thanks-for-the-reading-guys-see-you-in-the-next-one">Thanks for the reading guys, see you in the next one…</h3>
]]></content:encoded></item><item><title><![CDATA[You need to learn AWS right now!]]></title><description><![CDATA[Introduction
Amazon Web Services (AWS) is a cloud computing platform that offers a wide range of services such as computing power, storage, databases, and networking. If you're a beginner I’m here to help you with my experience of learning and buildi...]]></description><link>https://blog.surajdev.tech/you-need-to-learn-aws-right-now</link><guid isPermaLink="true">https://blog.surajdev.tech/you-need-to-learn-aws-right-now</guid><category><![CDATA[AWS]]></category><category><![CDATA[Cloud]]></category><category><![CDATA[Cloud Computing]]></category><category><![CDATA[Devops]]></category><category><![CDATA[AWS IAM]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Mon, 10 Mar 2025 06:23:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1741514885928/9ff1972b-8f27-45a1-aefd-e91bd99d382a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction"><strong>Introduction</strong></h1>
<p>Amazon Web Services (AWS) is a cloud computing platform that offers a wide range of services such as computing power, storage, databases, and networking. If you're a beginner I’m here to help you with my experience of learning and building project in AWS infrastructure, AWS provides scalable and flexible solutions for building applications.</p>
<p>In this guide, we'll be exploring the fundamentals of AWS and walk through the setup of <strong>Identity and Access Management (IAM)</strong>, which is essential for securing your AWS environment.</p>
<p><img src="https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExejNvbWt2ZDUzdWlwdGlmdGpvOXM3NWZtbHQ2OXhvNW5raGZsYjc4aiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/xT39Db8zIOODTppk08/giphy.gif" alt class="image--center mx-auto" /></p>
<h1 id="heading-what-is-aws"><strong>What is AWS?</strong></h1>
<p>AWS is a <strong>cloud computing service provided</strong> by <strong>Amazon</strong> that offers <strong>on-demand computing resources</strong> over the internet with <strong>pay-as-you-go pricing</strong>. It eliminates the need for physical hardware, reducing costs and increasing efficiency.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741526402136/40f219d7-eb69-427a-bbbb-64271f366882.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-key-features-of-aws"><strong>Key Features of AWS:</strong></h3>
<p>✅ <strong>Scalability</strong> – Automatically scales based on demand.</p>
<p>✅ <strong>Pay-as-you-go Pricing</strong> – No upfront costs; pay only for what you use.</p>
<p>✅ <strong>Security &amp; Compliance</strong> – Built-in security measures and compliance with industry standards.</p>
<p>✅ <strong>Global Infrastructure</strong> – Data centers across multiple regions for high availability.</p>
<p>✅ <strong>Wide Range of Services</strong> – Compute, storage, databases, AI/ML, and more.</p>
<h3 id="heading-popular-aws-services"><strong>Popular AWS Services:</strong></h3>
<ul>
<li><p><strong>EC2</strong> – Virtual machines for computing power.</p>
</li>
<li><p><strong>S3</strong> – Secure object storage.</p>
</li>
<li><p><strong>RDS</strong> – Managed relational database service.</p>
</li>
<li><p><strong>Lambda</strong> – Serverless computing.</p>
</li>
<li><p><strong>VPC</strong> – Private cloud networking.</p>
</li>
</ul>
<p>We’ll discuss most used AWS services in the Cloud/DevOps space in the next blog.</p>
<h1 id="heading-create-your-aws-account-now">Create your AWS account now!</h1>
<h3 id="heading-prerequisites"><strong>Prerequisites:</strong></h3>
<ol>
<li><p><strong>You’ll need a valid Email Address</strong></p>
</li>
<li><p><strong>A Payment Method (debit card for example) -</strong> don’t worry, broh 😂, they’re not here to swipe your cash!</p>
</li>
</ol>
<h3 id="heading-steps-to-create-an-aws-account"><strong>Steps to Create an AWS Account:</strong></h3>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=CjKhQoYeR4Q&amp;pp=ygUZaG93IHRvIGNyZWF0ZSBhd3MgYWNjb3VudA%3D%3D">https://www.youtube.com/watch?v=CjKhQoYeR4Q&amp;pp=ygUZaG93IHRvIGNyZWF0ZSBhd3MgYWNjb3VudA%3D%3D</a></div>
<p> </p>
<h2 id="heading-my-aws-console">My AWS Console:</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741528795602/3cd11709-5d04-456f-89f9-f91f1c65f386.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-understanding-iam-identity-and-access-management"><strong>Understanding IAM (Identity and Access Management)</strong></h1>
<p>AWS IAM is a security service that allows you to manage users, permissions, and access to AWS resources.</p>
<h3 id="heading-why-is-iam-important"><strong>Why is IAM Important?</strong></h3>
<p>🔒 <code>Access Control:</code> Defines who can access AWS resources.</p>
<p>🔒 <code>Least Privilege Principle:</code> Assigns only the required permissions to users.</p>
<p>🔒 <code>Multi-Factor Authentication (MFA):</code> Enhances security with an additional authentication step.</p>
<p>🔒 <code>AWS Root User Protection:</code> Avoid using the root account for daily tasks.</p>
<h3 id="heading-iam-components"><strong>IAM Components:</strong></h3>
<ol>
<li><p><strong><mark>Users</mark>:</strong> Individual AWS accounts that have credentials (such as a username, password, or access keys). Each user represents a person or an application that interacts with AWS resources.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741528979314/fbf25ad2-ad09-474c-89dd-1a84c4b9ef90.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong><mark>Groups</mark>:</strong> Collections of users that share the same set of permissions. This makes it easier to manage access controls for multiple users at once.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741528959581/e91fbcf0-a6c5-4218-aa8a-1b833d81ecc8.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong><mark>Roles</mark>:</strong> Entities that define a set of permissions for AWS services or external identities. Roles allow you to grant temporary access without having to share long-term credentials.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741529007677/e18bc983-0deb-4af7-8578-a27a785c0635.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong><mark>Policies</mark>:</strong> JSON-based documents that define permissions. They specify what actions are allowed or denied on which AWS resources. We can create custom policies which is the used according to use-case.</p>
<p> <code>Example</code>: A policy is a JSON document that specifies allowed or denied actions. For example, the <strong>S3ReadOnlyAccess</strong> policy grants read-only access to an S3 bucket.</p>
<pre><code class="lang-json"> {
   <span class="hljs-attr">"Version"</span>: <span class="hljs-string">"2012-10-17"</span>,
   <span class="hljs-attr">"Statement"</span>: [
     {
       <span class="hljs-attr">"Effect"</span>: <span class="hljs-string">"Allow"</span>,
       <span class="hljs-attr">"Action"</span>: <span class="hljs-string">"s3:GetObject"</span>,
       <span class="hljs-attr">"Resource"</span>: <span class="hljs-string">"arn:aws:s3:::example-bucket/*"</span>
     }
   ]
 }
</code></pre>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741529031660/5d088b8d-05c8-4b20-8798-c03458bde268.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h1 id="heading-setting-up-iam-in-aws"><strong>Setting Up IAM in AWS</strong></h1>
<h3 id="heading-iam-dashboard">IAM Dashboard:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741528911541/b89c1ed4-d4b0-4998-bdc8-d86ac0ac4a6a.png" alt class="image--center mx-auto" /></p>
<p>Follow these steps to configure IAM for a secure AWS environment.</p>
<h3 id="heading-step-1-create-an-aws-iam-user"><strong>Step 1: Create an AWS IAM User</strong></h3>
<ol>
<li><p>Log in to <strong>AWS Management Console</strong> using the <strong>root account</strong>.</p>
</li>
<li><p>Navigate to <strong>IAM</strong> → Click on <strong>Users</strong>.</p>
</li>
<li><p>Click <strong>Add user</strong> and specify the user details</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741534885223/85fa872c-c1b5-403e-835f-b75789e37a0c.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click <strong>Next</strong> → set <strong>Permissions</strong>, Choose the permission options and if you have created group you can attack to it.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741534923907/3fc0719c-b623-4842-a0e7-3cc270117cb4.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click <strong>Next</strong> → Add <strong>Tags</strong> (Optional).</p>
</li>
<li><p>Click <strong>Create User</strong> → Download credentials (.csv file).</p>
</li>
</ol>
<h3 id="heading-step-2-create-an-iam-group-amp-assign-policies"><strong>Step 2: Create an IAM Group &amp; Assign Policies</strong></h3>
<ol>
<li><p>Go to <strong>IAM</strong> → Click on <strong>Groups</strong>.</p>
</li>
<li><p>Click <strong>Create Group</strong> → Enter <strong>Group Name</strong>.</p>
</li>
<li><p>Attach a predefined <strong>IAM policy</strong> (e.g., <code>AdministratorAccess</code>, <code>ReadOnlyAccess</code>).</p>
</li>
<li><p>Add <strong>Users</strong> to the group → Click <strong>Create Group</strong>.</p>
</li>
</ol>
<h3 id="heading-step-3-enable-mfa-for-extra-security"><strong>Step 3: Enable MFA for Extra Security</strong></h3>
<ol>
<li><p>Navigate to <strong>IAM Users</strong> → Select the <strong>User</strong>.</p>
</li>
<li><p>Click <strong>Security Credentials</strong> → Enable <strong>Multi-Factor Authentication (MFA)</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741535298954/8fdc87b7-cdb8-432c-a79d-08d8f6fcf217.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Use an <strong>Authenticator App (Google Authenticator/AWS MFA)</strong> to scan the QR code.</p>
</li>
<li><p>Enter the <strong>generated MFA codes</strong> → Click <strong>Assign MFA</strong>.</p>
</li>
</ol>
<h3 id="heading-step-4-use-iam-role-for-aws-services"><strong>Step 4: Use IAM Role for AWS Services</strong></h3>
<p>An <strong>IAM Role</strong> is an AWS identity with a set of permissions that determine what actions are allowed or denied. Unlike IAM users, roles do not have long-term credentials (passwords or access keys). Instead, they provide <strong>temporary security credentials</strong> to AWS services or external identities.</p>
<ol>
<li><p>Go to <strong>IAM</strong> → Click <strong>Roles</strong> → <strong>Create Role</strong>.</p>
</li>
<li><p>Choose <strong>AWS Service</strong> (e.g., EC2, Lambda).</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741535819841/30745501-d01c-4878-a64a-2aba7f4e1df1.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Attach a <strong>Policy</strong> (e.g., <code>AmazonS3FullAccess</code>).</p>
</li>
<li><p>Click <strong>Create Role</strong>.</p>
</li>
</ol>
<h1 id="heading-best-practices-for-aws-iam-security"><strong>Best Practices for AWS IAM Security</strong></h1>
<p>✅ <strong>Use IAM Users Instead of Root Account</strong> – The root account should be used only for account setup and billing.</p>
<p>✅ <strong>Follow the Principle of Least Privilege</strong> – Grant only necessary permissions.</p>
<p>✅ <strong>Enable MFA for All Users</strong> – Adds an extra layer of security.</p>
<p>✅ <strong>Rotate Access Keys Regularly</strong> – Prevents unauthorized access.</p>
<p>✅ <strong>Monitor IAM Activity with CloudTrail</strong> – Track API calls and security events.</p>
<p>✅ <strong>Use IAM Roles for Applications</strong> – Avoid hardcoding credentials in code.</p>
<h2 id="heading-the-end">The end!</h2>
<blockquote>
<p>Hey guys, thanks for the reading, I hope you have learned something valuable today via this blog. Let me know in the comment if you have any doubt or anything you want to say. I would love to reply.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Cloud Computing 101]]></title><description><![CDATA[Introduction to Cloud Computing
Imagine renting a fully equipped kitchen instead of building one from scratch. Cloud computing works similarly: instead of owning physical servers or data centers, you "rent" computing power, storage, and services over...]]></description><link>https://blog.surajdev.tech/cloud-computing-101</link><guid isPermaLink="true">https://blog.surajdev.tech/cloud-computing-101</guid><category><![CDATA[Cloud]]></category><category><![CDATA[Cloud Computing]]></category><category><![CDATA[AWS]]></category><category><![CDATA[GCP]]></category><category><![CDATA[Azure]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Mon, 10 Feb 2025 20:17:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1729364533483/914a0d43-2d84-4977-b55d-6c39095aa233.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction-to-cloud-computing">Introduction to Cloud Computing</h1>
<p>Imagine <strong>renting a fully equipped kitchen</strong> instead of <strong>building one from scratch</strong>. Cloud computing works similarly: instead of <strong>owning physical servers</strong> or <strong>data centers</strong>, you "<strong>rent</strong>" <strong>computing power</strong>, <strong>storage</strong>, and <strong>services</strong> <strong>over the internet</strong>. <mark>This model allows businesses and individuals to focus on innovation without worrying about infrastructure.</mark></p>
<p><img src="https://i.imgflip.com/6mnq85.gif" alt class="image--center mx-auto" /></p>
<p>Cloud computing is reshaping the world of IT, providing the <strong>on-demand delivery of IT resources</strong> with <strong>pay-as-you-go pricing</strong>. This model enables businesses to <strong>scale</strong>, <strong>optimize costs</strong>, and <strong>access advanced technologies</strong> without <strong>managing</strong> <strong>physical infrastructure</strong>.</p>
<p><strong>Why This Matters</strong>:</p>
<ul>
<li><p><strong>Businesses</strong> and <strong>developers</strong> use the cloud to <strong>innovate faster</strong>.</p>
</li>
<li><p><strong>DevOps teams</strong> leverage it to <strong>automate workflow</strong>s and <strong>deploy apps seamlessly</strong>.</p>
</li>
</ul>
<h1 id="heading-core-characteristics-of-cloud-computing">Core Characteristics of Cloud Computing</h1>
<h3 id="heading-1-trade-upfront-expense-for-variable-expense"><strong>1. Trade Upfront Expense for Variable Expense</strong></h3>
<p>Replace large initial investments in hardware with a flexible "pay-as-you-go" model, like a monthly utility bill.</p>
<h3 id="heading-2-stop-spending-money-to-run-and-maintain-data-centers"><strong>2. Stop Spending Money to Run and Maintain Data Centers</strong></h3>
<p>Get rid of the costs and headaches of managing physical servers, cooling systems, and IT teams.</p>
<h3 id="heading-3-stop-guessing-capacity"><strong>3. Stop Guessing Capacity</strong></h3>
<p>Avoid overpaying for unused servers or crashing during traffic spikes—scale resources up or down instantly.</p>
<h3 id="heading-4-benefit-from-massive-economies-of-scale"><strong>4. Benefit from Massive Economies of Scale</strong></h3>
<p>Access cheaper rates for computing power, storage, and services by leveraging the cloud provider’s bulk purchasing power.</p>
<h3 id="heading-5-increase-speed-and-agility"><strong>5. Increase Speed and Agility</strong></h3>
<p>Launch applications in minutes, experiment freely, and adapt to market changes faster.</p>
<h3 id="heading-6-go-global-in-minutes"><strong>6. Go Global in Minutes</strong></h3>
<p>Deploy your app to users worldwide with a few clicks, no need to build physical data centers.</p>
<h1 id="heading-types-of-cloud-deployments">Types of Cloud Deployments</h1>
<p>Cloud computing offers different deployment models based on organizational needs:</p>
<ul>
<li><p><strong>Public Cloud</strong>: Services are provided over the internet by third-party providers, offering scalability and cost efficiency.</p>
</li>
<li><p><strong>Private Cloud</strong>: Dedicated infrastructure for a single organization, ensuring greater security and control. Managed in-house or by a provider.</p>
</li>
<li><p><strong>Hybrid Cloud</strong>: Combines public and private clouds, allowing seamless data and application movement for flexibility.</p>
</li>
<li><p><strong>Community Cloud</strong>: Shared infrastructure for organizations with common concerns (e.g., government, healthcare), offering cost-sharing and compliance benefits.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739216170281/8c42d519-8c72-46bb-aad3-c84c7fd96a40.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-the-3-core-cloud-service-models"><strong>The 3 Core Cloud Service Models</strong></h1>
<h3 id="heading-1-iaas-infrastructure-as-a-service"><strong>1. IaaS (Infrastructure as a Service)</strong></h3>
<ul>
<li><p><strong>What it is</strong>: Rent virtual servers, storage, and networks.</p>
</li>
<li><p><strong>For whom</strong>: Developers who want control over infrastructure.</p>
</li>
<li><p><strong>Analogy</strong>: Leasing a plot of land to build your dream house (you handle construction).</p>
</li>
</ul>
<h3 id="heading-2-paas-platform-as-a-service"><strong>2. PaaS (Platform as a Service)</strong></h3>
<ul>
<li><p><strong>What it is</strong>: Tools to build apps without managing servers.</p>
</li>
<li><p><strong>For whom</strong>: Teams focused on coding, not hardware.</p>
</li>
<li><p><strong>Analogy</strong>: Moving into a furnished apartment (you decorate; the landlord handles plumbing).</p>
</li>
</ul>
<h3 id="heading-3-saas-software-as-a-service"><strong>3. SaaS (Software as a Service)</strong></h3>
<ul>
<li><p><strong>What it is</strong>: Ready-to-use apps accessed via the internet.</p>
</li>
<li><p><strong>For whom</strong>: Everyone (e.g., <strong>Gmail</strong>, <strong>Netflix</strong>).</p>
</li>
<li><p><strong>Analogy</strong>: Ordering pizza delivery (no cooking, no cleanup).</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738867104887/a14bbc95-b1e8-4f12-beb3-95d2788761b4.jpeg" alt="The 3 Core Cloud Service Models" class="image--center mx-auto" /></p>
<h1 id="heading-how-cloud-computing-powers-devops"><strong>How Cloud Computing Powers DevOps</strong></h1>
<p><strong>DevOps</strong> bridges software <strong>development (Dev)</strong> and <strong>IT operations (Ops)</strong>. The cloud fuels this partnership with:</p>
<h3 id="heading-1-cicd-pipelines-automation-magic"><strong>1. CI/CD Pipelines: Automation Magic</strong></h3>
<ul>
<li><p><strong>CI (Continuous Integration)</strong>: Automatically test code changes.</p>
</li>
<li><p><strong>CD (Continuous Delivery)</strong>: Deploy updates to users instantly.</p>
</li>
</ul>
<h3 id="heading-2-infrastructure-as-code-iac"><strong>2. Infrastructure as Code (IaC)</strong></h3>
<ul>
<li><p><strong>What it is</strong>: Define servers and networks using code (e.g., Terraform).</p>
</li>
<li><p><strong>Why it matters</strong>: Spin up identical environments in minutes.</p>
</li>
</ul>
<h3 id="heading-3-scalability-amp-elasticity"><strong>3. Scalability &amp; Elasticity</strong></h3>
<ul>
<li><p><strong>Auto-scaling</strong>: Apps grow/shrink resources based on traffic.</p>
</li>
<li><p><strong>DevOps Impact</strong>: No more downtime during traffic spikes (e.g., holiday sales).</p>
</li>
</ul>
<h1 id="heading-debunking-cloud-myths"><strong>Debunking Cloud Myths</strong></h1>
<h3 id="heading-myth-1-the-cloud-isnt-secure"><strong>Myth 1: “The Cloud Isn’t Secure”</strong></h3>
<p><strong><mark>Reality</mark></strong>: Cloud providers invest more in security than most companies.</p>
<h3 id="heading-myth-2-its-only-for-tech-giants"><strong>Myth 2: “It’s Only for Tech Giants”</strong></h3>
<p><strong><mark>Reality</mark></strong>: Startups use it to compete with big players (e.g., Dropbox scaled on AWS).</p>
<h3 id="heading-myth-3-cloud-expensive"><strong>Myth 3: “Cloud = Expensive”</strong></h3>
<p><strong><mark>Reality</mark></strong>: Turn off unused servers—like shutting lights when you leave a room.</p>
<h1 id="heading-core-cloud-providers-and-their-offerings"><strong>Core Cloud Providers and Their Offerings</strong></h1>
<h2 id="heading-1-amazon-web-servicesaws">1. Amazon Web Services(AWS)</h2>
<p>Known for its scalability and vast array of services.</p>
<p><strong>Technical Strengths</strong>:</p>
<ul>
<li><p><strong>Service Breadth</strong>: Over 200 services, including compute (EC2), storage (S3), databases (RDS), and machine learning (SageMaker).</p>
</li>
<li><p><strong>Scalability</strong>: Auto-scaling groups and Elastic Load Balancing (ELB) handle traffic spikes.</p>
</li>
<li><p><strong>Global Reach</strong>: 32 geographic regions, 102 Availability Zones (AZs) for low-latency deployments.</p>
</li>
</ul>
<p><strong>DevOps Integration</strong>:</p>
<ul>
<li><p><strong>CI/CD</strong>: AWS CodePipeline for automated workflows.</p>
</li>
<li><p><strong>Infrastructure as Code</strong>: AWS CloudFormation.<br />  <strong>Use Case</strong>: Startups and enterprises needing flexibility and global reach.</p>
</li>
</ul>
<p><img src="https://assets.datamation.com/uploads/2022/04/AWS-logo-icon-e1663793981162.png" alt="Yahoo Selects AWS Public Cloud for Ad Division | Datamation" /></p>
<h2 id="heading-2-microsoft-azure"><strong>2. Microsoft Azure</strong></h2>
<p>Ideal for businesses using Microsoft tools and products .</p>
<p><strong>Technical Strengths</strong>:</p>
<ul>
<li><p><strong>Enterprise Integration</strong>: Seamless compatibility with Microsoft products (Active Directory, Office 365, SQL Server).</p>
</li>
<li><p><strong>Hybrid Cloud</strong>: Azure Stack bridges on-premises and cloud environments.</p>
</li>
<li><p><strong>AI/ML</strong>: Azure Machine Learning and Cognitive Services (pre-built APIs for vision, speech).</p>
</li>
</ul>
<p><strong>DevOps Integration</strong>:</p>
<ul>
<li><p><strong>CI/CD</strong>: Azure DevOps pipelines.</p>
</li>
<li><p><strong>Monitoring</strong>: Azure Monitor and Application Insights.<br />  <strong>Use Case</strong>: Enterprises already invested in Microsoft ecosystems.</p>
</li>
</ul>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a8/Microsoft_Azure_Logo.svg/2560px-Microsoft_Azure_Logo.svg.png" alt="File:Microsoft Azure Logo.svg - Wikipedia" /></p>
<h2 id="heading-3-google-cloud-platform-gcp"><strong>3. Google Cloud Platform (GCP)</strong></h2>
<p>Excellent for analytics and AI services.</p>
<p><strong>Technical Strengths</strong>:</p>
<ul>
<li><p><strong>Data &amp; AI</strong>: BigQuery (serverless data warehouse), TensorFlow (open-source ML framework).</p>
</li>
<li><p><strong>Kubernetes</strong>: Google Kubernetes Engine (GKE) dominates container orchestration.</p>
</li>
<li><p><strong>Sustainability</strong>: Carbon-neutral operations with commitments to 24/7 renewable energy.</p>
</li>
</ul>
<p><strong>DevOps Integration</strong>:</p>
<ul>
<li><p><strong>CI/CD</strong>: Google Cloud Build.</p>
</li>
<li><p><strong>Observability</strong>: Cloud Monitoring and Logging.<br />  <strong>Use Case</strong>: Data-driven companies prioritizing analytics, AI, or Kubernetes.</p>
</li>
</ul>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/Google_Cloud_logo.svg/1280px-Google_Cloud_logo.svg.png" alt="GCP Architecture Example" /></p>
<h3 id="heading-choosing-the-right-provider-key-considerations"><strong>Choosing the Right Provider: Key Considerations</strong></h3>
<ol>
<li><h4 id="heading-ease-of-use">Ease of Use</h4>
</li>
<li><h4 id="heading-cost-structure">Cost Structure</h4>
</li>
<li><h4 id="heading-service-variety">Service Variety</h4>
</li>
<li><h4 id="heading-compliance-amp-security">Compliance &amp; Security</h4>
</li>
<li><h4 id="heading-support-amp-ecosystem">Support &amp; Ecosystem</h4>
</li>
</ol>
<p><img src="https://nix-united.com/wp-content/uploads/2021/12/Big-Choosing-Dilemma.png" alt="Three big cloud provides Azure,GCP, and AWS " /></p>
<h3 id="heading-here-are-the-offering-of-three-big-cloud-provides">Here are the offering of three big cloud provides:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738853829146/f1541582-64f2-4622-8eab-c6aa7a07e570.jpeg" alt="Three major Cloud platforms: AWS, Azure, GCP their services comparison " class="image--center mx-auto" /></p>
<h1 id="heading-closing-remarks">Closing Remarks</h1>
<blockquote>
<p>Cloud computing isn’t magic, it’s a tool that democratizes technology. Whether you’re a developer automating deployments with DevOps or a small business backing up files, the cloud is your gateway to efficiency and innovation.</p>
<p>In the next blog we’ll discuss about <mark>AWS Cloud Platform</mark>.</p>
</blockquote>
<h3 id="heading-the-end-thanks-for-reading">The end - Thanks for reading</h3>
]]></content:encoded></item><item><title><![CDATA[Everything You Need to Know About Hacktoberfest 2025]]></title><description><![CDATA[Introduction to Hacktoberfest
Hacktoberfest is an annual month-long celebration of open-source that runs throughout October (Oct 1 - Oct 31).
Why should you participate?
Participating helps you learn new skills, collaborate with others, improve your ...]]></description><link>https://blog.surajdev.tech/everything-you-need-to-know-about-hacktoberfest</link><guid isPermaLink="true">https://blog.surajdev.tech/everything-you-need-to-know-about-hacktoberfest</guid><category><![CDATA[#hacktoberfest ]]></category><category><![CDATA[Open Source]]></category><category><![CDATA[community]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[GitLab]]></category><category><![CDATA[Git]]></category><category><![CDATA[DigitalOcean]]></category><category><![CDATA[Appwrite]]></category><category><![CDATA[mlh]]></category><category><![CDATA[Technical writing ]]></category><category><![CDATA[technical documentation]]></category><category><![CDATA[hacktoberfest2025]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Sun, 29 Sep 2024 09:12:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675127364/460368ab-e108-4d76-867d-190335645ed4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction-to-hacktoberfest"><strong>Introduction to Hacktoberfest</strong></h1>
<p>Hacktoberfest is an annual month-long celebration of open-source that runs throughout October (Oct 1 - Oct 31).</p>
<h2 id="heading-why-should-you-participate">Why should you participate?</h2>
<p>Participating helps you learn new skills, collaborate with others, improve your coding abilities, and give back to the developer community.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=gD0SI9HaWPc">https://www.youtube.com/watch?v=gD0SI9HaWPc</a></div>
<p> </p>
<h2 id="heading-who-organizes-hacktoberfest">Who organizes Hacktoberfest?</h2>
<p>Hacktoberfest is organized by DigitalOcean in partnership with GitHub and other companies in the tech community. It has been running annually since 2014.</p>
<h2 id="heading-official-sponsors-and-partners-for-hacktoberfest-2025">Official Sponsors and Partners for Hacktoberfest 2025</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Organization</td><td>Role</td><td>Official Link</td></tr>
</thead>
<tbody>
<tr>
<td>DigitalOcean</td><td>Main Organizer</td><td>digitalocean.com</td></tr>
<tr>
<td>Major League Hacking (MLH)</td><td>Sponsor</td><td>mlh.io</td></tr>
<tr>
<td>Auth0</td><td>Sponsor</td><td>auth0.com</td></tr>
<tr>
<td>AMD</td><td>Sponsor</td><td>amd.com</td></tr>
<tr>
<td>GitHub</td><td>Partner</td><td>github.com</td></tr>
<tr>
<td>GitLab</td><td>Partner</td><td>gitlab.com</td></tr>
<tr>
<td>CNCF (Cloud Native Computing Foundation)</td><td>Partner</td><td>cncf.io</td></tr>
<tr>
<td>Open Source Initiative (OSI)</td><td>Partner</td><td>opensource.org</td></tr>
<tr>
<td>DEV Community</td><td>Partner</td><td>dev.to</td></tr>
<tr>
<td>Holopin</td><td>Badge Partner</td><td>holopin.io</td></tr>
</tbody>
</table>
</div><div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Hacktoberfest <a target="_blank" href="https://hacktoberfest.com">Website</a></div>
</div>

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Join Hacktoberfest community <a target="_blank" href="https://discord.com/invite/hacktoberfest">Discord</a></div>
</div>

<h2 id="heading-how-hacktoberfest-works">How Hacktoberfest Works</h2>
<h3 id="heading-rules-and-guidelines-for-2025">Rules and guidelines for 2025:</h3>
<p>To participate in Hacktoberfest 2025, you must register on the official website at <a target="_blank" href="https://hacktoberfest.com/">hacktoberfest.com</a>.</p>
<p><strong>Key Requirements:</strong></p>
<ul>
<li><p>Make <strong>6 valid pull/merge requests</strong> to public repositories that have the <strong>"hacktoberfest" topic</strong> added</p>
</li>
<li><p>Contributions must be to repositories that have opted-in by adding the "hacktoberfest" topic</p>
</li>
<li><p>Only quality contributions count, and spammy PRs will be disqualified</p>
</li>
<li><p>Pull requests can be made to any participating repository on GitHub or GitLab</p>
</li>
</ul>
<h3 id="heading-key-dates-and-timeline">Key dates and timeline:</h3>
<ul>
<li><p><strong>Registration opens:</strong> Late September 2025</p>
</li>
<li><p><strong>Event start:</strong> October 1, 2025</p>
</li>
<li><p><strong>Event end:</strong> October 31, 2025</p>
</li>
<li><p><strong>Final review and PR count:</strong> PRs are analyzed continuously throughout October</p>
</li>
</ul>
<h3 id="heading-what-counts-as-a-valid-contribution">What counts as a valid contribution?</h3>
<p>Valid contributions include:</p>
<p><strong>Code Contributions:</strong></p>
<ul>
<li><p>Bug fixes</p>
</li>
<li><p>New features</p>
</li>
<li><p>Performance improvements</p>
</li>
<li><p>Code refactoring</p>
</li>
</ul>
<p><strong>Non-Code Contributions:</strong></p>
<ul>
<li><p>Documentation updates</p>
</li>
<li><p>Design work</p>
</li>
<li><p>Translations</p>
</li>
<li><p>Testing</p>
</li>
<li><p>Writing tutorials</p>
</li>
<li><p>Creating educational content</p>
</li>
</ul>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text"><strong>Contributions should follow the repository's contribution guidelines and shouldn't be spammy or repetitive. The repository must have the "hacktoberfest" topic to be eligible.</strong></div>
</div>

<h2 id="heading-setting-up-for-hacktoberfest-prerequisites"><strong>Setting Up for Hacktoberfest (Prerequisites)</strong></h2>
<ol>
<li><p>You should have a GitHub/GitLab account to participate in hacktoberfest.</p>
</li>
<li><p>Should be familiar with <strong>Git and GitHub</strong><br /> Git is a version control tool that tracks changes in your code. GitHub is a platform that hosts Git repositories and allows collaboration.</p>
</li>
<li><p>Essential tools for contributing</p>
<ul>
<li><p><strong>Git:</strong> Set up Git on your local machine.</p>
</li>
<li><p><strong>Code editors</strong>: <strong>VSCode</strong>(recommended) or any other text editor.</p>
</li>
</ul>
</li>
</ol>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Learn <a target="_self" href="https://blog.surajdev.tech/getting-to-know-git-and-github-your-codes-best-friends">Git &amp; GitHub</a> easy way</div>
</div>

<h2 id="heading-understanding-open-source"><strong>Understanding Open-Source</strong></h2>
<p><strong>What is open source?</strong></p>
<p>In general, it's free to use, access, and modify depending on the licenses. It's an inclusive community and you get to collaborate with people around the world.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Read more about <a target="_self" href="https://blog.surajdev.tech/what-is-open-source-beginners-guide-how-to-get-started"><strong>Open-Source</strong></a></div>
</div>

<h3 id="heading-ways-to-find-projects-for-hacktoberfest-2025">Ways to find projects for Hacktoberfest 2025</h3>
<ol>
<li><p><strong>Good First Issue label:</strong><br /> <code>good first issue</code> is the best way to start your <strong>Open-Source</strong> journey. You can find all of these on GitHub by doing a label search. Here is how:</p>
<p> Link:<a target="_blank" href="https://github.com/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22">https://github.com/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22</a></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675191070/c23a4f75-e678-4ad4-aa3d-359a75f4fe0e.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>GitHub Topics:</strong><br /> It's a very cool feature on GitHub. With the help of this, you can find a particular project with a topic. The topic can be languages, events, tech, etc.</p>
<p> Link: <a target="_blank" href="https://github.com/topics/javascript">https://github.com/topics/javascript</a></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675220904/95650b63-5860-4481-ac99-5f639f6f3e6d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>GitHub's advanced search:</strong></p>
<p> GitHub advanced search provides tons of filters to find repository and issues according to our preferences. You can filter by <code>language</code>, <code>extension</code>, <code>issue labels</code>, <code>number of stars/forks</code>, etc.</p>
<p> Link: <a target="_blank" href="https://github.com/search/advanced">https://github.com/search/advanced</a></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675236488/1fe636ad-ce80-441e-82db-6296010f69b4.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<h2 id="heading-resource-to-find-project-to-contribute">Resource to find project to contribute</h2>
<ol>
<li><p><strong>Awesome-Hacktoberfest</strong></p>
<p> %[https://github.com/mattjegan/awesome-hacktoberfest] </p>
</li>
<li><p>How to contribute to open-source repo of freecodecamp</p>
<p> %[https://github.com/freeCodeCamp/how-to-contribute-to-open-source] </p>
</li>
</ol>
<h2 id="heading-step-by-step-contribution-guide"><strong>Step-by-Step Contribution Guide</strong></h2>
<ol>
<li><p><strong>Forking a repository:</strong></p>
<p> Go to the repository you want to contribute to on GitHub, click the "Fork" button in the top-right corner. This creates a copy of the project under your GitHub account.</p>
<p> Link: <a target="_blank" href="https://github.com/Suraj-kumar00/Getting-started-with-Git-Github">https://github.com/Suraj-kumar00/Getting-started-with-Git-Github</a></p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675396921/9cdf21de-827c-4ee2-af19-221776ff087d.png" alt class="image--center mx-auto" /></p>
<ol start="2">
<li><p><strong>Cloning a repository to your local machine</strong></p>
<p> After forking, clone the repository by using the command:</p>
<pre><code class="lang-bash"> git <span class="hljs-built_in">clone</span> &lt;URL of your forked repository&gt;
</code></pre>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675451362/cd15a38e-e09a-4c63-8330-19b960a7d55c.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Making your first change (committing and pushin</strong><a target="_blank" href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"><strong>g)</strong></a></p>
<ol>
<li><p>Atiquette of writing a good commit message(good practices):<br /> Here are common commit message types in short:</p>
<ul>
<li><p><code>feat</code>: Adds a new feature.</p>
<ul>
<li>Example: <code>feat: add user login</code></li>
</ul>
</li>
<li><p><code>fix</code>: Fixes a bug.</p>
<ul>
<li>Example: <code>fix: resolve login error</code></li>
</ul>
</li>
<li><p><code>docs</code>: Documentation changes.</p>
<ul>
<li>Example: <code>docs: update README</code></li>
</ul>
</li>
<li><p><code>style</code>: Code style changes (e.g., formatting).</p>
<ul>
<li>Example: <code>style: format code to match guidelines</code></li>
</ul>
</li>
<li><p><code>refactor</code>: Code refactoring (no new feature or bug fix).</p>
<ul>
<li>Example: <code>refactor: simplify login logic</code></li>
</ul>
</li>
<li><p><code>test</code>: Adds or updates tests.</p>
<ul>
<li>Example: <code>test: add unit tests for auth</code></li>
</ul>
</li>
<li><p><code>chore</code>: Routine tasks (e.g., updating build scripts).</p>
<ul>
<li>Example: <code>chore: update dependencies</code></li>
</ul>
</li>
<li><p><code>perf</code>: Performance improvements.</p>
<ul>
<li>Example: <code>perf: improve API response time</code></li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Key Guidelines for Writing a Good Commit Message:</strong></p>
<ol>
<li><p><strong>Use a Clear Structure:</strong></p>
<ul>
<li><p>Subject line (max 50 chars).</p>
</li>
<li><p>Body (optional, explain why).</p>
</li>
<li><p>Footer (references issues, if any).</p>
</li>
</ul>
</li>
<li><p><strong>Present Tense:</strong></p>
<ul>
<li>Write as if the change is happening now (e.g., "Fix bug" instead of "Fixed bug").</li>
</ul>
</li>
<li><p><strong>Be Brief but Specific:</strong></p>
<ul>
<li>Summarize the change concisely (e.g., "Add user authentication" rather than "Update stuff").</li>
</ul>
</li>
<li><p><strong>Explain <em>Why</em>, Not Just <em>What</em>:</strong></p>
<ul>
<li>Give the reasoning behind the change, not just the action.</li>
</ul>
</li>
<li><p><strong>Bullet Points for Multiple Changes:</strong></p>
<ul>
<li>If the commit involves several tasks, list them clearly.</li>
</ul>
</li>
<li><p><strong>Reference Issues/PRs:</strong></p>
<ul>
<li>Mention related issues or pull requests for clarity (e.g., "Closes #123").</li>
</ul>
</li>
<li><p><strong>Active Voice:</strong></p>
<ul>
<li>Write directly and clearly (e.g., "Add feature" vs. "Feature added").</li>
</ul>
</li>
</ol>
</li>
<li><p><strong>Example</strong>:</p>
<pre><code class="lang-bash"> Fix user <span class="hljs-built_in">logout</span> bug

 This fixes a bug <span class="hljs-built_in">where</span> users were not fully logged out.

 Closes <span class="hljs-comment">#456</span>
</code></pre>
</li>
</ol>
</li>
<li><p><strong>Opening your first pull request:</strong></p>
<p> Push the changes to your forked repository using:</p>
<pre><code class="lang-bash"> git push origin main
</code></pre>
</li>
<li><p><strong>How to write a good pull request description</strong></p>
<p> Be clear about what changes you made and why. Link to any related issues. Use a concise and descriptive title for your PR.</p>
</li>
</ol>
<h2 id="heading-common-mistakes-to-avoid"><strong>Common Mistakes to Avoid</strong></h2>
<ol>
<li><p><strong>Understanding issues and PR guidelines</strong></p>
<p> Always read the project’s contributing guidelines before submitting PRs. Follow the maintainers' instructions on formatting and coding style.</p>
</li>
<li><p><strong>Avoiding low-quality or spammy contributions</strong></p>
<p> Don’t submit trivial changes just for the sake of completing Hacktoberfest. Only meaningful contributions will count.</p>
</li>
<li><p><strong>Properly communicating with maintainers</strong></p>
<p> When opening an issue or PR, be polite and respectful. Ask for feedback or clarification when necessary.</p>
</li>
</ol>
<h2 id="heading-navigating-hacktoberfest-challenges"><strong>Navigating Hacktoberfest Challenges</strong></h2>
<ol>
<li><p><strong>Solving merge conflicts</strong></p>
<p> A merge conflict happens when two people make changes to the same line of code. To resolve it, edit the conflicting file, remove the conflict markers, and commit the changes.</p>
</li>
<li><p><strong>Dealing with rejected pull requests</strong></p>
<p> If your PR is rejected, don’t get discouraged. Review the feedback, make improvements, and resubmit. It’s part of the learning process.</p>
</li>
<li><p><strong>How to ask for help (community forums, GitHub discussions, ask to maintainers etc.)</strong></p>
<p> If you’re stuck, don’t hesitate to ask for help on community forums or GitHub discussions. Be specific about what you need help with.</p>
</li>
</ol>
<h2 id="heading-completing-hacktoberfest"><strong>Completing Hacktoberfest</strong></h2>
<ol>
<li><p><strong>Tracking your progress:</strong></p>
<p> Once you register for Hacktoberfest, your contributions are automatically tracked on the official website. Make sure your pull requests are accepted before the deadline.</p>
</li>
<li><p><strong>Submitting the required pull requests:</strong></p>
<p> Complete 6 valid pull requests to qualify for the rewards. Contributions across multiple repositories count.</p>
</li>
<li><p><strong>What happens after you complete Hacktoberfest? (swag, certificates, etc.):</strong></p>
<p> Once you successfully complete Hacktoberfest, you will be eligible to claim swag (like a digital badges) or donate a tree. You’ll also receive a digital certificate of completion.</p>
</li>
</ol>
<h2 id="heading-post-hacktoberfest-continuing-your-open-source-journey"><strong>Post-Hacktoberfest: Continuing Your Open Source Journey</strong></h2>
<ol>
<li><p><strong>How to stay involved in open source projects</strong></p>
<p> Keep contributing to projects that interest you. Hacktoberfest is just the beginning of your open source journey.</p>
</li>
<li><p><strong>Finding new projects to contribute to</strong></p>
<p> Explore GitHub’s <code>Explore</code> tab or join open source communities to find new projects. Most open source projects welcome year-round contributions.</p>
<p> Link: <a target="_blank" href="https://github.com/explore">https://github.com/explore</a></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675273594/22ddea7a-c0cf-442c-8359-7a71c24accc4.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Building your portfolio through contributions</strong></p>
<p> Your GitHub profile is like a resume. Keep working on meaningful projects and build a strong portfolio that showcases your skills.</p>
</li>
</ol>
<h2 id="heading-join-our-community">Join our community:</h2>
<p><strong>DevsDeialogue</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759675292586/636379b0-d126-4c88-80d6-76c82bb8d6e3.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Github</strong>: <a target="_blank" href="https://github.com/DevsDialogue">https://github.com/DevsDialogue</a></p>
</li>
<li><p><strong>Discord</strong>: <a target="_blank" href="https://discord.gg/8g8Mwh7S">https://discord.gg/Q4t66h38</a></p>
</li>
</ol>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<blockquote>
<p>Whether you're an experienced developer or just starting out, Hacktoberfest 2025 is a great way to get involved in open source. You'll learn, grow, and make meaningful contributions to the developer community.</p>
<p>Open source is more than just Hacktoberfest. It's a year-round opportunity, and you can contribute to any open source project at any time based on your interest.</p>
<p><strong>Happy Hacking! 🎃</strong></p>
<p><em>Thanks for reading and happy contributing to Hacktoberfest 2025!</em></p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Python For DevOps: Part 1]]></title><description><![CDATA[Introduction
Python is a programming language which is:

Easy to learn

simple syntax

easy to setup



Large ecosystem

many libraries

large community



Flexible

you are not limited to language specifics



What Python is used for:

Web Developme...]]></description><link>https://blog.surajdev.tech/python-for-devops-part-1</link><guid isPermaLink="true">https://blog.surajdev.tech/python-for-devops-part-1</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[python beginner]]></category><category><![CDATA[Devops]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[PYTHON FOR DEVOPS]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Tue, 06 Aug 2024 08:24:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1722795727932/87a45a67-d9e8-42f5-81a0-d56c8ded3cf3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>Python is a programming language which is:</p>
<ol>
<li><p><strong>Easy to learn</strong></p>
<ul>
<li><p>simple syntax</p>
</li>
<li><p>easy to setup</p>
</li>
</ul>
</li>
<li><p><strong>Large ecosystem</strong></p>
<ul>
<li><p>many libraries</p>
</li>
<li><p>large community</p>
</li>
</ul>
</li>
<li><p><strong>Flexible</strong></p>
<ul>
<li>you are not limited to language specifics</li>
</ul>
</li>
</ol>
<p><strong>What Python is used for:</strong></p>
<ul>
<li><p>Web Development</p>
</li>
<li><p>Data Science</p>
</li>
<li><p>Machine Learning</p>
</li>
<li><p>Artificial Intelligence</p>
</li>
<li><p>Web Scrapping</p>
</li>
<li><p>Automation</p>
<ul>
<li><p>Like automating DevOps tasks</p>
</li>
<li><p>Automating general tasks</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-why-python-with-devops"><strong>Why Python with DevOps?</strong></h3>
<p>As an approach to culture, platform, and automation, Python is an important language for DevOps engineers or teams working to automate repetitive tasks, infrastructure management, provisioning, API driven deployment.</p>
<h2 id="heading-setup-python-locally-in-ubuntu">Setup python locally in Ubuntu</h2>
<p>Head over to the official Python <a target="_blank" href="https://www.python.org/downloads/"><mark>website</mark></a> and download the latest version of it according to your operating system.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1722840414640/500f342f-d857-4d49-ade0-1e01d1c0829e.png" alt class="image--center mx-auto" /></p>
<p><strong>Check that the Python is downloaded to your machine:</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment"># this comamand is for Linux users</span>
python3

<span class="hljs-comment"># Checking the Python Path</span>
<span class="hljs-built_in">which</span> python3
</code></pre>
<h1 id="heading-python-fundamentals">Python Fundamentals:</h1>
<h3 id="heading-print-function">Print Function</h3>
<p>The <code>print()</code> function in Python is used to output text or other data to the console.</p>
<ol>
<li><p><strong>objects</strong>: Any number of objects to be printed. Multiple objects are separated by a space by default.</p>
</li>
<li><p><strong>sep</strong>: A string inserted between each object. The default is a space.</p>
</li>
<li><p><strong>end</strong>: A string appended after the last object. The default is a newline.</p>
</li>
<li><p><strong>file</strong>: A file-like object (stream). The default is <code>sys.stdout</code>.</p>
</li>
</ol>
<pre><code class="lang-python"><span class="hljs-comment"># Basic usage</span>
print(<span class="hljs-string">"Hello, world!"</span>)

<span class="hljs-comment"># Printing multiple items</span>
print(<span class="hljs-string">"The answer is"</span>, <span class="hljs-number">42</span>)

<span class="hljs-comment"># Changing the separator</span>
print(<span class="hljs-string">"apple"</span>, <span class="hljs-string">"banana"</span>, <span class="hljs-string">"cherry"</span>, sep=<span class="hljs-string">", "</span>)

<span class="hljs-comment"># Changing the end character</span>
print(<span class="hljs-string">"Hello"</span>, end=<span class="hljs-string">" "</span>)
print(<span class="hljs-string">"world!"</span>)

<span class="hljs-comment"># Printing to a file</span>
<span class="hljs-keyword">with</span> open(<span class="hljs-string">"output.txt"</span>, <span class="hljs-string">"w"</span>) <span class="hljs-keyword">as</span> f:
    print(<span class="hljs-string">"Hello, file!"</span>, file=f)

<span class="hljs-comment"># This is the Output: Hello, file!</span>

<span class="hljs-comment"># Using formatted strings aka f-strings</span>
name = <span class="hljs-string">"Alice"</span>
age = <span class="hljs-number">30</span>
print(<span class="hljs-string">f"My name is <span class="hljs-subst">{name}</span> and I am <span class="hljs-subst">{age}</span> years old."</span>)
</code></pre>
<h3 id="heading-literals">Literals</h3>
<p>A <strong>literal</strong> is a notation for representing a fixed value directly in the source code. Here is an example of a literal:</p>
<pre><code class="lang-python"><span class="hljs-comment"># Integer Literal:</span>
<span class="hljs-number">93</span>
<span class="hljs-comment"># Floating-point Literal:</span>
<span class="hljs-number">3.14</span>
<span class="hljs-comment"># String Literal:</span>
<span class="hljs-string">"Hello, Suraj!"</span>
<span class="hljs-comment"># Boolean Literal</span>
<span class="hljs-literal">True</span>
<span class="hljs-comment"># None Literal: This represents the absesce of a value or null value</span>
<span class="hljs-literal">None</span>
<span class="hljs-comment"># Lits Literal:</span>
[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>]

<span class="hljs-comment"># Simple program for literals</span>
integer_literal = <span class="hljs-number">42</span>
string_literal = <span class="hljs-string">"Hello"</span>
print(integer_literal, string_literal)
</code></pre>
<h3 id="heading-variable">Variable</h3>
<p>A variable is a named storage location in memory that holds a value that can be changed during program execution.</p>
<p><strong>Variable Rules in Python</strong></p>
<ol>
<li><p><strong>Names can contain letters, digits, and underscores</strong>: e.g., <code>my_variable1</code>.</p>
</li>
<li><p><strong>Names must start with a letter or an underscore</strong>: e.g., <code>_variable</code> or <code>variable1</code>.</p>
</li>
<li><p><strong>Names cannot start with a digit</strong>: e.g., <code>1variable</code> is invalid.</p>
</li>
<li><p><strong>Names are case-sensitive</strong>: e.g., <code>Variable</code> and <code>variable</code> are different.</p>
</li>
<li><p><strong>Cannot use Python reserved keywords</strong>: e.g., <code>class</code>, <code>def</code>, <code>if</code>, etc.</p>
</li>
</ol>
<p><strong>Naming Convention:</strong><br />Naming conventions is a convention(generally agreed scheme) for naming variables.</p>
<ul>
<li>Use <strong>lowercase</strong> with words separated with <strong>Underscores</strong></li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program using variables</span>
my_number1 = <span class="hljs-number">10</span>
my_number2 = <span class="hljs-number">20</span>
print(<span class="hljs-string">"First No."</span>, my_number1, <span class="hljs-string">"Second No."</span>, my_number2)
</code></pre>
<h3 id="heading-keywords">Keywords</h3>
<p>Keywords in Python are reserved words that have special meaning and cannot be used as identifiers (variable names, function names, etc.). You don't need to remember all these <code>keywords</code> I just put it over here for reference.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Keyword</strong></td><td><strong>Description</strong></td></tr>
</thead>
<tbody>
<tr>
<td><code>False</code></td><td>Boolean false value.</td></tr>
<tr>
<td><code>None</code></td><td>Represents the absence of a value or a null value.</td></tr>
<tr>
<td><code>True</code></td><td>Boolean true value.</td></tr>
<tr>
<td><code>and</code></td><td>Logical AND operator.</td></tr>
<tr>
<td><code>as</code></td><td>Used to create an alias.</td></tr>
<tr>
<td><code>assert</code></td><td>Used for debugging purposes to test if a condition is true.</td></tr>
<tr>
<td><code>async</code></td><td>Defines an asynchronous function (coroutine).</td></tr>
<tr>
<td><code>await</code></td><td>Waits for the completion of an asynchronous function.</td></tr>
<tr>
<td><code>break</code></td><td>Exits a loop prematurely.</td></tr>
<tr>
<td><code>class</code></td><td>Defines a class.</td></tr>
<tr>
<td><code>continue</code></td><td>Skips the rest of the current loop iteration and moves to the next iteration.</td></tr>
<tr>
<td><code>def</code></td><td>Defines a function.</td></tr>
<tr>
<td><code>del</code></td><td>Deletes an object.</td></tr>
<tr>
<td><code>elif</code></td><td>Else if condition in control statements.</td></tr>
<tr>
<td><code>else</code></td><td>Else condition in control statements.</td></tr>
<tr>
<td><code>except</code></td><td>Catches exceptions in a try block.</td></tr>
<tr>
<td><code>finally</code></td><td>Executes code after a try block, regardless of whether an exception occurred.</td></tr>
<tr>
<td><code>for</code></td><td>Starts a for loop.</td></tr>
<tr>
<td><code>from</code></td><td>Imports specific parts of a module.</td></tr>
<tr>
<td><code>global</code></td><td>Declares a global variable.</td></tr>
<tr>
<td><code>if</code></td><td>Starts an if condition.</td></tr>
<tr>
<td><code>import</code></td><td>Imports a module.</td></tr>
<tr>
<td><code>in</code></td><td>Check if a value is present in a sequence.</td></tr>
<tr>
<td><code>is</code></td><td>Tests for object identity.</td></tr>
<tr>
<td><code>lambda</code></td><td>Creates an anonymous function.</td></tr>
<tr>
<td><code>nonlocal</code></td><td>Declares a non-local variable.</td></tr>
<tr>
<td><code>not</code></td><td>Logical NOT operator.</td></tr>
<tr>
<td><code>or</code></td><td>Logical OR operator.</td></tr>
<tr>
<td><code>pass</code></td><td>A null statement; does nothing.</td></tr>
<tr>
<td><code>raise</code></td><td>Raises an exception.</td></tr>
<tr>
<td><code>return</code></td><td>Exits a function and returns a value.</td></tr>
<tr>
<td><code>try</code></td><td>Starts a try block for exception handling.</td></tr>
<tr>
<td><code>while</code></td><td>Starts a while loop.</td></tr>
<tr>
<td><code>with</code></td><td>Used to simplify exception handling.</td></tr>
<tr>
<td><code>yield</code></td><td>Pauses a function and returns an intermediate value; used in generators.</td></tr>
</tbody>
</table>
</div><h3 id="heading-expressions-and-statements">Expressions and statements</h3>
<p><strong>Expressions</strong> are code segments that evaluate a value, while <strong>statements</strong> are instructions that perform an action in a program. A program is made up of several statements.</p>
<pre><code class="lang-python"><span class="hljs-comment"># These are the exmaple of Expressions:</span>

<span class="hljs-comment"># 1. Arithmetic expression:</span>
<span class="hljs-number">2</span>+<span class="hljs-number">3</span>
<span class="hljs-comment"># 2. String concatination</span>
<span class="hljs-string">"Hello, "</span>+<span class="hljs-string">" World!"</span>
<span class="hljs-comment"># 3. Function call expression:</span>
len(<span class="hljs-string">"example"</span>)
<span class="hljs-comment"># 4. Boolean expression:</span>
<span class="hljs-number">5</span>&gt;<span class="hljs-number">2</span>
<span class="hljs-comment"># List indexing:</span>
my_list[<span class="hljs-number">1</span>]

<span class="hljs-comment"># Simple program with expressions and statements</span>

a = <span class="hljs-number">5</span>  <span class="hljs-comment"># this is a statement (assignment statement with an expression on the right side)</span>
b = <span class="hljs-number">10</span>  <span class="hljs-comment"># this is a statement (assignment statement with an expression on the right side)</span>
result = a + b  <span class="hljs-comment"># this is a statement (assignment statement with an expression on the right side)</span>
print(<span class="hljs-string">"Result:"</span>, result)  <span class="hljs-comment"># this is a statement (function call statement with an expression as an argument)</span>
</code></pre>
<h3 id="heading-comments">Comments</h3>
<p>Comments in Python are used to explain code logic, making it easier for others to understand what the code does. It also helps to document the code’s purpose, usage, and functionality and enhances maintainability by making the code simpler to manage and update.</p>
<p><strong>Comments are of two types:</strong></p>
<ol>
<li><strong>Simple Line Comments</strong> that start with '#' and below is an example.</li>
</ol>
<pre><code class="lang-python">x = <span class="hljs-number">10</span>  <span class="hljs-comment"># Assigning 10 to x</span>
print(x)  <span class="hljs-comment"># Printing the value of x</span>
</code></pre>
<ol start="2">
<li><strong>Multi-line Comments</strong>: that uses triple quotes (<code>'''</code> or <code>"""</code>).</li>
</ol>
<pre><code class="lang-python"><span class="hljs-string">"""
This is a multi-line comment.
Hi there suraj this side.
"""</span>
</code></pre>
<h3 id="heading-indentation-in-python">Indentation in Python</h3>
<p>Indentation means spacing in statements in Python is very important. For example, in below code snippet below, you can see the print function has a lot more space from its original position which will give an <code>IndentationError: unexpected indent</code> .</p>
<pre><code class="lang-python"><span class="hljs-comment"># This program will give indentation error</span>
name = <span class="hljs-string">"Suraj"</span>
   print(name)
</code></pre>
<h3 id="heading-data-types">Data Types</h3>
<p>Different data types can do different things: We will see two immutable data types in this blog rest of all we'll learn in the journey...</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1722925612763/e8490a12-e6ec-4818-a457-4c8e03cb1a1a.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-number-data-types">Number Data Types</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with number data types</span>
pi = <span class="hljs-number">3.14</span>
print(<span class="hljs-string">"Pi:"</span>, pi)

<span class="hljs-comment"># Output: 3.14</span>
</code></pre>
<h3 id="heading-strings-data-types">Strings Data Types</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with strings</span>
message = <span class="hljs-string">"Hello, Python!"</span>
print(message)
</code></pre>
<h3 id="heading-string-concatenation">String Concatenation</h3>
<p>Adding strings together.</p>
<pre><code class="lang-python"><span class="hljs-comment"># String Concatenation program</span>
print(<span class="hljs-string">"Hello Suraj"</span> + <span class="hljs-string">"Are you learning Python?"</span>) <span class="hljs-comment"># we concatenate using '+' symbol</span>
</code></pre>
<p><strong>Instead of writing above style, we can use</strong><code>f-string</code><strong>:</strong></p>
<pre><code class="lang-python"><span class="hljs-comment"># This is a formatted string literal, introduced in Python 3.6</span>
print(<span class="hljs-string">f"Hello Suraj, are you <span class="hljs-subst">{<span class="hljs-number">21</span>}</span> years old?"</span>)

<span class="hljs-comment"># Output:</span>
Hello Suraj, are you <span class="hljs-number">21</span> years old?
</code></pre>
<h3 id="heading-string-methods">String Methods</h3>
<p>String methods...</p>
<ol>
<li><p><strong>upper()</strong>: Used to convert all characters in a string to uppercase.</p>
<pre><code class="lang-python">   <span class="hljs-comment"># Convert to uppercase</span>
   message = <span class="hljs-string">"hello, python!"</span>
   print(message.upper())

   <span class="hljs-comment"># Output:</span>
   HELLO, PYTHON!
</code></pre>
</li>
<li><p><strong>lower()</strong>: Convert all characters in a string to lowercase.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Convert to lowercase</span>
 message = <span class="hljs-string">"HELLO, PYTHON!"</span>
 print(message.lower())

 <span class="hljs-comment"># Output:</span>
 hello, python!
</code></pre>
</li>
<li><p><strong>strip()</strong>: Remove leading and trailing whitespace.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Remove whitespace</span>
 message = <span class="hljs-string">"   hello, python!   "</span>
 print(message.strip())

 <span class="hljs-comment"># Output:</span>
 hello, python!
</code></pre>
</li>
<li><p><strong>replace()</strong>: Replace a substring with another substring.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Replace substring</span>
 message = <span class="hljs-string">"hello, python!"</span>
 print(message.replace(<span class="hljs-string">"python"</span>, <span class="hljs-string">"world"</span>))

 <span class="hljs-comment"># Output:</span>
 hello, world!
</code></pre>
</li>
<li><p><strong>split()</strong>: Split a string into a list of substrings.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Split string into list</span>
 message = <span class="hljs-string">"hello, python!"</span>
 words = message.split()
 print(words)

 <span class="hljs-comment"># Output:</span>
 [<span class="hljs-string">'hello,'</span>, <span class="hljs-string">'python!'</span>]
</code></pre>
</li>
<li><p><strong>join()</strong>: Join elements of a list into a string.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Join list into string</span>
 words = [<span class="hljs-string">"hello"</span>, <span class="hljs-string">"python"</span>]
 message = <span class="hljs-string">" "</span>.join(words)
 print(message)

 <span class="hljs-comment"># Output:</span>
 hello python
</code></pre>
</li>
<li><p><strong>find()</strong>: Find the first occurrence of a substring.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Find substring</span>
 message = <span class="hljs-string">"hello, python!"</span>
 position = message.find(<span class="hljs-string">"python"</span>)
 print(<span class="hljs-string">"Position of 'python':"</span>, position)

 <span class="hljs-comment"># Output:</span>
 Position of <span class="hljs-string">'python'</span>: <span class="hljs-number">7</span>
</code></pre>
</li>
<li><p><strong>count()</strong>: Count the number of occurrences of a substring.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Count occurrences of substring</span>
 message = <span class="hljs-string">"hello, python! python is fun!"</span>
 count = message.count(<span class="hljs-string">"python"</span>)
 print(<span class="hljs-string">"Occurrences of 'python':"</span>, count)

 <span class="hljs-comment"># Output:</span>
 Occurrences of <span class="hljs-string">'python'</span>: <span class="hljs-number">2</span>
</code></pre>
</li>
<li><p><strong>capitalize()</strong>: Capitalize the first character of the string.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Capitalize first character</span>
 message = <span class="hljs-string">"hello, python!"</span>
 print(message.capitalize())

 <span class="hljs-comment"># Output:</span>
 Hello, python!
</code></pre>
</li>
<li><p><strong>title()</strong>: Capitalize the first character of each word.</p>
<pre><code class="lang-python"><span class="hljs-comment"># Capitalize first character of each word</span>
message = <span class="hljs-string">"hello, python!"</span>
print(message.title())

<span class="hljs-comment"># Output:</span>
Hello, Python!
</code></pre>
</li>
<li><p><strong>swapcase()</strong>: Swap the case of all characters in the string.</p>
<pre><code class="lang-python"><span class="hljs-comment"># Swap case of characters</span>
message = <span class="hljs-string">"Hello, Python!"</span>
print(message.swapcase())
</code></pre>
</li>
</ol>
<h3 id="heading-escaping-characters">Escaping Characters</h3>
<p><strong>Escaping characters</strong> in Python allows you to include special characters in strings that would otherwise be difficult or impossible to include directly. This is done using a backslash (<code>\</code>) followed by the character you want to escape.</p>
<pre><code class="lang-python"><span class="hljs-comment"># 1. Using a newline character(\n)</span>
print(<span class="hljs-string">"Hello\nSuraj"</span>)
<span class="hljs-comment">#Output:</span>
Hello
Suraj

<span class="hljs-comment"># 2. Tab Character(\t)</span>
print(<span class="hljs-string">"Hell0\tSuraj"</span>)
<span class="hljs-comment"># Output:</span>
Hello    Wolrd

<span class="hljs-comment"># 3. Backslash Character(\\)</span>
print(<span class="hljs-string">"This is a backslash: \\"</span>)
<span class="hljs-comment"># Output:</span>
This <span class="hljs-keyword">is</span> a backslash: \ <span class="hljs-comment"># This is the output because, The \\ sequence inserts a single backslash.</span>

<span class="hljs-comment"># 4. Single Qoute(\') and Double Qoute(\")</span>
print(<span class="hljs-string">'I said, \'This is single qoute!\''</span>)
print(<span class="hljs-string">"I said, \"This is double qoute!\""</span>)
<span class="hljs-comment"># Output:</span>
He said, <span class="hljs-string">'Hello, World!'</span>
He said, <span class="hljs-string">"Hello, World!"</span>

<span class="hljs-comment"># 5. Carriage Return(\r)</span>
print(<span class="hljs-string">"Hello\rBro"</span>)
<span class="hljs-comment"># Output:</span>
Bro <span class="hljs-comment"># The \r character moves the cursor to the beginning of the line, so "Bro" overwrites "Hello.</span>

<span class="hljs-comment"># 6. Bell/Alert(\a)</span>
print(<span class="hljs-string">"Hello\aBro"</span>)
<span class="hljs-comment"># Output: You might hear a beep sound, and the text "HelloBro" will be printed. BecauseThe \a character triggers the system bell (alert).</span>
</code></pre>
<h3 id="heading-string-characters-amp-slicing">String Characters &amp; Slicing</h3>
<p>A string is a sequence of characters. Each character in a string can be accessed using its index. Python strings are zero-indexed, meaning the first character has an index <code>0</code>, the second character has an index <code>1</code>, and so on.</p>
<pre><code class="lang-python">text = <span class="hljs-string">"Python"</span>
print(text[<span class="hljs-number">0</span>])  <span class="hljs-comment"># Output: P</span>
print(text[<span class="hljs-number">1</span>])  <span class="hljs-comment"># Output: y</span>
print(text[<span class="hljs-number">-1</span>]) <span class="hljs-comment"># Output: n (negative indexing starts from the end)</span>
</code></pre>
<h3 id="heading-string-slicing">String Slicing</h3>
<p>String slicing allows you to extract a portion of a string by specifying a start and end index. The syntax for slicing is: <code>string[start:stop:step]</code></p>
<h4 id="heading-examples-of-slicing">Examples of Slicing</h4>
<pre><code class="lang-python"><span class="hljs-comment"># Basic Slicing</span>
text = <span class="hljs-string">"Python"</span>
print(text[<span class="hljs-number">1</span>:<span class="hljs-number">4</span>])  <span class="hljs-comment"># Output: yth</span>

<span class="hljs-comment"># Omitting Start or Stop</span>
text = <span class="hljs-string">"Python"</span>
print(text[:<span class="hljs-number">4</span>])  <span class="hljs-comment"># Output: Pyth (Omits the start index, starts from the beginning)</span>
print(text[<span class="hljs-number">2</span>:])  <span class="hljs-comment"># Output: thon (Omits the end index, goes till the end)</span>

<span class="hljs-comment"># Using Step</span>
text = <span class="hljs-string">"Python"</span>
print(text[::<span class="hljs-number">2</span>])  <span class="hljs-comment"># Output: Pto (Takes every 2nd character)</span>

<span class="hljs-comment"># Negative Indices and Slicing</span>
text = <span class="hljs-string">"Python"</span>
print(text[<span class="hljs-number">-5</span>:<span class="hljs-number">-1</span>])  <span class="hljs-comment"># Output: ytho (From index -5 to -2, -1 is not included)</span>
print(text[::<span class="hljs-number">-1</span>])   <span class="hljs-comment"># Output: nohtyP (Reverses the string)</span>

<span class="hljs-comment"># Reversing a String</span>
text = <span class="hljs-string">"Python"</span>
reversed_text = text[::<span class="hljs-number">-1</span>]
print(reversed_text)  <span class="hljs-comment"># Output: nohtyP</span>
</code></pre>
<h3 id="heading-booleans">Booleans</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with booleans</span>
is_active = <span class="hljs-literal">True</span>
print(<span class="hljs-string">"Is active:"</span>, is_active)

<span class="hljs-comment"># Output:</span>
</code></pre>
<h3 id="heading-build-in-functions">Build-In Functions</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program using built-in functions</span>
message = <span class="hljs-string">"Hello, Python!"</span>
print(<span class="hljs-string">"Length of message:"</span>, len(message))

<span class="hljs-comment"># Output:</span>
</code></pre>
<h3 id="heading-enums">Enums</h3>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum

<span class="hljs-comment"># Define an enum for days of the week</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Day</span>(<span class="hljs-params">Enum</span>):</span>
    MONDAY = <span class="hljs-number">1</span>
    TUESDAY = <span class="hljs-number">2</span>
    WEDNESDAY = <span class="hljs-number">3</span>
    THURSDAY = <span class="hljs-number">4</span>
    FRIDAY = <span class="hljs-number">5</span>
    SATURDAY = <span class="hljs-number">6</span>
    SUNDAY = <span class="hljs-number">7</span>

<span class="hljs-comment"># Accessing enum members</span>
print(Day.MONDAY)            <span class="hljs-comment"># Output: Day.MONDAY</span>
print(Day.MONDAY.name)       <span class="hljs-comment"># Output: MONDAY</span>
print(Day.MONDAY.value)      <span class="hljs-comment"># Output: 1</span>

<span class="hljs-comment"># Iterating over enum members</span>
<span class="hljs-keyword">for</span> day <span class="hljs-keyword">in</span> Day:
    print(day.name, day.value)

<span class="hljs-comment"># this is the Output:</span>
<span class="hljs-string">"""
MONDAY 1
TUESDAY 2
WEDNESDAY 3
THURSDAY 4
FRIDAY 5
SATURDAY 6
SUNDAY 7
"""</span>
</code></pre>
<h3 id="heading-user-input">User input</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with user input</span>
name = input(<span class="hljs-string">"Enter your name: "</span>)
print(<span class="hljs-string">f"Hello, <span class="hljs-subst">{name}</span>"</span>)

<span class="hljs-comment"># Output:</span>
<span class="hljs-comment"># Enter your name: Suraj # In console</span>
<span class="hljs-comment"># Hello, Suraj # actual output after entring name</span>
</code></pre>
<h1 id="heading-logic-and-bit-operators">Logic and Bit operators</h1>
<h3 id="heading-operators">Operators</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with operators</span>
result = <span class="hljs-number">10</span> + <span class="hljs-number">5</span>
print(<span class="hljs-string">"Result of addition:"</span>, result)Logic <span class="hljs-keyword">and</span> Bit operators

Operators

<span class="hljs-comment"># Simple program with operators</span>
result = <span class="hljs-number">10</span> + <span class="hljs-number">5</span>
print(<span class="hljs-string">"Result of addition:"</span>, result)

<span class="hljs-comment"># Output:</span>

Arithmetic Operators

<span class="hljs-comment"># Simple program with arithmetic operators</span>
quotient = <span class="hljs-number">10</span> / <span class="hljs-number">2</span>
print(<span class="hljs-string">"Quotient:"</span>, quotient)

<span class="hljs-comment"># Output:</span>

Comparison Operators

<span class="hljs-comment"># Simple program with comparison operators</span>
is_equal = (<span class="hljs-number">10</span> == <span class="hljs-number">10</span>)
print(<span class="hljs-string">"10 is equal to 10:"</span>, is_equal)

<span class="hljs-comment"># Output:</span>

Boolean Operators

<span class="hljs-comment"># Simple program with boolean operators</span>
result = <span class="hljs-literal">True</span> <span class="hljs-keyword">and</span> <span class="hljs-literal">False</span>
print(<span class="hljs-string">"True and False:"</span>, result)

<span class="hljs-comment"># Output:</span>

Bitwise Operators

<span class="hljs-comment"># Simple program with bitwise operators</span>
bitwise_result = <span class="hljs-number">5</span> &amp; <span class="hljs-number">3</span>
print(<span class="hljs-string">"5 AND 3:"</span>, bitwise_result)

<span class="hljs-comment"># Output:</span>

<span class="hljs-keyword">is</span> &amp; <span class="hljs-keyword">in</span> Operators

<span class="hljs-comment"># Simple program with 'is' and 'in' operators</span>
x = <span class="hljs-number">5</span>
y = <span class="hljs-number">5</span>
is_same = (x <span class="hljs-keyword">is</span> y)
contains = <span class="hljs-string">'a'</span> <span class="hljs-keyword">in</span> <span class="hljs-string">'apple'</span>
print(<span class="hljs-string">"x is y:"</span>, is_same)
print(<span class="hljs-string">"'a' in 'apple':"</span>, contains)

<span class="hljs-comment"># Output:</span>

Ternary Operator

<span class="hljs-comment"># Simple program with ternary operator</span>
x = <span class="hljs-number">10</span>
result = <span class="hljs-string">"Even"</span> <span class="hljs-keyword">if</span> x % <span class="hljs-number">2</span> == <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"Odd"</span>
print(<span class="hljs-string">"x is:"</span>, result)

<span class="hljs-comment"># Output</span>

Control Flow - Conditional Blocks &amp; Loops:

Conditional Statements:

<span class="hljs-keyword">if</span> Statement: Executes a block of code <span class="hljs-keyword">if</span> a specified condition <span class="hljs-keyword">is</span> true.

<span class="hljs-comment"># Simple if statement</span>
x = <span class="hljs-number">10</span>
<span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">0</span>:
    print(<span class="hljs-string">"Positive"</span>)

<span class="hljs-comment"># Output:</span>
Positive

<span class="hljs-keyword">if</span>-<span class="hljs-keyword">else</span> Statement: Executes one block of code <span class="hljs-keyword">if</span> a condition <span class="hljs-keyword">is</span> true, <span class="hljs-keyword">and</span> another block of code <span class="hljs-keyword">if</span> the condition <span class="hljs-keyword">is</span> false.

<span class="hljs-comment"># Simple if-else statement</span>
x = <span class="hljs-number">-5</span>
<span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">0</span>:
    print(<span class="hljs-string">"Positive"</span>)
<span class="hljs-keyword">else</span>:
    print(<span class="hljs-string">"Non-positive"</span>)

<span class="hljs-comment"># Output</span>
Non-positive

<span class="hljs-keyword">if</span>-<span class="hljs-keyword">elif</span>-<span class="hljs-keyword">else</span> Statement: Executes different blocks of code based on multiple conditions.

<span class="hljs-comment"># Simple if-elif-else statement</span>
x = <span class="hljs-number">0</span>
<span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">0</span>:
    print(<span class="hljs-string">"Positive"</span>)
<span class="hljs-keyword">elif</span> x &lt; <span class="hljs-number">0</span>:
    print(<span class="hljs-string">"Negative"</span>)
<span class="hljs-keyword">else</span>:
    print(<span class="hljs-string">"Zero"</span>)

<span class="hljs-comment"># Output:</span>
Zero

Loops:

<span class="hljs-keyword">while</span> Loop: Repeats a block of code <span class="hljs-keyword">as</span> long <span class="hljs-keyword">as</span> a specified condition <span class="hljs-keyword">is</span> true.

<span class="hljs-comment"># Simple while loop</span>
count = <span class="hljs-number">1</span>
<span class="hljs-keyword">while</span> count &lt;= <span class="hljs-number">5</span>:
    print(<span class="hljs-string">"Count:"</span>, count)
    count += <span class="hljs-number">1</span>

<span class="hljs-comment"># Output:</span>
Count: <span class="hljs-number">1</span> 
Count: <span class="hljs-number">2</span> 
Count: <span class="hljs-number">3</span> 
Count: <span class="hljs-number">4</span> 
Count: <span class="hljs-number">5</span>

<span class="hljs-keyword">for</span> Loop: Iterates over a sequence (such <span class="hljs-keyword">as</span> a list, tuple, <span class="hljs-keyword">or</span> string).

<span class="hljs-comment"># Simple for loop</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
    print(<span class="hljs-string">"Iteration:"</span>, i)

<span class="hljs-comment"># Output:</span>
Iteration: <span class="hljs-number">0</span>
Iteration: <span class="hljs-number">1</span>
Iteration: <span class="hljs-number">2</span>
Iteration: <span class="hljs-number">3</span>
Iteration: <span class="hljs-number">4</span>
</code></pre>
<h3 id="heading-arithmetic-operators">Arithmetic Operators</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with arithmetic operators</span>
quotient = <span class="hljs-number">10</span> / <span class="hljs-number">2</span>
print(<span class="hljs-string">"Quotient:"</span>, quotient)
</code></pre>
<h3 id="heading-comparison-operators">Comparison Operators</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with comparison operators</span>
is_equal = (<span class="hljs-number">10</span> == <span class="hljs-number">10</span>)
print(<span class="hljs-string">"10 is equal to 10:"</span>, is_equal)
</code></pre>
<h3 id="heading-boolean-operators">Boolean Operators</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with boolean operators</span>
result = <span class="hljs-literal">True</span> <span class="hljs-keyword">and</span> <span class="hljs-literal">False</span>
print(<span class="hljs-string">"True and False:"</span>, result)
</code></pre>
<h3 id="heading-bitwise-operators">Bitwise Operators</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with bitwise operators</span>
bitwise_result = <span class="hljs-number">5</span> &amp; <span class="hljs-number">3</span>
print(<span class="hljs-string">"5 AND 3:"</span>, bitwise_result)

<span class="hljs-comment"># Output:</span>
</code></pre>
<h3 id="heading-is-amp-in-operators">is &amp; in Operators</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with 'is' and 'in' operators</span>
x = <span class="hljs-number">5</span>
y = <span class="hljs-number">5</span>
is_same = (x <span class="hljs-keyword">is</span> y)
contains = <span class="hljs-string">'a'</span> <span class="hljs-keyword">in</span> <span class="hljs-string">'apple'</span>
print(<span class="hljs-string">"x is y:"</span>, is_same)
print(<span class="hljs-string">"'a' in 'apple':"</span>, contains)

<span class="hljs-comment"># Output:</span>
</code></pre>
<h3 id="heading-ternary-operator">Ternary Operator</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Simple program with ternary operator</span>
x = <span class="hljs-number">10</span>
result = <span class="hljs-string">"Even"</span> <span class="hljs-keyword">if</span> x % <span class="hljs-number">2</span> == <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"Odd"</span>
print(<span class="hljs-string">"x is:"</span>, result)

<span class="hljs-comment"># Output</span>
</code></pre>
<h1 id="heading-control-flow-conditional-blocks-amp-loops">Control Flow - Conditional Blocks &amp; Loops:</h1>
<h3 id="heading-conditional-statements">Conditional Statements:</h3>
<ol>
<li><p><strong>if Statement</strong>: Executes a block of code if a specified condition is true.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Simple if statement</span>
 x = <span class="hljs-number">10</span>
 <span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">0</span>:
     print(<span class="hljs-string">"Positive"</span>)

 <span class="hljs-comment"># Output:</span>
 Positive
</code></pre>
</li>
<li><p><strong>if-else Statement</strong>: Executes one block of code if a condition is true, and another block of code if the condition is false.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Simple if-else statement</span>
 x = <span class="hljs-number">-5</span>
 <span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">0</span>:
     print(<span class="hljs-string">"Positive"</span>)
 <span class="hljs-keyword">else</span>:
     print(<span class="hljs-string">"Non-positive"</span>)

 <span class="hljs-comment"># Output</span>
 Non-positive
</code></pre>
</li>
<li><p><strong>if-elif-else Statement</strong>: Executes different blocks of code based on multiple conditions.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Simple if-elif-else statement</span>
 x = <span class="hljs-number">0</span>
 <span class="hljs-keyword">if</span> x &gt; <span class="hljs-number">0</span>:
     print(<span class="hljs-string">"Positive"</span>)
 <span class="hljs-keyword">elif</span> x &lt; <span class="hljs-number">0</span>:
     print(<span class="hljs-string">"Negative"</span>)
 <span class="hljs-keyword">else</span>:
     print(<span class="hljs-string">"Zero"</span>)

 <span class="hljs-comment"># Output:</span>
 Zero
</code></pre>
</li>
</ol>
<h3 id="heading-loops">Loops:</h3>
<ol>
<li><p><strong>while Loop</strong>: Repeats a block of code as long as a specified condition is true.</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Simple while loop</span>
 count = <span class="hljs-number">1</span>
 <span class="hljs-keyword">while</span> count &lt;= <span class="hljs-number">5</span>:
     print(<span class="hljs-string">"Count:"</span>, count)
     count += <span class="hljs-number">1</span>

 <span class="hljs-comment"># Output:</span>
 Count: <span class="hljs-number">1</span> 
 Count: <span class="hljs-number">2</span> 
 Count: <span class="hljs-number">3</span> 
 Count: <span class="hljs-number">4</span> 
 Count: <span class="hljs-number">5</span>
</code></pre>
</li>
</ol>
<p><strong>for Loop</strong>: Iterates over a sequence (such as a list, tuple, or string).</p>
<pre><code class="lang-python"><span class="hljs-comment"># Simple for loop</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
    print(<span class="hljs-string">"Iteration:"</span>, i)

<span class="hljs-comment"># Output:</span>
Iteration: <span class="hljs-number">0</span>
Iteration: <span class="hljs-number">1</span>
Iteration: <span class="hljs-number">2</span>
Iteration: <span class="hljs-number">3</span>
Iteration: <span class="hljs-number">4</span>
</code></pre>
<blockquote>
<p>Thanks for reading...</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Build & Package Manager tools in DevOps]]></title><description><![CDATA[Introduction to Build & Package Manager Tools:
What are built and package manager tools?
When developers create an application, it needs to be available to end users. This involves deploying the application on a production server, which requires movi...]]></description><link>https://blog.surajdev.tech/build-packages-manager-tools-in-devops</link><guid isPermaLink="true">https://blog.surajdev.tech/build-packages-manager-tools-in-devops</guid><category><![CDATA[gradle build tool]]></category><category><![CDATA[Build tool]]></category><category><![CDATA[Docker]]></category><category><![CDATA[Devops]]></category><category><![CDATA[maven build tool]]></category><category><![CDATA[package manager]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Sat, 20 Jul 2024 07:07:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721459973703/8e39ab10-8342-46c6-a9c6-8f54ceb2941c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-introduction-to-build-amp-package-manager-tools">Introduction to Build &amp; Package Manager Tools:</h3>
<p>What are built and package manager tools?</p>
<p>When developers create an application, it needs to be available to end users. This involves deploying the application on a production server, which requires moving the application code and its dependencies to the server. This is where build and package manager tools come into play.</p>
<ul>
<li><p><strong>Package</strong> application into a <strong>single movable file</strong></p>
</li>
<li><p>And this single movable file is called <strong>an artifact</strong>.</p>
</li>
<li><p>Packaging = “<strong>building the code</strong>”</p>
</li>
<li><p>Building the code involves:</p>
<ul>
<li><p>Compiling (Hundreds of files into 1 single file)</p>
</li>
<li><p>Compress (Hundreds of files into 1 single file)</p>
</li>
<li><p>After the artifact was built we kept artifacts in storage also</p>
</li>
<li><p>In case we need to deploy multiple times, have a backup, etc.</p>
<p>  E.g.: If we deploy the artifact on the <strong>dev</strong> server, we deploy the <strong>test environment,</strong> or later on the <strong>production environment.</strong></p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-artifact-repository"><strong>Artifact repository:</strong></h3>
<p>The storage location where we keep the artifact once we build it is called the artifact repository, an example is <strong>Nexus</strong>, <strong>JFrogArtifactory</strong>.</p>
<h2 id="heading-what-kind-of-file-is-in-the-artifact">What kind of file is in the artifact?</h2>
<ul>
<li><p>The artifact file looks different for each programming language</p>
</li>
<li><p>E.g., if you have a <strong>Java</strong> Application the artifact file will be a <strong>JAR</strong> or <strong>WAR</strong> file</p>
</li>
<li><p><strong>JAR</strong> = Java Archive</p>
</li>
<li><p>These include whole code and dependencies like:</p>
<ul>
<li><p>Spring Framework</p>
</li>
<li><p>datetime libraries</p>
</li>
<li><p>Pdf processing libraries</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-install-java-and-build-tools">Install Java and Build tools</h2>
<ul>
<li><p>Install java</p>
</li>
<li><p>Install Maven</p>
</li>
<li><p>install Node + npm</p>
</li>
<li><p>Download IntelliJ or VSCode</p>
</li>
</ul>
<h2 id="heading-how-to-build-the-artifact-with-dependencies">How to build the artifact with dependencies?</h2>
<ul>
<li><p>Using a Build Tool, so there are special tools to build the artifact</p>
</li>
<li><p>These tools are specific to the programming language</p>
</li>
<li><p>For Java:</p>
<ul>
<li>There is <strong>Maven</strong> and <strong>Gradle</strong></li>
</ul>
</li>
<li><p>For NodeJs Or JavaScritp</p>
<ul>
<li>There are <strong>npm</strong> and <strong>yarn</strong></li>
</ul>
</li>
<li><p>What These tools do:</p>
<ul>
<li><p>Install dependencies</p>
</li>
<li><p>Compile and compress your code</p>
</li>
<li><p>And can do some other different tasks</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-build-tools-in-java">Build tools in Java</h2>
<ul>
<li><p>JAR or WAR file</p>
</li>
<li><p><strong>Maven</strong>: Uses XML for configuration and is widely used for managing dependencies and building projects.</p>
</li>
<li><p><strong>Gradle:</strong> Uses Groovy for configuration and is known for its flexibility and performance.</p>
</li>
</ul>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Tools</td><td>Maven</td><td>Gradle</td></tr>
</thead>
<tbody>
<tr>
<td>Language uses</td><td>XML</td><td>Groovy</td></tr>
</tbody>
</table>
</div><ul>
<li><p>Which is more convenient for scripting and writing all those tasks for building the code or compiling etc.</p>
</li>
<li><p>Both have command line tools and commands to execute the tasks</p>
</li>
</ul>
<h3 id="heading-gradle-commands-to-execute-the-java-file-doing-hands-on">Gradle commands to execute the Java file (Doing Hands-On)</h3>
<p>This command will compile the code, resolve dependencies, and package the application into an artifact using Gradle.</p>
<pre><code class="lang-bash">./gradlew build
</code></pre>
<p>In the Gradle, we don’t need to configure how the JAR file is built.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721455613016/0e5c77e5-aab8-47e6-8ec7-4ff4c307087f.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-maven-command-to-execute-the-java-file">Maven command to execute the Java file</h3>
<p>Add this plugin to your <code>pom.xml</code> file:</p>
<pre><code class="lang-java">&lt;build&gt;
  &lt;plugins&gt;
    &lt;plugin&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;&lt;!-- Specify version here --&gt;&lt;/version&gt;
      &lt;executions&gt;
        &lt;execution&gt;
            &lt;goals&gt;
               &lt;goal&gt;repackage&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  &lt;/plugins&gt;
&lt;/build&gt;
</code></pre>
<p>The command will compile the code, run tests, package the application into an artifact, and install it into the local Maven repository.</p>
<pre><code class="lang-bash">mvn install
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721455584069/1e6824ae-0546-4c4a-a65f-1b0754d1b14e.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-build-tools-for-development-managing-dependencies">Build Tools for Development (Managing Dependencies)</h2>
<ul>
<li><p>It would help if you had the build tools also locally when developing the App</p>
</li>
<li><p>Because you need to run the app locally</p>
</li>
<li><p>run tests</p>
</li>
</ul>
<p>Maven and Gradle have their own dependency files</p>
<ul>
<li>Dependencies file = Managing the dependencies for the project</li>
</ul>
<p><strong>Where these Dependencies files lies:</strong></p>
<ul>
<li><p>For the maven its - pom.xml</p>
</li>
<li><p>For the Gradle it's - build.gradle</p>
</li>
</ul>
<p>You need a library to connect your Java application to <strong>ElasticSearch</strong></p>
<ul>
<li><p>Find a dependency with name and version</p>
</li>
<li><p>You add it to the dependencies file (e.g. <code>pom.xml</code>)</p>
</li>
<li><p>Dependency gets downloaded locally (e.g local maven repo)</p>
</li>
</ul>
<h2 id="heading-run-the-application">Run the application</h2>
<p>Now let’s say we’ve built an artifact, stored it in the artifact repository, and copied it also on the server.</p>
<p>Now the question is how do you run the application with the artifact</p>
<p>This is the command to execute the <code>.jar</code> file for example:</p>
<pre><code class="lang-java"><span class="hljs-comment">// This example is for gradle</span>
java -jar &lt;name of jar file&gt;

<span class="hljs-comment">//This is an example of Gradle</span>
java -jar build/libs/java-app-<span class="hljs-number">1.0</span>-SNAPSHOT.jar
</code></pre>
<pre><code class="lang-java"><span class="hljs-comment">// This example is for Maven</span>
java -jar &lt;name of jar file&gt;

<span class="hljs-comment">//This is an example of Maven</span>
java -jar target/java-maven-app-<span class="hljs-number">1.0</span>-SNAPSHOT.jar
</code></pre>
<p>So if you are on a fresh server where and you have Java installed you can download the artifact from the repository and start the application using above commands.</p>
<h2 id="heading-build-javascript-application">Build JavaScript application</h2>
<p>What about the JavaScrip Application</p>
<ul>
<li><p>JS doesn’t have a special artifact type</p>
</li>
<li><p>So it can’t be built in ZIP or TAR file</p>
</li>
</ul>
<p>So how do we build a js artifact file as a zip or tar file</p>
<p>These are the alternatives over Gradle and Maven in JavaScript</p>
<ul>
<li><p><code>npm</code> - much more widely used</p>
</li>
<li><p><code>yarn</code></p>
</li>
</ul>
<p>These both contain <strong>package.json</strong> file for dependencies</p>
<p><strong>npm</strong> and <strong>yarn</strong> are package managers and <strong>NOT</strong> build tools</p>
<p>These package managers install dependencies, but not used for transpiling JavaScript code or JavaScript artifact.</p>
<p><strong>npm repository for dependencies :</strong> It refers to the npm registry, which is a public repository of JavaScript packages. It is used to find and install dependencies (libraries or modules) required for JavaScript projects.</p>
<p><strong>Command Line Tools - npm</strong></p>
<ul>
<li><p><code>npm start</code> - start the application</p>
</li>
<li><p><code>npm stop</code> - stop the application</p>
</li>
<li><p><code>npm test</code> - run the test</p>
</li>
<li><p><code>npm publish</code> - publish the artifact</p>
</li>
</ul>
<h2 id="heading-what-does-the-ziptar-file-include">What does the zip/tar file include?</h2>
<ul>
<li>application code, but not the dependencies</li>
</ul>
<p>When you <strong>Run the app on the server</strong></p>
<ul>
<li><p>You must install the dependencies first</p>
</li>
<li><p>Unpack zip/tar</p>
</li>
<li><p>Run the app</p>
</li>
</ul>
<p>You need to copy the artifact &amp; package.json file to the server to run the application</p>
<p><strong>To create an artifact file from our node js application</strong></p>
<pre><code class="lang-java">npm pack
</code></pre>
<ul>
<li><p>JavaScript world is much more flexible than the Java world</p>
</li>
<li><p>But not as structured and standardized</p>
</li>
</ul>
<p>So the above is about nodejs a backed application but what about frontend application when it comes to package.</p>
<h2 id="heading-package-frontend-code">Package Frontend Code</h2>
<p>Different ways to package this</p>
<ul>
<li><p>Package fronted and backend code separately</p>
</li>
<li><p>Common artifact file</p>
</li>
</ul>
<p>For example, if we have <strong>reactjs</strong> and <strong>nodejs</strong> application both in <strong>Javascript</strong> than we can have:</p>
<ul>
<li><p>Separate pakcage.json file for frontend and backend</p>
</li>
<li><p>Common package.json file</p>
</li>
<li><p>Frontend/react code needs to be <strong>transpiled</strong>!</p>
</li>
<li><p>Browser don’t support latest JS versions or other fancy code decorations, like JSX</p>
</li>
<li><p>The code needs to be <strong>compressed/minified!</strong></p>
</li>
<li><p>Separate tools for that - Build Tools/Bundler!</p>
<p>  e.g.: <strong>webpack</strong></p>
</li>
</ul>
<h3 id="heading-build-tools-webpack">Build Tools - Webpack</h3>
<p>Webpack is a build tool that bundles, transpiles, and minifies JavaScript and other assets for frontend applications.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721446163263/66873e0b-d9cb-4b9e-9aca-665a67e05d75.png" alt /></p>
<p>It will transpiles, minified, bundles, compresses the code.</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// install the webpack</span>
npm install

<span class="hljs-comment">// It is used to bundle or compress the javascript code </span>
npm run build
</code></pre>
<h3 id="heading-dependencies-for-frontend-code">Dependencies for Frontend Code</h3>
<ul>
<li><p><strong>npm</strong> and <strong>yarn</strong> for dependencies</p>
</li>
<li><p>Separate <strong>package.json</strong> vs. <strong>common package.json</strong> with backend code</p>
</li>
<li><p>Can be an advantage to have the same build and package management tools</p>
</li>
</ul>
<p>In case react has Java as a backend:</p>
<ul>
<li><p>Bundle-fronted app with webpack</p>
</li>
<li><p>manage dependencies with npm or yarn</p>
</li>
<li><p>package everything into a WAR file</p>
</li>
</ul>
<h2 id="heading-what-are-build-tools-for-other-programming-languages">What are Build tools for other programming languages</h2>
<ul>
<li><p>These concepts are similar to other languages</p>
</li>
<li><p><strong>pip</strong> package manager for python</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721457691663/fa546905-2586-43ba-9c81-f8aa3c7beb0f.png" alt /></p>
<h2 id="heading-publish-an-artifact-into-the-repository">Publish an artifact into the repository</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721458301213/c3f3a4cd-163d-4f4c-aacc-349db7ddcd41.png" alt /></p>
<p>You build the artifact you need to push it to the artifact repository</p>
<ul>
<li><p>Build tools have commands for that</p>
</li>
<li><p>Then you can download (curl, get) it anywhere</p>
</li>
</ul>
<p>NOTE: we don’t fetch or push the artifact like that because of Docker.</p>
<p>The two important things to understand related to these package managers and build tools that we use for different programming languages Docker and another CI/CS pipeline(Jenkins)</p>
<h2 id="heading-build-tools-amp-docker">Build tools &amp; Docker</h2>
<p>With Docker, the need to create zip or tar files is reduced. Docker images can directly contain the application code, simplifying the deployment process.</p>
<ul>
<li><p>With docker, we don't need to build and move different artifact types.</p>
</li>
<li><p><strong>There is just one artifact type - Docker images</strong></p>
</li>
<li><p>Now, we build Docker images from the application and we don't need a repository for each file type, no need to move multiple files to the server like package.json, no need to zip, just copy everything into the docker filesystem and run it from docker image.</p>
</li>
<li><p><strong>Docker image is also an artifact</strong></p>
</li>
<li><p>In order to start the application you don't need npm or java on the server, execute everything ( command to run the JAR or node application) inside the docker image.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721458494836/876ef2cd-ff0e-44e5-bfa0-fca7e6cdf6d2.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p><strong>NOTE:</strong> For the different Java and javascript applications - we don’t need to create zip or tar files anymore because of docker images because we can directly copy and paste the JS code files into docker image <strong>but we have to build the application</strong></p>
</blockquote>
<p><strong>Docker file for Javascript</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721446116633/b43cbdcf-fdac-4484-96a0-836ac6062fd7.png" alt /></p>
<p><strong>Docker file for java</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721446104304/0312cf90-8884-4cf8-b08e-841ddb58d4e1.png" alt /></p>
<h2 id="heading-build-tools-for-devops-engineers">Build Tools for DevOps Engineers</h2>
<p>Why should you know these Build Tools?</p>
<p>DevOps engineers need to understand build tools to assist developers, automate builds, and manage CI/CD pipelines. This includes:</p>
<ul>
<li><p>Developers install dependencies locally and run the application, but don’t build it locally</p>
</li>
<li><p>You need to execute tests on the build servers</p>
<p>  <code>npm/yarn test</code></p>
<p>  <code>gradle/mvn test</code></p>
</li>
<li><p>Help Developers for building the application</p>
</li>
<li><p>Because you know where and how it will run</p>
</li>
<li><p><strong><mark>Build Docker image ⇒ Push to Repo ⇒ Run on Server</mark></strong></p>
</li>
<li><p>You need to configure the build automation tool CI/Cd pipeline</p>
</li>
<li><p><strong><mark>Install dependencies ⇒ run tests ⇒ build/bundle app ⇒ push to repo</mark></strong></p>
</li>
</ul>
<p><strong>NOTE</strong>: You don’t run the app locally</p>
]]></content:encoded></item><item><title><![CDATA[Shell/Bash Scripting - Let's write our first Bash Script]]></title><description><![CDATA[Pre-Requisites to learn Bash/Shell Scripting:

Linux basics

Command line basics

No programming knowledge required


What is a Kernel?
Interface between hardware and software

What is a Bash/Shell?

Bash: A command language interpreter used for inte...]]></description><link>https://blog.surajdev.tech/shellbash-scripting-lets-write-our-first-bash-script</link><guid isPermaLink="true">https://blog.surajdev.tech/shellbash-scripting-lets-write-our-first-bash-script</guid><category><![CDATA[shell script]]></category><category><![CDATA[Bash]]></category><category><![CDATA[bash script]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[Linux]]></category><category><![CDATA[bash scripting]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Tue, 09 Jul 2024 12:35:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1706695521993/03440fa0-f96e-4116-8c14-f249ca9d4f5a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-pre-requisites-to-learn-bashshell-scripting">Pre-Requisites to learn Bash/Shell Scripting:</h2>
<ul>
<li><p>Linux basics</p>
</li>
<li><p>Command line basics</p>
</li>
<li><p>No programming knowledge required</p>
</li>
</ul>
<h2 id="heading-what-is-a-kernel">What is a Kernel?</h2>
<p>Interface between hardware and software</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720451100040/e5a3261c-4d28-46f1-ba67-6c2407a9a349.png" alt /></p>
<h2 id="heading-what-is-a-bashshell">What is a Bash/Shell?</h2>
<ul>
<li><p><strong>Bash:</strong> A command language interpreter used for interacting with a computer from the command line.</p>
</li>
<li><p>It is like a container</p>
</li>
<li><p>The interface between users and Kernel</p>
</li>
<li><p><strong>Also Known As</strong> Commonly referred to as "the shell."</p>
</li>
<li><p>CLI is a shell</p>
</li>
<li><p><strong>Purpose:</strong></p>
<ul>
<li><p>Provides a user-friendly interface to interact with the operating system.</p>
</li>
<li><p>Hides the complex details of the operating system kernel.</p>
</li>
<li><p>Enables tasks such as accessing data and writing files through simple commands.</p>
</li>
</ul>
</li>
<li><p><strong>Historical Significance:</strong></p>
<ul>
<li><p>Introduced in the early 1970s.</p>
</li>
<li><p>Revolutionized how users interact with computers.</p>
</li>
</ul>
</li>
<li><p>When you open any operating system like macOS or Linux's any distro like Ubuntu the default Shell is usually Bash.</p>
</li>
<li><p>Bash is also a programming language that allows us to write scripts which means anything we manually type into the command line can be automated with code.</p>
</li>
</ul>
<p><strong>Find your Shell</strong></p>
<ul>
<li><pre><code class="lang-bash">      <span class="hljs-built_in">echo</span> <span class="hljs-variable">$0</span>
</code></pre>
</li>
<li><p><strong>Available Shells “cat /etc/shells”</strong></p>
<pre><code class="lang-bash">  cat /etc/shells
</code></pre>
<ul>
<li><strong>Your Shell? /etc/passwd</strong></li>
</ul>
</li>
</ul>
<pre><code class="lang-bash">    cat /etc/passwd
</code></pre>
<ul>
<li><p>Windows GUI is a shell</p>
</li>
<li><p>Linux KDE(K Desktop Environment.) GUI is a shell</p>
</li>
<li><p>Linus sh, bash, etc. is a shell</p>
</li>
</ul>
<h2 id="heading-what-is-bashshell-scripting">What is Bash/Shell Scripting?</h2>
<p>A bash script is a file that contains one or more commands that are meant to be executed within your bash shell.</p>
<h2 id="heading-why-shell-scripting">Why Shell Scripting?</h2>
<p>Shell scripts in Linux are an easy-to-use time-saving solution for automating repetitive or complex sets of tasks in a system administrator’s daily life. It can help save time and increase productivity, so it’s a must-have skill for anyone working on computers.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720451678414/908fdc15-7c7b-4eb6-9589-42fad222d694.png" alt /></p>
<ul>
<li><p>Automate daily backups</p>
</li>
<li><p>Automate installation and patching of software on multiple servers</p>
</li>
<li><p>Monitor system periodically</p>
</li>
<li><p>Raise alarms and send notification</p>
</li>
<li><p>Troubleshooting and Audits</p>
</li>
<li><p>Many more</p>
</li>
</ul>
<h2 id="heading-types-of-linux-shell">Types of Linux Shell</h2>
<p>Below both of these are the desktop GUI environment</p>
<ul>
<li><p>Gnome</p>
</li>
<li><p>KDE (K Desktop Environment)</p>
</li>
</ul>
<p><strong>CLI environment:</strong></p>
<ul>
<li><p><strong>sh</strong> - So, this just sh is a Bourne shell called sh, one of the original Linux shells. It is developed by Unix computers by Stephon Bourne. He worked for AT&amp;T Labs in 1977. It offers features such as:</p>
<ul>
<li><p>input and output redirection</p>
</li>
<li><p>shell scripting with string</p>
</li>
<li><p>integer variable and condition testing and looping etc…</p>
</li>
</ul>
</li>
<li><p><strong>bash</strong> - It means Bourne again shell so it</p>
</li>
<li><p><strong>csh and tcsh -</strong> used specifically in cases if you are proficient with c/c++ languages. tcsh doesn’t run bash.</p>
</li>
<li><p><strong>ksh -</strong> KornShell( developed by David Korn). Korn shell is compatible with shell and bash shell as well. Korn Shell improves on Bourne Shell by adding floating point automatic job control.</p>
</li>
</ul>
<h2 id="heading-best-practice-to-follow">Best practice to follow:</h2>
<ul>
<li><p>Give your script a name that makes sense.</p>
</li>
<li><p>Design your script to be reusable</p>
</li>
<li><p>The script should not require to be edited before running</p>
</li>
<li><p>Use command line arguments to pass inputs.</p>
</li>
<li><p>For example(good naming) create-and-launch-rocket</p>
</li>
<li><p>Bad Naming: script1.sh, myscript2.sh, test.sh, etc…</p>
</li>
<li><p>Leave out .sh extension for executables:</p>
</li>
<li><p>good: create-launch-rocket</p>
</li>
<li><p>bad: create-launch-rocket.sh</p>
</li>
</ul>
<h2 id="heading-writing-our-first-bash-script">Writing our first bash script:</h2>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># A script that will print out a message</span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">'Hello Bash bro'</span>
</code></pre>
<ul>
<li><p><strong>#!/bin/bash:</strong> this line is called a <strong>‘shebang’.</strong> This is the line from where the script starts to execute<a target="_blank" href="http://create-launch-rocket.sh">.</a></p>
</li>
<li><p>(hashtag or pound or number sign) !(exclamation mark) These together mean that hey, this is a <strong>shebang.</strong></p>
</li>
<li><p><strong>Shebang</strong> is used to tell the environment we’re in, and which interpreter we will be using.</p>
</li>
<li><p>In this case, since the shebang is /bin/bash, we’re telling it, hey, we’re going to use bash which makes sense because this is a bash shell.</p>
</li>
<li><p><strong>#message:</strong> with # (comment) is used to document your script, and provide clarity in context to what you’re creating here/what our program will do.</p>
</li>
<li><p><strong>echo ‘Hello Bash bro’:</strong> to print the output.</p>
</li>
</ul>
<h3 id="heading-how-to-execute-a-script">How to execute a script</h3>
<ul>
<li><p>First, make a file with the name you like. e.g.</p>
<pre><code class="lang-bash">  vi myscript
  OR
  vim myscript
</code></pre>
</li>
<li><p>Give you file permission to execute:</p>
<pre><code class="lang-bash">  chmod a+x myscript
  <span class="hljs-comment"># here a means to all users and x means execute</span>
</code></pre>
</li>
<li><p><strong>Execute Script Directly:</strong></p>
<p>  Run <code>./myscript</code> to execute the script.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720452553741/a2698144-7e0c-4e72-9952-562f1d7ea685.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720452581363/cf2c6c72-c049-409e-bcc0-5c05ce931b43.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-what-is-a-variable-and-how-do-we-use-them">What is a variable and how do we use them</h2>
<p>A variable is a way to store data and use it within our bash script.</p>
<p>Why would you want to do this?</p>
<ul>
<li>Well, it makes us more efficient because we’re repeating less code.</li>
</ul>
<p><strong>Variable</strong> - whose values can change</p>
<p><strong>Constants</strong> - whose value can not change</p>
<ul>
<li><p>Variable only contain Alphanumeric OR Underscores</p>
</li>
<li><p>And it’s Case Sensitive as well</p>
</li>
</ul>
<p><strong>Best practices:</strong></p>
<ul>
<li><p>good one: mission_name</p>
</li>
<li><p>bad one: Mission_Name, Mission Name, Mission-name</p>
</li>
</ul>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># This is when we assign value to a variable</span>
hello_message=<span class="hljs-string">'Hello, world!'</span>

<span class="hljs-comment"># If we want to print the current directory along with the message </span>
current_dir=$(<span class="hljs-built_in">pwd</span>)

<span class="hljs-comment">#  And this is when we are using variable</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$hello_message</span> from <span class="hljs-variable">$curret_dir</span>"</span>
</code></pre>
<h2 id="heading-what-are-the-positional-argumentsparameters-in-shell-scripting">What are the positional arguments/parameters in shell scripting?</h2>
<p>The positional parameters hold the arguments passed to a script or function. They are referenced using <strong>$1, $2, $3, etc.</strong>, where $1 is the first argument, $2 is the second, and so on. <strong>$0 refers to the script's name</strong>.</p>
<p><strong>Example script:</strong></p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash </span>

<span class="hljs-built_in">echo</span> <span class="hljs-string">"First argument: <span class="hljs-variable">$1</span>"</span> 
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Second argument: <span class="hljs-variable">$2</span></span>
</code></pre>
<p>If the script is executed with <code>./myscript</code> arg1 arg2,<br />it will output: First argument: arg1 Second argument: arg2</p>
<h2 id="heading-how-to-accept-user-input">How to accept user input</h2>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-built_in">echo</span> Hello, My name is Suraj.
<span class="hljs-built_in">echo</span>
<span class="hljs-built_in">echo</span> What is your name?
<span class="hljs-built_in">echo</span> 
<span class="hljs-built_in">read</span> broname
<span class="hljs-built_in">echo</span>
<span class="hljs-built_in">echo</span> Hello <span class="hljs-variable">$broname</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720521229539/57397fe0-6a54-43ba-be71-879b8affbf2b.png" alt /></p>
<pre><code class="lang-bash"><span class="hljs-built_in">read</span> -p <span class="hljs-string">"Enter mission name:"</span> variable_name
<span class="hljs-built_in">echo</span> <span class="hljs-variable">$variable_name</span>

<span class="hljs-comment"># read take the input </span>
<span class="hljs-comment"># -p display the text</span>
</code></pre>
<h2 id="heading-what-are-the-conditional-statements-in-bash">What are the conditional statements in bash?</h2>
<p>Conditionals are just if else statements we can understand by the below example:</p>
<p><strong>A simple if-then code in bash</strong></p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

number=25

<span class="hljs-keyword">if</span> [ $((number % <span class="hljs-number">2</span>)) -eq 0 ];
<span class="hljs-keyword">then</span>
   <span class="hljs-built_in">echo</span> <span class="hljs-string">"The number <span class="hljs-variable">$number</span> is even!"</span>;
<span class="hljs-keyword">else</span> 
   <span class="hljs-built_in">echo</span> <span class="hljs-string">"The number <span class="hljs-variable">$number</span> is odd!"</span>
<span class="hljs-keyword">fi</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

clear

<span class="hljs-keyword">if</span> [ -e /home/devopsbro/basicbashscript/bro.txt ]

                <span class="hljs-keyword">then</span>
                <span class="hljs-built_in">echo</span> <span class="hljs-string">"File exists"</span>
                <span class="hljs-keyword">else</span>
                <span class="hljs-built_in">echo</span> <span class="hljs-string">"File does not exist"</span>
<span class="hljs-keyword">fi</span>
</code></pre>
<h2 id="heading-what-are-case-statements-in-bash">What are Case Statements in Bash?</h2>
<p>Most of the installation programs are written in case statements where the scripts wait for user input to select from choices.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># A script that will ask for a number and print out a message depending on the value. </span>

<span class="hljs-built_in">read</span> -p <span class="hljs-string">"Enter a value: "</span> n
<span class="hljs-keyword">case</span> <span class="hljs-variable">$n</span> <span class="hljs-keyword">in</span>
    ???) 
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"One"</span>;;
    2) 
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Two"</span>;;
    aa) 
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Three"</span>;;
    *.txt) 
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Four"</span>;;
    *) 
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Other"</span>;;
<span class="hljs-keyword">esac</span>

<span class="hljs-comment"># read: it is the command to ask the user to provide a number</span>

<span class="hljs-comment"># -p: allows us to provide a prompt which in this case is enter a value</span>

<span class="hljs-comment"># n: name of the variable</span>
</code></pre>
<h2 id="heading-what-are-loops-in-bash">What are loops in Bash?</h2>
<ul>
<li><p>Program to automate the repeating task</p>
</li>
<li><p>Here we are learning to <strong>do while done</strong> keywords</p>
</li>
</ul>
<p><strong>While loop</strong></p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># A script to display a series of numbers using a while loop.</span>

counter=1
<span class="hljs-comment"># here ‘ -le ‘ is less then</span>
<span class="hljs-keyword">while</span> [[ <span class="hljs-string">"<span class="hljs-variable">$counter</span>"</span> -le 10 ]]; <span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The counter is at: <span class="hljs-variable">$counter</span>"</span>
    counter=$((counter + <span class="hljs-number">1</span>))
<span class="hljs-keyword">done</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"The count has finished."</span>
</code></pre>
<p><strong>Until loop</strong></p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># A script to display a series of numbers using while.</span>

counter=1
until [[ <span class="hljs-string">"<span class="hljs-variable">$counter</span>"</span> -gt 10 ]]; <span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The counter is at: <span class="hljs-variable">$counter</span>"</span>
    counter=$((counter + <span class="hljs-number">1</span>))
<span class="hljs-keyword">done</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"The count has finished."</span>
</code></pre>
<p><strong>for loop traditional</strong></p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Print values in an array using for loops</span>

services=(<span class="hljs-string">"loadbalancer"</span> <span class="hljs-string">"virtualmachine"</span> <span class="hljs-string">"storage"</span>)

<span class="hljs-comment"># here @ mean all the elements of the array services</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-string">"<span class="hljs-variable">${services[@]}</span>"</span>
<span class="hljs-keyword">do</span>
   <span class="hljs-built_in">echo</span> <span class="hljs-variable">$i</span>
<span class="hljs-keyword">done</span>
</code></pre>
<p><strong>for loop new</strong></p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># A script to display a series of numbers using a for loop.</span>

<span class="hljs-keyword">for</span> (( i=0; i&lt;5; i=i+1 )); <span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The counter is at: <span class="hljs-variable">$i</span>"</span>
<span class="hljs-keyword">done</span>
</code></pre>
<p><strong>loop and break</strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#/bin/bash</span>

<span class="hljs-comment"># A script that will recieve input and break depending on condition. </span>

<span class="hljs-keyword">while</span> <span class="hljs-literal">true</span>; <span class="hljs-keyword">do</span>
<span class="hljs-comment"># here n is variable that store the user input</span>
  <span class="hljs-built_in">read</span> -p <span class="hljs-string">"Enter a number between 1 and 25: "</span> n
  <span class="hljs-keyword">if</span> [[ <span class="hljs-variable">$n</span> -ge 1 &amp;&amp; <span class="hljs-variable">$n</span> -le 25 ]]; <span class="hljs-keyword">then</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"You entered <span class="hljs-variable">$n</span>"</span>
  <span class="hljs-keyword">else</span> 
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"You didn't enter a number in range, goodbye."</span>
    <span class="hljs-built_in">break</span>
  <span class="hljs-keyword">fi</span>
<span class="hljs-keyword">done</span>
<span class="hljs-built_in">echo</span> <span class="hljs-string">"Break happened"</span>
<span class="hljs-comment"># the ‘fi’ here is the opposite of ‘if’ to stop if statement</span>
</code></pre>
<h2 id="heading-what-are-the-functions-in-bash">What are the functions in bash?</h2>
<p>A function in Bash is a reusable block of code that can be called with a name to perform a specific task, defined using the syntax <code>function_name() { commands; }</code>.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># function name and definition</span>
<span class="hljs-function"><span class="hljs-title">check_even</span></span> () {
    <span class="hljs-built_in">local</span> mod=2
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"The value of mod is <span class="hljs-variable">$mod</span>"</span>
    <span class="hljs-keyword">if</span> [ $(("<span class="hljs-variable">$1</span>" % <span class="hljs-variable">$mod</span>)) -eq 0 ]
    <span class="hljs-keyword">then</span> 
       <span class="hljs-built_in">echo</span> <span class="hljs-string">"The number <span class="hljs-variable">$1</span> is even!"</span>;
    <span class="hljs-keyword">else</span> 
       <span class="hljs-built_in">echo</span> <span class="hljs-string">"The number <span class="hljs-variable">$1</span> is odd!"</span>
    <span class="hljs-keyword">fi</span>
}
<span class="hljs-comment"># Variable Declaration</span>
number=2344

<span class="hljs-comment"># Function Call</span>
check_even <span class="hljs-variable">$number</span>
<span class="hljs-built_in">echo</span> <span class="hljs-variable">$mod</span>
</code></pre>
<p><strong>local</strong>: It is a scope here which means whatever is defined inside the function which {} can’t access outside but only inside.</p>
<h2 id="heading-check-remote-servers-connectivity">Check Remote Servers Connectivity</h2>
<p>A script to check the status of remote hosts</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># this is a simple script</span>
ping -c1 192.168.1.1
        <span class="hljs-keyword">if</span> [ $? -eq 0 ]
        <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">echo</span> OK
        <span class="hljs-keyword">else</span>
        <span class="hljs-built_in">echo</span> NOT OK
        <span class="hljs-keyword">fi</span>

<span class="hljs-comment"># Change the IP to 192.168.1.235</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># This is a good one</span>
<span class="hljs-comment"># Don't show the output</span>
ping -c1 192.168.1.1 &amp;&gt; /dev/null
        <span class="hljs-keyword">if</span> [ $? -eq 0 ]
        <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">echo</span> OK
        <span class="hljs-keyword">else</span>
        <span class="hljs-built_in">echo</span> NOT OK
        <span class="hljs-keyword">fi</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># This is the better one</span>
<span class="hljs-comment"># Define variable</span>

hosts=<span class="hljs-string">"192.168.1.1"</span>
ping -c1 <span class="hljs-variable">$hosts</span> &amp;&gt; /dev/null
        <span class="hljs-keyword">if</span> [ $? -eq 0 ]
        <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">echo</span> <span class="hljs-variable">$hosts</span> OK
        <span class="hljs-keyword">else</span>
        <span class="hljs-built_in">echo</span> <span class="hljs-variable">$hosts</span> NOT OK
        <span class="hljs-keyword">fi</span>

<span class="hljs-comment"># Change the IP to 192.168.1.235</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment">#Multiple IPs</span>
IPLIST=<span class="hljs-string">"path_to_the_Ip_list_file"</span>


<span class="hljs-keyword">for</span> ip <span class="hljs-keyword">in</span> $(cat <span class="hljs-variable">$IPLIST</span>)

<span class="hljs-keyword">do</span>
   ping -c1 <span class="hljs-variable">$ip</span> &amp;&gt; /dev/null
   <span class="hljs-keyword">if</span> [ $? -eq 0 ]
   <span class="hljs-keyword">then</span>
   <span class="hljs-built_in">echo</span> <span class="hljs-variable">$ip</span> ping passed
   <span class="hljs-keyword">else</span>
   <span class="hljs-built_in">echo</span> <span class="hljs-variable">$ip</span> ping failed
   <span class="hljs-keyword">fi</span>
<span class="hljs-keyword">done</span>
</code></pre>
<h1 id="heading-aliasesalias">Aliases(alias)</h1>
<p>In real life, aliases are short names of long ones to remember.</p>
<p>Aliases is a very popular command that is used to cut down on lengthy and repetitive commands</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Here are the some example of how you can make an alias of any command</span>

<span class="hljs-built_in">alias</span> ls=<span class="hljs-string">"ls -al"</span>
<span class="hljs-built_in">alias</span> pl=<span class="hljs-string">"pws; ls"</span>
<span class="hljs-built_in">alias</span> tell=<span class="hljs-string">"whoami; hostname; pwd"</span>
<span class="hljs-built_in">alias</span> dir=<span class="hljs-string">"ls -l | grep ^d"</span>
<span class="hljs-built_in">alias</span> lmar=<span class="hljs-string">"ls -l | grep Mar"</span>
<span class="hljs-built_in">alias</span> wpa=<span class="hljs-string">"chmod a+w"</span>
<span class="hljs-built_in">alias</span> d=<span class="hljs-string">"df -h |awk '{print \$6}' | cut -cl-4"</span>
</code></pre>
<p><strong>Note</strong>: <code>{print \$6}</code> here before $6, we put backslash “\” because we don't want Linux to not think of $6 as a variable.</p>
<ul>
<li><p>To know what and how many aliases you have made use the command <code>alias</code> to know.</p>
</li>
<li><p>To delete an alias</p>
<pre><code class="lang-bash">  <span class="hljs-built_in">unalias</span> nameOfAlias
</code></pre>
</li>
<li><p>To delete all the aliases at once</p>
<pre><code class="lang-bash">  <span class="hljs-built_in">unalias</span> -a
</code></pre>
</li>
</ul>
<h3 id="heading-user-and-global-aliases">User and Global Aliases</h3>
<p><strong>Creating User or Global Aliases.</strong></p>
<ul>
<li><p>User = Applies only to a specific user profile</p>
<pre><code class="lang-bash">  User = /home/user/.bashrc
</code></pre>
</li>
<li><p>Global = Applies to everyone who has an account on the system</p>
<pre><code class="lang-bash">  Global = /etc/bashrc
</code></pre>
</li>
</ul>
<p><strong>Note</strong>: So basically if we are creating an alias in the terminal without user-specific then it’ll stay only for that session and when you close and open the terminal you’ll not find the alias again. So to solve this we’ll be creating a user alias:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720523543393/941c9750-a1a0-48bb-b20c-bc80b83105ea.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720523564768/f047f250-1f51-488c-b035-ebbc5d28317f.png" alt /></p>
<p><strong>Now let's make the alias Global:</strong></p>
<p>for me, this command works to add a global alias</p>
<pre><code class="lang-bash">sudo nano /etc/bash.bashrc
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720523605242/9ff4afde-c12a-4e3b-87f1-af358f554ee4.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720523625522/2faf842d-3962-4427-9752-61d874652b22.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-shell-history">Shell History</h2>
<p>You can know all the commands that you have run in your terminal by just running the command <code>history</code> .</p>
<pre><code class="lang-bash"><span class="hljs-built_in">history</span>
</code></pre>
<p>If you want to scroll more command of history just run this command:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">history</span> | more
</code></pre>
<p>If you want to run any command from you history just remember the number of that command left side and run it this way:</p>
<pre><code class="lang-bash">!8
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720523673975/33ddf783-c094-4d9a-b87c-f68a1dae99f2.png" alt /></p>
<p><strong>Note:</strong> The file where the history of your shell commands is saved and to know that run the below command:</p>
<pre><code class="lang-bash">/home/username/.bash_history
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720523720076/9726b4d1-6fb6-452d-b903-e6b91a385436.png" alt /></p>
<h1 id="heading-the-linux-commands-youll-use-while-working-with-bash">The Linux commands you'll use while working with Bash</h1>
<ol>
<li><p><code>ls --help</code> : To know more about ls command.</p>
</li>
<li><p><code>echo --help</code> : To know more about echo command.</p>
</li>
<li><p><code>man</code> : An interface to the system reference manuals.</p>
</li>
<li><p><code>pushd</code> : Adds a directory to the directory stack.</p>
</li>
<li><p><code>popd</code> : Removes a directory from the stack and changes to it.</p>
</li>
<li><p><code>mkdir foldername</code> : Create the folder with the name specified.</p>
</li>
<li><p><code>mkdir -p suraj1/suraj2/suraj3</code> : For creating parent directories.</p>
</li>
<li><p><code>touch filename</code> : To create a file.</p>
</li>
<li><p><code>mv source_name destination_name</code> : Used to move or rename files and directories from <code>source_name</code> to <code>destination_name</code> .</p>
</li>
<li><p><code>cp source_name destination_name</code> : Copies <code>source_name</code> to <code>destination_name</code>, creating a duplicate file or directory.</p>
</li>
<li><p><code>rm file_name_you_want_to_delete</code> : Used to remove files or directories.</p>
</li>
<li><p><code>rm -r file_name_you_want_to_delete</code> : For recursive deletion</p>
</li>
<li><p><code>rmdir directory_name</code> : Used to delete</p>
</li>
<li><p><code>cat file_name</code> : Used to view to content of the file.</p>
</li>
<li><p><code>head file_name</code> : This will display by default the first 10 lines of your content.</p>
</li>
<li><p><code>head -n 5 file_name</code> : Now this will display the first 5 number of lines of your content because we have specified it using the ‘-n’ flag.</p>
</li>
<li><p><code>tail file_name</code> : This will display by default the last 10 lines of your content.</p>
</li>
<li><p><code>tail -n 5 file_name</code> : This will display the last 5 number of lines of your content.</p>
</li>
<li><p><code>more file_name</code> : It will give the information page by page. and hit the space bar to go page by page.</p>
</li>
<li><p><code>less file_name</code> : ‘less’ and ‘more’ are very similar just the less has a lot more options in its navigation.</p>
</li>
<li><p><code>grep --help</code> : To know more about grep</p>
</li>
</ol>
<p><strong>Use of Wildcards:</strong></p>
<ul>
<li><p>To find any files with an asterisk(*) and with ??:</p>
</li>
<li><p>To print all the files with the uppercase and lowercase as well:</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720524789361/7ad17569-1ec8-4f13-8368-6c51d0c2f288.png" alt /></p>
<p><strong>How to use ‘whereis’ command:</strong></p>
<pre><code class="lang-bash">whereis file_name
</code></pre>
<pre><code class="lang-bash">whereis -b file_name
</code></pre>
<pre><code class="lang-bash"><span class="hljs-built_in">which</span> file_name
</code></pre>
<p><strong>How to use the find command:</strong></p>
<pre><code class="lang-bash">find . -name <span class="hljs-string">"*.md"</span>
</code></pre>
<p>The above command says to find in the current directory(.) all the name which has the .md extension</p>
<pre><code class="lang-bash">find /home -name file.txt
</code></pre>
<pre><code class="lang-bash">find /home -iname file.text
</code></pre>
<p>So here I mean it’ll remove the case sensitivity and show all the files whose name is file.txt regardless if it is in lowercase or uppercase</p>
<pre><code class="lang-bash">find . -<span class="hljs-built_in">type</span> d
</code></pre>
<h3 id="heading-how-to-use-the-environment-variables-command">How to use the environment variables command:</h3>
<p>As the name suggests the environment variables set several variables for your shell environment. Environment variables are important because applications, command line tools, and shell scripts use them to determine their configuration.</p>
<ul>
<li>Knowing how to view, create, and modify environment variables is a must if you were to learn the ways of the terminal.</li>
</ul>
<h3 id="heading-the-env-command">The ‘env’ command:</h3>
<p>this command will show you all the environment variables that are available currently.</p>
<pre><code class="lang-bash">env
</code></pre>
<ul>
<li>If we want to see just a single environment variable, we can use the ‘echo’ command:</li>
</ul>
<p>These are the environment variables:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-variable">$SHELL</span>
<span class="hljs-comment"># OUTPUT: /bin/bash</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-variable">$HOME</span>
<span class="hljs-comment"># /home/user</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-variable">$USER</span>
<span class="hljs-comment"># user</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-variable">$PATH</span>
<span class="hljs-comment"># (example): /home/devopsbro/.nvm/versions/node/v20.15.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin</span>
</code></pre>
<h3 id="heading-the-command-to-create-an-environment-variable-is-export">The command to create an environment variable is ‘export’:</h3>
<p><code>export --help</code> : To know more about export command.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> newVar=value
<span class="hljs-built_in">echo</span> <span class="hljs-variable">$newVar</span>

<span class="hljs-comment"># output: value</span>
</code></pre>
<p><strong>Important</strong>: The environment variable that we just created is only for the current session. And the question comes in :</p>
<p><strong>“How do you persist environment variables across sessions?”</strong></p>
<p>and “the answer to this question is what bash calls <strong>startup files</strong>.”</p>
<ul>
<li>So there are several locations for the <strong>startup files</strong> but two worth mentioning are the <strong>‘global configuration’</strong> which is located under the ‘etc’ profile, and if you were to make changes to this particular file, it would affect every user logged in to the machine or their bash session for every user logged in the machine.</li>
</ul>
<pre><code class="lang-bash">ls /etc/profile
</code></pre>
<ul>
<li>Another one is the ‘.’ profile which exists underneath the user’s home directory</li>
</ul>
<pre><code class="lang-bash">ls -a ~

<span class="hljs-comment"># it will output: .bashrc or .profile kind of profiles</span>
</code></pre>
<h2 id="heading-how-to-use-redirection">How to use Redirection:</h2>
<p>Everything that you see on the terminal either comes from an output stream or an input stream. In bash, you can redirect or chain together that output using the redirection operator and the pipeline.</p>
<ul>
<li><p>One of the streams that command right to is the standard output:</p>
<pre><code class="lang-bash">  ls - l
</code></pre>
</li>
<li><p>Using redirection operator now:</p>
<pre><code class="lang-bash">  ls -l &gt; file_name.txt
</code></pre>
</li>
<li><p>If you want to put the new content in a new like you want to append:</p>
<pre><code class="lang-bash">  touch file_name.txt
  ls -l &gt;&gt; file_name_in_which_you_want_to_apppent.txt
</code></pre>
</li>
</ul>
<h3 id="heading-standard-error">Standard error:</h3>
<pre><code class="lang-bash">ls -l ./dir

<span class="hljs-comment"># This will give an error</span>
</code></pre>
<p><strong>Here 2 is the file descriptor</strong> that indicates the standard error, and so it’s saying redirect standard error to this particular location.</p>
<pre><code class="lang-bash">ls -l ./dir 2&gt; error.txt
</code></pre>
<p>Now, this is without a file descriptor:</p>
<pre><code class="lang-bash">ls -l ./dir &gt; error.txt

<span class="hljs-comment"># It just redirects to the terminal because I'm not redirecting standard error, I am trying to redirect the standard output</span>
</code></pre>
<p>So here 2&gt;&amp;1 in this we’re saying stream one and stream two redirects to these files.</p>
<pre><code class="lang-bash">ls -l ./dir &gt; error.txt 2&gt;&amp;1
or 
ls -l &amp;&gt; error.txt 

<span class="hljs-comment"># The above two commands are the same as long as we're doing this is in the same directory but not append.</span>
</code></pre>
<p>If we want to append we can do this:</p>
<pre><code class="lang-bash">ls -l &gt;&gt; error.txt 2&gt;&amp;1
</code></pre>
<h3 id="heading-how-to-use-pipelines">How to use pipelines ( | ):</h3>
<p>This is without the pipe symbol</p>
<pre><code class="lang-bash">ls -l /usr/bin
</code></pre>
<p>as we know what <code>less</code> command do this will show the content less and we can scroll using the spacebar</p>
<pre><code class="lang-bash">ls -l /usr/bin | less
</code></pre>
<p>This will find the echo in this directory</p>
<pre><code class="lang-bash">ls -l /usr/bin | grep <span class="hljs-built_in">echo</span>
</code></pre>
<p>This will find and sort the content</p>
<pre><code class="lang-bash">ls -l /usr/bin | grep <span class="hljs-built_in">echo</span> | sort
</code></pre>
<p>This will show the first content of this file.</p>
<pre><code class="lang-bash">ls -l file_name.txt | head -n 1
</code></pre>
<p>This will show the last line of the file.</p>
<pre><code class="lang-bash">ls -l file_name.txt | tail -n 1
</code></pre>
<h2 id="heading-how-to-modify-file-permissions-in-bash">How to modify file permissions in Bash:</h2>
<p><strong>How to view permissions:</strong></p>
<pre><code class="lang-bash">ls -ltr or
ls -l
</code></pre>
<p>Command to change the owner for Ubuntu users:</p>
<pre><code class="lang-bash">sudo chown root file_name.txt
<span class="hljs-comment"># Here chown is the command and root is the new owner and the file name whose owner you want to change.</span>
</code></pre>
<pre><code class="lang-bash">sudo chown :root file_name
<span class="hljs-comment"># This command is used for changing the group owner</span>
</code></pre>
<pre><code class="lang-bash">chgrp owner_name_you_want_change file_name
<span class="hljs-comment"># This is the another command to change the group owner</span>
</code></pre>
<h3 id="heading-how-to-use-the-chmod-command">How to use the chmod command:</h3>
<p>This command will add the execute permission to the file for user, group, and other</p>
<pre><code class="lang-bash">chmod +x file_name
</code></pre>
<pre><code class="lang-bash">chmod 444 file_name
<span class="hljs-comment"># The 444 means here in the user,group,and other it will give permission to execute the file.</span>
</code></pre>
<p>Afterward, executing <code>ls -l file_name</code> might show something like:</p>
<pre><code class="lang-bash">-r--r--r-- 1 user group 1234 Jul 9 10:00 file_name
</code></pre>
<p><strong>This table will help you to understand better:</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Octal Number</td><td>Permissions</td><td>Meaning</td></tr>
</thead>
<tbody>
<tr>
<td>0</td><td>---</td><td>No permissions</td></tr>
<tr>
<td>1</td><td>--x</td><td>Execute only</td></tr>
<tr>
<td>2</td><td>-w-</td><td>Write only</td></tr>
<tr>
<td>3</td><td>-wx</td><td>Write and execute</td></tr>
<tr>
<td>4</td><td>r--</td><td>Read-only</td></tr>
<tr>
<td>5</td><td>r-x</td><td>Read and execute</td></tr>
<tr>
<td>6</td><td>rw-</td><td>Read and write</td></tr>
<tr>
<td>7</td><td>rwx</td><td>Read, write, and execute</td></tr>
</tbody>
</table>
</div><h1 id="heading-best-resources-from-where-i-learned">Best Resources from where I learned</h1>
<p><strong>YouTube Video Resources:</strong></p>
<ol>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=I4EWvMFj37g">Bash in 100 Seconds By Fireship</a></p>
</li>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=ldqmDIexAsA">Shell Scripting Zero To Hero || Shell Scripting for Devops &amp; Cloud || Shell scripting for Beginners</a></p>
</li>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=nrfwcbYJZfc&amp;list=PLlrxD0HtieHh9ZhrnEbZKhzk0cetzuX7l">Welcome to Bash for Beginners [1 of 20] | Bash for Beginners</a></p>
</li>
</ol>
<blockquote>
<p>Thanks for reading guys</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[My LFX Mentorship Experience]]></title><description><![CDATA[What is the LFX Mentorship program?
The Linux Foundation Mentorship Program, commonly known as LFX Mentorship, LFX mentorship is previously known as community bridge. It's a platform designed by the Linux foundation that accelerates the adoption, inn...]]></description><link>https://blog.surajdev.tech/my-lfx-mentorship-experience</link><guid isPermaLink="true">https://blog.surajdev.tech/my-lfx-mentorship-experience</guid><category><![CDATA[cloudforet]]></category><category><![CDATA[LFX Mentorship]]></category><category><![CDATA[lfx]]></category><category><![CDATA[Open Source]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Wed, 03 Apr 2024 14:15:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1711358788030/c94476af-9de9-48e8-a773-7871e9355d0f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-the-lfx-mentorship-program">What is the LFX Mentorship program?</h2>
<p>The Linux Foundation Mentorship Program, commonly known as <strong>LFX Mentorship</strong>, LFX mentorship is previously known as <strong>community bridge</strong>. It's a platform designed by the Linux foundation that <mark>accelerates the adoption, innovation, and sustainability of open-source software.</mark> Basically Linux Foundation mentorship program is designed for developers mainly first-time open-source contributors learn, experiment, and contribute effectively in the open-source communities.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1712148080536/4ac69668-7df9-4b21-9f82-dd53f6d001f3.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p>What is open-source?<br />Open source is like joining a creative community fair where you and others build awesome things together. <mark>You contribute your ideas and skills, learn new things, and collaborate like friends working on a big project.</mark> It's a global effort, making a positive impact on people's lives, and it's a joyful journey of growth and achievement.</p>
<p>open-source is everywhere(means there are code and non-code contributions it's not just for developers keep that in mind!).</p>
<p>In general, it's free to use, access, and modify depending on the licenses. It's an inclusive community and you get to collaborate with people around the world.</p>
</blockquote>
<h2 id="heading-how-do-i-get-to-know-about-lfx-mentorship">How do I get to know about LFX Mentorship?</h2>
<p>Actually I get know about LFX Mentorship program from the tech communites/People on platforms like Twitter, Discord etc...</p>
<p>OpenSource is life-changing for a lot of folks. Companies are hiring OpenSource Engineers. LFX Mentorship is for folks starting out in OpenSource and interested in exploring the modern tech niches companies are looking forward to.</p>
<p><strong>Watch this video for more:</strong></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=o0V7Z6UQMBY&amp;t=529s">https://www.youtube.com/watch?v=o0V7Z6UQMBY&amp;t=529s</a></div>
<p> </p>
<p><strong>Varies for each term(as per the LFX Website):</strong></p>
<ul>
<li><p>(Spring) Mentorships available on LFX Mentorship: mid-January</p>
</li>
<li><p>(Summer) Mentorships available on LFX Mentorship: mid-April</p>
</li>
<li><p>(Fall) Mentorships available on LFX Mentorship: mid-July</p>
</li>
</ul>
<p><strong>There are only two criteria to get into the LFX Mentorship Program:</strong></p>
<ol>
<li><p>You have to be 18 years old.</p>
</li>
<li><p>Not to be a prior participant in the LFX mentorship program</p>
</li>
<li><p>Other than it's open to all.</p>
</li>
</ol>
<h3 id="heading-apply-here">Apply Here:</h3>
<p><a target="_blank" href="https://mentorship.lfx.linuxfoundation.org/#projects_all"><strong>Explore Mentorship Programs</strong></a></p>
<h2 id="heading-what-is-cloudforet">What is CloudForet?</h2>
<p>Cloudforet is an <strong>Open Source Platform</strong> for Enabling <strong>Integrated Management of Multi-Clouds.</strong></p>
<p><a target="_blank" href="https://dev.to/choonho/introduction-to-cloudforet-1611"><strong>Read more about Cloudforet</strong></a></p>
<h2 id="heading-my-journey-at-cloudforet-as-a-lfx-mentee23"><strong>My Journey at Cloudforet as a LFX Mentee’23</strong></h2>
<p>It was a great experience to be an LFX Mentee at Cloudforet because it allowed me to learn more about cloud and DevOps concepts.</p>
<h3 id="heading-i-got-selected-for-the-cloudforet-plugin-development-mentorship-program">I got selected for the Cloudforet plugin development mentorship program:</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1712145002188/b6620a8d-c84f-4d9f-9d07-178fa5d1581c.jpeg" alt class="image--center mx-auto" /></p>
<p>After the selection of Cloudforet LFX mentorship, I have been assigned to 5 Tasks to do:</p>
<ul>
<li><p>Week 1. Orientation and Fundamentals</p>
<ul>
<li>So in this, I've been introduced to the organization and the installation of the Cloudforet with minikube in my local system(I used Ubuntu OS for this).</li>
</ul>
</li>
<li><p>Step 2. Understanding of Cloud Computing &amp; Kubernetes</p>
<ul>
<li>Learned about the fundamentals of cloud computing and Kubernetes and CI/CD using github actions also.</li>
</ul>
</li>
<li><p>Step 3. Understanding of Protobuf &amp; gRPC</p>
<ul>
<li>To understand Protobuf &amp; gRPC is the base framework of Cloudforet the LFX certification course was assigned, and I learned about it.</li>
</ul>
</li>
<li><p>Step 4. Plugin Development Basic</p>
<ul>
<li>I've been assigned to first install Cloudforet, and then create a user for the service. and then create an API user and then create an API Key for CLI.<br />  After that to registered the local plugin marketplace for myself. Then I can enable my custom plugin.</li>
</ul>
</li>
<li><p>Step 5. Real-World Plugin Project</p>
<ul>
<li><p>Code Analysis of plugin-http-file-cost-datasource</p>
</li>
<li><p>In this, I've been assigned to do:</p>
<ul>
<li><p>Updating the DataSource at Step 4.</p>
</li>
<li><p>change base_url with your own CSV file (using Spacectl CLI)</p>
</li>
<li><p>Report for <strong><em>sync</em></strong> API call flow</p>
</li>
<li><p>based on interface, service, manager layer</p>
</li>
<li><p>How cost-analysis service and plugin-http-file-cost-datasource interact</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>I graduated successfully from Cloudforet:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1712144834663/71043f56-5ce4-4e7e-bc00-219d1d008b4e.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-cloudforet-11-mentorship-by-choonho-sonmentor">Cloudforet 1:1 mentorship by Choonho Son(Mentor)</h3>
<p>While doing this mentorship program I was stuck most of the time in understanding the tasks and completing them so my mentor <a target="_blank" href="https://www.linkedin.com/in/choonhoson/">Choonho</a> sir always helped me to understand and complete those tasks and I learned a lot from him.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1712144638044/3e578fec-4d5e-4113-bea2-1ad2d80bc8eb.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-conclusion">Conclusion</h3>
<blockquote>
<p>My experience was great at Cloudforet as a LFX mentorship. And you should apply in the open-source programs like as soon as possible because I can give the this surity that you'll gain somethign new and valuable skills from these programs and networking( you'll meet amazing people from around the world who are working in these kind of organizations.</p>
<p><a target="_blank" href="https://surajk00.hashnode.dev/what-is-open-source-beginners-guide-how-to-get-started">Check my blog on open-source</a></p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Computer Networking Course: How does the internet work?]]></title><description><![CDATA[How did it all start?

During the Cold War, the United States and the Soviet Union competed to be the best.

In 1957, the Soviet Union surprised everyone by launching Sputnik 1, the first man-made satellite.

To keep up, the U.S. created ARPA (Advanc...]]></description><link>https://blog.surajdev.tech/computer-networking-course-how-does-the-internet-work</link><guid isPermaLink="true">https://blog.surajdev.tech/computer-networking-course-how-does-the-internet-work</guid><category><![CDATA[computer networking]]></category><category><![CDATA[networking]]></category><category><![CDATA[Devops]]></category><category><![CDATA[internet]]></category><category><![CDATA[how internet works]]></category><dc:creator><![CDATA[Suraj]]></dc:creator><pubDate>Fri, 23 Feb 2024 15:06:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1695924470719/00c5f7e5-fdf7-4bc8-a273-0e942d38f969.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-how-did-it-all-start">How did it all start?</h2>
<ul>
<li><p>During the Cold War, the United States and the Soviet Union competed to be the best.</p>
</li>
<li><p>In 1957, the Soviet Union surprised everyone by launching Sputnik 1, the first man-made satellite.</p>
</li>
<li><p>To keep up, the U.S. created ARPA (Advanced Research Project Agency) to stay ahead in science.</p>
</li>
<li><p>ARPA made ARPANET, the first big computer network using packet switching.</p>
</li>
<li><p>ARPANET laid the foundation for the internet we use today, changing how we connect and work together.</p>
</li>
</ul>
<p>The U.S. Advanced Research Projects Agency Network (ARPANET) was the first big computer network. It started in 1969 and stopped in 1989. ARPANET was mainly for academics and research.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708276549925/6a63d4f8-4b31-46fb-a73f-7dd5a616a26e.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-www-came-into-the-picture">WWW came into the picture:</h2>
<p>We wanted to easily share research papers, but couldn't because there was no automatic way to do it.</p>
<p>Then, Mr. Tim Berners-Lee created the World Wide Web (www). It lets us store and access documents online. However, back then, we couldn't search for things on the website.</p>
<p>This is the world's first <a target="_blank" href="http://info.cern.ch/"><strong>website</strong></a></p>
<ul>
<li>The World Wide Web, also called the Web, is a place on the Internet where we find documents and other stuff. Each thing has its special address called a URL, like <a target="_blank" href="https://example.com/"><code>https://example.com/</code></a><code>.</code> These things can link to each other, and we can access them through the internet.</li>
</ul>
<h3 id="heading-who-is-responsible-for-managing-all-this-stuff">Who is responsible for managing all this stuff:</h3>
<p>The Internet Society is responsible for all the rules and regulations that we have to send our data over the Internet.</p>
<h2 id="heading-client-server-architecture">Client-Server Architecture:</h2>
<p><strong>This is the typical client-server model:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708451362245/244bd90d-d387-4992-a0c5-799bff535531.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Your computer/laptop can work as a client and server.</p>
</li>
<li><p>The client-server model is a way computers communicate over networks.</p>
</li>
<li><p>In this model, one computer acts as a client, requesting services or resources.</p>
</li>
<li><p>Another computer acts as a server, providing those services or resources.</p>
</li>
<li><p>These computers can be anywhere in the world, connected by wires laid under oceans.</p>
</li>
<li><p>Your computer or laptop can act as both a client, requesting information, and a server, providing information, depending on the situation.</p>
</li>
</ul>
<p><strong>Submarine cables map (Optical Fibre Cable)</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708450818039/1343de66-f171-474a-a855-300692d0f30a.png" alt="Submarine Cables Map(optical fiber cables)" class="image--center mx-auto" /></p>
<p><mark>”So the internet is not like in the clouds but it’s under the sea”</mark></p>
<h2 id="heading-how-is-data-transferred">How is data Transferred?</h2>
<p><strong>Packets</strong>: Packets are small chunks of data that travel across networks like digital envelopes. They have destination addresses and come together to deliver messages or files.</p>
<p><strong>This is how the data is transferred:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708452106737/5220af03-4f48-47c2-8d86-de761cdc0659.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Connected to the Internet</strong>: Devices connect via Wi-Fi, Ethernet, or mobile data.</p>
</li>
<li><p><strong>ISP (Internet Service Provider)</strong>: Provides internet access.</p>
</li>
<li><p><strong>Modem/Router</strong>: Provided by the ISP, assigns global IP addresses.</p>
</li>
<li><p><strong>Device1,2,3</strong>: Receives local IP addresses via DHCP for communication within the network.</p>
</li>
<li><p><strong>IP (Internet Protocol)</strong>: Global IP identifies devices on the internet; local IP identifies devices within a network.</p>
</li>
<li><p><strong>Data Transfer</strong>: Devices package data into packets with destination IP addresses. Modem/router routes packets based on global IP. Destination devices receive and reconstruct data using local IP.</p>
</li>
</ol>
<p><strong>Finally, if we talk:</strong><br />Devices connect to the internet through an ISP, which assigns a global IP via a modem/router; data is then packaged into packets with destination IP addresses, routed based on global IP, and received using local IP addresses on destination devices for reconstruction.</p>
<ul>
<li><p>IP address determines which device you are using and</p>
</li>
<li><p>The Port Number will determine which application you are using to communicate</p>
</li>
<li><p><strong>Tata Communications</strong> is the <strong>tier 1 ‘ISP</strong>’ provided in <strong>India</strong></p>
</li>
<li><p>Tier 2 <strong>‘ISPs’</strong> are like <strong>Airtel</strong> or others…</p>
</li>
</ul>
<h2 id="heading-what-is-a-network"><strong>What is a network?</strong></h2>
<p>A network is a collection of network-enabled devices, typically made up of computers, switches, routers, printers, and servers.</p>
<h3 id="heading-panpersonal-area-network">PAN(Personal area network):</h3>
<ul>
<li><p>PAN connects devices within a small area, like a room or an individual.</p>
</li>
<li><p>e.g. include Bluetooth connections between devices or wireless connections within a home.</p>
</li>
</ul>
<h3 id="heading-lanlocal-area-network">LAN(Local area network):</h3>
<ul>
<li><p>LAN is used in small-scale settings such as homes, offices, or schools.</p>
</li>
<li><p>Provides networking capabilities for devices within a limited geographic area.</p>
</li>
<li><p>Typically connected via Ethernet cables or Wi-Fi routers.</p>
</li>
</ul>
<h3 id="heading-manmetropolitan-area-network">MAN(Metropolitan area network):</h3>
<ul>
<li><p>MAN covers a larger geographical area, such as a city or town.</p>
</li>
<li><p>Used to interconnect various LANs within the same metropolitan region.</p>
</li>
<li><p>Utilizes technologies like fiber optics or wireless connections.</p>
</li>
</ul>
<h3 id="heading-wanwide-area-network">WAN(Wide area network):</h3>
<ul>
<li><p>WAN spans large distances, connecting networks across cities, countries, or even continents.</p>
</li>
<li><p>Enables communication between LANs and MANs over extensive geographical areas.</p>
</li>
<li><p>Relies on high-speed data transmission technologies like optical fiber cables for long-distance connections.</p>
</li>
</ul>
<blockquote>
<ol>
<li><p><strong>SONET</strong>( Synchronous optical networking): So it carries the data using an optical fiber cable, hence it covers a larger distance.</p>
</li>
<li><p><strong>Frame relay:</strong> It is a way to connect your local area network to the wider area network like the Internet.</p>
</li>
</ol>
</blockquote>
<h2 id="heading-modemrouter">Modem/Router:</h2>
<p><strong>Modem:</strong></p>
<ul>
<li><p>A modem is used to convert the digital signal into an analog signal and vice-versa.</p>
</li>
<li><p>Converts digital signals from your devices into signals that can travel over phone lines or cables, and vice versa.</p>
</li>
<li><p>Links your home network to your internet service provider (ISP).</p>
</li>
</ul>
<p><strong>Router:</strong></p>
<ul>
<li><p>Directs internet traffic between devices in your home network and the internet.</p>
</li>
<li><p>Uses IP addresses to send data packets to their intended destinations.</p>
</li>
<li><p>Provides features like Wi-Fi, firewall protection, and network management.</p>
</li>
<li><p>Work on the network layer.</p>
</li>
</ul>
<h2 id="heading-topologies">Topologies:</h2>
<ol>
<li><p><strong>Bus</strong>: A network topology where all devices are connected to a single communication line.</p>
</li>
<li><p><strong>Ring</strong>: A network topology where devices are connected in a circular manner, forming a closed loop.</p>
</li>
<li><p><strong>Mesh</strong>: A network topology where devices are interconnected with multiple redundant paths between them.</p>
</li>
<li><p><strong>Star</strong>: A network topology where all devices are connected to a central hub or switch.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708609106477/3ee59c05-2657-46f1-b400-d776c85e9a5c.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ol>
<blockquote>
<ul>
<li><p><strong>Ethernet:</strong> Widely used networking standard for LAN, MAN, and WAN networks.</p>
</li>
<li><p><strong>Fast Ethernet:</strong> Developed to support data transmission speeds of up to 100 Mbps.</p>
</li>
<li><p><strong>Gigabit Ethernet:</strong> Developed to support faster communication networks, reaching speeds of 1 Gbps.</p>
</li>
<li><p><strong>10 Gigabit Ethernet:</strong> Standardized with a nominal data transfer speed of 10 Gbps.</p>
</li>
<li><p><strong>Terabit Ethernet:</strong> Offers data transfer speeds of 200 Gbps and 400 Gbps.</p>
</li>
</ul>
</blockquote>
<h2 id="heading-structure-of-the-network">Structure of the Network:</h2>
<p>Let’s understand it by a real-world scenario:<br />That's how the Internet works</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708610717655/5e2136ee-dc62-4d51-a476-c7d65f05e9ad.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-osi-open-system-interconnection-layer">OSI (Open System Interconnection) Layer:</h2>
<h3 id="heading-1-application-layer"><strong>1. Application Layer:</strong></h3>
<ul>
<li><p>Facilitates communication between applications and users, providing services like email and web browsing.</p>
</li>
<li><p><strong>Example:</strong> Sending an email using Outlook.</p>
</li>
<li><p><strong>Protocol:</strong> HTTP/HTTPS for web browsing, SMTP for email.</p>
</li>
</ul>
<h3 id="heading-2-presentation-layer"><strong>2. Presentation Layer:</strong></h3>
<ul>
<li><p>Handles data translation, encryption, and compression, ensuring compatibility between different systems.</p>
</li>
<li><p><strong>Example:</strong> Viewing an image on a website.</p>
</li>
<li><p><strong>Protocol:</strong> SSL/TLS for secure data transmission, JPEG for image compression.</p>
</li>
</ul>
<h3 id="heading-3-session-layer"><strong>3. Session Layer:</strong></h3>
<ul>
<li><p>Manages communication sessions between devices, establishing, maintaining, and terminating connections.</p>
</li>
<li><p><strong>Example:</strong> Video conferencing with Skype.</p>
</li>
<li><p><strong>Protocol:</strong> SSH for secure remote login, NetBIOS for session control.</p>
</li>
</ul>
<h3 id="heading-4-transport-layer"><strong>4. Transport Layer:</strong></h3>
<ul>
<li><p>Provides reliable end-to-end data delivery, error-checking, and flow control.</p>
</li>
<li><p><strong>Example:</strong> Downloading a file using FTP.</p>
</li>
<li><p><strong>Protocol:</strong> TCP for reliable transmission, UDP for faster but less reliable transmission.</p>
</li>
<li><p><strong>checksum:</strong></p>
<ul>
<li>Data will travel in order and the receiver get in the order.</li>
</ul>
</li>
</ul>
<p>    <strong>Times (Retransmission timer):</strong></p>
<ul>
<li>The timer starts when you send the data and it’ll expire when the receiver gets the data</li>
</ul>
<ul>
<li><p><strong>UDP (User Datagram Protocol):</strong></p>
<ul>
<li><p>Data may or may not be delivered</p>
</li>
<li><p>Data may be corrupted/change</p>
</li>
<li><p>Data may not be in order</p>
</li>
<li><p>UDP uses checksum</p>
</li>
</ul>
</li>
<li><p><strong>UDP Packet:</strong></p>
<p>  | Source Port No. (2 bytes) | Length of datagram (2bytes) |
  | --- | --- |
  | Destination port No.(2bytes) | Checksum (2bytes) |
  | Data |  |</p>
<p>  <strong>Use Cases:</strong></p>
<ul>
<li><p>It’s very fast</p>
</li>
<li><p>video conferencing apps</p>
</li>
<li><p>DNS also uses UDP</p>
</li>
<li><p>Gaming</p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-bash">    sudo tcpdump -c5
</code></pre>
<ul>
<li><p><strong>TCP (Transmission Control Protocol):</strong></p>
<ul>
<li><p>Transport layer protocol</p>
</li>
<li><p>congestion control</p>
</li>
<li><p>The application layer sends lots of raw data, and TCP segments this data → divides it into chunks, and adds headers. It may also collect data from the network layer( data in the form of packets)</p>
</li>
<li><p>Takes care of :</p>
<ul>
<li><p>when data does not arrive.</p>
</li>
<li><p>Maintains the order of data using sequence numbers.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Features:</strong></p>
<ul>
<li><p>Connection-oriented( means first the connection must be established)</p>
</li>
<li><p>Error-control</p>
</li>
<li><p>Congestion control</p>
</li>
<li><p>Full-Duplex (two-way communication)</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-5-network-layer"><strong>5. Network Layer:</strong></h3>
<ul>
<li><p>Handles routing and forwarding of data packets across networks, enabling inter-network communication.</p>
</li>
<li><p><strong>Example:</strong> Sending data between two computers on different networks.</p>
</li>
<li><p><strong>Protocol:</strong> IP for addressing and routing packets, ICMP for network diagnostics.</p>
</li>
<li><p><strong>Control place:</strong></p>
<ul>
<li><p>Routers are responsible for managing nodes within a network.</p>
</li>
<li><p>Links establish connections between nodes and are referred to as edges.</p>
</li>
<li><p><strong>Static Routing:</strong></p>
<ul>
<li>Implemented manually by configuring routing tables on routers.</li>
</ul>
</li>
<li><p><strong>Dynamic Routing:</strong></p>
<ul>
<li>Utilizes algorithms to automatically adjust routing tables based on network conditions.</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="heading-6-data-link-layer"><strong>6. Data Link Layer:</strong></h3>
<ul>
<li><p>Organizes data into frames and manages access to the physical transmission medium.</p>
</li>
<li><p><strong>Example:</strong> Transferring data between a computer and a printer.</p>
</li>
<li><p><strong>Protocol:</strong> Ethernet for LAN communication, Wi-Fi for wireless LAN.</p>
</li>
<li><p><strong>ARP (Address Resolution Protocol):</strong> The Address Resolution Protocol (ARP) is a communications protocol within the Internet Protocol suite. It's a request-response protocol used to resolve the media access control (MAC) address for a given IP address.</p>
<ul>
<li><p><strong>Framing:</strong> ARP is a protocol used to map IP addresses to MAC addresses on a local network.</p>
</li>
<li><p><strong>Error Detection:</strong> It helps devices find the MAC address corresponding to an IP address within the same network segment.</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-7-physical-layer"><strong>7. Physical Layer:</strong></h3>
<ul>
<li><p>Deals with the physical connection between devices, including transmission of raw data bits.</p>
</li>
<li><p><strong>Example:</strong> Connecting a computer to a router via Ethernet cable.</p>
</li>
<li><p><strong>Protocol:</strong> IEEE 802.3 for Ethernet, IEEE 802.11 for Wi-Fi.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708663764022/a0130012-cd56-41ea-9456-554e8ab451d6.jpeg" alt class="image--center mx-auto" /></p>
<blockquote>
<p><mark>The OSI model is more theoratical approch or concept based.</mark></p>
</blockquote>
<h2 id="heading-tcpip-model5-layers">TCP/IP Model(5 Layers):</h2>
<ol>
<li><p><strong>Application Layer:</strong> Users interact with applications running on their devices.</p>
</li>
<li><p><strong>Transport Layer:</strong> Ensures reliable data delivery between devices.</p>
</li>
<li><p><strong>Internet Layer:</strong> Manages addressing and routing across networks.</p>
</li>
<li><p><strong>Data Link Layer:</strong> Handles communication within a network segment.</p>
</li>
<li><p><strong>Physical Layer:</strong> Deals with the physical transmission of data over the network medium.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708663755684/250ac69f-7d40-42c3-8fde-44e5334d176d.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p><mark>The TCP/IP Model is more practical approch</mark></p>
</blockquote>
<h2 id="heading-peep-to-peer-architecture">Peep-to-Peer Architecture:</h2>
<p>Peer-to-peer (P2P) architecture distributes tasks or workloads among peers without the need for a central server, enabling decentralized communication and resource sharing.</p>
<p><strong>Rapid Scalability</strong>:</p>
<ul>
<li>Allows for quick expansion as more participants join.</li>
</ul>
<p><strong>Decentralization</strong>:</p>
<ul>
<li>Operates without a central authority or server control.</li>
</ul>
<p><strong>Example: BitTorrent</strong>:</p>
<ul>
<li>Users share files directly, enabling efficient distribution without a central server.</li>
</ul>
<h2 id="heading-networking-devices">Networking Devices:</h2>
<p><strong>Repeater:</strong></p>
<ul>
<li><p>A two-port device that repeats network signals without modifying data packets.</p>
</li>
<li><p>Regenerates data packets at original strength for devices located at a distance.</p>
</li>
</ul>
<p><strong>Bridge:</strong></p>
<ul>
<li><p>Divides network into segments and forwards data packets based on MAC addresses.</p>
</li>
<li><p>Reduces unnecessary traffic by filtering data between segments.</p>
</li>
</ul>
<p><strong>Hub:</strong></p>
<ul>
<li><p>A multiport repeater that connects multiple devices in a network.</p>
</li>
<li><p>Operates at the speed of the slowest device and sends copies of data packets to all devices.</p>
</li>
</ul>
<p><strong>Types of Hub:</strong></p>
<ul>
<li><p><strong>Active Hub:</strong> Requires external power and regenerates signals.</p>
</li>
<li><p><strong>Passive Hub:</strong> This does not require external power and does not regenerate signals.</p>
</li>
</ul>
<p><strong>Switch:</strong></p>
<ul>
<li><p>Combines bridge and hub functionalities, segmenting networks and filtering packet data.</p>
</li>
<li><p>Uses MAC addresses to direct data packets and operates in full-duplex mode.</p>
</li>
</ul>
<p><strong>Types of Ethernet Switch:</strong></p>
<ul>
<li><p><strong>Unmanaged:</strong> No configuration capability, suitable for small-office/home-office environments.</p>
</li>
<li><p><strong>Managed:</strong> Offers extensive configuration options via CLI or web interface, including QoS, VLANs, STP, port mirroring, etc.</p>
</li>
<li><p><strong>Smart:</strong> Limited configuration options through a web-based interface, a midpoint between unmanaged and managed switches.</p>
</li>
<li><p><strong>Enterprise:</strong> Fully managed switches with comprehensive configuration capabilities for enterprise networks.</p>
</li>
</ul>
<p><strong>Bridge:</strong></p>
<ul>
<li>Connects multiple network segments, forwarding data packets based on MAC addresses.</li>
</ul>
<p><strong>Types of Bridge:</strong></p>
<ul>
<li>Transparent Bridge, Source Route Bridge, and Translational Bridge.</li>
</ul>
<p><strong>Routers:</strong></p>
<ul>
<li>Direct network traffic between different networks based on IP addresses.z</li>
</ul>
<p><strong>Gateway:</strong></p>
<ul>
<li>Acts as an entry or exit point between networks, often performing protocol translation.</li>
</ul>
<p><strong>Brouter:</strong></p>
<ul>
<li>Combines the functionalities of a bridge and a router, forwarding packets between networks based on both MAC and IP addresses.</li>
</ul>
<h2 id="heading-protocols">Protocols:</h2>
<ul>
<li><p><strong>Web Protocols:</strong></p>
<ul>
<li><p><strong>TCP/IP:</strong> Suite of protocols governing internet communication.</p>
</li>
<li><p><strong>HTTP:</strong> Hypertext Transfer Protocol for web browsing.</p>
</li>
<li><p><strong>DHCP:</strong> Dynamic Host Configuration Protocol for automatic IP address assignment.</p>
</li>
<li><p><strong>FTP:</strong> File Transfer Protocol for transferring files between computers.</p>
</li>
<li><p><strong>SMTP:</strong> Simple Mail Transfer Protocol for sending email.</p>
</li>
<li><p><strong>POP3 &amp; IMAP:</strong> Post Office Protocol and Internet Message Access Protocol for email retrieval.</p>
</li>
<li><p><strong>SSH (Secure Shell):</strong> Secure remote login and file transfer protocol.</p>
</li>
<li><p><strong>VNC (Virtual Network Computing):</strong> Remote desktop access protocol.</p>
</li>
<li><p><strong>Telnet (Terminal Emulation):</strong> Protocol for remote access to command-line interfaces, typically on port 23.</p>
</li>
<li><p><strong>UDP (User Datagram Protocol):</strong> Connectionless protocol for data transmission without error checking or correction.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-sockets">Sockets:</h2>
<ul>
<li><p>Software endpoints facilitate communication between processes over a network.</p>
</li>
<li><p>They enable data exchange between applications running on different devices.</p>
</li>
</ul>
<p><strong>Let's Understand with example:</strong></p>
<ul>
<li><p>Two computers running chat applications establish a socket connection.</p>
</li>
<li><p>This connection allows the applications to send and receive messages in real time.</p>
</li>
</ul>
<h2 id="heading-ports">Ports:</h2>
<ul>
<li><p>Ports identify which application we're using with a 16-bit number.</p>
</li>
<li><p>There are about <strong>65,000 port numbers</strong> available.</p>
</li>
<li><p>Common ports include HTTP (80), MongoDB (27017), and SQL (1433).</p>
</li>
<li><p>Ports 0-1023 are reserved, while 1024-19152 are typically used for applications.</p>
</li>
<li><p>Ephemeral ports are dynamic and used to differentiate between instances or processes within an application.</p>
</li>
<li><p>They exist on the client side and must be known on the server side for data routing.</p>
<blockquote>
<ul>
<li><p>1 kbps (kilobit per second) = 1,000 bits/s</p>
</li>
<li><p>1 Mbps (megabit per second) = 1,000,000 bits/s</p>
</li>
<li><p>1 Gbps (gigabit per second) = 1,000,000,000 bits/s</p>
</li>
</ul>
</blockquote>
</li>
</ul>
<p><strong>The following table lists some of the more common well-known port numbers.</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Port number</td><td>Assignment</td></tr>
</thead>
<tbody>
<tr>
<td>20</td><td>File Transfer Protocol for data transfer</td></tr>
<tr>
<td>21</td><td>File Transfer Protocol for command control</td></tr>
<tr>
<td>22</td><td>Secure Shell for secure authentication</td></tr>
<tr>
<td>23</td><td>Telnet remote authentication service for unencrypted text messages</td></tr>
<tr>
<td>25</td><td>Simple Mail Transfer Protocol for email routing</td></tr>
<tr>
<td>53</td><td>Domain Name System service</td></tr>
<tr>
<td>80</td><td>Hypertext Transfer Protocol for use in the web</td></tr>
<tr>
<td>110</td><td>Post Office Protocol</td></tr>
<tr>
<td>119</td><td>Network News Transfer Protocol (NNTP)</td></tr>
<tr>
<td>123</td><td>Network Time Protocol (NTP)</td></tr>
<tr>
<td>143</td><td>Internet Message Access Protocol for management of digital mail</td></tr>
<tr>
<td>161</td><td>Simple Network Management Protocol</td></tr>
<tr>
<td>194</td><td>Internet Relay Chat (IRC)</td></tr>
<tr>
<td>443</td><td>HTTP Secure HTTP over TLS/SSL</td></tr>
</tbody>
</table>
</div><h3 id="heading-http-hypertext-transfer-protocol">HTTP (Hypertext transfer protocol):</h3>
<ul>
<li><p>HTTP( Application layer ) used TCP ( transport layer )</p>
</li>
<li><p>Stateless protocol, the server did not store any information about the client by default.</p>
</li>
</ul>
<h3 id="heading-http-methodsget-post-put-delete">HTTP Methods(GET, POST ,PUT ,DELETE):</h3>
<ul>
<li>What is a method: A method is something that tells the server what to do.</li>
</ul>
<h3 id="heading-get"><strong>GET:</strong></h3>
<ul>
<li><p>You are requesting some data.</p>
</li>
<li><p>Example: Retrieve information from a website by entering its URL in a browser's address bar.</p>
</li>
</ul>
<h3 id="heading-post"><strong>POST:</strong></h3>
<ul>
<li><p>Like I'm a client and I'm giving something to the server, like when you register somewhere, username, password, etc.</p>
</li>
<li><p>Example: Submitting a form with user information to create a new account on a website.</p>
</li>
</ul>
<h3 id="heading-putpatch"><strong>PUT/PATCH:</strong></h3>
<ul>
<li><p>Put the data at a specific location.</p>
</li>
<li><p>Patch usually is for partial updates.</p>
</li>
<li><p>Example: Updating a specific user's profile information on a website.</p>
</li>
</ul>
<h3 id="heading-delete"><strong>DELETE:</strong></h3>
<ul>
<li><p>When you want to delete any data.</p>
</li>
<li><p>Example: Removing a post or comment from a social media platform.</p>
</li>
</ul>
<h3 id="heading-errorstatus-codes">Error/Status Codes:</h3>
<ul>
<li><p><strong>100</strong>: Informational codes</p>
</li>
<li><p><strong>200</strong>: Success codes</p>
</li>
<li><p><strong>300</strong>: redirecting</p>
</li>
<li><p><strong>400</strong>: client error</p>
</li>
<li><p><strong>500</strong>: server error</p>
</li>
</ul>
<h3 id="heading-response-status-codes">Response status codes</h3>
<p>The HTTP <strong><mark>200 OK success</mark></strong> status response code indicates that <strong>the request has succeeded</strong></p>
<p>Status codes have conventions. For example, any status code starting with a "2xx" (a "200-level response") represents a successful call. Get familiar with other status code categories:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Code range</td><td>Meaning</td><td>Example</td></tr>
</thead>
<tbody>
<tr>
<td>2xx</td><td>Success</td><td>200 - OK201 - Created204 - No content (silent OK)</td></tr>
<tr>
<td>3xx</td><td>Redirection</td><td>301 - Moved (path changed)</td></tr>
<tr>
<td>4xx</td><td>Client error</td><td>400 - Bad request401 - Unauthorized403 - Not Permitted404 - Not Found</td></tr>
<tr>
<td>5xx</td><td>Server error</td><td>500 - Internal server error502 - Bad gateway504 - Gateway timeout</td></tr>
</tbody>
</table>
</div><h3 id="heading-cookies">Cookies:</h3>
<ul>
<li><p>Unique string</p>
</li>
<li><p>Stored in browser</p>
</li>
<li><p>Small data pieces</p>
</li>
<li><p>Used for session management, personalization, and tracking</p>
</li>
<li><p>Maintain user sessions and preferences</p>
</li>
<li><p>Track user behavior</p>
</li>
</ul>
<h3 id="heading-third-party-cookies"><strong>Third-Party Cookies</strong></h3>
<ul>
<li><p>Cookies set by domains other than the one the user is currently visiting</p>
</li>
<li><p>Often used for tracking and advertising purposes</p>
</li>
<li><p>Enable cross-site tracking</p>
</li>
<li><p>Can be used by advertisers to gather information about user browsing habits</p>
</li>
<li><p>Controversial due to privacy concerns</p>
</li>
<li><p>Subject to regulation and browser restrictions</p>
</li>
</ul>
<h3 id="heading-cache">Cache:</h3>
<ul>
<li><p>Temporary storage location</p>
</li>
<li><p>Used to store frequently accessed data</p>
</li>
<li><p>Improves website performance by reducing load times</p>
</li>
<li><p>Can be browser cache or server cache</p>
</li>
<li><p>Stores copies of web pages, images, and other resources</p>
</li>
<li><p>Helps minimize server load and network traffic</p>
</li>
</ul>
<h3 id="heading-how-does-email-work">How does email work?</h3>
<p>Email works by composing messages in an email client, which are then sent to an outgoing mail server using SMTP. The recipient's mail server receives the email and stores it until the recipient's email client retrieves it using POP3 or IMAP. The recipient accesses the email through their email client or webmail interface for reading, replying, and managing messages.</p>
<p>Email operates through a series of protocols and standards to facilitate communication and message retrieval:</p>
<ul>
<li><p><strong>SMTP (Simple Mail Transfer Protocol)</strong>: This protocol is employed to send emails over the Internet. It operates on top of the TCP (Transmission Control Protocol) to ensure reliable data delivery.</p>
</li>
<li><p><strong>POP3 (Post Office Protocol, Port No. 110)</strong>: Used for retrieving emails from a mail server to a client device. POP3 allows users to download their emails to their local devices for offline access.</p>
</li>
<li><p><strong>IMAP (Internet Message Access Protocol)</strong>: Unlike POP3, IMAP permits users to access their emails from multiple devices while keeping them synchronized with the server. This protocol allows for managing emails across various devices without the need to download them locally.</p>
</li>
</ul>
<pre><code class="lang-bash">-<span class="hljs-built_in">type</span>=mx gmail.com
</code></pre>
<h3 id="heading-dns-domain-name-system">DNS (Domain Name System):</h3>
<ul>
<li><p>So basically when you enter <a target="_blank" href="http://google.com">google.com</a> it’ll use DNS to find the IP address of Google’s server.</p>
</li>
<li><p>You can't buy a domain name but you can rent it. For example, you rent the .org domain name which top-level domain name to GoDaddy for example and then you have to pay GoDaddy and GoDaddy will pay the <a target="_blank" href="https://www.icann.org/"><strong>Internet Corporation for Assigned Names and Numbers (ICANN)</strong></a></p>
</li>
</ul>
<h2 id="heading-3-way-handshake">3-Way Handshake:</h2>
<ol>
<li><p><strong>Initiation (First handshake)</strong>:</p>
<ul>
<li><p>The client sends a synchronization (SYN) packet to the server, indicating its intent to establish a connection and specifying initial sequence numbers.</p>
</li>
<li><p>This packet contains TCP header flags indicating the SYN flag is set, along with other connection-related information.</p>
</li>
</ul>
</li>
<li><p><strong>Agreement (Second handshake)</strong>:</p>
<ul>
<li><p>Upon receiving the SYN packet, the server responds with a SYN-ACK packet.</p>
</li>
<li><p>The server acknowledges the client's SYN packet (SYN-ACK), indicating its readiness to establish the connection.</p>
</li>
<li><p>The SYN-ACK packet contains its own initial sequence number, as well as TCP header flags indicating both the SYN and ACK flags are set.</p>
</li>
</ul>
</li>
<li><p><strong>Communication (Third handshake)</strong>:</p>
<ul>
<li><p>Finally, the client sends an acknowledgment (ACK) packet to the server.</p>
</li>
<li><p>This packet acknowledges the server's SYN-ACK packet and confirms the connection establishment.</p>
</li>
<li><p>The ACK packet contains an incremented acknowledgment number, confirming receipt of the server's SYN-ACK packet.</p>
</li>
</ul>
</li>
<li><p><strong>Established Connection</strong>:</p>
<ul>
<li><p>With the three-way handshake completed, a reliable, bidirectional communication channel is established between the client and server.</p>
</li>
<li><p>Subsequent data exchange can occur over this established connection, with both parties synchronized and ready to transmit and receive data packets.</p>
</li>
</ul>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708450938869/f50d7ac2-047a-4f9d-8f7b-29a33017b20a.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-ip-internet-protocol-address">IP ( Internet Protocol ) Address:</h3>
<ul>
<li><p>IP addresses tell us which device we are working with.</p>
</li>
<li><p>IP addresses uniquely identify devices connected to a network.</p>
</li>
<li><p>They consist of a series of numbers separated by dots, like 192.168.2.30</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708451847907/e97f1134-f598-403a-b539-cf43b3961790.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Each device, such as a computer or smartphone, has its own IP address.</p>
</li>
<li><p>IP addresses help devices communicate with each other over the internet.</p>
</li>
<li><p>They play a crucial role in directing data packets to their intended destinations.</p>
</li>
</ul>
<pre><code class="lang-bash">curl ifconfig.me -s
</code></pre>
<p>The command <code>curl ifconfig.me -s</code> is used to retrieve your public IP address from the <a target="_blank" href="http://ifconfig.me">ifconfig.me</a> service using the cURL command-line tool. The <code>-s</code> flag is used to suppress the progress meter and other unnecessary output.</p>
<h3 id="heading-ipv4">IPv4:</h3>
<ul>
<li><p>32-bit address space, expressed in four decimal numbers.</p>
</li>
<li><p>Limited to approximately 4.3 billion unique addresses.</p>
</li>
<li><p>Uses NAT for address conservation.</p>
</li>
<li><p>Limited support for security features.</p>
</li>
<li><p>An example of an IPv4 address is: 192.168.0.1</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708699747248/b95beb60-dad8-43b9-bc15-4afb8efeba5b.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-ipv6">IPv6:</h3>
<ul>
<li><p>128-bit address space, expressed in hexadecimal notation.</p>
</li>
<li><p>Offers an extremely large number of unique addresses.</p>
</li>
<li><p>Simplifies address assignment and configuration.</p>
</li>
<li><p>Supports built-in security features like IPsec.</p>
</li>
<li><p>Facilitates efficient routing and packet processing.</p>
</li>
<li><p>Transition mechanisms ensure compatibility during the transition from IPv4.</p>
</li>
<li><p>An example of an IPv6 address is: 2001:0db8:85a3:0000:0000:8a2e:0370:7334</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708699755753/aee2a34b-86f9-4442-bd7d-f1fcf7280947.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-ipv4-vs-ipv6">IPv4 Vs IPv6</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>IPv4</td><td>IPv6</td></tr>
</thead>
<tbody>
<tr>
<td>Address Space</td><td>32-bit, limited (approx. 4.3 billion)</td><td>128-bit, vast (approx. 3.4 x 10^38)</td></tr>
<tr>
<td>Address Format</td><td>Decimal (e.g., 192.168.1.1)</td><td>Hexadecimal (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334)</td></tr>
<tr>
<td>Address Configuration</td><td>Manual or DHCP</td><td>Stateless Address Autoconfiguration (SLAAC)</td></tr>
<tr>
<td>Security Features</td><td>Limited</td><td>Built-in support for IPsec</td></tr>
<tr>
<td>Routing Efficiency</td><td>Less efficient</td><td>More efficient due to simplified headers</td></tr>
<tr>
<td>Transition Mechanisms</td><td>Requires transition mechanisms</td><td>Transition mechanisms for coexistence</td></tr>
</tbody>
</table>
</div><h3 id="heading-classes-of-ip-addresses">Classes of IP Addresses:</h3>
<p>Classification system dividing IP addresses into Class A, B, C, D, and E based on their leading bits, determining network size and address allocation.</p>
<p><strong>Class A:</strong></p>
<ol>
<li><p>First bit is always fixed to 0.</p>
</li>
<li><p>Allows for a very large number of hosts (over 16 million).</p>
</li>
<li><p>Primarily used by large organizations or internet service providers.</p>
</li>
</ol>
<p><strong>Class B:</strong></p>
<ol>
<li><p>First two bits are fixed to 10.</p>
</li>
<li><p>Suitable for medium-sized networks with moderate numbers of hosts (up to 65,534).</p>
</li>
<li><p>Provides a balance between network and host addresses.</p>
</li>
</ol>
<p><strong>Class C:</strong></p>
<ol>
<li><p>First three bits are fixed to 110.</p>
</li>
<li><p>Designed for small networks with a limited number of hosts (up to 254).</p>
</li>
<li><p>Commonly used for small businesses or home networks.</p>
</li>
</ol>
<p><strong>Class D:</strong></p>
<ol>
<li><p>First four bits are fixed to 1110.</p>
</li>
<li><p>Reserved for multicast addressing, used for one-to-many communication.</p>
</li>
<li><p>Not used for traditional unicast communication between hosts.</p>
</li>
</ol>
<p><strong>Class E:</strong></p>
<ol>
<li><p>First four bits are fixed to 1111.</p>
</li>
<li><p>Reserved for experimental or research purposes.</p>
</li>
<li><p>Not intended for general use in production networks.</p>
</li>
</ol>
<h3 id="heading-what-is-a-subnet"><strong>What is a subnet?</strong></h3>
<p>A subnet defines one or more logical networks within the class A, B, or C network. Without subnets, you're restricted to a single network in each of the class A, B, or C networks.</p>
<h3 id="heading-middle-boxes">Middle Boxes:</h3>
<p>A middlebox is a network device or appliance that provides specific services such as firewalling or NAT (Network Address Translation) between different network segments.</p>
<p><strong>Firewall</strong>:</p>
<ul>
<li><p>Monitors and controls network traffic based on security rules.</p>
</li>
<li><p>Acts as a barrier between trusted internal and untrusted external networks.</p>
</li>
<li><p>Can be hardware or software-based, analyzing data packets to determine passage.</p>
</li>
</ul>
<p><strong>NAT (Network Address Translation):</strong></p>
<ul>
<li><p>Modifies network address information in packet headers.</p>
</li>
<li><p>Allows multiple devices to share a single public IP address.</p>
</li>
<li><p>Translates private IP addresses to a single public IP address, facilitating communication between local devices and the internet.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708450986033/5bfdb71c-6aef-4dab-a1df-232352e31520.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-mac-addresses">MAC Addresses:</h2>
<p>The media access control (MAC) address is a <strong>unique identifier</strong> assigned to e<strong>very network-enabled device</strong> at the <strong>time of manufacture</strong>. It's sometimes referred to as the <strong>burned-in address</strong>, the <strong>Ethernet hardware address</strong>, or a <strong>physical address</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708622406153/662c2357-b47a-4517-b9c3-c8984a4ab9b3.png" alt class="image--center mx-auto" /></p>
<p>The MAC address has a standard composition of <strong>six hexadecimal numbers separated by a colon or dash</strong>. The first three numbers of the MAC address define the manufacturer's organizationally unique identifier (OUI), and the remaining three numbers uniquely identify the device. For example, if the MAC address is <code>ff:ff:ff:ff:ff:ff</code> then the OUI is <code>ff:ff:ff</code> and <code>ff:ff:ff</code> is the device ID.</p>
<h2 id="heading-vpn-tunneling">VPN tunneling</h2>
<p>VPN tunneling is the process of encrypting data packets sent over a public network, creating a secure "tunnel" between the user's device and the VPN server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1708700210343/9fe55754-9e30-4f05-b6aa-e3733df8db1e.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>VPN tunneling encrypts data packets for secure transmission over a public network.</p>
</li>
<li><p>It establishes a virtual encrypted connection between the user's device and the VPN server.</p>
</li>
<li><p>This process ensures data confidentiality, integrity, and privacy.</p>
</li>
<li><p><strong>Example</strong>: User data is encrypted at their device, transmitted securely to the VPN server through an encrypted tunnel, decrypted at the server, and then forwarded to the intended destination.</p>
</li>
</ul>
<h2 id="heading-tls-and-ssl">TLS and SSL</h2>
<ul>
<li><p><strong>TLS</strong> (Transport Layer Security) and <strong>SSL</strong> (Secure Sockets Layer) are cryptographic protocols.</p>
</li>
<li><p>They provide <strong>secure communication</strong> over a network by encrypting data transmitted between clients and servers.</p>
</li>
<li><p>TLS is the <strong>successor of SSL</strong> and offers improved security features.</p>
</li>
<li><p>Example: TLS/SSL encrypts data exchanged between a web browser (client) and a web server, ensuring confidentiality and integrity of information such as login credentials or financial transactions.</p>
</li>
</ul>
<blockquote>
<p>Ofcourse this blog does not consists all about computer networking and if you want to learn more reger this structure learning path by microsoft learn.</p>
<p><a target="_blank" href="https://learn.microsoft.com/en-us/training/modules/network-fundamentals/">Computer Networking</a></p>
</blockquote>
]]></content:encoded></item></channel></rss>