<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Radha on Medium]]></title>
        <description><![CDATA[Stories by Radha on Medium]]></description>
        <link>https://medium.com/@radharamadoss?source=rss-ebf80e44c203------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8CWj_UZ7ZleJyBHSXW3KQA.png</url>
            <title>Stories by Radha on Medium</title>
            <link>https://medium.com/@radharamadoss?source=rss-ebf80e44c203------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 07:09:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@radharamadoss/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kubernetes StatefulSet PVC Deletion: Simplifying Cleanup with the whenDeleted Option]]></title>
            <link>https://medium.com/@radharamadoss/kubernetes-statefulset-pvc-deletion-simplifying-cleanup-with-the-whendeleted-option-79ba3238ec2e?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/79ba3238ec2e</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Wed, 15 Jan 2025 02:44:19 GMT</pubDate>
            <atom:updated>2025-01-15T02:44:19.245Z</atom:updated>
            <content:encoded><![CDATA[<h4>Default PVC Behavior in StatefulSets</h4><p>StatefulSets in Kubernetes create PersistentVolumeClaims (PVCs) for each replica, but previously, these PVCs were not automatically deleted when a StatefulSet was scaled down or removed. This required manual cleanup or additional tools to manage them. While retaining PVCs is useful for critical data, it often leads to unnecessary costs and maintenance when the data is temporary or easily reproducible.</p><h4>PersistentVolumeClaim Reclaim policy</h4><p>While Kubernetes always had a PVC reclaim policy to manage what happens to Persistent Volumes (PVs) when a PVC is deleted (e.g., delete the PV and its backing storage), it did not provide a way to handle PVCs when pods in a StatefulSet are terminated or scaled down. This gap meant PVCs persisted even when they were no longer needed, requiring manual cleanup or external automation.</p><h4>PersistentVolumeClaim Retention Policy</h4><p>The new StatefulSet PVC retention policy is used to control if and when PVCs created from a StatefulSet’s volumeClaimTemplate are deleted.</p><p>The StatefulSetAutoDeletePVC feature was introduced as an alpha in Kubernetes version 1.23, promoted to beta in version 1.27, and graduated to stable in version 1.32.<br>And this feature is enabled by default in 1.32 version</p><h4>Scenario Without the Feature Enabled:</h4><p>Using a Kind cluster running Kubernetes version 1.32.</p><p><strong>Default Storage Class:</strong><br>default storage class in the Kind cluster:</p><pre>kubectl get storageclass<br>NAME                 PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE<br>standard (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  7d4h</pre><p><strong>statefulset.yaml</strong></p><pre>apiVersion: apps/v1<br>kind: StatefulSet<br>metadata:<br>  name: nginx-statefulset<br>spec:<br>  serviceName: &quot;nginx&quot;<br>  replicas: 3  # Number of replicas for the StatefulSet<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:latest<br>        volumeMounts:<br>        - mountPath: /usr/share/nginx/html<br>          name: nginx-storage  # This must match the volume name in volumeClaimTemplates<br>  volumeClaimTemplates:<br>  - metadata:<br>      name: nginx-storage  # This name will be used as a PVC name<br>    spec:<br>      accessModes:<br>        - ReadWriteOnce<br>      resources:<br>        requests:<br>          storage: 1Gi</pre><p>After the statefulset is created in the cluster, it creates 3 replica pods..</p><pre>kubectl get pods<br>NAME                                        READY   STATUS      RESTARTS   AGE<br>nginx-statefulset-0                         1/1     Running     0          21s<br>nginx-statefulset-1                         1/1     Running     0          12s<br>nginx-statefulset-2                         1/1     Running     0          7s</pre><p>Each StatefulSet pod gets its own dynamically created</p><p><strong>PersistentVolumeClaim (PVC):</strong></p><pre>kubectl get pvc <br>NAME                                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE<br>nginx-storage-nginx-statefulset-0   Bound    pvc-43c1100f-93b1-4248-bc79-6db2b644c504   1Gi        RWO            standard       &lt;unset&gt;                 77s<br>nginx-storage-nginx-statefulset-1   Bound    pvc-09d474f8-d453-4344-89fb-9c80db9fdb0a   1Gi        RWO            standard       &lt;unset&gt;                 68s<br>nginx-storage-nginx-statefulset-2   Bound    pvc-c0d12ebf-9870-4c49-8a20-20cea0c094c9   1Gi        RWO            standard       &lt;unset&gt;                 63s</pre><p><strong>Corresponding PersistentVolumes (PVs):</strong></p><pre>kubectl get pv <br>NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                       STORAGECLASS   VOLUMEATTRIBUTESCLASS   REASON   AGE<br>pvc-09d474f8-d453-4344-89fb-9c80db9fdb0a   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-1   standard       &lt;unset&gt;                          2m43s<br>pvc-43c1100f-93b1-4248-bc79-6db2b644c504   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-0   standard       &lt;unset&gt;                          2m52s<br>pvc-c0d12ebf-9870-4c49-8a20-20cea0c094c9   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-2   standard       &lt;unset&gt;                          2m37s</pre><p>Note that the PVs have a ReclaimPolicy set to Delete, meaning when the PVC is deleted, the PV is also deleted. However, this deletion does not depend on the lifecycle of the StatefulSet pods.</p><p>Execute the following commands to create data in the storage used by the StatefulSet pod:</p><pre>kubectl exec -it nginx-statefulset-0 -- bash   <br>root@nginx-statefulset-0:/# echo &quot;test&quot; &gt; /usr/share/nginx/html/index.html<br>root@nginx-statefulset-0:/#     </pre><p><strong>Verify Data on the Node’s Storage:</strong><br>Check if the file is created in the underlying storage of the Kind cluster.</p><p><strong>Identify the Kind cluster container:</strong></p><pre>podman ps<br>CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br>f8fdd01ec3ae docker.io/kindest/node@sha256:c48c62eac5da28cdadcf560d1d8616cfa6783b58f0d94cf63ad1bf49600cb027 5 days ago Up 5 days</pre><pre><br>podman exec -it f8fdd01ec3ae bash<br><br>root@sandbox-control-plane:/# cd /var/local-path-provisioner<br><br>root@sandbox-control-plane:/var/local-path-provisioner# ls<br>pvc-09d474f8-d453-4344-89fb-9c80db9fdb0a_default_nginx-storage-nginx-statefulset-1<br>pvc-43c1100f-93b1-4248-bc79-6db2b644c504_default_nginx-storage-nginx-statefulset-0<br>pvc-c0d12ebf-9870-4c49-8a20-20cea0c094c9_default_nginx-storage-nginx-statefulset-2<br><br>root@sandbox-control-plane:/var/local-path-provisioner# cd pvc-43c1100f-93b1-4248-bc79-6db2b644c504_default_nginx-storage-nginx-statefulset-0<br><br>root@sandbox-control-plane:/var/local-path-provisioner/pvc-43c1100f-93b1-4248-bc79-6db2b644c504_default_nginx-storage-nginx-statefulset-0# cat index.html<br>test</pre><p>Delete the StatefulSet and verify that the pods are removed:</p><pre>kubectl delete -f statefulset.yaml             <br>statefulset.apps &quot;nginx-statefulset&quot; deletedkubectl get pods<br>NAME                                        READY   STATUS      RESTARTS   AGE<br>buildpack-nodejs-buildrun-h5l2x-rbggs-pod   0/2     Completed   0          3d23h</pre><p>pods are deleted</p><pre>kubectl get pods<br></pre><p>Even though the StatefulSet and its pods are deleted, the PersistentVolumeClaims (PVCs) and PersistentVolumes (PVs) remain in the cluster:</p><pre>kubectl get pvc    <br>NAME                                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE<br>nginx-storage-nginx-statefulset-0   Bound    pvc-43c1100f-93b1-4248-bc79-6db2b644c504   1Gi        RWO            standard       &lt;unset&gt;                 15m<br>nginx-storage-nginx-statefulset-1   Bound    pvc-09d474f8-d453-4344-89fb-9c80db9fdb0a   1Gi        RWO            standard       &lt;unset&gt;                 15m<br>nginx-storage-nginx-statefulset-2   Bound    pvc-c0d12ebf-9870-4c49-8a20-20cea0c094c9   1Gi        RWO            standard       &lt;unset&gt;                 15m<br><br>kubectl get pv     <br>NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                       STORAGECLASS   VOLUMEATTRIBUTESCLASS   REASON   AGE<br>pvc-09d474f8-d453-4344-89fb-9c80db9fdb0a   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-1   standard       &lt;unset&gt;                          15m<br>pvc-43c1100f-93b1-4248-bc79-6db2b644c504   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-0   standard       &lt;unset&gt;                          15m<br>pvc-c0d12ebf-9870-4c49-8a20-20cea0c094c9   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-2   standard       &lt;unset&gt;                          15m</pre><p>When the <strong>ReclaimPolicy</strong> is set to Delete, deleting the PVCs will also delete the associated PVs from the cluster.</p><pre>kubectl delete pvc nginx-storage-nginx-statefulset-0 nginx-storage-nginx-statefulset-1 nginx-storage-nginx-statefulset-2<br>persistentvolumeclaim &quot;nginx-storage-nginx-statefulset-0&quot; deleted<br>persistentvolumeclaim &quot;nginx-storage-nginx-statefulset-1&quot; deleted<br>persistentvolumeclaim &quot;nginx-storage-nginx-statefulset-2&quot; deleted<br><br>kubectl get pvc    <br>No resources found in default namespace.<br><br>kubectl get pv <br>No resources found<br><br>The underlying storage was also deleted from the kind cluster container. Verifying the directory contents confirms that no files or folders remain:<br>root@sandbox-control-plane:/var/local-path-provisioner# ls</pre><p>Now, let’s enable the “whenDeleted” PVC retention policy.</p><pre>apiVersion: apps/v1<br>kind: StatefulSet<br>metadata:<br>  name: nginx-statefulset<br>spec:<br>  persistentVolumeClaimRetentionPolicy:<br>    whenDeleted: Delete<br>  serviceName: &quot;nginx&quot;<br>  replicas: 3  # Number of replicas for the StatefulSet<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:latest<br>        volumeMounts:<br>        - mountPath: /usr/share/nginx/html<br>          name: nginx-storage  # This must match the volume name in volumeClaimTemplates<br>  volumeClaimTemplates:<br>  - metadata:<br>      name: nginx-storage  # This name will be used as a PVC name<br>    spec:<br>      accessModes:<br>        - ReadWriteOnce<br>      resources:<br>        requests:<br>          storage: 1Gi</pre><pre>kubectl apply -f statefulset.yaml<br>statefulset.apps/nginx-statefulset created<br><br>kubectl get pvc                  <br>NAME                                STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE<br>nginx-storage-nginx-statefulset-0   Bound    pvc-4acc1cec-8bfa-4a59-b422-22bbc19a4a09   1Gi        RWO            standard       &lt;unset&gt;                 28s<br>nginx-storage-nginx-statefulset-1   Bound    pvc-64e2b6b2-9980-49be-962e-0865b6fc227d   1Gi        RWO            standard       &lt;unset&gt;                 24s<br>nginx-storage-nginx-statefulset-2   Bound    pvc-2a4eb8cc-2d7c-44e7-afa2-b545e80bd65e   1Gi        RWO            standard       &lt;unset&gt;                 18s<br><br>kubectl get pv <br>NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                       STORAGECLASS   VOLUMEATTRIBUTESCLASS   REASON   AGE<br>pvc-2a4eb8cc-2d7c-44e7-afa2-b545e80bd65e   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-2   standard       &lt;unset&gt;                          109s<br>pvc-4acc1cec-8bfa-4a59-b422-22bbc19a4a09   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-0   standard       &lt;unset&gt;                          2m1s<br>pvc-64e2b6b2-9980-49be-962e-0865b6fc227d   1Gi        RWO            Delete           Bound    default/nginx-storage-nginx-statefulset-1   standard       &lt;unset&gt;                          116s</pre><p>A file was created inside pod-0, and it is visible in the storage:</p><pre>root@sandbox-control-plane:/var/local-path-provisioner/pvc-4acc1cec-8bfa-4a59-b422-22bbc19a4a09_default_nginx-storage-nginx-statefulset-0# ls<br>index.html</pre><p>Next, the StatefulSet was deleted:</p><pre>kubectl delete -f statefulset.yaml<br>statefulset.apps &quot;nginx-statefulset&quot; deleted<br><br>kubectl get pods                  <br>NAME                                        READY   STATUS      RESTARTS   AGE<br> <br></pre><p>After deletion, the PVC, PV, and the underlying storage were also deleted. The underlying storage directory is now empty, confirming the storage deletion.</p><pre>kubectl get pvc <br>No resources found in default namespace.<br><br>kubectl get pv <br>No resources found<br><br>kind cluster container<br>root@sandbox-control-plane:/var/local-path-provisioner# ls</pre><p>This demonstrates that using the Delete reclaim policy causes the automatic deletion of PVCs, PVs, and underlying storage when the associated StatefulSet is deleted.</p><pre>kubectl get storageclass<br>NAME                 PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE<br>standard (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  7d4h</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79ba3238ec2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My CNCF GitOps Exam Day — A day of chaos and success]]></title>
            <link>https://medium.com/@radharamadoss/my-cncf-gitops-exam-day-a-day-of-chaos-and-success-ad09f5813ec4?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad09f5813ec4</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 03:33:59 GMT</pubDate>
            <atom:updated>2024-12-30T04:31:22.604Z</atom:updated>
            <content:encoded><![CDATA[<h3>My CNCF GitOps Exam Day — A day of chaos and success</h3><p>I recently passed the CNCF GitOps certification exam with an 88% — woohoo!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RUVhDmSRw7i52irwfOh8lw.png" /></figure><p>But this post isn’t about study tips or prep materials (those have already been excellently shared by someone <a href="https://github.com/otkd/CGOA-Study-Guide">here</a>). No, this is all about the rollercoaster ride that was my exam day!</p><p>This exam was multiple-choice, and honestly, I always get a bit nervous with those. There are always those tricky options that make you second-guess yourself, like, “Is this the right answer, or am I just overthinking it?”<br>I spent time reviewing concepts like CI, CD, CI+CD, CI-CD, CI+GitOps … 😁These terms can be tricky, almost like a riddle with the answer always being “it depends.” For example, is CI+CD a team or a couple? 🤔</p><p>This was my first exam in two years, so the usual <strong>exam fever</strong> kicked in. The night before, I meticulously revised and followed the golden advice of my school teachers: <em>“Get a good night’s sleep for a fresh mind!”</em> 😴 The next morning, I ate a healthy breakfast of fiber-rich fruits and nuts to power my brain.</p><h4>Exam Day: The Technical Drama</h4><p>My exam was scheduled for <strong>7 AM on a Saturday</strong>, and I could log in 30 minutes early. Like a diligent candidate, I joined early and went through the prerequisites — browser plugins, system checks, the works. But then, disaster struck.</p><p>An error popped up: <strong>“ScreensharingSubscriber app is open.”</strong> I checked Activity Monitor, but there was no sign of this mysterious app. With just 20 minutes left, I restarted my laptop, reinstalled the browser, and retried everything. Still, no luck. Panic started creeping in.</p><p>With no time to waste, I submitted a support ticket on the CNCF portal, hoping for a miracle. Then, an idea struck me — <strong>my son’s Windows laptop!</strong> The exam portal loaded perfectly in his laptop, and I was finally greeted with the proctor’s welcome screen. Crisis averted! 😌</p><h4>The Proctor Screening</h4><p>The proctor screening was quite thorough and interesting. First, I was asked to remove photos from my desk. Then, I had to show a 360-degree view of my room to confirm everything was exam-compliant, followed by a quick clean desk check.</p><p>Then came the most unexpected question:<br><em>“Are your glasses smart glasses?”</em></p><p>Let me tell you, my glasses are far from “smart” 😁 They’ve definitely seen better days and are due for a replacement at my next vision appointment.. Still, I couldn’t help but marvel at how much technology has advanced over the years! 😎</p><p>As if that wasn’t enough, the proctor asked me to show a close-up of my ears to confirm I wasn’t wearing earbuds. This threw me back to my school days when some kids would hide cheat sheets in their socks and sneak peeks when the teacher wasn’t looking. Ah, nostalgia!</p><h3>The Exam Begins</h3><p>Finally, the exam started. The questions were mostly manageable, but as expected with multiple-choice exams, a few options were downright confusing. I took my time, carefully analyzing each question. The proctor kept reminding me to keep my face perfectly centered in the camera frame. Staying so still for an extended period started giving me a bit of neck pain, but I powered through.</p><p>And then, midway through the exam, my dog was out of her crate and ready for attention! She started scratching the door, demanding her morning walk. This broke my focus for a moment, and When I turned my head, the proctor immediately issued a warning:</p><p><em>“One more warning, and your session will be terminated.”</em></p><p>That’s when the real panic set in 😧 — not about the questions but about ensuring my dog didn’t burst into the room or my son didn’t barge in asking for breakfast.</p><h3>Almost There!</h3><p>For the last 20 questions, I was in survival mode. I answered as quickly as possible, just wanting to avoid another warning. Once I finished, I debated whether to review my answers or submit immediately. Cautiously, I spent 5 minutes reviewing key questions before finally hitting <strong>Submit.</strong></p><p>The moment the exam ended, I felt an overwhelming sense of relief. I opened the door, and there was my poor dog, shivering and scratching, waiting for her walk. Feeling guilty yet triumphant, I took her for a walk with a sense of relief finally settling in. 😌</p><h3>The Experience from Exam Day</h3><p>Exams are not just about preparation; they’re about handling the unexpected — technical glitches, tough Proctoring Protocols, and even family interruptions. Despite everything, I made it through, and the experience left me with lessons to share.</p><p>To anyone planning to take any exam: stay calm, prepare well, and most importantly, be ready to tackle surprises — because they will happen! 😀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad09f5813ec4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seamless Automation with Argo Workflows and Events]]></title>
            <link>https://medium.com/@radharamadoss/seamless-automation-with-argo-workflows-and-events-982d4674e74f?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/982d4674e74f</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 18:25:44 GMT</pubDate>
            <atom:updated>2024-12-19T18:25:44.965Z</atom:updated>
            <content:encoded><![CDATA[<p>Automation in cloud infrastructure is essential for efficiency and reliability. Argo Workflows, paired with Argo Events, provide a seamless way to automate tasks using a Kubernetes-native system. In this article, we’ll explore how these tools can automatically create a virtual machine (VM) in OpenStack using Terraform, all triggered by a simple event.</p><p>Here’s how it works: when a file is pushed to a repository, it triggers an event that starts a Terraform workflow in Argo. This workflow automates the creation of a VM instance in OpenStack. The process begins with an event source detecting changes in the repository and sending this information to an event bus. A sensor then listens for this event and activates the Terraform workflow.</p><h3>Configuration details</h3><p>In this section, we’ll break down how Argo Workflows and Argo Events work together to automate the creation of a VM instance in OpenStack using Terraform. <br>This process is initiated by a simple action: pushing a file to a repository, which generates an event to trigger the workflow.</p><h4>Event Source Configuration</h4><p>The <strong>EventSource</strong> configuration sets up a webhook that listens for events from a Bitbucket Server repository. Eventsource is a CRD in Argo events.</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: EventSource<br>metadata:<br>  name: bitbucketserver<br>spec:<br>  service:<br>    ports:<br>      - port: 12000<br>        targetPort: 12000<br>  bitbucketserver:<br>    example:<br>      # Bitbucket Server repository list<br>      repositories:<br>        - projectKey: &quot;projectA&quot; # key of the project<br>          repositorySlug: &quot;argoworkflow&quot; # repository slug<br><br>      # Bitbucket Server will send events to following port and endpoint<br>      webhook:<br>        # endpoint to listen to events on<br>        endpoint: /push<br>        # port to run internal HTTP server on<br>        port: &quot;12000&quot;<br>        # HTTP request method to allow. In this case, only POST requests are accepted<br>        method: POST<br>        # url the event-source will use to register in Bitbucket Server.<br>        # This url must be reachable from outside the cluster.<br>        # The name for the service is in `&lt;event-source-name&gt;-eventsource-svc` format.<br>        # You will need to create an Ingress or Openshift Route for the event-source service so that it can be reached from Bitbucket Server.<br>        url: https://test-bitbucket-argoevent.xyz.com<br>      # events to listen to<br>      # Visit https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html<br>      events:<br>        - repo:refs_changed<br>      # accessToken refers to K8s secret that stores the bitbucket personal api token<br>      accessToken:<br>        # Name of the K8s secret that contains the access token<br>        name: bitbucket-webhook-secret<br>        # Key within the K8s secret whose corresponding value (must be base64 encoded) is access token<br>        key: token<br>      webhookSecret:<br>        # Name of the K8s secret that contains the webhook secret<br>        name: bitbucket-webhook-secret<br>        # Key within the K8s secret whose corresponding value (must be base64 encoded) is the webhook secret<br>        key: secret<br>      # Delete the webhook when the eventsource is deleted<br>      deleteHookOnFinish: true<br>      # Bitbucket Base url to the REST API. This URL should include the &quot;/rest&quot; path.<br>      bitbucketserverBaseURL: https://gitscm.xyz.com/rest</pre><h4>Key Configurations to note in the EventSource setup</h4><p><strong>Service Configuration</strong> in the EventSource specifies the network details that allow the EventSource to receive incoming event notifications</p><p><strong>BitbucketServer Setup</strong>: It specifies the repository to monitor (projectKey, repositorySlug) and the types of events to listen to, such as repo:refs_changed.</p><p><strong>Webhook Details</strong>: The webhook listens on /push and accepts POST requests. It registers with Bitbucket Server using a URL (https://test-bitbucket-argoevent.xyz.com) that is accessible externally.</p><p>Here this external accessibility is enabled through a configured Istio VirtualService.</p><pre>apiVersion: networking.istio.io/v1beta1<br>kind: VirtualService<br>metadata:<br>  name: virtualservice-with-dns<br>  namespace: argo-events<br>spec:<br>  hosts:<br>  - &quot;test-bitbucket-argoevent.xyz.com&quot; # this is used by external-dns to extract DNS names only if gateway_host is &quot;*&quot;<br>  gateways:<br>  - argo-events/gateway-with-dns<br>  http:<br>  - route:<br>    - destination:<br>        host: bitbucketserver-eventsource-svc # this is the service name of the green version of the app, interpreted as sample-app-service-v2.ingress-dns-examples.svc.cluster.local</pre><p><strong>Security</strong>: It uses Kubernetes secrets to manage authentication and secure communication with Bitbucket Server.</p><p><strong>Bitbucket webhook</strong> is automatically created when we deploy this event source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gS4bpROjIJHFgrM26zMrpg.png" /></figure><h4>Sensor</h4><p>The <strong>Sensor</strong> is responsible for detecting events from the event bus and triggering the workflow:</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Sensor<br>metadata:<br>  name: webhook<br>spec:<br>  template:<br>    serviceAccountName: operate-workflow-sa<br>  dependencies:<br>    - name: example<br>      eventSourceName: bitbucketserver<br>      eventName: example<br>  triggers:<br>    - template:<br>        name: argo-workflow-trigger<br>        argoWorkflow:<br>          operation: submit<br>          source:<br>            resource:<br>              apiVersion: argoproj.io/v1alpha1<br>              kind: Workflow<br>              metadata:<br>                generateName: terraform-<br>              spec:<br>                entrypoint: main<br>                volumeClaimTemplates:<br>                - metadata:<br>                    name: workspace<br>                  spec:<br>                    accessModes: [ &quot;ReadWriteOnce&quot; ]<br>                    storageClassName: standard-nfs-rwx-delete<br>                    resources:<br>                      requests:<br>                        storage: 1Gi<br>                templates:<br>                - name: main<br>                  steps:<br>                  - - name: clone-repo<br>                      template: git-clone<br>                  - - name: terraform-plan<br>                      template: terraform-plan<br>                      arguments:<br>                        parameters:<br>                        - name: action<br>                          value: &quot;plan&quot;<br>                  - - name: wait-for-approval<br>                      template: approval-step<br>                  - - name: terraform-apply<br>                      template: terraform-apply<br>                      arguments:<br>                        parameters:<br>                        - name: action<br>                          value: &quot;apply&quot;<br>                        - name: auto-approve<br>                          value: &quot;-auto-approve&quot;<br>                - name: git-clone<br>                  container:<br>                    image: alpine/git:latest<br>                    command: [&quot;/bin/sh&quot;, &quot;-c&quot;]<br>                    args: [&quot;git clone https://$(cat /secrets/username):$(cat /secrets/password)@gitscm.xyz.com/scm/xyz/argoworkflow.git /workspace; cd /workspace/terraform/artifacts;&quot;]<br>                    volumeMounts:<br>                    - name: git-credentials<br>                      mountPath: /secrets<br>                      readOnly: true<br>                    - name: workspace<br>                      mountPath: /workspace<br>                - name: terraform-plan<br>                  inputs:<br>                    parameters:<br>                    - name: action<br>                  container:<br>                    image: hashicorp/terraform:latest<br>                    command: [&quot;/bin/sh&quot;, &quot;-c&quot;]<br>                    args: [&quot;set -xe; ls -la /workspace; cd /workspace/terraform/artifacts; pwd; ls; terraform init; ls; TF_LOG=DEBUG terraform {{inputs.parameters.action}} -input=false -out=/workspace/terraform/artifacts/terraform.tfplan; ls; cat /workspace/terraform/artifacts/terraform.tfplan&quot;]<br>                    env:<br>                    - name: TF_VAR_os_user_name  <br>                      valueFrom:<br>                        secretKeyRef:<br>                          name: openstack-secret<br>                          key: os_user_name<br>                    - name: TF_VAR_os_password<br>                      valueFrom:<br>                        secretKeyRef:<br>                          name: openstack-secret<br>                          key: os_password<br>                    volumeMounts:<br>                    - name: workspace<br>                      mountPath: /workspace<br>                    - name: git-credentials<br>                      mountPath: /secrets<br>                      readOnly: true<br>                - name: approval-step<br>                  suspend: {}<br>                - name: terraform-apply<br>                  inputs:<br>                    parameters:<br>                    - name: action<br>                    - name: auto-approve<br>                  container:<br>                    image: hashicorp/terraform:latest<br>                    command: [&quot;/bin/sh&quot;, &quot;-c&quot;]<br>                    args: [&quot;set -xe; cd /workspace/terraform/artifacts; terraform init; env; ls; TF_LOG=DEBUG terraform {{inputs.parameters.action}} {{inputs.parameters.auto-approve}} -input=false /workspace/terraform/artifacts/terraform.tfplan&quot;]   <br>                    env:<br>                    - name: TF_VAR_os_user_name<br>                      valueFrom:<br>                        secretKeyRef:<br>                          name: openstack-secret<br>                          key: os_user_name<br>                    - name: TF_VAR_os_password<br>                      valueFrom:<br>                        secretKeyRef:<br>                          name: openstack-secret<br>                          key: os_password<br>                    volumeMounts:<br>                    - name: workspace<br>                      mountPath: /workspace<br>                    - name: git-credentials<br>                      mountPath: /secrets<br>                      readOnly: true<br>                volumes:<br>                - name: git-credentials<br>                  secret:<br>                    secretName: git-credentials</pre><h4>Key Configurations to note in the Sensor setup</h4><p><strong>Service Account</strong>: The serviceAccountName specifies operate-workflow-sa, which provides the necessary permissions to execute the workflow.</p><p><strong>Dependencies</strong>: It listens for events from the bitbucketserver EventSource, specifically the example event. This establishes a link between the event source and the sensor, allowing it to react to specific events.</p><p><strong>Triggers</strong>: When the sensor detects an event, it triggers the argo-workflow-trigger, which submits a new Terraform workflow.</p><p><strong>Workflow Specification</strong></p><ul><li><strong>Clone Repo</strong>: Clones the Git repository containing the Terraform resources.</li><li><strong>Terraform Plan</strong>: Executes terraform plan to prepare the infrastructure deployment.</li><li><strong>Approval Step</strong>: Includes a manual pause for human intervention, if necessary.</li><li><strong>Terraform Apply</strong>: Executes terraform apply to provision the infrastructure, with the option for auto-approval.</li><li><strong>Security and Credentials</strong>: The Sensor uses Kubernetes secrets to manage credentials securely. These secrets are mounted as volumes in the workflow steps to provide access to Git and OpenStack credentials.</li></ul><p>Now, when a file is pushed to the repository, it initiates an event that seamlessly triggers the Terraform Argo Workflow. This automated process results in the creation of a VM instance in OpenStack.</p><p>The Terraform configuration used in this workflow defines an OpenStack compute instance with specific attributes like name, flavor, image, and key pair. It also includes network settings and security groups to ensure the instance is properly configured and secure.</p><pre>resource &quot;openstack_compute_instance_v2&quot; &quot;basic_instance&quot; {<br>  name            = &quot;test_instance&quot;<br>  flavor_name     = &quot;1vCPUx2GB&quot;<br>  image_name      = &quot;RHEL-xx-xx-xxx&quot;<br>  key_pair        = &quot;test&quot;<br>  security_groups = [&quot;default&quot;]<br><br>  network {<br>    uuid = &quot;xxx-xx-xx-xxxx&quot;<br>  }<br><br>  metadata = {<br>    instance_type = &quot;simple_instance&quot;<br>  }<br>}</pre><p>This demonstrates the effectiveness of using Argo Workflows and Argo Events for streamlined cloud infrastructure management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=982d4674e74f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Persistent Volume backup — EKS]]></title>
            <link>https://medium.com/@radharamadoss/persistent-volume-backup-eks-a2fa079ba1fa?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2fa079ba1fa</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 18:39:35 GMT</pubDate>
            <atom:updated>2023-10-28T18:39:35.317Z</atom:updated>
            <content:encoded><![CDATA[<h3>Persistent Volume backup — EKS</h3><h3>Objective</h3><p>This document outlines the process of backing up persistent volumes in EKS and provides a solution for backing up persistent storage.</p><h3>Solution</h3><p>Amazon EBS volume snapshots can be utilized to back up data in the EKS pods. This process involves the following components:</p><ul><li>VolumeSnapshotClass</li><li>VolumeSnapshot</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*1bp-edOB7skTYJwY" /></figure><h4>Prerequisites</h4><ol><li>Amazon EBS CSI driver. We can have this installed in our EKS cluster using <a href="https://kubernetes-sigs.github.io/aws-ebs-csi-driver">https://kubernetes-sigs.github.io/aws-ebs-csi-driver</a> helm chart</li></ol><p>2. To use snapshot functionality of EBS CSI driver, we need to install crds, controller for snapshot feature that includes,<br><strong>CustomResourceDefinition</strong>: volumesnapshotclasses, volumesnapshots and volumesnapshotcontents<br><strong>RBAC</strong>: ClusterRole, ClusterRoleBinding<br><strong>Controller Deployment</strong></p><p>To install the CRDs, execute the following commands:</p><pre>kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/master/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml<br>kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/master/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml<br>kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/master/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml</pre><p>To install the Volume Snapshot controller, execute the following commands:</p><pre>kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/master/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml<br>kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/master/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml</pre><p><strong><em>Note:</em></strong> The volume snapshot controller and crds need to be installed prior to ebs csi driver.<br> Otherwise Volumesnapshot will not be in Ready status when we create it.<br>And we see this error,</p><pre>&quot;Waiting for a snapshot default/test-snapshot to be created by the CSI driver.&quot;</pre><h4>Storage Class for PVC and VolumeSnapshotClass</h4><p>Create Storage Class (for dynamically provisioning Persistent Volumes) and VolumeSnapshotClass:</p><p><strong>Storage Class</strong></p><pre>kind: StorageClass<br>apiVersion: storage.k8s.io/v1<br>metadata:<br>  name: ebs-sc<br>provisioner: ebs.csi.aws.com<br>volumeBindingMode: WaitForFirstConsumer<br></pre><p><strong>VolumeSnapshotClass</strong></p><pre>apiVersion: snapshot.storage.k8s.io/v1<br>kind: VolumeSnapshotClass<br>metadata:<br>  name: test-snapclass<br>driver: ebs.csi.aws.com<br>deletionPolicy: Delete</pre><p><strong>Creating Persistent Volume Claim (PVC) and Pod</strong></p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: ebs-claim<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  storageClassName: ebs-sc<br>  resources:<br>    requests:<br>      storage: 4Gi</pre><p><strong>Create a Pod using the PVC</strong></p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: app<br>spec:<br>  containers:<br>  - name: app<br>    image: centos<br>    command: [&quot;/bin/sh&quot;]<br>    args: [&quot;-c&quot;, &quot;while true; do echo $(date -u) &gt;&gt; /data/out.txt; sleep 5; done&quot;]<br>    volumeMounts:<br>    - name: persistent-storage<br>      mountPath: /data<br>  volumes:<br>  - name: persistent-storage<br>    persistentVolumeClaim:<br>      claimName: ebs-claim</pre><p>Pod status is Running</p><pre>kubectl get pods<br>NAME           READY   STATUS    RESTARTS   AGE<br>app            1/1     Running   0          24h<br></pre><p>Volume binded with the pod is “pvc-200d2d75–5cdb-41d3-a870–5a4eb9125aee”</p><pre>name: persistent-storage<br>persistentVolumeClaim:<br>  claimName: ebs-claim<br><br>kubectl get pvc ebs-claim<br>NAME        STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE<br>ebs-claim   Bound    pvc-200d2d75-5cdb-41d3-a870-5a4eb9125aee   4Gi        RWO            ebs-sc         24h</pre><p>Logs from the pod:</p><pre>kubectl exec -it app -- cat /data/out.txt | tail -n 3<br>Thu Oct 19 18:59:06 UTC 2023<br>Thu Oct 19 18:59:11 UTC 2023<br>Thu Oct 19 18:59:16 UTC 2023</pre><p><strong>Creating VolumeSnapshot from the Persistent storage</strong></p><p>When we want backup of this persistent storage, we create Volumesnapshot</p><p>Create a VolumeSnapshot referencing the PersistentVolumeClaim name</p><pre>apiVersion: snapshot.storage.k8s.io/v1<br>kind: VolumeSnapshot<br>metadata:<br>  name: ebs-volume-snapshot<br>spec:<br>  volumeSnapshotClassName: csi-aws-vsc<br>  source:<br>    persistentVolumeClaimName: ebs-claim</pre><p><strong>Note:</strong> the source of Volumesnapshot is the persistentVolumeClaim created above</p><p>Checking the status of the VolumeSnapshot:</p><pre>kubectl get volumesnapshot<br>NAME             READYTOUSE   SOURCEPVC   SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS    SNAPSHOTCONTENT                                    CREATIONTIME   AGE<br>test-snapshot    true         ebs-claim                           4Gi           test-snapclass   snapcontent-36452e1b-0dab-45e8-9698-087725963614   24h            24h</pre><p><strong>Note:</strong> ReadyToUse is true. If it is false, then snapshot volume is not ready for use.</p><p><strong>Validating the snapshot by restoring it to a pod</strong></p><p>Lets first delete the pod and pvc created from above steps.</p><pre>kubectl delete pod app<br>kubectl delete pvc ebs-claim</pre><p>Creating a PersistentVolumeClaim that references the VolumeSnapshot for restoration</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: ebs-snapshot-restored-claim<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  storageClassName: ebs-sc<br>  resources:<br>    requests:<br>      storage: 10Gi<br>  dataSource:<br>    name: ebs-volume-snapshot<br>    kind: VolumeSnapshot<br>    apiGroup: snapshot.storage.k8s.io</pre><p><strong>Note: </strong>the datasource of PVC is pointing to Volumesnapshot we created above</p><p>Now restoring the application</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: app<br>spec:<br>  containers:<br>  - name: app<br>    image: centos<br>    command: [&quot;/bin/sh&quot;]<br>    args: [&quot;-c&quot;, &quot;while true; do echo $(date -u) &gt;&gt; /data/out.txt; sleep 5; done&quot;]<br>    volumeMounts:<br>    - name: persistent-storage<br>      mountPath: /data<br>  volumes:<br>  - name: persistent-storage<br>    persistentVolumeClaim:<br>      claimName: ebs-snapshot-restored-claim</pre><p><strong>Note:</strong> PersistentVolumeClaim is pointing to the PVC created above</p><p>PVC shows Bound status</p><pre>kubectl get pvc pvc-restore         <br>NAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE<br>pvc-restore   Bound    pvc-4e22b947-5c2f-460f-8501-8fa0e6c1de42   20Gi       RWO            ebs-sc         26h</pre><p>Verifying if the pod has the restored data</p><pre>kubectl exec app -- cat /data/out.txt | head -n 30<br>Thu Oct 19 18:58:41 UTC 2023<br>Thu Oct 19 18:58:46 UTC 2023<br>Thu Oct 19 18:58:51 UTC 2023<br>Thu Oct 19 18:58:56 UTC 2023<br>Thu Oct 19 18:59:01 UTC 2023<br>Thu Oct 19 18:59:06 UTC 2023<br>Thu Oct 19 18:59:11 UTC 2023<br>Thu Oct 19 18:59:16 UTC 2023<br>Thu Oct 19 18:59:21 UTC 2023<br>Thu Oct 19 18:59:26 UTC 2023</pre><p>This above message in the pod shows that the data has been restored from the Volume backup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2fa079ba1fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Istio — Part 1 — Installation in EKS]]></title>
            <link>https://medium.com/@radharamadoss/istio-part-1-installation-in-eks-3a075809f204?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a075809f204</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 18:19:52 GMT</pubDate>
            <atom:updated>2024-12-30T03:44:24.250Z</atom:updated>
            <content:encoded><![CDATA[<h3>Istio — Installation in EKS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*65ZipB6Sc5oJTqtHsCGWLg.png" /></figure><p>In this article, I’ll share my experience with installing Istio on Amazon Elastic Kubernetes Service (EKS) and provide solutions to the issues I encountered. My hope is that this information will be valuable to others facing similar challenges.</p><h4>Setting Up the EKS Cluster</h4><p><strong>Creating an EKS Cluster</strong></p><p>To begin, I’ll guide you through the process of creating an EKS cluster. Additionally, I’ll cover the necessary configuration steps for Istio’s security group.</p><p>This vpc.tf file contains the following code for configuring the Virtual Private Cloud (VPC). The comments in the code explain the purpose of each resource and the details for setting specific parameters.</p><pre>locals {<br>  tags = {<br>    Project = &quot;EKSTest&quot;<br>  }<br>}<br>module &quot;vpc&quot; {<br>  source  = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;~&gt; 5.0&quot;<br><br>  name = var.vpc_name<br>  cidr = var.vpc_cidr<br><br>  azs             = [&quot;${var.region}a&quot;, &quot;${var.region}b&quot;, &quot;${var.region}c&quot;]<br>  private_subnets = var.private_subnets_cidr<br>  public_subnets  = var.public_subnets_cidr<br><br>  create_egress_only_igw = true<br><br>  enable_nat_gateway   = true<br>  single_nat_gateway   = true //Should be true if you want to provision a single shared NAT Gateway across all of your private networks<br>  enable_dns_hostnames = true //Should be true to enable DNS hostnames in the VPC<br><br>  enable_flow_log                      = true //Whether or not to enable VPC Flow Logs<br>  create_flow_log_cloudwatch_iam_role  = true<br>  create_flow_log_cloudwatch_log_group = true<br><br>  public_subnet_tags = {<br>    // AWS Cloud Controller Manager require subnets to have this tags<br>    &quot;kubernetes.io/cluster/${var.cluster_name}&quot; = &quot;shared&quot; //AWS Cloud Controller Manager query a cluster&#39;s subnets to identify them. The shared value allows more than one cluster to use the subnet.<br>    &quot;kubernetes.io/role/elb&quot;                    = 1        //Cloud Controller Manager determines if a subnet is public<br>  }<br><br>  private_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${var.cluster_name}&quot; = &quot;shared&quot; //AWS Cloud Controller Manager query a cluster&#39;s subnets to identify them. The shared value allows more than one cluster to use the subnet.<br>    &quot;kubernetes.io/role/internal-elb&quot;           = 1        //Cloud Controller Manager determines if a subnet is private<br>  }<br><br>  tags = local.tags<br>}</pre><p>versions.tf file is to specify the required Terraform provider versions.</p><pre>terraform {<br>  required_version = &quot;&gt;= 1.0&quot;<br><br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;&gt;= 4.47&quot;<br>    }<br>    helm = {<br>      source  = &quot;hashicorp/helm&quot;<br>      version = &quot;&gt;= 2.9&quot;<br>    }<br>    kubernetes = {<br>      source  = &quot;hashicorp/kubernetes&quot;<br>      version = &quot;&gt;= 2.20&quot;<br>    }<br>  }<br>  backend &quot;s3&quot; {}<br><br>}<br><br>provider &quot;aws&quot; {<br>  region = var.region<br><br>}<br><br>// Kubernetes (K8S) provider is used to interact with the resources supported by Kubernetes. To create a cluster and access it using the user who created the cluster. Here we are adding Kubernetes Provider because we are enabling aws-auth config map in eks terraform module<br>provider &quot;kubernetes&quot; {<br>  host                   = module.eks.cluster_endpoint<br>  cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)<br><br>  exec {<br>    api_version = &quot;client.authentication.k8s.io/v1beta1&quot;<br>    command     = &quot;aws&quot;<br>    args        = [&quot;eks&quot;, &quot;get-token&quot;, &quot;--cluster-name&quot;, module.eks.cluster_name]<br>  }<br>}<br><br>provider &quot;helm&quot; {<br>  kubernetes {<br>    host                   = module.eks.cluster_endpoint<br>    cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)<br><br>    exec {<br>      api_version = &quot;client.authentication.k8s.io/v1beta1&quot;<br>      command     = &quot;aws&quot;<br>      # This requires the awscli to be installed locally where Terraform is executed<br>      args = [&quot;eks&quot;, &quot;get-token&quot;, &quot;--cluster-name&quot;, module.eks.cluster_name]<br>    }<br>  }<br>}</pre><p>variables.tf is used to declare input variables that can be passed into your Terraform modules and resources</p><pre>variable &quot;cluster_name&quot; {<br>  type        = string<br>  description = &quot;name of cluster&quot;<br>}<br><br>variable &quot;vpc_name&quot; {<br>  type        = string<br>  description = &quot;name of vpc&quot;<br>}<br><br>variable &quot;region&quot; {<br>  type        = string<br>  description = &quot;region of vpc&quot;<br>}<br><br>variable &quot;vpc_cidr&quot; {<br>  type        = string<br>  description = &quot;vpc cidr&quot;<br>}<br><br>variable &quot;private_subnets_cidr&quot; {<br>  type        = list(string)<br>  description = &quot;private subnets cidr&quot;<br>}<br><br>variable &quot;public_subnets_cidr&quot; {<br>  type        = list(string)<br>  description = &quot;public subnets cidr&quot;<br>}</pre><p>backend.tfvars is used to store configuration values specific to the backend configuration.</p><pre>bucket = &quot;testcloud&quot;<br>key = &quot;terraform-aws-eks-workshop.tfstate&quot;<br>region = &quot;us-east-1&quot;</pre><p>This is the main configuration file for creating an EKS cluster.</p><p>eks.tf</p><pre>module &quot;eks&quot; {<br>  source  = &quot;terraform-aws-modules/eks/aws&quot;<br>  version = &quot;~&gt; 19.16&quot;<br><br>  cluster_name    = var.cluster_name<br>  cluster_version = &quot;1.27&quot;<br><br>  vpc_id     = module.vpc.vpc_id<br>  subnet_ids = module.vpc.private_subnets //Cluster is deployed in private subnet<br><br>  cluster_endpoint_private_access = true<br>  cluster_endpoint_public_access  = true<br>  //cluster_endpoint_public_access_cidrs can be added to restrict the cidrs for public access. https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1867<br><br>  # Note: By default, the IAM Role or IAM User that was used to create the cluster, is added to the system:masters group and gets cluster-wide admin permission with cluster-admin ClusterRole. This is required when we want EKS to allow giving access to other users by adding them in a configmap aws-auth in kube-system namespace.<br>  manage_aws_auth_configmap = true //to manage aws-auth configmap<br><br>  eks_managed_node_group_defaults = { //Map of EKS managed node group default configurations<br>    create_launch_template = true<br>    launch_template_name   = &quot;eks-launch-template&quot;<br>    ami_type               = &quot;BOTTLEROCKET_x86_64&quot;<br>    disk_size              = 50<br>    instance_types         = [&quot;t3.small&quot;, &quot;t3.medium&quot;]<br>  }<br>  eks_managed_node_groups = { //Map of EKS managed node group definitions to create<br>    nodegroup1 = {<br>      labels = {<br>        NodeGroup = &quot;nodegroup1&quot;<br>      }<br>      min_size     = 1<br>      max_size     = 3<br>      desired_size = 2<br><br>      instance_types = [&quot;t3.medium&quot;]<br>      capacity_type  = &quot;SPOT&quot;<br>    }<br>  }<br>  node_security_group_additional_rules = {<br>    ingress_15017 = {<br>      description                   = &quot;Cluster API - Istio Webhook namespace.sidecar-injector.istio.io&quot;<br>      protocol                      = &quot;TCP&quot;<br>      from_port                     = 15017<br>      to_port                       = 15017<br>      type                          = &quot;ingress&quot;<br>      source_cluster_security_group = true<br>    }<br>    ingress_15012 = {<br>      description                   = &quot;Cluster API to nodes ports/protocols&quot;<br>      protocol                      = &quot;TCP&quot;<br>      from_port                     = 15012<br>      to_port                       = 15012<br>      type                          = &quot;ingress&quot;<br>      source_cluster_security_group = true<br>    }<br>  }<br>  tags = local.tags<br><br>}<br><br>module &quot;eks_blueprints_addons&quot; {<br>  source  = &quot;aws-ia/eks-blueprints-addons/aws&quot;<br>  version = &quot;~&gt; 1.0&quot;<br><br>  cluster_name      = module.eks.cluster_name<br>  cluster_endpoint  = module.eks.cluster_endpoint<br>  cluster_version   = module.eks.cluster_version<br>  oidc_provider_arn = module.eks.oidc_provider_arn<br><br>  eks_addons = {<br>    coredns    = {}<br>    vpc-cni    = {}<br>    kube-proxy = {}<br>  }<br><br>  # This is required to expose Istio Ingress Gateway<br>  enable_aws_load_balancer_controller = true<br>  tags = local.tags<br>}</pre><p><strong><em>Note:<br></em></strong>The ‘<strong>node_security_group_additional_rules’</strong> block is added to create Security Group ingress rules for the nodegroup. <br>These rules are specifically for <strong>ports 15017 and 15012</strong>, allowing traffic from the EKS cluster. <br>Its important to note that <strong>‘source_cluster_security_group’</strong> is set to <strong>true</strong>.</p><p>Without the ingress rules for ports 15017 and 15012, the installation of Istio in the EKS cluster may result in multiple errors. Some of these errors are shown below.</p><pre>kubectl get - raw /api/v1/namespaces/istio-system/services/https:istiod:https-webhook/proxy/inject -v4<br><br>I0909 18:17:30.703828 10859 helpers.go:246] server response object: [{<br>&quot;metadata&quot;: {},<br>&quot;status&quot;: &quot;Failure&quot;,<br>&quot;message&quot;: &quot;error trying to reach service: dial tcp 172.44.30.55:15017: connect: connection timed out&quot;,<br>&quot;reason&quot;: &quot;ServiceUnavailable&quot;,<br>&quot;code&quot;: 503<br>}]<br>Error from server (ServiceUnavailable): error trying to reach service: dial tcp 172.44.30.55:15017: connect: connection timed out</pre><pre>kubectl get events -n istio-ingress<br><br>7m6s Warning FailedCreate replicaset/istio-ingress-54464bcb87 Error creating: Internal error occurred: failed calling webhook &quot;object.sidecar-injector.istio.io&quot;: failed to call webhook: Post &quot;https://istiod.istio-system.svc:443/inject?timeout=10s&quot;: context deadline exceeded<br><br>2023–09–10T05:18:55.390302Z warn sds failed to warm certificate: failed to generate workload certificate: create certificate: rpc error: code = Unavailable desc = connection error: desc = &quot;transport: Error while dialing: dial tcp 10.100.19.43:15012: i/o timeout&quot;</pre><p>Lastly, let’s define the terraform.tfvars file.</p><pre>region               = &quot;us-west-2&quot;<br>vpc_name             = &quot;testvpc&quot;<br>cluster_name         = &quot;testeks&quot;<br>vpc_cidr             = &quot;172.44.0.0/16&quot;<br>private_subnets_cidr = [&quot;172.44.0.0/19&quot;, &quot;172.44.64.0/19&quot;, &quot;172.44.128.0/19&quot;]<br>public_subnets_cidr  = [&quot;172.44.32.0/19&quot;, &quot;172.44.96.0/19&quot;, &quot;172.44.160.0/19&quot;]</pre><p>Execute terraform plan and apply to deploy the resources.</p><pre>terraform plan<br>terraform apply - auto-approve</pre><p>Now the EKS cluster is ready!</p><h4>Istio installation using helm chart</h4><p>To install Istio on Kubernetes, we install the Istio Base Chart and then the istiod component.</p><p><strong>Install Istio Base chart</strong><br>The Istio Base Chart includes the core Istio components but not the control plane (istiod) yet.</p><pre>helm repo add istio https://istio-release.storage.googleapis.com/charts<br>helm repo update<br>kubectl create namespace istio-system<br>helm install istio-base istio/base -n istio-system - set defaultRevision=default</pre><p><strong>Install istiod</strong><br>After installing the base chart, we can install the istiod component using Helm. The istiod component is responsible for the control plane of Istio.</p><pre>helm install istiod istio/istiod -n istio-system - wait</pre><p>Verifying the installation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ie_QKI4QmzCLtv14SgqdNA.png" /></figure><p><strong>Install Istio-Ingress<br></strong>We can install the Istio Ingress Gateway using Helm. The Ingress Gateway is responsible for handling external traffic into Istio service mesh.</p><p>To enable access to the Istio Ingress Gateway from a public subnet and create a load balancer service, we customize certain default values in the <strong>‘istio-ingress/values.yaml’</strong> file.</p><pre>service:<br>  annotations:<br>    service.beta.kubernetes.io/aws-load-balancer-type: &quot;nlb&quot;<br>    service.beta.kubernetes.io/aws-load-balancer-scheme: &quot;internet-facing&quot;<br>    service.beta.kubernetes.io/aws-load-balancer-attributes: &quot;load_balancing.cross_zone.enabled=true&quot;</pre><p>Install Istio-ingress helm chart</p><pre>kubectl create namespace istio-ingress<br>helm install istio-ingress istio/gateway -n istio-ingress -f istio-ingress/values.yaml</pre><p>Verifying the installation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gx2GAkTqoSmfHdeq5NWCg.png" /></figure><p>That’s it! We have successfully installed and configured both the EKS cluster and Istio.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a075809f204" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Service Account Tokens -Security Improvements]]></title>
            <link>https://medium.com/@radharamadoss/kubernetes-service-account-tokens-security-improvements-a9734c186afb?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9734c186afb</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Sat, 11 Mar 2023 06:23:33 GMT</pubDate>
            <atom:updated>2023-03-11T06:23:33.415Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why Service Account token is important?</h4><p>A user authenticates himself to Kubernetes api server using authentication methods such as X509 client certs, Bearer tokens, OpenID connect tokens etc,. <br>On the other hand, an application running in a Kubernetes cluster uses a service account to authenticate itself to the Kubernetes API. <br><em>Service accounts</em> that are attached to the application pods by default, and can be used by the application inside to prove its identity.</p><h4>Whats the security problem with Legacy Service Account token (Kubernetes version &lt; 1.22) ?</h4><p>Service account is associated with a token which is used to authenticate with Kubernetes API server.<br>These are bearer tokens (JWT), which means that anyone who holds the token has the power to authenticate as your application’s service account.</p><h4>How is a Service account token (JWT) used to authenticate with api server?</h4><p>When your application talks to the API server in its cluster, the Kubernetes client library loads this JWT from the container filesystem and sends it in the Authorization header of all API requests. The API Server then validates the JWT signature and uses the token’s claims to determine your application’s identity.</p><h4>How is a Service account token (JWT) used to authenticate between services?</h4><p>The JWT token also works for authenticating to other services. If Service A wants to communicate with Service B, then Service B which is the relying party just needs to call TokenReview API provided by Kubernetes. <br>The return value indicates whether or not the token was valid.</p><h4><strong>Legacy tokens (Kubernetes version &lt; 1.21)</strong></h4><p>Legacy Tokens from Kubernetes version lesser than 1.21 do not have expiry. If it gets stolen, then an attacker can make requests to the Kubernetes API server to compromise cluster resources which causes privilege escalation attack. Kubernetes provides a long-lived, static token to the Pod as a Secret.</p><p>Also Legacy JWT token does not have a concept of audience. So ifyour application wants to pass a token to service A, service A can just forward the token to service B and pretend to be your application.</p><h3>Bound tokens: Kubernetes 1.21 and up</h3><p>Bound tokens address all the security issues of legacy tokens:</p><ul><li>The tokens themselves are much harder to steal and misuse; they are time-bound, audience-bound.</li><li>They are distributed to pods more securely, as projected volume type.</li></ul><p>Lets try to explore this by poking into bound tokens in Kubernetes cluster version 1.21 and 1.26</p><h4>Bound tokens — K8s version 1.21 and up</h4><p>Create a kind cluster with v1.21</p><pre>kind create cluster - name k21 - image kindest/node:v1.21.1</pre><p>Create a service account</p><pre>kubectl create sa testsa</pre><p>Notice that a secret which holds the token of the service account gets created automatically.</p><pre>kubectl describe secret testsa-token-gjfqb<br>Name:         testsa-token-gjfqb<br>Namespace:    default<br>Labels:       &lt;none&gt;<br>Annotations:  kubernetes.io/service-account.name: testsa<br>              kubernetes.io/service-account.uid: 0af4a78f-8f10-4685-ac29-cae08659bcae<br><br>Type:  kubernetes.io/service-account-token<br><br>Data<br>====<br>token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IkRVdTJXUGNPLUthZjk2c3ZJcXhFWlBsRHUyUUx5cWxrUm1qT0s2VG9XQTAifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6InRlc3RzYS10b2tlbi1namZxYiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJ0ZXN0c2EiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIwYWY0YTc4Zi04ZjEwLTQ2ODUtYWMyOS1jYWUwODY1OWJjYWUiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmYXVsdDp0ZXN0c2EifQ.Y683lBdmc5e0wvL3BPXj4hVkYXiu7M4bn2w1tvqIdrXdat3Fnqlv5Qgih3RS1VRETXDOMp3_CA8Jv7Nqe_PSIrBPvLStRYvvRByWDWY3PvYDfFxeARKj0E_AQnFkXQxEN21eXkJi3k0i93uhGGNvUr5bNpk7buMbD2UKt-y8N7sQmTIQ6nPdjaC3YHn32-MHpAquqwbTqXhETPrvk9RjSzE4jszcd_P1Gi7BdZoHPErnCc5XaEVBJnHiWsZCsJDL00nAaAS_Ru8TsIdX_z1pyp91sigxfvFrGwhns3oXq54rrhpBuloPwmDW0gWDAV-qjje5MPFuaiov431ocKrOsg<br>ca.crt:     1066 bytes<br>namespace:  7 bytes</pre><p>Create a nginx Pod by assigning serviceAccount “testsa”</p><p>When we examine the deployed nginx pod, it shows the the <strong>secret </strong>of the service account is added as a volume and then mounted in the standard directory <strong>/var/run/secrets/kubernetes.io/serviceaccount</strong>.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: nginxpod<br>spec:<br>  containers:<br>  - image: nginx:latest<br>    name: nginxpod<br>    volumeMounts:<br>    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount<br>      name: kube-api-access-fspjp<br>      readOnly: true<br>  serviceAccount: testsa<br>  serviceAccountName: testsa<br>  terminationGracePeriodSeconds: 30<br>  volumes:<br>  - name: kube-api-access-fspjp<br>    projected:<br>      defaultMode: 420<br>      sources:<br>      - serviceAccountToken:<br>          expirationSeconds: 3607<br>          path: token</pre><p>Also note the expiration seconds in the service account token. This expiration was not present in the older versions of K8s. Hence these token are called as Bound (Time bound) tokens.</p><p>Lets examine the token.</p><pre>kubectl exec -it nginxpod -- bash<br><br>cd /var/run/secrets/kubernetes.io/serviceaccount<br><br>cat token<br>eyJhbGciOiJSUzI1NiIsImtpZCI6IkRVdTJXUGNPLUthZjk2c3ZJcXhFWlBsRHUyUUx5cWxrUm1qT0s2VG9XQTAifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzEwMDQ4MTc4LCJpYXQiOjE2Nzg1MTIxNzgsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJkZWZhdWx0IiwicG9kIjp7Im5hbWUiOiJuZ2lueHBvZCIsInVpZCI6ImY5ZTg0M2I0LTBiY2ItNDEyMy04NWZmLTM0ZWIwNmI4YzJhOCJ9LCJzZXJ2aWNlYWNjb3VudCI6eyJuYW1lIjoidGVzdHNhIiwidWlkIjoiMGFmNGE3OGYtOGYxMC00Njg1LWFjMjktY2FlMDg2NTliY2FlIn0sIndhcm5hZnRlciI6MTY3ODUxNTc4NX0sIm5iZiI6MTY3ODUxMjE3OCwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmRlZmF1bHQ6dGVzdHNhIn0.yp8jNHH6709sDLUZxCKHnf5sWWRze7JcXkDFg1y9ksxcvds83azpM7niRW3BjUfDCaudXkhLrGtyNIskRvt9PxWWRqo0YNpGOcO7sY7DeymR2T4-dpO_QuqnKmDn7iNhOIg2ZquVVBq3QGU6IsLXLZN0Zjni_r95qf9s24qt492QIUWbiyJR3llRi3fZgAiRn2kQARszTMkw47p5sF1qRZmOi97FutKLogttN0qHGJNbDPle9hKhM0DQYBhrY5TgCy7nd1SCzBYpF85VVX1n_biFdiy-l_NCuGPNi_7QeetdFhWozVJMrBC45ZtFfY1buGTPrYOjfjyqp1TKdSwu5g<br></pre><p><strong><em>Note: </em></strong><em>The token fetched from the pod is not same as the token fetched from the secret. How can they be different? This is a concept of Projected volumes. ( Good Read: </em><a href="https://stackoverflow.com/questions/72093374/why-k8s-automounted-service-account-token-in-a-pod-is-different-from-the-token-r"><em>https://stackoverflow.com/questions/72093374/why-k8s-automounted-service-account-token-in-a-pod-is-different-from-the-token-r</em></a><em> )</em></p><p>The token fetched from the pod can be examined in <a href="https://jwt.io/">jwt</a>.io</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9BdgxV7HBgvFViR3_P3Gw.png" /></figure><p><strong>Note </strong>the <strong>expiry </strong>and <strong>audience </strong>in the JWT token.</p><h4>Service account token improvements from 1.24 and up</h4><p>In version v1.24 when you create a service account, secrets are no longer automatically created.</p><p><strong>Security: </strong>The current model of storing the service account token in a Secret and delivering it to nodes results in a broad attack surface for the Kubernetes control plane when powerful components are run — giving a service account a permission means that any component that can see that service account’s secrets is at least as powerful as the component. (<a href="https://github.com/kubernetes/enhancements/blob/master/keps/sig-auth/1205-bound-service-account-tokens/README.md">https://github.com/kubernetes/enhancements/blob/master/keps/sig-auth/1205-bound-service-account-tokens/README.md</a>)</p><p>Create a Kubernetes cluster with &gt; 1.24 version</p><p>Create “testsa” service account</p><p>Try ,</p><pre>kubectl get secrets</pre><p>You will observe that there are no secrets created for the Service Account…</p><p>Create deployment object</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginxtest<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: nginxtest<br>  template:<br>    metadata:<br>      labels:<br>        app: nginxtest<br>    spec:<br>      serviceAccount: testsa<br>      volumes:<br>        - name: testvol<br>          projected:<br>            sources:<br>            - serviceAccountToken:<br>                path: test-token<br>                expirationSeconds: 600<br>                audience: curlsvc<br>                # audience: https://kubernetes.default.svc<br>      containers:<br>      - name: nginxtest<br>        image: nginx:latest<br>        volumeMounts:<br>          - mountPath: /var/run/secrets/tokens<br>            name: testvol</pre><p>Note the audience “curlssvc” , expirationseconds set as 600 and token mount path “/var/run/secrets/tokens”</p><p>Lets examine the token,</p><pre>kubectl exec -it nginxtest-55b685bb94-64mld -- bash        <br>root@nginxtest-55b685bb94-64mld:/# cat test-token <br>eyJhbGciOiJSUzI1NiIsImtpZCI6IjIxNzg2ZTUzOTM1ZjNkNTgxN2RhODA5NjQyYzc0ZTg3NzExYWIzMjEifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjIl0sImV4cCI6MTY3ODUxNTI0MSwiaWF0IjoxNjc4NTE0NjQxLCJpc3MiOiJodHRwczovL29pZGMuZWtzLnVzLXdlc3QtMi5hbWF6b25hd3MuY29tL2lkLzVGOUE0RTRCQ0YwQUIzRUJDNjBBNDg5RTZBMUUyMjlFIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJkZWZhdWx0IiwicG9kIjp7Im5hbWUiOiJuZ2lueHRlc3QtNTViNjg1YmI5NC02NG1sZCIsInVpZCI6ImJmMzU0OGE1LTBlYmQtNDZiZC1hZmUzLTI0ZWFiNzdjY2E4ZiJ9LCJzZXJ2aWNlYWNjb3VudCI6eyJuYW1lIjoidGVzdHNhIiwidWlkIjoiNGI2Y2VkMmMtMmIxZi00MjZlLTk3N2UtNWJhM2I0Y2Y5MDk0In19LCJuYmYiOjE2Nzg1MTQ2NDEsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OnRlc3RzYSJ9.ZV7XgtHQYgWnPIAn1ys0123bbk6rAIy7d1kO-NOEIV8fdL1SVxPxN2vzu4uNcIf3R_1OoggwUEWR_3zZtl7bhcLnH7KC9BUL9yeERszE1j6ppvkLANo0IsOTfIorGBeiWNfPVgwMhP2rxBuUlXt70aM5LmeBdi-M2Z5nX_7hFUiwlF4XDVpK3l7n1BddTEJt1npVdLx39tYE8AlOu74GHegJZCszDu8Iip4MFPCsw5w3aRI8JTDi7zeFI03MZvNYsDbVi4CukpLk3KYkNgx1CA5mp8DLJUZPXdO-7dipen_1SR32W54PGjaplBvn-iyRQ6JjJ0VO4muiXbrZgTh1gw</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QA3rM1XQrLbpoBwdf8oODg.png" /></figure><p>Note the audience set to “curlsvc”.</p><p>Lets try to use TokenReview API to check if kubernetes apiserver is able to validate the token.</p><p>verify_token.yaml</p><pre>kind: TokenReview<br>apiVersion: authentication.k8s.io/v1<br>metadata:<br>  name: test<br>spec:<br>  token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjIxNzg2ZTUzOTM1ZjNkNTgxN2RhODA5NjQyYzc0ZTg3NzExYWIzMjEifQ.eyJhdWQiOlsiY3VybHN2YyJdLCJleHAiOjE2Nzg0OTM1NDYsImlhdCI6MTY3ODQ5Mjk0NiwiaXNzIjoiaHR0cHM6Ly9vaWRjLmVrcy51cy13ZXN0LTIuYW1hem9uYXdzLmNvbS9pZC81RjlBNEU0QkNGMEFCM0VCQzYwQTQ4OUU2QTFFMjI5RSIsImt1YmVybmV0ZXMuaW8iOnsibmFtZXNwYWNlIjoiZGVmYXVsdCIsInBvZCI6eyJuYW1lIjoibmdpbnh0ZXN0LWM2Zjk2N2Y2NC1iOGxtNyIsInVpZCI6IjkxYTcyNmY4LTc4NjctNGI1ZC05OTJjLTk3MzdmMGViZTdlNCJ9LCJzZXJ2aWNlYWNjb3VudCI6eyJuYW1lIjoidGVzdHNhIiwidWlkIjoiNGI2Y2VkMmMtMmIxZi00MjZlLTk3N2UtNWJhM2I0Y2Y5MDk0In19LCJuYmYiOjE2Nzg0OTI5NDYsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OnRlc3RzYSJ9.aEOmZZ4_Imlwdr0Vo2gFqQi_NVu2_a46Su89C7GoBuKpkeRHCO0CEZLDTdLsSHMvh6W_GXCvdJ_ZND_EK3UfyfsKd2s1vQ3ohBEx0a7HR0P1a4BbagEDunjiDrpbElS40ppuP92DfE7X83MoyHyFYW9boCN1DlZVECzHdqpyu5Pk01bR2bM69td7NM0SdTYvTdxuiKnd81CtX1YpbE5uy82vb604hkjoDrypuOWEpuek4faoaLzpZ1fBtDVz8Aso4OjeMr_HoQ0Tkika8uWMzqKZEYi4hkf3RvnI8A0BOvi1wIiCutOKYwNfR8hwLSrLu0MHv2vI-4L2KHN13eA5yw</pre><pre>kubectl apply -f verify_token.yaml -o yaml <br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USVkTD7360nnVmPgxTdxlQ.png" /></figure><p>The token failed authentication with audience Kubernetes API server.</p><p>Let us change the deployment object with audience as Kubernetes API server.</p><pre>      volumes:<br>        - name: testvol<br>          projected:<br>            sources:<br>            - serviceAccountToken:<br>                path: test-token<br>                expirationSeconds: 600<br>                audience: https://kubernetes.default.svc</pre><p>After applying this change in the deployment object, the new token can be examined in jwt token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4HrhaF0jk0Cdi6lOnDF_7Q.png" /></figure><p>Verify the token using Kubernetes TokenVerifyAPI<br>kubectl apply -f verify_token.yaml -o yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ExAomyWJpwtueOAJRAC6Q.png" /></figure><p>Oops!! We tried a old token. Remember that this is Bound token. So it expires with default timeout 1 hour.</p><p>Try to fetch the latest token from pod and retry….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vDWhFU10GPYd3klM33ljMw.png" /></figure><p><strong><em>Note:</em></strong><em> </em><strong><em>authenticated</em></strong><em> set to </em><strong><em>true</em></strong><em>, as this is a valid authenticated token by kubernetes api server (audience)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9734c186afb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singly Linked List implementation in Golang]]></title>
            <link>https://medium.com/@radharamadoss/singly-linked-list-implementation-in-golang-25ed710adbbc?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/25ed710adbbc</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 16:11:18 GMT</pubDate>
            <atom:updated>2023-02-09T16:11:18.709Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, lets look at the easy way of implementing singly linked list in Golang.</p><p>LinkedList contains Nodes. And every Node has an element in it and a pointer to point to next node.<br>So lets begin with creating the Node and LinkedList structs.</p><pre>type Node struct {<br> num  int<br> next *Node<br>}<br><br>type Linkedlist struct {<br> head *Node<br>}</pre><p>Next .. lets create some functions that are required to operate the LinkedList.</p><pre>func (ll *Linkedlist) Getlength() int {<br> if ll.head == nil {<br>  return 0<br> }<br> ptr := ll.head<br> count := 0<br> for ptr.next != nil {<br>  ptr = ptr.next<br>  count++<br> }<br> return  count+1<br>}</pre><pre><br>func (ll *Linkedlist) Insert(n int) {<br> node := &amp;Node{num: n}<br> if ll.head == nil {<br>  node.next = nil<br>  ll.head = node<br>  return<br> }<br> ptr := ll.head<br> for ptr.next != nil {<br>  ptr = ptr.next<br> }<br> node.next = nil<br> ptr.next = node<br>}</pre><pre>func (ll *Linkedlist) Delete(n int) {<br> if ll.head == nil {<br>  return<br> }<br> if ll.head.num == n {<br>  ll.head = ll.head.next<br>  return<br> }<br> curr := ll.head<br> prev := curr<br><br> for curr != nil &amp;&amp; curr.num != n {<br>  prev = curr<br>  curr = curr.next<br> }<br><br> if curr == nil {<br>  fmt.Println(&quot;Key not found&quot;)<br>  return<br> }<br><br> prev.next = curr.next<br><br><br>}</pre><pre><br>func (ll *Linkedlist) Show() {<br><br> if ll.head == nil {<br>  return<br> }<br> if ll.Getlength() == 1 {<br>  fmt.Println(ll.head.num)<br>  return<br> }<br> ptr := ll.head<br><br> for ptr.next != nil {<br>  fmt.Printf(&quot;%v --&gt;&quot;, ptr.num)<br>  ptr = ptr.next<br> }<br> fmt.Println(ptr.num)<br><br>}</pre><p>Here comes the main function:</p><pre><br>func main() {<br><br> ll := &amp;Linkedlist{}<br><br> ll.Insert(1)<br> ll.Insert(2)<br> fmt.Println(ll.Getlength())<br> ll.Show()<br> ll.Insert(4)<br> ll.Insert(5)<br> ll.Insert(6)<br> ll.Delete(5)<br> fmt.Println(ll.Getlength())<br> ll.Show()<br> ll.Delete(1)<br> fmt.Println(ll.Getlength())<br> ll.Show()<br><br>}</pre><p>Complete code:</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>type Node struct {<br> num  int<br> next *Node<br>}<br><br>type Linkedlist struct {<br> head *Node<br>}<br><br>func (ll *Linkedlist) Insert(n int) {<br> node := &amp;Node{num: n}<br> if ll.head == nil {<br>  node.next = nil<br>  ll.head = node<br>  return<br> }<br> ptr := ll.head<br> for ptr.next != nil {<br>  ptr = ptr.next<br> }<br> node.next = nil<br> ptr.next = node<br>}<br><br>func (ll *Linkedlist) Delete(n int) {<br> if ll.head == nil {<br>  return<br> }<br> if ll.head.num == n {<br>  ll.head = ll.head.next<br>  return<br> }<br> curr := ll.head<br> prev := curr<br><br> for curr != nil &amp;&amp; curr.num != n {<br>  prev = curr<br>  curr = curr.next<br> }<br><br> if curr == nil {<br>  fmt.Println(&quot;Key not found&quot;)<br>  return<br> }<br><br> prev.next = curr.next<br><br><br>}<br><br>func (ll *Linkedlist) Getlength() int {<br> if ll.head == nil {<br>  return 0<br> }<br> ptr := ll.head<br> count := 0<br> for ptr.next != nil {<br>  ptr = ptr.next<br>  count++<br> }<br> return  count+1<br>}<br><br>func (ll *Linkedlist) Show() {<br><br> if ll.head == nil {<br>  return<br> }<br> if ll.Getlength() == 1 {<br>  fmt.Println(ll.head.num)<br>  return<br> }<br> ptr := ll.head<br><br> for ptr.next != nil {<br>  fmt.Printf(&quot;%v --&gt;&quot;, ptr.num)<br>  ptr = ptr.next<br> }<br> fmt.Println(ptr.num)<br><br>}<br><br>func main() {<br><br> ll := &amp;Linkedlist{}<br><br> ll.Insert(1)<br> ll.Insert(2)<br> fmt.Println(ll.Getlength())<br> ll.Show()<br> ll.Insert(4)<br> ll.Insert(5)<br> ll.Insert(6)<br> ll.Delete(5)<br> fmt.Println(ll.Getlength())<br> ll.Show()<br> ll.Delete(1)<br> fmt.Println(ll.Getlength())<br> ll.Show()<br><br>}</pre><p>Output</p><pre>go run main.go<br><br>2<br>1 --&gt;2<br>4<br>1 --&gt;2 --&gt;4 --&gt;6<br>3<br>2 --&gt;4 --&gt;6</pre><p><em>“Having fun is the best way to learn” —Albert Einstein</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25ed710adbbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an EKS cluster using Terraform — a simple approach]]></title>
            <link>https://medium.com/@radharamadoss/building-an-eks-cluster-using-terraform-a-simple-approach-cc2d1d148fcd?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc2d1d148fcd</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Thu, 19 Jan 2023 23:26:06 GMT</pubDate>
            <atom:updated>2023-09-04T23:51:47.402Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an EKS cluster using Terraform — a simple approach</h3><p>Lets learn to build an EKS cluster using Terraform from scratch using terraform aws modules.</p><p>In this article, I am going to explain every terraform file that is used to create an EKS cluster.</p><h4>Architecture</h4><p>The EKS cluster worker nodes are placed in Private subnets. Public access for the cluster endpoint has been enabled so the cluster is accessible using kubectl commands from your machine.</p><h4>Create IAM user</h4><p>Create an IAM user “<strong>eksadmin</strong>” and provide “<strong>Administrator</strong>” permission to this user. For Production scenarios, we restrict the permissions needed to create EKS cluster. For the sake of simplicity, we create a new IAM user with full admin permission.</p><p>Store the below AWS Profile config in <strong>~/.aws/config</strong></p><pre>[profile eksadmin]<br>region=us-west-2<br>output=json</pre><p>Save the credentials of eksadmin user in <strong>~/.aws/credentials</strong></p><pre>[eksadmin]<br>aws_access_key_id=&lt;REDACTED&gt;<br>aws_secret_access_key=&lt;REDACTED&gt;</pre><p>Set the <strong>AWS_PROFILE</strong> environment variable as eksadmin</p><pre>export AWS_PROFILE=eksadmin</pre><p>Create a project folder to place the terraform files.</p><p>Create a s3 bucket named “eks-infra” in AWS to store Terraform Statefile</p><p>Inside the project folder, create “<strong>backend.tfvars</strong>” for Terraform Remote state backend configuration</p><pre>bucket = &quot;eks-infra&quot;<br>key = &quot;terraform-aws-eks-workshop.tfstate&quot;<br>region = &quot;us-west-2&quot;    </pre><p>Place “<strong>versions.tf”</strong> in the project folder with the below contents.<br><em>Note: In the comments, I have described why certain arguments are used in Terraform modules.</em></p><pre>terraform {<br>  required_version = &quot;&gt;= 1.3.0&quot;<br><br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 4.0&quot;<br>    }<br>    kubernetes = {<br>      source  = &quot;hashicorp/kubernetes&quot;<br>      version = &quot;&gt;= 2.10.0&quot;<br>    }<br>  }<br>  backend &quot;s3&quot; {}<br><br>}<br><br>provider &quot;aws&quot; {<br>  region = var.region<br><br>}<br><br>// Kubernetes (K8S) provider is used to interact with the resources supported by Kubernetes. To create a cluster and access it using the user who created the cluster. Here we are adding Kubernetes Provider because we are enabling aws-auth config map in eks terraform module<br>provider &quot;kubernetes&quot; {<br>  host                   = module.eks.cluster_endpoint<br>  cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)<br><br>  exec {<br>    api_version = &quot;client.authentication.k8s.io/v1beta1&quot;<br>    command     = &quot;aws&quot;<br>    args        = [&quot;eks&quot;, &quot;get-token&quot;, &quot;--cluster-name&quot;, module.eks.cluster_id]<br>  }<br>}</pre><p>We utilize the “vpc.tf” file shown below to build vpc, subnets, Internet GWs, and NAT GWs. Place the vpc.tf file in the project folder.</p><pre>locals {<br>  tags = {<br>    Project = &quot;EKSTest&quot;<br>  }<br>}<br>module &quot;vpc&quot; {<br>  source  = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;~&gt; 3.0&quot;<br><br>  name = var.vpc_name<br>  cidr = var.vpc_cidr<br><br>  azs             = [&quot;${var.region}a&quot;, &quot;${var.region}b&quot;, &quot;${var.region}c&quot;]<br>  private_subnets = var.private_subnets_cidr<br>  public_subnets  = var.public_subnets_cidr<br><br>  create_egress_only_igw = true<br><br>  enable_nat_gateway   = true<br>  single_nat_gateway   = true //Should be true if you want to provision a single shared NAT Gateway across all of your private networks<br>  enable_dns_hostnames = true //Should be true to enable DNS hostnames in the VPC<br><br>  enable_flow_log                      = true //Whether or not to enable VPC Flow Logs<br>  create_flow_log_cloudwatch_iam_role  = true<br>  create_flow_log_cloudwatch_log_group = true<br><br>  public_subnet_tags = {<br>    // AWS Cloud Controller Manager require subnets to have this tags<br>    &quot;kubernetes.io/cluster/${var.cluster_name}&quot; = &quot;shared&quot; //AWS Cloud Controller Manager query a cluster&#39;s subnets to identify them. The shared value allows more than one cluster to use the subnet.<br>    &quot;kubernetes.io/role/elb&quot;                    = 1        //Cloud Controller Manager determines if a subnet is public<br>  }<br><br>  private_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${var.cluster_name}&quot; = &quot;shared&quot; //AWS Cloud Controller Manager query a cluster&#39;s subnets to identify them. The shared value allows more than one cluster to use the subnet.<br>    &quot;kubernetes.io/role/internal-elb&quot;           = 1        //Cloud Controller Manager determines if a subnet is private<br>  }<br><br>  tags = local.tags<br>}</pre><p>Place “<strong>eks.tf</strong>” with below content in the project folder to create eks cluster. It also creates a nodegroup named “nodegroup1”.</p><pre>module &quot;eks&quot; {<br>  source  = &quot;terraform-aws-modules/eks/aws&quot;<br>  version = &quot;~&gt; 18.0&quot;<br><br>  cluster_name    = var.cluster_name<br>  cluster_version = &quot;1.24&quot;<br><br>  vpc_id     = module.vpc.vpc_id<br>  subnet_ids = module.vpc.private_subnets //Cluster is deployed in private subnet<br><br>  cluster_endpoint_private_access = true<br>  cluster_endpoint_public_access  = true<br>  //cluster_endpoint_public_access_cidrs can be added to restrict the cidrs for public access. https://github.com/terraform-aws-modules/terraform-aws-eks/issues/1867<br><br>  # Note: By default, the IAM Role or IAM User that was used to create the cluster, is added to the system:masters group and gets cluster-wide admin permission with cluster-admin ClusterRole. This is required when we want EKS to allow giving access to other users by adding them in a configmap aws-auth in kube-system namespace.<br>  manage_aws_auth_configmap = true //to manage aws-auth configmap<br><br>  eks_managed_node_group_defaults = { //Map of EKS managed node group default configurations<br>    create_launch_template = true<br>    launch_template_name   = &quot;eks-launch-template&quot;<br>    ami_type               = &quot;BOTTLEROCKET_x86_64&quot;<br>    disk_size              = 50<br>    instance_types         = [&quot;t3.small&quot;, &quot;t3.medium&quot;]<br>  }<br>  eks_managed_node_groups = { //Map of EKS managed node group definitions to create<br>    nodegroup1 = {<br>      labels = {<br>        NodeGroup = &quot;nodegroup1&quot;<br>      }<br>      min_size     = 1<br>      max_size     = 3<br>      desired_size = 2<br><br>      instance_types = [&quot;t3.medium&quot;]<br>      capacity_type  = &quot;SPOT&quot;<br>    }<br>  }<br>  tags = local.tags<br><br>}</pre><p><strong>variables.tf</strong></p><pre>variable &quot;cluster_name&quot; {<br>  type        = string<br>  description = &quot;name of cluster&quot;<br>}<br><br>variable &quot;vpc_name&quot; {<br>  type        = string<br>  description = &quot;name of vpc&quot;<br>}<br><br>variable &quot;region&quot; {<br>  type        = string<br>  description = &quot;region of vpc&quot;<br>}<br><br>variable &quot;vpc_cidr&quot; {<br>  type        = string<br>  description = &quot;vpc cidr&quot;<br>}<br><br>variable &quot;private_subnets_cidr&quot; {<br>  type        = list(string)<br>  description = &quot;private subnets cidr&quot;<br>}<br><br>variable &quot;public_subnets_cidr&quot; {<br>  type        = list(string)<br>  description = &quot;public subnets cidr&quot;<br>}</pre><p><strong>terraform.tfvars</strong></p><pre>region               = &quot;us-west-2&quot;<br>vpc_name             = &quot;Testvpc&quot;<br>cluster_name         = &quot;Testeks&quot;<br>vpc_cidr             = &lt;REDACTED&gt;<br>private_subnets_cidr = [&lt;REDACTED&gt;, &lt;REDACTED&gt;, &lt;REDACTED&gt;]<br>public_subnets_cidr  = [&lt;REDACTED&gt;, &lt;REDACTED&gt;, &lt;REDACTED&gt;]</pre><p>Finally execute below terraform commands,</p><p><strong>terraform init -backend-config=backend.tfvars </strong>(To initialize the modules)</p><p><strong>terraform plan</strong> (To generate the plan of the resources going to be created)</p><p><strong>terraform apply</strong> <strong>— auto-approve</strong> (To create the resources)</p><p>After running the above terraform commands successfully, you can verify if the cluster is created by running the command<br><strong>eksctl get clusters</strong></p><p>To update Kubeconfig file to access your cluster,</p><pre>aws eks update-kubeconfig --region us-west-2  --name Testeks                           <br>Updated context arn:aws:eks:us-west-2:xxxxx:cluster/Testeks in /Users/rramadoss/.kube/config</pre><p>Success!!!</p><pre>kubectl get nodes                                                                     &lt;aws:eksadmin&gt;<br>NAME                                          STATUS   ROLES    AGE   VERSION<br>ip-x-x-x-x.us-west-2.compute.internal   Ready    &lt;none&gt;   10m   v1.24.6-eks-4360b32<br>ip-x-x-x-x.us-west-2.compute.internal    Ready    &lt;none&gt;   10m   v1.24.6-eks-4360b32</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc2d1d148fcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Public facing Load Balancer to Private EC2 instances]]></title>
            <link>https://medium.com/@radharamadoss/setting-up-public-facing-load-balancer-to-private-ec2-instances-a9e3831eb5a?source=rss-ebf80e44c203------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9e3831eb5a</guid>
            <dc:creator><![CDATA[Radha]]></dc:creator>
            <pubDate>Sat, 05 Nov 2022 00:42:38 GMT</pubDate>
            <atom:updated>2022-11-05T00:45:08.032Z</atom:updated>
            <content:encoded><![CDATA[<p>This article provides step by step instructions on how to set up the infrastructure so that public traffic can be routed through an internet-facing load balancer to private EC2 instances.</p><p>In a production level environment, the backend application is placed in Private subnets so that it cannot be accessed from the internet. The Internet facing Load Balancer is the only layer that is accessible from internet.<br>I will go over every configuration process with you step by step.</p><p>Here is the architecture of the full setup</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ft05Aq5c-rlFL7buOjCtA.png" /></figure><p>Let’s first construct a VPC after selecting a Region for the VPC.</p><p>Provide the Name of VPC and IPV4 CIDR block address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*54GX9zhyFilw0kGcCDx-6Q.png" /></figure><p>Create four subnets (2 Public and 2Private).</p><p>At this stage, we are only creating subnets with naming convention as Public and private subnets. The actual distinction between Public and private subnets happens only when we attach Internet gateway to the routing table of Public subnet.</p><p>Also curious as to why we require two Public subnets given that our EC2 instances are located in private subnets? The reason is , Load balancer should only be placed in ‘public’ subnets, that is subnets that have a route out to the Internet Gateway. We want our Load balancer in public subnet to talk to our EC2 instances in private subnets. To solve this, we have to ensure that we have a corresponding public subnet for each availability zone in which we have private subnets.</p><p>Provide following details to create subnets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddFJuhnVrZIHwrfcASguuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*M-K6HP9R7dJOqPLxBrZqAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*e_3v1uCUs0GxyrUgMlPi4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*JQjazv-IJEjOBIvSc8omkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*XjHvbHWsWjd9AFeK82U1CQ.png" /></figure><p>All four subnets are created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lYNj7qli_-49d6JP1PF51w.png" /></figure><p>Create Internet Gateway</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*10Lfh7my50qGlsCcCYlQcA.png" /></figure><p>Attach the Internet gateway to the VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*O0iQpbBTKLSbkYzUczGaLA.png" /></figure><p>Create an Elastic IP for NAT Gateway — We need Elastic IP because <em>NAT gateway sends the traffic to the internet gateway, using its Elastic IP address as the source IP address</em></p><p>Choose the region in Network Border Group and select “Allocate”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*uHVZ6w6dHU9A46sBAgo_eQ.png" /></figure><p>Next step is to create a NAT Gateway.</p><p>Provide the following details<br>Name — demo-natgw<br>subnet — Choose a public subnet. <br>Elastic IP allocation ID — choose the elastic ip created in the previous step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*c77uU7fElzAPn7FaE4aF0Q.png" /></figure><p>It is now time to build the route table in order to make the public subnet truly public. Remember that only its name has been made public thus far :)</p><p>Create a Public Route Table with the following details<br>Name — public-rt<br>VPC — choose the VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*-jLUUZ9aZIK5MB8cYTHYzQ.png" /></figure><p>Edit the routes in the Public routing table which is an important step.<br>Add the below route</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*4iLZkNVErWshLxyFPtH1Wg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXUr0qAqdJ2tPri0AwjTHQ.png" /></figure><p>Associate the Public subnets to the Public route table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y8jKC8CwGIo83Iu7H947Rg.png" /></figure><p>We can now create a separate Route table for Private subnet.<br>Create a private route table with the following details<br>Name — private-rt<br>VPC — choose the VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*SeQEYow62ujzxIVcbqkyxQ.png" /></figure><p>Edit the routes in the Private routing table .<br>Add the below route</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*G3tDQPeQP4rQeaBDgnilSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*erW7xUiacrfJn8mbl7qMEg.png" /></figure><p>Associate the Private subnets to the Private route table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ny8xpJuNKzwSxIX4WyuFBQ.png" /></figure><p>We are almost there :)</p><p>Now let’s create two private Apache web server EC2 instances.</p><p>Create first EC2 instance with the following details<br>Name : private-ec2-1<br>Amazon Linux — AMI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*rb7tbrr4vRaaeKXV8qNr1Q.png" /></figure><p>Create a key pair</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*Oz3s2t75f1RXbp_kccqD0A.png" /></figure><p>Edit Network settings<br>Choose the VPC and Subnet as Private Subnet-1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*yq17SSC-Wx6hrTKFbp7vxg.png" /></figure><p>Create a new Security group for the Private EC2 instance to allow inbound traffic at port 80 from Load balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*Xzo9C3t6XEVZa3lkjKOoDw.png" /></figure><p>Under Advanced details, update User data to install Apache web server for Amazon Linux 2 Image</p><pre>#!/bin/bash </pre><pre>#####################################<br>####USE THIS WITH AMAZON LINUX 2##### #####################################<br># get admin privileges<br>sudo su </pre><pre># install httpd (Linux 2 version)<br>yum update -y<br>yum install -y httpd.x86_64<br>systemctl start httpd.service<br>systemctl enable httpd.service<br>echo &quot;Hello World from $(hostname -f)&quot; &gt; /var/www/html/index.html</pre><p>Create the second EC2 instance in private subnet with the following details</p><p>Name: private-ec2–2<br>Amazon Linux — AMI</p><p>Edit the Network settings<br>Choose VPC and subnet as Private Subnet-2<br>Select the same Security Group created in the first EC2 instance and also provide the userdata as explained in Private EC2 instance 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*li4dRc0kh2reNZCJeaUDIw.png" /></figure><p>Finally, we reach the Load balancer, which completes our configuration :)</p><p>Create a security group for the Load balancer<br>Edit the Inbound rules:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*elcjbVUtCqLsW-PZOrJPDA.png" /></figure><p><strong>Note</strong>: MyIP is in the Source so the load balancer inbound is not open to any address in Internet for security reasons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*31Cve-JelS0jAqHtEBYlRw.png" /></figure><p>Create Target groups — Load balancer routes the traffic to the registered targets in Target group<br>Let us now register the two Private EC2 instances in the Target group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrnS-fqRqI4wUnIbkMDzGA.png" /></figure><p>Provide the target group name, Protocol,Port, VPC, Health checks as shown in the below screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*5uaX1dN22BsdE33gvcb-vg.png" /></figure><p>Register the two Private EC2 instances in the Target group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_QMfymPRfMkxvAg-lsaS_Q.png" /><figcaption>Register the two Private EC2 instances in the Target group</figcaption></figure><p>It is now time to create the Application Load Balancer</p><p>Provide the name of ALB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g976wWXPOF-SEtpHNNoKiA.png" /></figure><p>Choose the VPC name and Public Subnets in ALB (ALB routes traffic to its internal nodes in the public subnet and then the traffic is routed to EC2 instances in private subnets) Refer to the Architecture diagram in this page for better understanding on how this works <a href="https://docs.aws.amazon.com/prescriptive-guidance/latest/load-balancer-stickiness/subnets-routing.html">https://docs.aws.amazon.com/prescriptive-guidance/latest/load-balancer-stickiness/subnets-routing.html</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u6iTaLmuMDulj_ZcHcOHMA.png" /></figure><p>Note that we have only enabled HTTP 80 inbound traffic in the ALB Security group created in previous step but for all the internal communication we also need to add the default VPC security group in ALB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*PUhtzaiJb92FfYAPV9OBEw.png" /></figure><p>Choose the Target group created above under Listeners and Routing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUhK7MEYX2GlBYCjZoN59w.png" /></figure><p>Wait until the Load balancer becomes Active</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IPtzMEuvf5r_MtsDvTBnJA.png" /></figure><p>Observe that the Health status is still in Initial status in the Targetgroup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmIFwNwUKJown5Rpis9YrA.png" /></figure><p>After 5mins, the instances become healthy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LSMvZY5nXX8HqdK5U5yBnA.png" /></figure><p>Copy the DNS name from Load balancer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*cUw5hqXjRGUBum3vGgT0NQ.png" /></figure><p>Paste the DNS address in a browser. <br>Voila!! We see the response from the Private EC2 Apache webserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*xUSIive8utZBckH3aRbgKw.png" /></figure><p>Refresh the browser for couple of times and note the response from both the private EC2 instances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*1QDB6pFmzH2VsSofim4TJQ.png" /></figure><p>Do you not see the response? Hmmmm… Lets try out some Troubleshooting steps..</p><p><strong>Test that the instances are responding to requests</strong></p><p>You could launch an EC2 instance in the public subnet, SSH to it <br>then send requests <em>directly</em> to the EC2 instances to see if they respond (eg curl <a href="http://private-ip-address)./">http://private-ip-address).</a></p><p>If they respond correctly, then the instances themselves are fine and the problem lies with the Load Balancer.</p><p><strong>Check the Load Balancer security group</strong></p><p>Make sure that you also choose the default security group in ALB configuration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9e3831eb5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>