<?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[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://swarnadeep.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 12:52:06 GMT</lastBuildDate><atom:link href="https://swarnadeep.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[DevOps Project: Continuous Deployment of a Reddit Clone application in Prod on K8S Cluster]]></title><description><![CDATA[The Reddit clone application is deployed via K8S cluster on AWS EKS integrated with Ansible, Docker, Jenkins, Docker Hub & GitHub. When any change happens…]]></description><link>https://swarnadeep.hashnode.dev/devops-project-continuous-deployment-of-a-reddit-clone-application-in-prod-on-k8s-cluster</link><guid isPermaLink="true">https://swarnadeep.hashnode.dev/devops-project-continuous-deployment-of-a-reddit-clone-application-in-prod-on-k8s-cluster</guid><dc:creator><![CDATA[Swarnadeep jena]]></dc:creator><pubDate>Fri, 24 Mar 2023 18:29:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1679682864771/9b8229a4-c74c-44de-8ba1-2eb743108cc9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-project-summary"><strong><em>Project Summary:</em></strong></h3>
<ol>
<li><p><em>The Reddit clone application is deployed via K8S cluster on AWS EKS integrated with Ansible, Docker, Jenkins, Docker Hub &amp; GitHub.</em></p>
</li>
<li><p><em>When any change happens on app</em> code*, the CI job is automatically triggered and Ansible Playbook executes, that build Docker image &amp; push it to Docker Hub. Then CD job is triggered and Ansible Playbook runs Pods on EKS cluster.*</p>
</li>
<li><p><em>After that we can access Reddit app by using Load Balancer's DNS with target port.</em></p>
</li>
</ol>
<p><strong>Prerequisite:</strong> First We have to install &amp; setup some Prerequisites (i.e. Ansible, Docker, Jenkins, Kubectl) for this project.</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQFCLYYxHRzLTQ/article-inline_image-shrink_1500_2232/0/1678791768745?e=1684972800&amp;v=beta&amp;t=ZPOtitIjyrT8bqY29WsaMEnyYHYzL56CryXvj14EMO4" alt="No alt text provided for this image" /></p>
<p>Servers</p>
<p><em>GitHub Repo</em>: <a target="_blank" href="https://github.com/swarnadeepjena/reddit-clone-k8s-ingress-1.git">https://github.com/swarnadeepjena/reddit-clone-k8s-ingress-1.git</a></p>
<h3 id="heading-cicd-with-github-jenkins-ansible-and-docker"><strong>CI/CD with GitHub, Jenkins, Ansible and Docker</strong></h3>
<p><img src="https://media.licdn.com/dms/image/D4D12AQG3WhA5no5S7Q/article-inline_image-shrink_1500_2232/0/1678789207461?e=1684972800&amp;v=beta&amp;t=VePbLVnJ3uB5kGccYnxiIPoqKwOG1OTCO-UbM38q6tU" alt="No alt text provided for this image" /></p>
<p>CI Job Build Environment</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQHobp0a3YVipQ/article-inline_image-shrink_1500_2232/0/1678789505214?e=1684972800&amp;v=beta&amp;t=1nOn2FJAoLJaFmRC5RRvGnOSqYfr9FWRFSGngc1--Sg" alt="No alt text provided for this image" /></p>
<p>CI Job Build Environment</p>
<ul>
<li><p>Setup Ansible server</p>
</li>
<li><p>Integrate Docker host with Ansible</p>
</li>
<li><p>Ansible playbook to create image &amp; push the image to Docker Hub</p>
</li>
<li><p>Integrate Ansible with Jenkins</p>
</li>
</ul>
<blockquote>
<p>Dockerfile</p>
</blockquote>
<pre><code class="lang-yaml"><span class="hljs-string">FROM</span> <span class="hljs-string">node:19-alpine3.15</span>
<span class="hljs-string">WORKDIR</span> <span class="hljs-string">/reddit-clone</span>
<span class="hljs-string">COPY</span> <span class="hljs-string">.</span> <span class="hljs-string">/reddit-clone</span>
<span class="hljs-string">RUN</span> <span class="hljs-string">npm</span> <span class="hljs-string">install</span> 
<span class="hljs-string">EXPOSE</span> <span class="hljs-number">3000</span>
<span class="hljs-string">CMD</span> [<span class="hljs-string">"npm"</span>,<span class="hljs-string">"run"</span>,<span class="hljs-string">"dev"</span>]
</code></pre>
<hr />
<blockquote>
<p>Ansible Playbook for Docker to build &amp; push image to Docker Hub</p>
</blockquote>
<pre><code class="lang-yaml"><span class="hljs-meta">---</span>
<span class="hljs-bullet">-</span> <span class="hljs-attr">hosts:</span> <span class="hljs-string">ansible</span>
  <span class="hljs-attr">tasks:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">crete</span> <span class="hljs-string">docker</span> <span class="hljs-string">image</span>
      <span class="hljs-attr">command:</span> <span class="hljs-string">docker</span> <span class="hljs-string">build</span> <span class="hljs-string">/home/svcans/reddit-clone-k8s/</span> <span class="hljs-string">-t</span> <span class="hljs-string">reddit-clone:latest</span>

    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">create</span> <span class="hljs-string">tag</span> <span class="hljs-string">to</span> <span class="hljs-string">push</span> <span class="hljs-string">image</span> <span class="hljs-string">to</span> <span class="hljs-string">dockerhub</span>
      <span class="hljs-attr">command:</span> <span class="hljs-string">docker</span> <span class="hljs-string">tag</span> <span class="hljs-string">reddit-clone:latest</span> <span class="hljs-string">swarnadeep/reddit-clone:latest</span>

    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">push</span> <span class="hljs-string">docker</span> <span class="hljs-string">image</span>
      <span class="hljs-attr">command:</span> <span class="hljs-string">docker</span> <span class="hljs-string">push</span> <span class="hljs-string">swarnadeep/reddit-clone:latest</span>
</code></pre>
<p><img src="https://media.licdn.com/dms/image/D4D12AQHsxMGXyhJlpA/article-inline_image-shrink_1500_2232/0/1678789703770?e=1684972800&amp;v=beta&amp;t=2RT3t6Q_e6dPJqC81vNNKi4QSxAxr5lEkkBbLXGSSrM" alt="No alt text provided for this image" /></p>
<p>Docer Hub Image</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQH1UVHY_7rVmQ/article-inline_image-shrink_1500_2232/0/1678788985720?e=1684972800&amp;v=beta&amp;t=QC3yXqX4NgVWjjmgX6LRIxtGjsZb2JuBoCU3rcLLTuE" alt="No alt text provided for this image" /></p>
<p>CI Job Buid</p>
<h3 id="heading-cicd-with-github-jenkins-ansible-and-kubernets"><strong>CI/CD with GitHub, Jenkins, Ansible and Kubernets</strong></h3>
<p><img src="https://media.licdn.com/dms/image/D4D12AQGkAwmCAesGlQ/article-inline_image-shrink_1500_2232/0/1678789087811?e=1684972800&amp;v=beta&amp;t=JXBs2BdBaDr1PZQqa7KJZoNJUUEH-daMuW8c3_9e-2s" alt="No alt text provided for this image" /></p>
<p>CD Job Build</p>
<p>Setup Kubernetes (EKS)</p>
<ul>
<li><p>Write service and deployment manifest files</p>
</li>
<li><p>Integrate Kubernetes with Ansible</p>
</li>
<li><p>Ansible playbooks to create deployment and service in K8S cluster</p>
</li>
<li><p>CI/CD job to build code on ansible and deploy it on Kubernetes</p>
</li>
</ul>
<p><img src="https://media.licdn.com/dms/image/D4D12AQGqswrYkBK5HA/article-inline_image-shrink_1500_2232/0/1678788346166?e=1684972800&amp;v=beta&amp;t=ZSI0CTQ1NAL2A4792Ta9BPdtvrSVYuvmFVsTuHksGm0" alt="No alt text provided for this image" /></p>
<p>CI / CD Job</p>
<ul>
<li>Automated deployment of app through integration of GitHub with CI/CD Job via GitHub Webhooks.</li>
</ul>
<hr />
<blockquote>
<p>Deployment.yml</p>
</blockquote>
<pre><code class="lang-yaml"><span class="hljs-attr">apiVersion:</span> <span class="hljs-string">apps/v</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">Deployment</span>
<span class="hljs-attr">metadata:</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone-deployment</span>
  <span class="hljs-attr">labels:</span>
    <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
<span class="hljs-attr">spec:</span>
  <span class="hljs-attr">replicas:</span> <span class="hljs-number">2</span>
  <span class="hljs-attr">selector:</span>
    <span class="hljs-attr">matchLabels:</span>
      <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
  <span class="hljs-attr">template:</span>
    <span class="hljs-attr">metadata:</span>
      <span class="hljs-attr">labels:</span>
        <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
    <span class="hljs-attr">spec:</span>
      <span class="hljs-attr">containers:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">swarnadeep/reddit-clone</span>
        <span class="hljs-attr">ports:</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">containerPort:</span> <span class="hljs-number">3000</span>
</code></pre>
<hr />
<blockquote>
<p>Service.yml</p>
</blockquote>
<pre><code class="lang-yaml"><span class="hljs-attr">apiVersion:</span> <span class="hljs-string">v1</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">Service</span>
<span class="hljs-attr">metadata:</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone-service</span>
  <span class="hljs-attr">labels:</span>
    <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
<span class="hljs-attr">spec:</span>
  <span class="hljs-attr">type:</span> <span class="hljs-string">LoadBalancer</span>
  <span class="hljs-attr">ports:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">port:</span> <span class="hljs-number">3000</span>
    <span class="hljs-attr">targetPort:</span> <span class="hljs-number">3000</span>
    <span class="hljs-attr">nodePort:</span> <span class="hljs-number">31000</span>
  <span class="hljs-attr">selector:</span>
    <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
</code></pre>
<hr />
<blockquote>
<p>Ansible Playbook for Deployment &amp; Service</p>
</blockquote>
<pre><code class="lang-yaml"><span class="hljs-meta">---</span>
<span class="hljs-bullet">-</span> <span class="hljs-attr">hosts:</span> <span class="hljs-string">kubernets</span>
  <span class="hljs-attr">user:</span> <span class="hljs-string">root</span>
  <span class="hljs-attr">tasks:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">deploy</span> <span class="hljs-string">app</span> <span class="hljs-string">on</span> <span class="hljs-string">eks</span>
      <span class="hljs-attr">command:</span> <span class="hljs-string">kubectl</span> <span class="hljs-string">apply</span> <span class="hljs-string">-f</span> <span class="hljs-string">Deployment.yml</span>

    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">deploy</span> <span class="hljs-string">reddit</span> <span class="hljs-string">app</span> <span class="hljs-string">on</span> <span class="hljs-string">k8s</span>
      <span class="hljs-attr">command:</span> <span class="hljs-string">kubectl</span> <span class="hljs-string">apply</span> <span class="hljs-string">-f</span> <span class="hljs-string">/root/Service.yml</span>
</code></pre>
<h3 id="heading-manage-dockerhost-eks-bootstrap-server-with-ansible-node-server"><strong>Manage DockerHost, EKS BootStrap Server with Ansible Node Server</strong></h3>
<p><img src="https://media.licdn.com/dms/image/D4D12AQFmaLlxBTYVxg/article-inline_image-shrink_1500_2232/0/1678788790029?e=1684972800&amp;v=beta&amp;t=lxT-doInSIgVPby-sQw7-HQmTWiSI6JBrOlpkCq0JyQ" alt="No alt text provided for this image" /></p>
<p>sudoers file</p>
<h3 id="heading-on-host-servers"><em>On Host Servers</em></h3>
<p><img src="https://media.licdn.com/dms/image/D4D12AQG-6NyCkLM2gw/article-inline_image-shrink_1500_2232/0/1678788544914?e=1684972800&amp;v=beta&amp;t=GvmZ2cwlATnFtUGQ7mtSHwjKeSk6ODjNLxR55fOZQOI" alt="No alt text provided for this image" /></p>
<p>/etc/ssh/sshd_config</p>
<p>•   Create svcans user</p>
<p>•    Add svcans to sudoers files</p>
<p>•    Enable password based login</p>
<blockquote>
<p>Ansible Inventory File</p>
</blockquote>
<pre><code class="lang-yaml">[<span class="hljs-string">svcans@ansible-server</span> <span class="hljs-string">~</span>]<span class="hljs-string">$</span> <span class="hljs-string">cat</span> <span class="hljs-string">/etc/ansible/host</span>
[<span class="hljs-string">ansible</span>]
<span class="hljs-number">172.31</span><span class="hljs-number">.10</span><span class="hljs-number">.155</span>

[<span class="hljs-string">kubernets</span>]
<span class="hljs-number">172.31</span><span class="hljs-number">.49</span><span class="hljs-string">.62s</span>
</code></pre>
<hr />
<h3 id="heading-on-ansible-node">On Ansible Node</h3>
<p>•     Add IPs to hosts file</p>
<p>•     Generate ssh keys &amp; copy that key to DockerHost, EKS BootStrap server</p>
<p>•     Test the connection</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQFq-zIMmjGsjw/article-inline_image-shrink_1500_2232/0/1678791157904?e=1684972800&amp;v=beta&amp;t=RraISjm5RHAQKgrGY1hDtCwYSqjk5ND3LkxolWUu7Vs" alt="No alt text provided for this image" /></p>
<p>Ansible Test Connection</p>
<h3 id="heading-eks-setup"><strong>EKS Setup</strong></h3>
<p><img src="https://media.licdn.com/dms/image/D4D12AQFHk5J0QbCAZQ/article-inline_image-shrink_1500_2232/0/1678787845292?e=1684972800&amp;v=beta&amp;t=rsnnoNPs72djJnko1N6-ayDvKrSJzrhZi8Sao8cTOls" alt="No alt text provided for this image" /></p>
<p>EKS Cluster</p>
<p>•        Launch EC2 instance – Bootstrap</p>
<p>•        Latest version of AWSCLI</p>
<pre><code class="lang-yaml"><span class="hljs-string">curl</span> <span class="hljs-string">"https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"</span> <span class="hljs-string">-o</span> <span class="hljs-string">"awscliv2.zip
unzip awscliv2.zip
sudo ./aws/install"</span>
</code></pre>
<p>•        Setup kubectl</p>
<pre><code class="lang-yaml"><span class="hljs-string">curl</span> <span class="hljs-string">-O</span> <span class="hljs-string">https://s3.us-west-2.amazonaws.com/amazon-eks/1.25.6/2023-01-30/bin/linux/amd64/kubect</span>
<span class="hljs-string">chmod</span> <span class="hljs-string">+x</span> <span class="hljs-string">./kubectl</span>
<span class="hljs-string">sudo</span> <span class="hljs-string">mv</span> <span class="hljs-string">/tmp/eksctl</span> <span class="hljs-string">/usr/local/bin</span>
</code></pre>
<p>•        Setup eksctl</p>
<pre><code class="lang-yaml"><span class="hljs-string">curl</span> <span class="hljs-string">--silent</span> <span class="hljs-string">--location</span> <span class="hljs-string">"https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz"</span> <span class="hljs-string">|</span> <span class="hljs-string">tar</span> <span class="hljs-string">xz</span> <span class="hljs-string">-C</span> <span class="hljs-string">/tmp</span>
<span class="hljs-string">sudo</span> <span class="hljs-string">mv</span> <span class="hljs-string">/tmp/eksctl</span> <span class="hljs-string">/usr/local/bin</span>
<span class="hljs-string">eksctl</span> <span class="hljs-string">version</span>
</code></pre>
<p><img src="https://media.licdn.com/dms/image/D4D12AQHpjLp-pJeu_Q/article-inline_image-shrink_1500_2232/0/1678791688517?e=1684972800&amp;v=beta&amp;t=ds6t_ZKCIbwubUbt1y2GRCUVG5ZvYdcJ7a6NKkanLmQ" alt="No alt text provided for this image" /></p>
<p>Servers</p>
<p>•        Create IAM role for EC2 to access AWS CloudFormation</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQG2JA2kioAZTA/article-inline_image-shrink_1500_2232/0/1678788015540?e=1684972800&amp;v=beta&amp;t=dRCMcZrH9bUCteNczHoKsqDHpHnTCnCmCeK6tGrjZuY" alt="No alt text provided for this image" /></p>
<p>CloudFormation Stack</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQEb5Kf5pugRdA/article-inline_image-shrink_1500_2232/0/1678791576206?e=1684972800&amp;v=beta&amp;t=O1umo8EzRch0-txxlkX1MSlULzgvaibZEvMEH7aQ88o" alt="No alt text provided for this image" /></p>
<p>CloudoFormation Resources</p>
<p>•        Create a cluster</p>
<pre><code class="lang-yaml"><span class="hljs-string">eksctl</span> <span class="hljs-string">create</span> <span class="hljs-string">cluster</span> <span class="hljs-string">--name</span> <span class="hljs-string">reddit-prod</span> 
<span class="hljs-string">--region</span> <span class="hljs-string">us-east-1</span> <span class="hljs-string">\</span>
<span class="hljs-string">--node-type</span> <span class="hljs-string">t2.micro</span> <span class="hljs-string">\</span>
<span class="hljs-string">--zones</span> <span class="hljs-string">us-east-1a,</span> <span class="hljs-string">us-east-1b\</span>
</code></pre>
<p><img src="https://media.licdn.com/dms/image/D4D12AQHFLgRFjzM0KQ/article-inline_image-shrink_1500_2232/0/1678787739004?e=1684972800&amp;v=beta&amp;t=miA5GwziRRRNgBNIlC_tZD4v57b5DQXlBK_Gdy4cn7U" alt="No alt text provided for this image" /></p>
<p>•        Validate cluster</p>
<pre><code class="lang-csharp">cat /root/.kube/config
kubectl gat
</code></pre>
<p><img src="https://media.licdn.com/dms/image/D4D12AQF7KqTmuVA7Bg/article-inline_image-shrink_1500_2232/0/1678787597276?e=1684972800&amp;v=beta&amp;t=2o7Es80OnxM_z_yVtUzgwYoL7roQN0aWsmlHjvGN1J4" alt="No alt text provided for this image" /></p>
<p>•        Delete cluster</p>
<pre><code class="lang-yaml"><span class="hljs-string">eksctl</span> <span class="hljs-string">delete</span> <span class="hljs-string">cluster</span> <span class="hljs-string">--name</span> <span class="hljs-string">reddit-prod</span> <span class="hljs-string">--region</span> <span class="hljs-string">us-east-1</span>
</code></pre>
<p><img src="https://media.licdn.com/dms/image/D4D12AQHtH5ycGVXfUA/article-inline_image-shrink_1500_2232/0/1678791369973?e=1684972800&amp;v=beta&amp;t=Q8qAJOyrKxSYexOXKkyRlne2SFFRfYvOZ84Waj5PwPg" alt="No alt text provided for this image" /></p>
<p>Node Group Configuration</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQELdX8i9iQ1-w/article-inline_image-shrink_1500_2232/0/1678788051247?e=1684972800&amp;v=beta&amp;t=i3SlkyO2tgYoI3gTHwlrc9GkaJkenq0oJPtn5zpeRrQ" alt="Load Balancer" /></p>
<p>Load Balancers</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQGBt2wYR574DA/article-inline_image-shrink_1500_2232/0/1678788255670?e=1684972800&amp;v=beta&amp;t=OjYPz6LhKmc-exrTwCRai7_39FtQUDDZBhULMJrqM4o" alt="No alt text provided for this image" /></p>
<p>Reddit Clone Application</p>
<p><img src="https://media.licdn.com/dms/image/D4D12AQEC3edK3p9BoA/article-inline_image-shrink_1500_2232/0/1678794171979?e=1684972800&amp;v=beta&amp;t=-De4LzV41KKTXo6k0Ka0nePHDWuHR9eku45yHbSAjmw" alt="No alt text provided for this image" /></p>
<h2 id="heading-thank-you"><strong><em>Thank You!</em></strong></h2>
]]></content:encoded></item><item><title><![CDATA[Deployed a Reddit Copy on Kubernetes with Ingress Enabled]]></title><description><![CDATA[For Pre-Requsite take the reference of: The first step is to clone the source code for the app. You can do this by using this command git clone]]></description><link>https://swarnadeep.hashnode.dev/deployed-a-reddit-copy-on-kubernetes-with-ingress-enabled</link><guid isPermaLink="true">https://swarnadeep.hashnode.dev/deployed-a-reddit-copy-on-kubernetes-with-ingress-enabled</guid><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Swarnadeep jena]]></dc:creator><pubDate>Fri, 24 Mar 2023 17:47:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1679679861810/7aa6c1b5-da59-4bc6-939d-c7570a6d8ec4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For Pre-Requsite take the reference of: <a target="_blank" href="https://swarnadeep.hashnode.dev/prerequisite-for-deployment-of-a-reddit-copy-on-kubernetes-with-ingress-enabled">https://swarnadeep.hashnode.dev/prerequisite-for-deployment-of-a-reddit-copy-on-kubernetes-with-ingress-enabled</a></p>
<h1 id="heading-step-1-clone-the-source-code"><strong>Step 1: Clone the source code</strong></h1>
<p>The first step is to clone the source code for the app. You can do this by using this command <code>git clone</code> <a target="_blank" href="https://github.com/swarnadeepjena/reddit-clone-k8s-ingress-1.git">https://github.com/swarnadeepjena/reddit-clone-k8s-ingress-1.git</a></p>
<h1 id="heading-step-2-containerize-the-application-using-docker">Step 2: Containerize the Application using Docker</h1>
<ul>
<li>Write a Dockerfile with the following code:</li>
</ul>
<pre><code class="lang-go">
FROM node:<span class="hljs-number">19</span>-alpine3<span class="hljs-number">.15</span>

WORKDIR /reddit-clone

COPY . /reddit-clone

RUN npm install 

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

CMD [<span class="hljs-string">"npm"</span>,<span class="hljs-string">"run"</span>,<span class="hljs-string">"dev"</span>]
</code></pre>
<h1 id="heading-step-3-building-docker-image">Step 3) Building Docker-Image</h1>
<p>Now it's time to build Docker Image from this Dockerfile. <code>docker build -t &lt;DockerHub_Username&gt;/&lt;Imagename&gt; .</code> use this command to build a docker image.</p>
<h1 id="heading-step-4-push-the-image-to-dockerhub">Step 4) Push the Image To DockerHub</h1>
<p>Now push this Docker image to DockerHub so our Deployment file can pull this image &amp; run the app in Kubernetes pods.</p>
<ul>
<li><p>First login to your DockerHub account using Command i.e <code>docker login</code> and give your username &amp; password.</p>
</li>
<li><p>Then used <code>docker push &lt;DockerHub_Username&gt;/&lt;Imagename&gt;</code> for pushing to the DockerHub.</p>
</li>
<li><p>You can use an existing docker image i.e <strong><em>swarnadeep/Reddit-clone</em></strong> for deployment.</p>
</li>
</ul>
<h1 id="heading-step-5-write-a-kubernetes-manifest-file">Step 5) Write a Kubernetes Manifest File</h1>
<p>Now, You might be wondering what this manifest file in Kubernetes is. Don't worry, I'll tell you in brief.</p>
<p>When you are going to deploy to Kubernetes or create Kubernetes resources like a pod, replica-set, config map, secret, deployment, etc, you need to write a file called manifest that describes that object and its attributes either in yaml or json. Just like you do in the ansible playbook.</p>
<p>Of course, you can create those objects by using just the command line, but the recommended way is to write a file so that you can version control it and use it in a repeatable way.</p>
<ol>
<li><h2 id="heading-write-deploymentyml-file">Write Deployment.yml file</h2>
</li>
</ol>
<p>Let's Create a Deployment File For our Application. Use the following code for the <strong><em>Deployment.yml</em></strong> file.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">apiVersion:</span> <span class="hljs-string">apps/v1</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">Deployment</span>
<span class="hljs-attr">metadata:</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone-deployment</span>
  <span class="hljs-attr">labels:</span>
    <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
<span class="hljs-attr">spec:</span>
  <span class="hljs-attr">replicas:</span> <span class="hljs-number">2</span>
  <span class="hljs-attr">selector:</span>
    <span class="hljs-attr">matchLabels:</span>
      <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
  <span class="hljs-attr">template:</span>
    <span class="hljs-attr">metadata:</span>
      <span class="hljs-attr">labels:</span>
        <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
    <span class="hljs-attr">spec:</span>
      <span class="hljs-attr">containers:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">swarnadeep/reddit-clone</span>
        <span class="hljs-attr">ports:</span>
        <span class="hljs-bullet">-</span> <span class="hljs-attr">containerPort:</span> <span class="hljs-number">3000</span>
</code></pre>
<ol>
<li><h2 id="heading-write-serviceyml-file">Write Service.yml file</h2>
</li>
</ol>
<pre><code class="lang-yaml"><span class="hljs-attr">apiVersion:</span> <span class="hljs-string">v1</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">Service</span>
<span class="hljs-attr">metadata:</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone-service</span>
  <span class="hljs-attr">labels:</span>
    <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
<span class="hljs-attr">spec:</span>
  <span class="hljs-attr">type:</span> <span class="hljs-string">NodePort</span>
  <span class="hljs-attr">ports:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">port:</span> <span class="hljs-number">3000</span>
    <span class="hljs-attr">targetPort:</span> <span class="hljs-number">3000</span>
    <span class="hljs-attr">nodePort:</span> <span class="hljs-number">31000</span>
  <span class="hljs-attr">selector:</span>
    <span class="hljs-attr">app:</span> <span class="hljs-string">reddit-clone</span>
</code></pre>
<h1 id="heading-step-5-deploy-the-app-to-kubernetes-andamp-create-a-service-for-it">Step 5) Deploy the app to Kubernetes &amp; Create a Service For It</h1>
<p>Now, we have a deployment file for our app and we have a running Kubernetes cluster, we can deploy the app to Kubernetes. To deploy the app you need to run following the command: <code>kubectl apply -f Deployment.yml</code> Just Like this create a Service using <code>kubectl apply -f Service.yml</code></p>
<p>If You want to check your deployment &amp; Service use the command <code>kubectl get deployment</code> &amp; <code>kubectl get services</code></p>
<h1 id="heading-step-6-lets-configure-ingress">Step 6) Let's Configure Ingress</h1>
<h2 id="heading-ingress">Ingress:</h2>
<p>Pods and services in Kubernetes have their IP; however, it usually is not the interface you'd provide to the external internet. Though there is a service with node IP configured, the port in the node IP can't be duplicated among the services. It is cumbersome to decide which port to manage with which service. Furthermore, the node comes and goes, it wouldn't be clever to provide a static node IP to an external service. Ingress defines a set of rules that allows the inbound connection to access Kubernetes cluster services. It brings the traffic into the cluster at L7 and allocates and forwards a port on each VM to the service port. This is shown in the following figure. We define a set of rules and post them as source type ingress to the API server. When the traffic comes in, the ingress controller will then fulfill and route the ingress by the ingress rules. As shown in the following figure, ingress is used to route external traffic to the Kubernetes endpoints by different URLs:</p>
<p><img src="https://matthewpalmer.net/kubernetes-app-developer/articles/ingress.png" alt /></p>
<p>Let's write ingress.yml and put the following code in it:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">ersion:</span> <span class="hljs-string">networking.k8s.io/v1</span>
<span class="hljs-attr">kind:</span> <span class="hljs-string">Ingress</span>
<span class="hljs-attr">metadata:</span>
  <span class="hljs-attr">name:</span> <span class="hljs-string">ingress-reddit-app</span>
<span class="hljs-attr">spec:</span>
  <span class="hljs-attr">rules:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">host:</span> <span class="hljs-string">"domain.com"</span>
    <span class="hljs-attr">http:</span>
      <span class="hljs-attr">paths:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">pathType:</span> <span class="hljs-string">Prefix</span>
        <span class="hljs-attr">path:</span> <span class="hljs-string">"/test"</span>
        <span class="hljs-attr">backend:</span>
          <span class="hljs-attr">service:</span>
            <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone-service</span>
            <span class="hljs-attr">port:</span>
              <span class="hljs-attr">number:</span> <span class="hljs-number">3000</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">host:</span> <span class="hljs-string">"*.domain.com"</span>
    <span class="hljs-attr">http:</span>
      <span class="hljs-attr">paths:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">pathType:</span> <span class="hljs-string">Prefix</span>
        <span class="hljs-attr">path:</span> <span class="hljs-string">"/test"</span>
        <span class="hljs-attr">backend:</span>
          <span class="hljs-attr">service:</span>
            <span class="hljs-attr">name:</span> <span class="hljs-string">reddit-clone-service</span>
            <span class="hljs-attr">port:</span>
              <span class="hljs-attr">number:</span> <span class="hljs-number">3000</span>
</code></pre>
<p>Minikube doesn't enable ingress by default; we have to enable it first using <code>minikube addons enable ingress</code> command.</p>
<ul>
<li>If you want to check the current setting for addons in minikube use <code>minikube addons list</code> command.</li>
</ul>
<p>Now you can be able to create ingress for your service. <code>kubectl apply -f ingress.yml</code> use this command to apply ingress settings.</p>
<ul>
<li>Verify that the ingress resource is running correctly by using <code>kubectl get ingress ingress-reddit-app</code> command.</li>
</ul>
<h1 id="heading-step-8-expose-the-app">Step 8) Expose the app</h1>
<ol>
<li><p>First We need to expose our deployment so use <code>kubectl expose deployment reddit-clone-deployment --type=NodePort</code> command.</p>
</li>
<li><p>You can test your deployment using curl -L <a target="_blank" href="http://192.168.49.2:31000"><strong>http://192.168.49.2:31000</strong></a>. <strong>192.168.49.2</strong> is a minikube ip &amp; Port <strong>31000</strong> is defined in Service.yml</p>
</li>
<li><p>Then We have to expose our app service <code>kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0 &amp;</code></p>
</li>
</ol>
<h1 id="heading-test-ingress">Test Ingress</h1>
<p>Now It's time to test your ingress so use the <strong><em>curl -L domain/test</em></strong> command in the terminal.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1677665654407/76061aa0-1d26-4f2d-9000-447936ca5181.png?auto=compress,format&amp;format=webp" alt /></p>
<p>You can also see the deployed application on <strong>Ec2_ip:3000</strong></p>
<p><em><mark>Note:- Make sure you open the 3000 port in a security group of your Ec2 Instance.</mark></em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1677780495226/7ba8afd2-e45e-455c-9b18-ee0a91d8c5a1.png?auto=compress,format&amp;format=webp" alt /></p>
<p><strong>You have successfully Deployed a Reddit Copy on Kubernetes with Ingress Enabled.</strong></p>
]]></content:encoded></item><item><title><![CDATA[Prerequisite For Deployment of a Reddit Copy on Kubernetes with Ingress Enabled]]></title><description><![CDATA[Before we begin with the Project, we need to make sure we have the following prerequisites installed: EC2 ( AMI- Ubuntu, Type- t2.medium ) Docker Minikube…]]></description><link>https://swarnadeep.hashnode.dev/prerequisite-for-deployment-of-a-reddit-copy-on-kubernetes-with-ingress-enabled</link><guid isPermaLink="true">https://swarnadeep.hashnode.dev/prerequisite-for-deployment-of-a-reddit-copy-on-kubernetes-with-ingress-enabled</guid><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><dc:creator><![CDATA[Swarnadeep jena]]></dc:creator><pubDate>Fri, 24 Mar 2023 17:32:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1679679065008/dcd5dd1d-abba-4caf-ae03-84dd1f7fd8f9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before we begin with the Project, we need to make sure we have the following prerequisites installed:</p>
<ol>
<li><p>EC2 ( AMI- Ubuntu, Type- t2.medium )</p>
</li>
<li><p>Docker</p>
</li>
<li><p>Minikube</p>
</li>
<li><p>kubectl</p>
</li>
</ol>
<p>You can Install all this by doing the below steps one by one. and these steps are for Ubuntu AMI.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># Steps:-</span>

<span class="hljs-comment"># For Docker Installation</span>
sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker <span class="hljs-variable">$USER</span> &amp;&amp; newgrp docker

<span class="hljs-comment"># For Minikube &amp; Kubectl</span>
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/<span class="hljs-built_in">local</span>/bin/minikube 

sudo snap install kubectl --classic
minikube start --driver=docker
</code></pre>
<p>Great! You're all set for the project. Your Minikube cluster is now prepared for deploying the Reddit clone application. For additional information on deployment.</p>
<p>Once you done, follow mentioned link for deloyment : <a target="_blank" href="https://swarnadeep.hashnode.dev/deployed-a-reddit-copy-on-kubernetes-with-ingress-enabled">https://swarnadeep.hashnode.dev/deployed-a-reddit-copy-on-kubernetes-with-ingress-enabled</a></p>
]]></content:encoded></item></channel></rss>