<?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 Arunkumar Krishnakumar on Medium]]></title>
        <description><![CDATA[Stories by Arunkumar Krishnakumar on Medium]]></description>
        <link>https://medium.com/@iamarunkrish?source=rss-fe5bda89d1e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K9-WvxQDX4hu3nB10vA_gQ.jpeg</url>
            <title>Stories by Arunkumar Krishnakumar on Medium</title>
            <link>https://medium.com/@iamarunkrish?source=rss-fe5bda89d1e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:08:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iamarunkrish/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[️ Custom Runner Hooks Definition]]></title>
            <link>https://iamarunkrish.medium.com/%EF%B8%8F-arc-custom-runner-hooks-definition-c943e88d050a?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c943e88d050a</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Sat, 30 Aug 2025 18:56:31 GMT</pubDate>
            <atom:updated>2025-08-30T19:05:23.836Z</atom:updated>
            <content:encoded><![CDATA[<h3>📌 Purpose:</h3><p>Define custom runner hooks for ARC (Actions Runner Controller) in Kubernetes mode to ensure resource limits are applied to workflow and service containers.</p><h3>❗ Problem:</h3><p>When a job is triggered in ARC (GitHub Runner Scale Set Controllers &amp; Scale Sets) in Kubernetes mode with ACTIONS_RUNNER_REQUIRE_JOB_CONTAINER=true, two pods are created:</p><ul><li>The default job pod</li><li>The workflow pod</li></ul><p>The workflow pod is launched by default runner container hook definitions. However, it does not inherit resource limits/requests from the job pod manifest, leading to unrestricted resource usage — a critical issue in shared Kubernetes clusters.</p><p>Service containers suffer from the same problem.</p><h3>✅ Solution</h3><p>Create a custom runner hook definition and mount it to the scale sets to enforce resource limits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AbiWwGikfBkNAayO83gziA.jpeg" /></figure><h3>🔧 Steps to Customize Runner Hook Definitions</h3><h3>1. Create a ConfigMap in the scale set’s namespace</h3><blockquote><em>🔹 </em><em>$job must remain unchanged—it maps to the workflow container.<br>🔹 Service container names must match the workflow definition, prefixed with </em><em>$.</em></blockquote><pre>---<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: gha-runner-hook-template<br>  namespace: arc-runners<br>data:<br>  hook-template.yaml: |<br>    spec:<br>      containers:<br>        - name: $job    # Main worker pod as in the container section on the workflow<br>          resources:<br>            limits:<br>              cpu: &quot;2&quot;<br>              memory: &quot;2Gi&quot;<br>            requests:<br>              cpu: &quot;1&quot;<br>              memory: &quot;1Gi&quot;<br>        - name: $redis   ## service container 1(name should match the service container name as in the workflow with a $ prefix)<br>          resources:<br>            limits:<br>              cpu: &quot;500m&quot;<br>              memory: &quot;512Mi&quot;<br>            requests:<br>              cpu: &quot;250m&quot;<br>              memory: &quot;256Mi&quot;<br>        - name: $selenium                    ## service container 2<br>          resources:<br>            limits:<br>              cpu: &quot;300m&quot;<br>              memory: &quot;512Mi&quot;<br>            requests:<br>              cpu: &quot;150m&quot;<br>              memory: &quot;256Mi&quot;<br>        - name: $postgres                    ## service container 3<br>          resources:<br>            limits:<br>              cpu: &quot;300m&quot;<br>              memory: &quot;512Mi&quot;<br>            requests:<br>              cpu: &quot;150m&quot;<br>              memory: &quot;256Mi&quot;<br>        - name: $vault                      ## service container 4<br>          resources:<br>            limits:<br>              cpu: &quot;300m&quot;<br>              memory: &quot;512Mi&quot;<br>            requests:<br>              cpu: &quot;150m&quot;<br>              memory: &quot;256Mi&quot;</pre><p><strong>For Workflow Pod/Job:</strong></p><p>Do not change the <strong><em>*$job*(as above) </em></strong>as it parses the container name by default for workflow pods. Ensure that the name and namespace are unique and matches with your scale-set definitions. Also, set the resource quota as per the scale-set pod definitions.</p><p><strong><em>For Service Container:<br></em></strong> 📌 Name should match the service container name as in the workflow with a *$* prefix. If you are using a postgres service container, then it should be “$postgress”.</p><p>Its a must for service container as per the extension defintion and for the above workflow pod just $job would suffice.</p><p><a href="https://github.com/actions/runner-container-hooks/blob/main/examples/extension.yaml">runner-container-hooks/examples/extension.yaml at main · actions/runner-container-hooks</a></p><p>We will have to <strong><em>mount the configmap</em></strong> to all the scale-sets deployed on the same namespace. If you have a custom resource requirement, then create a different configmap and mount that to the corresponding scale-sets.</p><h3>2. Mount the ConfigMap in the Scale Set Definition</h3><pre>values:<br> containerMode:<br> type: &quot;kubernetes&quot;<br> template:<br> spec:<br> imagePullSecrets:<br> - name: test<br> securityContext:<br> fsGroup: 1001<br>###<br> volumes:<br> - name: hook-template ## for HOOK <br> configMap:<br> name: gha-runner-hook-template<br>###<br> - name: work<br> ephemeral:<br> volumeClaimTemplate:<br> spec:<br> accessModes: [&quot;ReadWriteOnce&quot;]<br> resources:<br> requests:<br> storage: 1Gi<br> containers:<br> - name: runner<br> image: gh-action-runner:latest<br> command: [&quot;/home/runner/run.sh&quot;]<br> volumeMounts:<br> - name: work<br> mountPath: /home/runner/_work<br>####<br> - name: hook-template ## for HOOK<br> mountPath: /home/runner/hook-template.yaml<br> subPath: hook-template.yaml<br>####<br> env:<br>####<br> - name: ACTIONS_RUNNER_CONTAINER_HOOK_TEMPLATE ## for HOOK<br> value: /home/runner/hook-template.yaml<br>####<br> - name: ACTIONS_RUNNER_CONTAINER_HOOKS<br> value: /home/runner/k8s/index.js<br> - name: ACTIONS_RUNNER_POD_NAME<br> valueFrom:<br> fieldRef:<br> fieldPath: metadata.name<br> - name: ACTIONS_RUNNER_REQUIRE_JOB_CONTAINER<br> value: &quot;true&quot;</pre><p>Look for the comment <strong><em>*## for HOOK*</em></strong> as those are the ones that are needed to be added in addition to the existing ARC scale set kubernetes mode definitions.</p><h3>3. Verify Resource Limits</h3><p>Run the following commands to inspect resource settings:</p><p>Once it’s applied, trigger a workflow and check the<strong><em>{.spec.containers[*].resources} </em></strong>for both the job and workflow pods.</p><p>You can run this command to verify the same.</p><pre>## workflow pod<br>$ kubectl get pod runner-abcd5-runner-abcde-workflow -o jsonpath=&quot;{.spec.containers[*].resources}&quot;<br>{&quot;limits&quot;:{&quot;cpu&quot;:&quot;2&quot;,&quot;memory&quot;:&quot;2Gi&quot;},&quot;requests&quot;:{&quot;cpu&quot;:&quot;1&quot;,&quot;memory&quot;:&quot;1Gi&quot;}}<br><br>## default pod<br>$ kubectl get pod runner-abcd5-runner-abcde -o jsonpath=&quot;{.spec.containers[*].resources}&quot;<br>{&quot;limits&quot;:{&quot;cpu&quot;:&quot;2&quot;,&quot;memory&quot;:&quot;2Gi&quot;},&quot;requests&quot;:{&quot;cpu&quot;:&quot;1&quot;,&quot;memory&quot;:&quot;2Gi&quot;}}<br><br>## Workflow pods and Service Containers<br>$ kubectl get pod runner-abcd5-runner-abcde-workflow -o jsonpath=&quot;{.spec.containers[*].name}{&#39;\n&#39;}{.spec.containers[*].resources}&quot;<br>job <br>redis <br>vault<br>{&quot;limits&quot;:{&quot;cpu&quot;:&quot;2&quot;,&quot;memory&quot;:&quot;2Gi&quot;},&quot;requests&quot;:{&quot;cpu&quot;:&quot;1&quot;,&quot;memory&quot;:&quot;1Gi&quot;}} <br>{&quot;limits&quot;:{&quot;cpu&quot;:&quot;500m&quot;,&quot;memory&quot;:&quot;512Mi&quot;},&quot;requests&quot;:{&quot;cpu&quot;:&quot;250m&quot;,&quot;memory&quot;:&quot;256Mi&quot;}} <br>{&quot;limits&quot;:{&quot;cpu&quot;:&quot;300m&quot;,&quot;memory&quot;:&quot;512Mi&quot;},&quot;requests&quot;:{&quot;cpu&quot;:&quot;150m&quot;,&quot;memory&quot;:&quot;256Mi&quot;}}[<br></pre><h3>🚫 Limitation &amp; Security</h3><p>Without enforcement, users can define arbitrary service containers that bypass resource quotas.</p><p>If you have not noticed it already, we can add any service containers which are not in the configmap and misuse the resource quota. In order to avoid that, we can create an OPA Gatekeeper policy which will restrict any workflow from spinning up random service containers apart from the ones that are in the configmap. So that if the container names are not matching this will fail to run as we have a Gatekeeper OPA policy which restricts from spinning up unknown service containers.</p><p>There are two things that have to be created as a part of OPA.</p><h3>✅ Mitigation: OPA Gatekeeper Policy</h3><p>1.<strong><em> ConstraintTemplate</em></strong></p><pre>---<br>apiVersion: templates.gatekeeper.sh/v1beta1<br>kind: ConstraintTemplate<br>metadata:<br> name: allowedservicecontainers<br>spec:<br> crd:<br> spec:<br> names:<br> kind: AllowedServiceContainers<br> targets:<br> - target: admission.k8s.gatekeeper.sh<br> rego: |<br> package allowedservicecontainers<br>allowed_names = {&quot;vault&quot;, &quot;redis&quot;, &quot;selenium&quot;, &quot;postgres&quot;}<br>violation[{&quot;msg&quot;: msg}] {<br> some i<br> container := input.review.object.spec.containers[i]<br> i &gt; 0<br> not allowed_names[container.name]<br> msg := sprintf(&quot;Service container &#39;%s&#39; is not allowed&quot;, [container.name])<br> }</pre><p>This basically is a generic template definition, which is set to be consumed by the kind that is specified.</p><p>In the above template, you can see the <strong><em>*allowed names*</em></strong> which are only service containers that are allowed to run in ARC. It must fail for the rest.</p><p>2. <strong><em>AllowedServiceContainers</em></strong></p><pre>---<br>apiVersion: constraints.gatekeeper.sh/v1beta1<br>kind: AllowedServiceContainers<br>metadata:<br> name: restrict-service-containers<br>spec:<br> match:<br> kinds:<br> - apiGroups: [&quot;&quot;]<br> kinds: [&quot;Pod&quot;]<br> namespaces:<br> - arc-runners</pre><p>This is the one which consumes the <strong><em>ConstraintTemplate</em></strong> and applies it to a specific kinds or apigroups. This is how it restricts it from creating under that namespace. Just ensure that the <strong><em>ConstraintTemplate is </em></strong>created before the<strong><em> restrict-service-containers definition.</em></strong></p><p>✅ Whitelisting New Service Containers</p><ol><li>Update the gha-runner-hook-template ConfigMap with the new container name and resource limits.</li><li>Add the container name to allowed_names in the Gatekeeper policy.</li></ol><h3>🧪 Sample Workflow (Allowed)</h3><pre>name: ARC Test<br>on:<br> workflow_dispatch:<br>jobs:<br> Create:<br> runs-on: test-gha-runner<br> container:<br> image: alpine:3.18<br>services:<br> redis:<br> image: redis<br>postgres:<br> image: postgres<br>vault:<br> image: hashicorp/vault:1.15.5<br> options: &gt;-<br> - health-cmd=&quot;vault status&quot;<br> - health-interval=10s<br> - health-timeout=5s<br> - health-retries=5<br><br>steps:<br> - uses: actions/checkout@v4<br><br> - name: Test ARC Runner<br>   run: |<br>     echo &quot;Hello ARC Runner&quot;<br>     env | grep &quot;HOSTNAME&quot;<br>     pwd<br></pre><h3>❌ Sample Workflow (Blocked)</h3><pre>name: ARC Test<br>on:<br> workflow_dispatch:<br>jobs:<br> Create:<br> runs-on: test-gha-runner<br> container:<br> image: alpine:3.18<br>services:<br> redis:<br> image: redis<br><br>postgres:<br> image: postgres<br><br>busybox: ### busybox is not part of configmap and ConstraintTemplate, it fails<br> image: busybox<br><br>vault:<br> image: hashicorp/vault:1.15.5<br> options: &gt;-<br> - health-cmd=&quot;vault status&quot;<br> - health-interval=10s<br> - health-timeout=5s<br> - health-retries=5<br><br>steps:<br> - uses: actions/checkout@v4<br><br> - name: Test ARC Runner<br>   run: |<br>     echo &quot;Hello ARC Runner&quot;<br>     env | grep &quot;HOSTNAME&quot;<br>     pwd<br></pre><p>This should help adding custom resource quotas and also restricting non-whitelisted service containers from spinning up.</p><h3>🧪 References:</h3><p>[Runner Extensions]</p><p><a href="https://github.com/actions/runner-container-hooks/blob/main/examples/extension.yaml">runner-container-hooks/examples/extension.yaml at main · actions/runner-container-hooks</a></p><p>[ADR-0134]</p><p><a href="https://github.com/actions/runner-container-hooks/blob/main/docs/adrs/0134-hook-extensions.md">runner-container-hooks/docs/adrs/0134-hook-extensions.md at main · actions/runner-container-hooks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c943e88d050a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accessing Private ECR images for Service Containers via GHA]]></title>
            <link>https://iamarunkrish.medium.com/accessing-private-ecr-images-for-service-containers-via-gha-cc27698c85fa?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc27698c85fa</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ecr]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[service-container]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Sat, 28 Dec 2024 21:48:35 GMT</pubDate>
            <atom:updated>2024-12-28T21:48:35.117Z</atom:updated>
            <content:encoded><![CDATA[<p>This page is to describe a way to Access the private ECR images for Service containers within the GHA workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*Mjro6V5Ya2pEf2i2CVvXZQ.png" /></figure><p>Unless we have a license for Docker, the docker pull requests are rate limited and you will get an error :</p><pre>toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading</pre><p><strong>Why?</strong></p><p>You get this error when you try to pull an image from the public Docker Hub repository after you have reached your Docker pull rate limit. Docker Hub uses IP addresses to authenticate the users, and pull rates limits are based on individual IP addresses.</p><ul><li>For anonymous users, the rate limit is set to 100 pulls per 6 hours per IP address.</li><li>For authenticated users with a Docker ID, the pull rate is set to 200 pulls per 6-hour period.</li><li>If your image pull request exceeds these limits, these requests are denied until the six-hour window elapses.</li></ul><p>Every docker pull command execution counts against your quota regardless if the requested image is up to date or not. Hitting the request limit is a piece of cake if you deploy your application stack to a cluster.</p><p>So in order to avoid this, the docker suggests a workaround of keeping it in your private repositories.</p><p>This can help with the default Github Action workflows jobs to pull it from a private registries like ECR etc.</p><p>However, if you use a service container in your Github Actions workflow, then you will hit the rate limit as the service container step does not provide a default way to authenticate to private registries.</p><p><strong>Now , how can we solve that ?</strong></p><p><a href="https://github.com/arun291091/service-container-private-ecr/blob/main/.github/workflows/service-container-test-ecr.yaml">https://github.com/arun291091/service-container-private-ecr/blob/main/.github/workflows/service-container-test-ecr.yaml</a></p><p>I have created the above workaround for authenticating to a private ECR registry for a service container , so that you do not run into the Docker rate limits, instead store it in your private ecr registry and access the same.</p><p>Ref: <a href="https://github.com/aws-actions/amazon-ecr-login?tab=readme-ov-file#run-an-image-as-a-service">https://github.com/aws-actions/amazon-ecr-login?tab=readme-ov-file#run-an-image-as-a-service</a></p><p>From the above workflow, All you need to modify is the following :</p><ol><li>Environment variable <strong>ROLE — Provide the right irsa role to access the ECR from your runner.</strong> As per : <a href="https://github.com/arun291091/service-container-private-ecr/blob/main/.github/workflows/service-container-test-ecr.yaml#L30">https://github.com/arun291091/service-container-private-ecr/blob/main/.github/workflows/service-container-test-ecr.yaml#L30</a></li><li>The outputs for docker username and password as per : <a href="https://github.com/arun291091/service-container-private-ecr/blob/main/.github/workflows/service-container-test-ecr.yaml#L46-L47">https://github.com/arun291091/service-container-private-ecr/blob/main/.github/workflows/service-container-test-ecr.yaml#L46-L47</a></li></ol><p>So by this way, you can authenticate to your private ECR registry and avoid Docker pull rate limit issue for Service containers on your github actions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc27698c85fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yaml Linter To Scan a Changes related to a PR]]></title>
            <link>https://iamarunkrish.medium.com/yaml-linter-to-scan-a-changes-related-to-a-pr-7c682f06e8db?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c682f06e8db</guid>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[linter]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Sat, 21 Dec 2024 20:36:51 GMT</pubDate>
            <atom:updated>2024-12-24T13:36:54.921Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/marketplace/actions/yaml-linter-gha">Yaml Linter GHA - GitHub Marketplace</a></p><p><strong>Yamllint</strong><br>Github Actions for “<strong>Yamllint</strong>” for a specific PR</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*AuFyPPZn20Le7vHPKDkLVQ.jpeg" /></figure><p><strong>Agenda</strong></p><p>This action is helpful to add it as a linter to your repo which needs to execute yaml linter only to the specific files that was modified in your PR rather than checking the netire repository files.</p><p><strong>To whom it is useful</strong></p><p>if you need to execute yaml linter only to the specific files that was modified in your PR rather than checking the netire repository files</p><p><strong>Pre-requisites</strong></p><p>1. You can directly start using it.</p><p><strong>How to works?</strong></p><p>An action has been created to add an yaml linter only to the specific files that was modified in your PR. It has all the dependancies installed, all you have to do is use this and create a yamlinter.yaml in your repo.</p><p>like : [Sample Yaml Linter to be added in your repo](<a href="https://github.com/arun291091/yamllint/blob/main/.github/workflows/sampleyamllinter.yaml">https://github.com/arun291091/yamllint/blob/main/.github/workflows/sampleyamllinter.yaml</a>)</p><ol><li>It runs the yaml linter only to the newly created/modified files of PR and publishes the result in the Github Summary.</li><li>It only checks for Syntax and indendation error, You can control the rest via .yamllint in your root directory.</li><li>It throws warning for indendation error and fail for syntax errors.</li></ol><p>Sample yamllint : [.yamllint](<a href="https://github.com/arun291091/yamllint/blob/main/.yamllint">https://github.com/arun291091/yamllint/blob/main/.yamllint</a>)</p><p><strong>How to use?</strong></p><p>Use this action within your GitHub workflow step where you need to wait for some additional approval before proceeding to the next step.</p><pre>- name: Yaml Linter GHA Action<br>  uses: arun291091/yamllinter@v1</pre><p><strong>How to report issues?</strong></p><p>Raise an issue via github for any issues.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c682f06e8db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KEDA — An Event Driven Autoscaler]]></title>
            <link>https://iamarunkrish.medium.com/keda-an-event-driven-autoscaler-fa941ba72923?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa941ba72923</guid>
            <category><![CDATA[keda]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Wed, 05 Jun 2024 09:50:56 GMT</pubDate>
            <atom:updated>2024-06-07T07:22:20.038Z</atom:updated>
            <content:encoded><![CDATA[<h3>KEDA — An Event Driven Autoscaler</h3><p>This Page is about the KEDA tool for Horizontal pod autoscaling using custom metrics.</p><p>Example : This was implemented for an application which had a requirement to Scale the pods based on number of messages in AWS SQS length in this case.</p><p>Let us see how it was implemented and scaled.</p><h3>Overview :</h3><p><strong>KEDA</strong> is an Event Driven Autoscaler. It was mainly added to enable the horizontal pod autoscaling for an application based on custom metrics.</p><h3>How it works ?</h3><p><strong>KEDA </strong>acts to monitor the event source and feed that data to Kubernetes and the HPA (Horizontal Pod Autoscaler) to drive rapid scale of a deployment. Each replica of a deployment is actively pulling items from the event source.</p><p>More on how it works is here :</p><p><a href="https://keda.sh/docs/2.13/concepts/#how-keda-works">KEDA | KEDA Concepts</a></p><h3>Architecture :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XIJarbhgaG04G_bdX0yVPQ.png" /><figcaption>Referred from KEDA official page</figcaption></figure><p>Here’s how these components interact in a typical workflow:​</p><p><strong>Define a ScaledObject</strong>:​</p><ul><li>A user creates a ScaledObject that specifies the target workload ​<br>(e.g., Deployment) and the external metric source ​<br>(e.g., AWS SQS Queue, Kafka topic,Rabbit MQ etc).​</li></ul><p><strong>Admission Webhook</strong>:​</p><ul><li>When the ScaledObject is created or updated, the admission webhook ​<br>validates the configuration and applies any necessary mutations.​</li></ul><p><strong>Controller</strong>:​</p><ul><li>The KEDA controller detects the new or updated ScaledObject and ​<br>determines the appropriate scaler to use based on the external metric source ​<br>specified.​</li></ul><p><strong>Scaler</strong>:​</p><ul><li>The scaler fetches metrics from the external source at regular intervals.​</li></ul><p><strong>Metrics Adapter</strong>:​</p><ul><li>The scaler provides these metrics to the metrics adapter, which then exposes​<br> them in a format that the Kubernetes HPA can understand.​</li></ul><p><strong>Horizontal Pod Autoscaler (HPA)</strong>:​</p><ul><li>The HPA uses these metrics to make scaling decisions, adjusting the number ​<br>of replicas of the target workload as needed.​</li></ul><h3>What is a scaled object?</h3><h4>ScaledObject spec:</h4><p>This specification describes the ScaledObject custom resource definition which is used to define how KEDA should scale your application and what the triggers are :</p><p>This specification describes the ScaledObject custom resource definition which is used to define how KEDA should scale your application and what the triggers are :<a href="https://github.com/kedacore/keda/blob/v1.5.0/pkg/apis/keda/v1alpha1/scaledobject_types.go">scaledobject_types.go</a></p><ul><li>ScaledObjects represent the desired mapping between an event source (e.g. AWS SQS) and the Kubernetes Deployment, StatefulSet or any Custom Resource that defines /scale sub-resource.</li><li>ScaledJobs represent the mapping between event source and Kubernetes Job.</li><li>ScaledObject/ScaledJob may also reference a TriggerAuthentication or ClusterTriggerAuthentication which contains the authentication configuration or secrets to monitor the event source.</li></ul><h4>Scalers :</h4><p>There are around 64 ways to scale the applications .You can view all the scalers here : <a href="https://keda.sh/docs/2.14/scalers/">KEDA | Scalers</a> and scale your application with any of these scalers.</p><p><strong>CRDs</strong> :</p><p>Keda creates 4 CRDs while installing it.</p><p>More About CRDS here:<a href="https://keda.sh/docs/2.13/concepts/#custom-resources-crd">KEDA | KEDA Concepts</a></p><h3>Pre-requisites :</h3><ol><li>An EKS Cluster with OIDC enabled</li><li>Resources which acts as a event source needs to be created (eg : AWS SQS, RabbitMQ etc.)</li><li>Namespace for the KEDA deployment</li><li>A KEDA Operator IAM Role has to be created and mapped to the KEDA operator Service Account</li><li>KEDA operator role must have permissions to the resource which is the source for the event to trigger the scaling.</li><li><strong>ScaledObject</strong> with<strong> </strong>respective<strong> Triggers </strong>and<strong> TriggerAuthentication</strong> needs to be created along with the application (app.yaml) in our argocd app folder.</li></ol><h3>Deploying KEDA using HELM + ArgoCD :</h3><p>It can be deployed on the cluster via argocd calling the official helm charts with additional modifications to the values.yaml as prescribed by official KEDA website.</p><p><strong>App Deployment using ArgoCD :</strong></p><p>app.yaml :</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Application<br>metadata:<br>  name: &#39;keda&#39;<br>  namespace: argocd<br>  finalizers:<br>    - resources-finalizer.argocd.argoproj.io<br>spec:<br>  destination:<br>    namespace: &#39;keda&#39;<br>    server: &#39;https://kubernetes.default.svc&#39;<br><br>  source:<br>    chart: &#39;keda&#39;<br>    repoURL: &#39;https://kedacore.github.io/charts&#39;<br>    targetRevision: &#39;2.14.1&#39;<br>    helm:<br>      values: |<br>        podSecurityContext:<br>          fsGroup: 1001<br>          runAsGroup: 1001<br>          runAsUser: 1001<br>        serviceAccount:<br>          operator:<br>            create: true<br>            name: keda-operator<br>            annotations:<br>                eks.amazonaws.com/role-arn: arn:aws:iam::xxxxxxxx:role/keda-operator-iam-role<br><br>  project: keda<br>  syncPolicy:<br>    automated:<br>      prune: true<br>      selfHeal: true<br>    syncOptions:<br>      - Replace=true<br>      - ApplyOutOfSyncOnly=true</pre><p>We need to needs to override <strong>podSecurityContext</strong> and <strong>serviceAccount</strong> with the above as the role created for KEDA operator must be mapped to the default keda-operator service account . <strong>podSecurityContext </strong>was added to resolve this known issue : <a href="https://github.com/kedacore/keda/issues/837">https://github.com/kedacore/keda/issues/837</a></p><p><strong>Source Image </strong>:<a href="https://artifacthub.io/packages/helm/kedacore/keda/2.14.1">keda 2.14.1 · helm/kedacore</a></p><p><strong>Source Helm Chart</strong> : <a href="https://github.com/kedacore/charts/tree/main/keda/templates">https://github.com/kedacore/charts/tree/main/keda/templates</a></p><h3>ScaledObject :</h3><p>The scaled object has to be created on the application namespace (eg : keda-test)</p><p><strong>NOTE</strong> : For this setup, we have used <strong>AWS SQS Scaler</strong> to scale the pods based on the number of messages in the AWS SQS queue: <a href="https://keda.sh/docs/2.13/scalers/aws-sqs/">KEDA | AWS SQS Queue</a></p><pre>### KEDA HPA to scale based on Number Of Messages in SQS #####<br><br>apiVersion: keda.sh/v1alpha1<br>kind: ScaledObject<br>metadata:<br>  name: aws-sqs-queue-scaledobject<br>  namespace: keda-test<br>spec:<br>  scaleTargetRef:<br>    name: keda-test-consumer     # Name of the Deployment<br>  minReplicaCount: 0  # If We don&#39;t want pods if the queue is empty<br>  maxReplicaCount: 5  # We don&#39;t want to have more than 5 replicas<br>  pollingInterval: 30 # How frequently we should go for metrics (in seconds)<br>  cooldownPeriod:  25 # How many seconds should we wait for downscale  <br>  triggers:<br>  - type: aws-sqs-queue<br>    authenticationRef:<br>      name: keda-aws-role # Random<br>    metadata:<br>      queueURL: https://sqs.&lt;region&gt;.amazonaws.com/xxxxxxxx/test-app-actions-queue.fifo<br>      queueLength: &quot;1&quot;     # Based on queue length it scales a POD<br>      awsRegion: &quot;&lt;region&gt;&quot;<br>      identityOwner: operator # Must be set to operator<br>---<br>apiVersion: keda.sh/v1alpha1<br>kind: TriggerAuthentication<br>metadata:<br>  name: keda-aws-role<br>  namespace: keda-test<br>spec:<br>  podIdentity:<br>    provider: aws-eks # must be aws_eks for EKS , GCP for google cloud</pre><p>More auth providers here :<a href="https://keda.sh/docs/2.14/authentication-providers/">KEDA | Authentication Providers</a></p><h3>AM Role — KEDA Operator Role (One time setup during installation)</h3><p>An IAM role needs to be created for keda-operator with cluster OIDC mapped to the keda-opertor service account for it to assume and execute HPA based on IAM permissions.</p><p><strong>Assume Role Policy for the Keda Operator Role:</strong></p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;Federated&quot;: &quot;arn:aws:iam::&lt;region&gt;:oidc-provider/oidc.eks.xxxxx.amazonaws.com/id/xxxxxxxxxx&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,<br>            &quot;Condition&quot;: {<br>                &quot;StringEquals&quot;: {<br>                    &quot;oidc.eks.&lt;region&gt;.amazonaws.com/id/xxxxxxx:sub&quot;: [<br>                      &quot;system:serviceaccount:keda:keda-operator&quot;<br>                    ],<br>                    &quot;oidc.eks.&lt;region&gt;.amazonaws.com/id/xxxxxx:aud&quot;: &quot;sts.amazonaws.com&quot;<br>                }<br>            }<br>        }<br>    ]<br>}</pre><p>NOTE : Ensure that the source is set to keda-operator under the namespace keda</p><p><strong>IAM Policy </strong>:</p><p>##############################################################################</p><p><strong>Main Policy for Keda Operator</strong> :</p><p><strong><em>This is the policy where you can add additional permissions for the other triggers , So that Keda-operator will have the permissions to set scale triggers on that particular resource.</em></strong></p><p>##############################################################################</p><pre>data &quot;aws_iam_policy_document&quot; &quot;keda_operator_policy&quot; {<br>  statement {<br>    sid = &quot;sqs&quot;<br>    actions = [<br>      &quot;sqs:SendMessage&quot;,<br>      &quot;sqs:GetQueueUrl&quot;,<br>      &quot;sqs:ReceiveMessage&quot;,<br>      &quot;sqs:GetQueueAttributes&quot;,<br>      &quot;sqs:ChangeMessageVisibility&quot;,<br>      &quot;sqs:ListDeadLetterSourceQueues&quot;,<br>      &quot;sqs:ListQueues&quot;<br>    ]<br>    resources = [<br>      &quot;arn:aws:sqs:${var.aws_region}:${var.account_id}:test-keda-queue*&quot;<br>    ]<br>    effect = &quot;Allow&quot;<br>  }<br><br>  statement {<br>    sid       = &quot;sts&quot;<br>    effect    = &quot;Allow&quot;<br>    actions   = [&quot;sts:AssumeRole&quot;]<br>    resources = [&quot;*&quot;]<br>  }<br><br>}</pre><p><strong>Important Note (One time Setup during installation):</strong></p><p><strong>NOTE</strong> : <em>Once the IAM role and policy are created, map the role to the KEDA operator Service Account as per the app.yaml Above.</em></p><p>Once its setup and the scaledobjects are mapped to deployment, the scaling is triggered.</p><h4>Points to add in app.yaml for the application :</h4><p>The ArgoCD app immediately goes out of sync due to the HPA activity and mismatch in the ArgoCD diff to HPA especially due to replica count of the app pod. In order to Avoid that issue, we can Simply ignore that in the argocd app config to avoid this out of sync argocd issue.</p><p><strong>NOTE</strong> :</p><p>Kindly add the following to your application app.yaml to avoid ArgoCD out of sync issue due to HPA by KEDA.</p><pre>spec:<br>  ignoreDifferences:<br>    - group: &quot;apps&quot;<br>      kind: &quot;Deployment&quot;<br>      jsonPointers:<br>        - /spec/replicas</pre><p>and</p><pre>    syncOptions:<br>      - ApplyOutOfSyncOnly=true<br>      - RespectIgnoreDifferences=true</pre><h4>How the scaling was tested? :</h4><p>You should have an SQS Queue created and shouldhave logged into one of those app pods and send some dummy messages to the SQS Queue with a sample payload.</p><p>Command :</p><pre>aws sqs send-message --queue-url https://sqs.&lt;region&gt;.amazonaws.com/xxxxxx/test-keda-actions-dlq.fifo --message-body &quot;Information about the largest city in Any Region &quot; --message-attributes file://send-message.json --region xxxxx --message-group-id Group1 --message-deduplication-id 123</pre><p>Sample Payload :</p><pre>{<br>  &quot;attribute1&quot;: {<br>    &quot;DataType&quot;: &quot;String&quot;,<br>    &quot;StringValue&quot;: &quot;Hello World&quot;<br>  },<br>  &quot;attribute2&quot;: {<br>    &quot;DataType&quot;: &quot;Number&quot;,<br>    &quot;StringValue&quot;: &quot;123&quot;<br>  }<br>}</pre><h3>Logging :</h3><p>You can describe the scaledobject to view the status/logs :</p><p>kubectl describe scaledobject aws-sqs-queue-scaledobject</p><p>or</p><p>The Keda-operator logs can be view from the keda-operator pod via argocd or via CMD.</p><p>— — — — — — — — THE END — — — — — — — — — — — — — — — — — —</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa941ba72923" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to maintain Base docker image in your org]]></title>
            <link>https://iamarunkrish.medium.com/how-to-maintain-base-docker-image-in-your-org-83418561969c?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/83418561969c</guid>
            <category><![CDATA[security-vulnerabilities]]></category>
            <category><![CDATA[dependabot]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 16:46:54 GMT</pubDate>
            <atom:updated>2023-08-08T16:46:54.774Z</atom:updated>
            <content:encoded><![CDATA[<p>Hola Folks, We are going to see how we are going to maintain a custom base images and periodically auto update it without our intervention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rPXw8XrdYq1uqqJJUZYww.png" /><figcaption>Automated Workflow to update and push the base image</figcaption></figure><p><strong>Pre-requisites :</strong></p><ol><li>AWS ECR or any repository (using ECR for this example)</li><li>Programmatic or role based access to pull the image</li><li>Github Action workflow for CICD</li><li>Github as a source code repository</li></ol><p>Every Organisations would love to have a vulnerable free base images in order to get rid of vulnerabilities.</p><p>I have created a process to maintain our own base images in our case we use Java based base images.</p><p><strong>What is the Agenda?</strong></p><p>As a part of securing our infrastructure, we are trying to implement a Structure/Process to remove all the vulnerable images and keeping a <strong>Centralized Base Image Repository</strong> to have all the required images for Each of the applications which can be managed/patched by us periodically.</p><p><strong>What are we trying to Achieve here ?</strong></p><p>Basically, creating a process to remove the vulnerable base images and to update the Docker base images across all the repos periodically in order to avoid falling into the vulnerability pit.</p><h3>How its going to be implemented ?</h3><p>We are going to maintain a separate custom base images for <strong>Java 8, 11,17 and 20</strong> and a pipeline to update the same periodically automatically.</p><ol><li>The Current plan is to have the list of base images in a sre/base-images ECR repository</li><li>Keeping a <strong>static tag</strong> of each version (eg:- <strong>jre-alpine-17</strong> for java 17, jre-alpine-20 for Java 20) so that we dont have to keep editing the docker files for each Minor/Patch releases.</li><li>We will be keeping the same tag for <strong>minor/patch</strong> updates for a specific major versions due to vulnerabilities for each versions.</li><li>No changes would be required in the docker file for the <strong>minor and patch </strong>updates for the specific version that you are using, unless you are planning to update the version itself(eg : java 11 to java 17)</li><li>We can notify the teams via webhook for each patch updates(periodically) for all the versions of base images and the team just need to rebuild their app image and re-deploy the application to pull the updated changes. <strong>No code changes would be required after you make the first change to use base images.</strong></li></ol><p>We will be creating an Automated workflow to check for latest <strong>Minor and Patched </strong>releases for all these specified versions above from the public ECR using Github native <strong>Dependabot</strong> . It checks for the <strong>Minor and Patched</strong> versions of each major versions mentioned which is by default vulnerable free and Bumps with a PR and Automatically pushes the update to our <strong>sre/base-images ECR </strong>Repo Automatically post our approval on a monthly Basis through a GHA pipeline.</p><p>You don’t have to worry about automatic updates as we are not doing a major change to the existing versions and there wont be any compatibility issues unless you are migrating to new versions.</p><p>First create a <strong>dependabot.yml</strong> with the following contents.</p><p><a href="https://github.com/arun12cool/Github-actions/blob/main/.github/dependabot">https://github.com/arun12cool/Github-actions/blob/main/.github/dependabot</a></p><p><strong>NOTE : We have basically configured the dependabot to avoid Major release updates. so it Automatically creates a PR if there Are minor and patched releases for A specific versions which Are ideally vulnerable free .</strong></p><p>Now we have dependabot ready , lets create a GHA pipeline to be triggered when a PR is raised by Github dependabot . It by default adds a label named “dependencies” while creating it which makes our life easier to Automate or to trigger a pipeline.</p><p>Create a GHA workflow like this :</p><p><a href="https://github.com/arun12cool/Github-actions/blob/main/.github/workflows/base-ecr-push.yaml">https://github.com/arun12cool/Github-actions/blob/main/.github/workflows/base-ecr-push.yaml</a></p><p>Ensure to modify your AWS account IDs , region, repo name, github url , Runner etc.</p><p><strong>IMPORTANT : So whenever your Dependabot bumps a new PR for any Minor or Patched updates, then this pipeline will be triggered and waits for your PR approval and as soon you approve the PR, its merges automatically and pushes the latest patches to the same tag for that specific version in the ECR. Ensure to enable Mutability for your ECR repos to overwrite it.</strong></p><p>Ensure to have CODEOWNERS under .github to automatically request for Their approval.</p><p>I hope this could help your org to maintain a custom base image and have a vulnerable free enviornment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83418561969c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Add an Approval Stage in Github Actions]]></title>
            <link>https://iamarunkrish.medium.com/how-to-add-an-approval-stage-in-github-actions-5d318533e069?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d318533e069</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Fri, 14 Jul 2023 17:17:41 GMT</pubDate>
            <atom:updated>2024-01-02T12:25:20.832Z</atom:updated>
            <content:encoded><![CDATA[<p>Many of you would have used Jenkins, where you can add a stage and wait for Approval. However, in Github Actions , there are no explicit ways to add a waiting stage for manual approval before it goes to the live environment.</p><p>Here is a hacky way, how you can add a wait stage for the Github Action workflow to halt the Execution of the upcoming steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o868q0dDg9OEF6NXdoAvIw.png" /></figure><p><a href="https://www.linkedin.com/feed/update/urn:li:activity:7085669266942767104/">https://www.linkedin.com/feed/update/urn:li:activity:7085669266942767104</a></p><p>An Action has been created for everyone to make use of this approval stage</p><h3>wait_for_approval</h3><p>Github Actions for “wait_for_approval” Stage</p><p><a href="https://github.com/marketplace/actions/wait-for-approval-gha">https://github.com/marketplace/actions/wait-for-approval-gha</a></p><h3>Agenda</h3><p>As we know that there are no native way in github to wait for approval like jenkins. This is an approach to wait for approval within the actions via a dummy PR and waiting for its approval and to proceed further post approval.</p><h3>To whom it is useful</h3><p>if you need an additional layer of approval on top of your existing PR.</p><p>Like: Waiting for approval during terraform apply or during some test cases or deployment or any other use cases where you need to hold before proceeding to the next step</p><h3>Pre-requisites</h3><ol><li>Ensure that you have GITHUB_TOKEN which has permissions to create a feature branch,PR and to merge a PR and have it in the github secrets.</li><li>Ensure you provide all the necessary inputs as requested when you call the actions</li></ol><h3>How to works?</h3><p>An action has been created to add an approval stage within the workflow</p><p>Once this action is added with the requested inputs like repo name, default branch name, org, pr_reviewer , github_token, time-limit etc . The action is then triggered and does the following.</p><ol><li>Creates a new feature branch in the repository that is mentioned in the inputs.</li><li>Creates a dummy commit with some default details like who triggered it along with the date and workflow number.</li><li>Creates a PR and waits for the approval from the reviewer. It can be an individual person or a team as mentioned in the inputs.</li><li>The approval wait time depends on the time-limit inputs in seconds. The workflow run will wait until the approved has approved within that time frame and then proceeds with the further action.</li></ol><h3>How to use?</h3><p>Use this action within your GitHub workflow step where you need to wait for some additional approval before proceeding to the next step.</p><pre>- name: Wait_for_approval Action<br>        uses: arun291091/wait_for_approval_gha@v1<br>        with:<br>          base_repository_branch: &lt;Base branch name&gt;<br>          github_org: &lt;org name&gt;<br>          repository_name: &lt;repo name&gt;<br>          pr_reviewer: &lt;reviewer&gt;<br>          time_limit: &lt;time wait for approval in Seconds&gt;<br>          github_token: &lt;Github auth token&gt;</pre><p><strong>Where</strong></p><ol><li>base_repository_branch : Should be the default branch name of the specific repository either main or master</li><li>github_org : The Github organization name</li><li>repository_name: The name of the repository where you need the dummy PR approval to be.</li><li>pr_reviewer : PR reviewer can be a team or an individual member whom you would need to Wait for approval.</li><li>time_limit: Waiting time in Seconds for the approval</li><li>github_token: Github Auth token with necessary permissions to create/merge PR, branch .</li></ol><h3>How to report issues?</h3><p>Raise an issue via github for any issues.</p><h3>Upcoming updates:</h3><ol><li>Authentication using Github App</li><li>Adding a custom content for the dummy PR.Reach out to me for any queries.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d318533e069" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Github Action Org-level Self Hosted Runner]]></title>
            <link>https://iamarunkrish.medium.com/github-action-org-level-self-hosted-runner-fd3e58a2fa4?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd3e58a2fa4</guid>
            <category><![CDATA[self-hosted-runner]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Tue, 11 Jul 2023 16:36:21 GMT</pubDate>
            <atom:updated>2023-07-13T05:59:57.581Z</atom:updated>
            <content:encoded><![CDATA[<p>I hope most of the folks are using Github as their code base. If so, Then this could be a useful read for you. In this Blog, we are going to see how to create an Org-level Self hosted Runners for your organization in order to have to a seamless CI-CD within Github itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*ncctR3uW69oHLtnrjRsNCg.jpeg" /></figure><p>In this blog, we are going to keep the backend as AWS EKS and app deployment using ArgoCD.</p><p><strong>Pre-requisities:</strong></p><ol><li>AWS EKS</li><li>ARGOCD or any CI/CD mechanism for app deployment</li><li>A Source Repo like Github with org access</li></ol><p><strong>Components Required for GHA runners :</strong></p><ol><li>Actions-runner-Controller (ARC)</li><li>Cert-manager</li><li>Runner deployment config</li><li>Runner group in Github(Need org level permissions)</li><li>NS in K8s</li><li>Github App created to consume the secret instead of token(<a href="https://github.com/actions/actions-runner-controller/blob/master/docs/authenticating-to-the-github-api.md#deploying-using-github-app-authentication">https://github.com/actions/actions-runner-controller/blob/master/docs/authenticating-to-the-github-api.md#deploying-using-github-app-authentication</a>)</li></ol><p><strong>Installation Process :</strong></p><p>The workflow would be :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*1bkI5T-RboqkbNFrq-xY3Q.png" /></figure><p><strong>Before installing it, Ensure you have created all the resources as per the prerequisites below.</strong></p><p><strong>Pre-requisite:</strong></p><ol><li><strong>Namespace</strong> for ARC And Cert manager.</li></ol><p>2.<strong> K8s secret</strong> in the ARC Namespace with your <strong>Github App Creds</strong> and name it as “<strong>controller-manager</strong>” (More on <a href="https://github.com/actions/actions-runner-controller/blob/master/docs/authenticating-to-the-github-api.md#deploying-using-github-app-authentication">https://github.com/actions/actions-runner-controller/blob/master/docs/authenticating-to-the-github-api.md#deploying-using-github-app-authentication</a>))</p><p>3. Create a <strong>runner group </strong>by following this blog (<a href="https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/managing-access-to-self-hosted-runners-using-groups#creating-a-self-hosted-runner-group-for-an-organization">https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/managing-access-to-self-hosted-runners-using-groups#creating-a-self-hosted-runner-group-for-an-organization</a>)</p><p><strong>Installing Actions-runner-Controller (ARC):</strong></p><p>This is the controller object in k8s to manage the Github runners. We are going to use the official helm charts to install the ARC.</p><p>More on that in &gt; <a href="https://github.com/actions/actions-runner-controller#about">https://github.com/actions/actions-runner-controller#about</a></p><p>Since I am using ArgoCD for app deployment, I have created a app.yaml file for installing the ARC .</p><p><a href="https://github.com/arun12cool/Github-actions/blob/main/Github/GHA-install/app.yaml">Github-actions/Github/GHA-install/app.yaml at main · arun12cool/Github-actions</a></p><p>You can refer the configuration details in the repo . You can also build a custom image for ARC and refer your Repository endpoint to pull the image. I am not digging deeper as it is pretty straight forward and all the configuration details are in my Github repo above.</p><p>If you need to customize or add Additional parameters to the helm charts, here are the list of available parameters you can add.</p><p><a href="https://github.com/actions/actions-runner-controller/blob/master/charts/actions-runner-controller/values.yaml">actions-runner-controller/charts/actions-runner-controller/values.yaml at master · actions/actions-runner-controller</a></p><p>Apply the App.yaml to install ARC and voila you have the ARC created.</p><p>NOTE &gt; Kindly note that you have created everything as per <strong>Pre-requisite </strong>before moving into the installation Step.</p><p><strong>Installing Cert-Manager:</strong></p><p>Similar to ARC, Ihave added the app file for installing Cert-manager as well.</p><p><a href="https://github.com/arun12cool/Github-actions/tree/main/Github/cert-manager">Github-actions/Github/cert-manager at main · arun12cool/Github-actions</a></p><p>Ensure, you have the NS created before as per the pre-requisite and just apply the app.yaml file to install cert-manager.</p><p>Now that we have installed the controller objects. lets go with the runner deployment.</p><p><strong>Creating a Runner-Deployment:</strong></p><p>Before creating a runner deployment, ensure that you have created the Runner group in the Github org which will have runner pool for the Github action jobs to pick it up from.</p><p>Create a <strong>Runner Deployment</strong> like the one below :</p><p><a href="https://github.com/arun12cool/Github-actions/blob/main/Github/GHA-Runner/runner.yaml">Github-actions/Github/GHA-Runner/runner.yaml at main · arun12cool/Github-actions</a></p><p>Also, Create a <strong>runner HRA</strong> as well to Scale up runners upon request by keeping the min replica to 1 always. Keeping the min replica to 0 wont work as per their documentation, so ensure to keep the min replicas to 1 for proper HRA.</p><p><a href="https://github.com/arun12cool/Github-actions/blob/main/Github/GHA-Runner/runner-hra.yaml">Github-actions/Github/GHA-Runner/runner-hra.yaml at main · arun12cool/Github-actions</a></p><p><strong>IMPORTANT NOTE</strong>:</p><p>Ensure that you are keeping a proper label to be used by all the Github workflows in your org and ensure that the repos are Added in the runner group which you had created earlier to ensure that the Github workflows are picking up the runners from the Runner group pool.</p><p>Also in this blog, we were using the public charts and images for installation, you can also have a customized runner for your org by keeping this as the base and build yours on top of it.</p><p><a href="https://github.com/actions/actions-runner-controller/tree/master/runner">actions-runner-controller/runner at master · actions/actions-runner-controller</a></p><p>I would suggest to use the public images for ARC and Cert-manager and a customized one for the runner image to have more control and to add more generic dependancies based on the requirements from different teams.</p><p>Once you have applied the runner deployment, it should be up and running and listening for jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2cIAXeZ88u3JCEmsvx00eg.png" /></figure><p>Thatz it, we have successfully installed self hosted Github Action runners in EKS.</p><p>You can reach out to me via linkedin or comment for any clarifications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd3e58a2fa4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving App From Elastic Beanstalk to EKS]]></title>
            <link>https://iamarunkrish.medium.com/moving-app-from-elastic-beanstalk-to-eks-95619e7259ac?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/95619e7259ac</guid>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Mon, 01 May 2023 12:56:29 GMT</pubDate>
            <atom:updated>2023-05-01T13:01:46.213Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Everyone, In this section, we are about to see how we can migrate an Application from the Elastic Beanstalk Environment to EKS.</p><p>There were not much blogs around about this , so thought of sharing some insights on this. The App migration from Beanstalk would completely be independent for everyone , But this will help you to get started or atleast will give you some insights on where to start with.</p><p>Here we are going to use a Java Springboot app which is in Elastic Beanstalk and to be migrated to AWS EKS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*e7VG8vwlJaKGlKlX1rNSug.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*Ge-akz7JTCiuFtcA6_Ll9Q.png" /><figcaption>Copyrights to AWS</figcaption></figure><p><strong>Pre-requisities:</strong></p><ol><li>An EKS Cluster</li><li>Docker Image of the application</li><li>Helm Installed</li><li>Argocd setup or any CI/CD deployment mechanisms</li></ol><p>Lets take a java spring boot app along with external services like AWS RDS, Secrets Manager, EFS, ECR etc.</p><p>Lets start with the Application first.</p><p>Assuming you application is dockerized . If not , you may need to dockerize your application with the developer’s help. If you already have a Docker compose file, you can use a tool like <a href="https://kompose.io/"><strong>Kompose</strong></a><strong> </strong>to convert your Json to Kubernetes manifest or better to convert it as an Helm chart Deployment.</p><p>In this blog , we are going to make use of Helm along with the Docker image to deploy the application using Argocd.</p><p>I hope you already have a way to deploy your cluster and other applications to that cluster through a CI/CD Mechanism. In this case lets use the Argocd approach.</p><p><strong>EKS Cluster :</strong></p><p>I am assuming, you already have a way to Create and Deploy the cluster and its applications . If not , I would ask you create your cluster through terraform or any other mechanism which is feasible for you. Ensure that the connectivity is properly established to access the services like S3, ECR, RDS etc.</p><p><strong>Docker Image:</strong></p><p>Ensure that the Cluster has the necessary Connectivity along with the Role/Policy and secrets/Service Account in place to access the image from the external repository like Docker Hub or ECR repository. In my case, I have the app image ready in my ECR repo and i made sure that i am able to pull the image from the cluster.</p><p><strong>Helm:</strong></p><p>Now that you have the cluster and App Image in place , We can start writing the helm charts . I would always suggest you to go with the Helm Create command and keep things as much as possible in the values file itself.</p><pre>Helm create arun-java-springboot</pre><p>This creates a directory along with the helm templates to deploy an application to the cluster. All we need to do is to ensure that we have the proper values in place and additional manifests that are required for the app to work.</p><pre>arunkumar@Aruns-MacBook-Air arun-java-springboot % ls -al<br>total 24<br>drwxr-xr-x   7 arunkumar  staff   224 Feb 26 17:34 .<br>drwxr-xr-x   3 arunkumar  staff    96 Feb 26 17:34 ..<br>-rw-r--r--   1 arunkumar  staff   349 Feb 26 17:34 .helmignore<br>-rw-r--r--   1 arunkumar  staff  1156 Feb 26 17:34 Chart.yaml<br>drwxr-xr-x   2 arunkumar  staff    64 Feb 26 17:34 charts<br>drwxr-xr-x  10 arunkumar  staff   320 Feb 26 17:34 templates<br>-rw-r--r--   1 arunkumar  staff  1887 Feb 26 17:34 values.yaml</pre><p><strong>Chart.yaml :</strong></p><p>Please make sure that you are putting the right version of your application in <strong>Version</strong> and the right docker image version in <strong>Appversion</strong>.</p><pre>apiVersion: v2<br>name: arun-java-springboot<br>description: A Helm chart for Kubernetes<br><br># A chart can be either an &#39;application&#39; or a &#39;library&#39; chart.<br>#<br># Application charts are a collection of templates that can be packaged into versioned archives<br># to be deployed.<br>#<br># Library charts provide useful utilities or functions for the chart developer. They&#39;re included as<br># a dependency of application charts to inject those utilities and functions into the rendering<br># pipeline. Library charts do not define any templates and therefore cannot be deployed.<br>type: application<br><br># This is the chart version. This version number should be incremented each time you make changes<br># to the chart and its templates, including the app version.<br># Versions are expected to follow Semantic Versioning (https://semver.org/)<br>version: 0.1.0<br><br># This is the version number of the application being deployed. This version number should be<br># incremented each time you make changes to the application. Versions are not expected to<br># follow Semantic Versioning. They should reflect the version the application is using.<br># It is recommended to use it with quotes.<br>appVersion: &quot;1.16.0&quot;</pre><p><strong>Values.yaml :</strong></p><p>This is the one to play with as you integrate a lot of configurations in here. You will have to add all the values , secrets, ingress etc. A sample configuration looks like :</p><pre># Default values for arun-java-springboot.<br># This is a YAML-formatted file.<br># Declare variables to be passed into your templates.<br><br>replicaCount: 1<br><br>image:<br>  repository: jdk-image<br>  pullPolicy: IfNotPresent<br>  # Overrides the image tag whose default is the chart appVersion.<br>  tag: &quot;&quot;<br><br>imagePullSecrets: []<br>nameOverride: &quot;&quot;<br>fullnameOverride: &quot;&quot;<br><br>serviceAccount:<br>  # Specifies whether a service account should be created<br>  create: true<br>  # Annotations to add to the service account<br>  annotations: {}<br>  # The name of the service account to use.<br>  # If not set and create is true, a name is generated using the fullname template<br>  name: &quot;springboot-sa&quot;<br><br>podAnnotations: {}<br><br>podSecurityContext: {}<br>  # fsGroup: 2000<br><br>securityContext: {}<br>  # capabilities:<br>  #   drop:<br>  #   - ALL<br>  # readOnlyRootFilesystem: true<br>  # runAsNonRoot: true<br>  # runAsUser: 1000<br><br>service:<br>  type: ClusterIP<br>  port: 80<br><br>ingress:<br>  enabled: false<br>  className: &quot;&quot;<br>  annotations: {}<br><br>  hosts:<br>    - host: arun-java-springboot.svc.ns.local<br>      paths:<br>        - path: /<br>          pathType: Prefix<br>  tls: []<br><br><br>resources: {}<br>  # We usually recommend not to specify default resources and to leave this as a conscious<br>  # choice for the user. This also increases chances charts run on environments with little<br>  # resources, such as Minikube. If you do want to specify resources, uncomment the following<br>  # lines, adjust them as necessary, and remove the curly braces after &#39;resources:&#39;.<br>  limits:<br>    cpu: 100m<br>    memory: 128Mi<br>  requests:<br>      cpu: 100m<br>      memory: 128Mi<br><br>autoscaling:<br>  enabled: true<br>  minReplicas: 1<br>  maxReplicas: 100<br>  targetCPUUtilizationPercentage: 80<br>  targetMemoryUtilizationPercentage: 80<br><br>nodeSelector: {}<br><br>tolerations: []<br><br>affinity: {}<br><br>configs:<br>  serviceProperties: &quot;config/DEV/app/configmap.yaml&quot;<br><br><br>externalSecrets:<br>  enabled: true<br>  awsRegion: eu-central-1<br>  serviceAccount: app-sa<br>  secrets:<br>    - externalSecretName: app-token<br>      secretRefreshInterval: 1h<br>      awsSecretsManagerSecretName: aws-shared/app-token<br>      targetSecretName: app-token<br>      secretData:<br>        - remoteSecretKey: app-token<br>          targetSecretKey: app-token<br><br>secretEnv:<br>  - name: &quot;app-token&quot;<br>    valueFrom: <br>      secretKeyRef:<br>        name: app-token<br>        key: app-token</pre><p>Here to keep the secrets, I have used AWS secrets Manager and integrated it with EKS via external secrets controller and a SecretStore and connectivity through a service account. Ensure, that you have already Added the secrets to the AWS secrets manager and then the Above in your values.yaml and creates the below files under the templates directory to pickup and create the secrets.</p><p><strong>Config Map:</strong></p><p>You can use the config-map to add all the application properties as env. create a file : “config/DEV/app/configmap.yaml” (as specified in the values file) and add your app envs.</p><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: app-configmap<br>  namespace: app<br>data:<br>  management_endpoints_web_exposure_include: &quot;info, health&quot;<br>  management_endpoints_web_basePath: &quot;/&quot;<br>  management_info_env_enabled: &quot;true&quot;<br>  cloud_aws_region_static: &quot;eu-central-1&quot;</pre><p><strong>Additional Manifests :</strong></p><p>Note&gt; All the below files are to be added under the templates directory and values of this will be taken from the values.yaml.</p><p><strong>External Secrets :</strong></p><pre>{{- if .Values.externalSecrets.enabled }}<br>{{- $fullName := include &quot;arun-java-springboot.fullname&quot; . -}}<br>{{- $labels := include &quot;arun-java-springboot.labels&quot; . -}}<br>{{- range $externalSecrets := .Values.externalSecrets.secrets -}}<br>---<br>apiVersion: external-secrets.io/v1beta1<br>kind: ExternalSecret<br>metadata:<br>  name: {{ $fullName }}-externalsecret-{{ $externalSecrets.externalSecretName }}<br>  labels: <br>    {{ $labels | nindent 4 }}<br>spec:<br>  refreshInterval: {{ $externalSecrets.secretRefreshInterval }}<br>  secretStoreRef:<br>    name: {{ $fullName }}-secretstore<br>    kind: SecretStore<br>  target:<br>    name: {{ $externalSecrets.targetSecretName }}<br>  data:<br>  {{- range $externalSecrets.secretData }}<br>  - secretKey: {{ .targetSecretKey }}<br>    remoteRef:<br>      key: {{ $externalSecrets.awsSecretsManagerSecretName }}<br>      property: {{ .remoteSecretKey }}<br>  {{- end }}    <br><br>{{ end }}<br>{{- end }}</pre><p><strong>secret store :</strong></p><pre>{{- if .Values.externalSecrets.enabled }}<br>apiVersion: external-secrets.io/v1beta1<br>kind: SecretStore<br>metadata:<br>  name: {{ include &quot;arun-java-springboot.fullname&quot; . }}-secretstore<br>  labels: <br>    {{- include &quot;arun-java-springboot.labels&quot; . | nindent 4 }}<br>spec:<br>  provider:<br>    aws:<br>      service: SecretsManager<br>      region: {{ .Values.externalSecrets.awsRegion }}<br>      auth:<br>        jwt:<br>          serviceAccountRef:<br>            name: {{ .Values.externalSecrets.serviceAccount }}<br>{{- end }}</pre><p><strong>Configmap:</strong></p><pre>{{- $root := . }}<br>  {{- range $path, $bytes := .Files.Glob .Values.configs.serviceProperties -}}<br>---<br>{{ $root.Files.Get $path }}<br>  {{- end -}}</pre><p><strong>Deployment.yaml</strong></p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: {{ include &quot;arun-java-springboot.fullname&quot; . }}<br>  labels:<br>    {{- include &quot;arun-java-springboot.labels&quot; . | nindent 4 }}<br>spec:<br>  {{- if not .Values.autoscaling.enabled }}<br>  replicas: {{ .Values.replicaCount }}<br>  {{- end }}<br>  selector:<br>    matchLabels:<br>      {{- include &quot;arun-java-springboot.selectorLabels&quot; . | nindent 6 }}<br>  template:<br>    metadata:<br>      {{- with .Values.podAnnotations }}<br>      annotations:<br>        {{- toYaml . | nindent 8 }}<br>      {{- end }}<br>      labels:<br>        {{- include &quot;arun-java-springboot.selectorLabels&quot; . | nindent 8 }}<br>    spec:<br>      {{- with .Values.imagePullSecrets }}<br>      imagePullSecrets:<br>        {{- toYaml . | nindent 8 }}<br>      {{- end }}<br>      serviceAccountName: {{ include &quot;arun-java-springboot.serviceAccountName&quot; . }}<br>      securityContext:<br>        {{- toYaml .Values.podSecurityContext | nindent 8 }}<br>      containers:<br>        - name: {{ .Chart.Name }}<br>          envFrom:<br>          - configMapRef:<br>              name: app-configmap<br>          env:<br>          {{- with .Values.secretEnv }}<br>          {{- toYaml . | nindent 12 }}<br>          {{- end }}  <br>          securityContext:<br>            {{- toYaml .Values.securityContext | nindent 12 }}<br>          image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;<br>          imagePullPolicy: {{ .Values.image.pullPolicy }}<br>          ports:<br>            - name: app-port<br>              containerPort: 8080<br>              protocol: TCP<br>          startupProbe:<br>            httpGet:<br>              path: /health<br>              port: app-port<br>            failureThreshold: 3<br>            initialDelaySeconds: 120<br>            periodSeconds: 30<br>            successThreshold: 1<br>            timeoutSeconds: 20<br>          livenessProbe:<br>            httpGet:<br>              path: /health<br>              port: app-port<br>            initialDelaySeconds: 120<br>            periodSeconds: 30<br>            timeoutSeconds: 20<br>          readinessProbe:<br>            httpGet:<br>              path: /health<br>              port: app-port<br>            initialDelaySeconds: 120<br>            periodSeconds: 30<br>            timeoutSeconds: 20<br>          resources:<br>            {{- toYaml .Values.resources | nindent 12 }}<br>      {{- with .Values.nodeSelector }}<br>      nodeSelector:<br>        {{- toYaml . | nindent 8 }}<br>      {{- end }}<br>      {{- with .Values.affinity }}<br>      affinity:<br>        {{- toYaml . | nindent 8 }}<br>      {{- end }}<br>      {{- with .Values.tolerations }}<br>      tolerations:<br>        {{- toYaml . | nindent 8 }}<br>      {{- end }}</pre><p>If you have already worked with Helm to deploy your applications, then it would be easy for you and all you need to do is to update the values file and also add all the necessary additional manifests for secrets , configmap etc under templates directory.</p><p>Now that, We have the helm chart ready to deploy an application, lets first ensure that we have all the application related components in place.</p><p>Ensure that cluster is able to reach to your DB, AWS secrets, SNS, SQS etc..Make sure that the connectivity is established and ensure that you have all the necessary roles mapped to service account in order to access it from the cluster.</p><p>Now that we have all in place, I am gonna use the argocd for app deployment to the cluster. I am not gonna spend time to explain about argocd setup. I am assuming its in place already.</p><p>Now push all the changes to the github and merge to master. Ensure, That you have your argocd app.yaml file with the right github source of the app and Deploy it…</p><p>Sample ArgoCD app.yaml :</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Application<br>metadata:<br>  name: &#39;arun-java-springboot&#39;<br>  namespace: argocd<br>  finalizers:<br>    - resources-finalizer.argocd.argoproj.io<br>spec:<br>  destination:<br>    namespace: &#39;app&#39;<br>    server: &#39;https://kubernetes.default.svc&#39;<br>  source:<br>    path: &#39;helm/INT&#39;<br>    repoURL: &#39;https://github.com/arun12cool/arun-java-springboot.git&#39;<br>    targetRevision: master<br>    helm:<br>      valueFiles:<br>        - &quot;values.yaml&quot;<br>      values: |<br>        resources:<br>          limits:<br>            cpu: &quot;300m&quot;<br>            memory: &quot;512Mi&quot;<br>          requests:<br>            cpu: &quot;250m&quot;<br>            memory: &quot;450Mi&quot;<br>      parameters:<br>        - name: nameOverride<br>  project: app<br>  syncPolicy:<br>    syncOptions:<br>      - ApplyOutOfSyncOnly=true<br>    automated:<br>      prune: true<br>      selfHeal: false</pre><p>YaYYYYY!!!! the app is Deployed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95619e7259ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Crossplane]]></title>
            <link>https://iamarunkrish.medium.com/getting-started-with-crossplane-b3c2bd7a61d5?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3c2bd7a61d5</guid>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[crossplane]]></category>
            <category><![CDATA[terraform-provider]]></category>
            <category><![CDATA[argo-cd]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Thu, 03 Mar 2022 16:59:12 GMT</pubDate>
            <atom:updated>2022-03-11T04:47:00.637Z</atom:updated>
            <content:encoded><![CDATA[<p>As you all know that <strong>Crossplane</strong> is a buzzing word in the market now. In this <strong>GitOps</strong> era, companies are trying to evolve and trying to follow the best practices available in the market instead of writing loads of templates, maintaining and manage those resources. <strong>Crossplane</strong> is here to help you in managing or allowing a developer to create,modify,update,delete resources from the cluster itself. This helps you create cloud resources in a cloud native way like how you deploy apps in realtime. Lets say, you are deploying an application in your cluster and you would like to create an s3 bucket resources in AWS from that cluster itself to store the data, all you have to do write a Crossplane manifest (MR) to create the s3 resource as a part of the app deployment process. Woo… this might look overwhelming now but not to worry at the end of this blog you will see how useful this can be.</p><p><strong>What are we going to see in this Blog ?</strong></p><blockquote><strong><em>Picture speaks a thousand words</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wFPoX_ekuQFE3Jo9PqFh1w.png" /></figure><p><strong>Intent of this Blog :</strong></p><p>Eventhough , you can create AWS or any cloud resources via Crossplane cloud API’s itself from the Cluster. I additionally wanted to show you that if you already have the terraform templates for all your resources in place, we can basically leverage those modules into crossplane and get the resources created through the GitOps Model like the workflow above.</p><p><strong>What is the Endgame here? :</strong></p><p>We are gonna see how can we start afresh with Crossplane and how to achieve the workflow above to create an S3 bucket in the AWS with the <strong>Gitops</strong> Model.</p><p><strong>NOTE : Kindly note that the S3 bucket can directly be created via crossplane AWS API itself.</strong></p><p><a href="https://doc.crds.dev/github.com/crossplane/provider-aws/s3.aws.crossplane.io/Bucket/v1beta1@v0.24.1">Bucket.s3.aws.crossplane.io/v1beta1</a></p><p><strong>However, I have used it as a common resource to demonstrate how all it can be created using Crossplane with </strong><a href="https://doc.crds.dev/github.com/crossplane/provider-aws"><strong>AWS</strong></a><strong> and </strong><a href="https://github.com/crossplane-contrib/provider-terraform"><strong>Terraform Provider</strong></a><strong>, so that if you already have a terraform template, then you leverage that as well and inject those in the crossplane manifest.</strong></p><p>Crossplane supports around 124 AWS resources currently as on 9th March 2022. <br>Ref : <a href="https://doc.crds.dev/github.com/crossplane/provider-aws">https://doc.crds.dev/github.com/crossplane/provider-aws</a></p><p>Ref : <a href="https://github.com/crossplane-contrib/provider-terraform">https://github.com/crossplane-contrib/provider-terraform</a>,</p><p><strong>Crossplane VS Terraform :</strong></p><p><strong>Crossplane</strong> is often compared to <strong>HashiCorp’s Terraform</strong>. You can get the Key Difference Between <strong>Crossplane and Terraform</strong> via : <a href="https://blog.crossplane.io/crossplane-vs-terraform"><strong>https://blog.crossplane.io/crossplane-vs-terraform</strong></a> which will help you to understand the difference between Why Crossplane and Why not Terraform .Instead of re-iterating the same definition here, I would recommend you to go through this blog before you move on further to understand the difference and how we can leverage Crossplane for resource creation and to manage the resources within the Cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8jhmTqn9FGm7vFyZywWmA.png" /><figcaption>Image Credits: <a href="https://crossplane.github.io/">Crossplane</a></figcaption></figure><p><strong>What is Crossplane ?</strong></p><p>Crossplane is an open source Kubernetes add-on that transforms your cluster into a <strong>universal control plane</strong>. Crossplane enables platform teams to assemble infrastructure from multiple vendors, and expose higher level self-service APIs for application teams to consume, without having to write any code.</p><p><em>Crossplane extends your Kubernetes cluster to support orchestrating any infrastructure or managed service</em>. Compose Crossplane’s granular resources into higher level abstractions that can be versioned, managed, deployed and consumed using your favorite tools and existing processes.</p><p><strong>How do you restrict access to Crossplane actions ?</strong></p><p>In Crossplane, every piece of infrastructure is an API endpoint that supports <strong>create, read, update, and delete operations</strong>.</p><p><strong>Note :</strong> Good thing to note here is you can restrict certain actions to the developer and allow him to create or claim the resources from the Cluster itself using <strong>Role Based Access Control(RBAC). </strong>This is an added advantage.</p><p><strong>What are Crossplane Terms/Objects ?</strong></p><p><strong>XRD — Composite Resource Definition :</strong></p><p>This is a Cluster Scoped CRD. This follows <strong>openapiV3</strong> schema and to be used to define the inputs that is to be read by composition.</p><p><strong>Composition</strong> :</p><p>A Composition lets Crossplane know what to do when someone creates a Composite Resource. This is where integration logic and credentials injection logic is defined.</p><p>For this blog, We are using Crossplane “<strong>terraform-provider</strong>” in the backend to execute terraform templates to create an S3 resource.</p><p><strong>XRC (Claim)</strong> — <strong>Composite Resource Claim :</strong></p><p>Crossplane uses Composite Resource Claims (or just claims, for short) to allow application operators to provision and manage XR.</p><p><strong>Terraform Analogy of Crossplane Terms:</strong></p><p><strong>XRD</strong> as Terraform <strong>variable</strong> blocks of a Terraform module,</p><p><strong>Composition</strong> is the rest of the <strong>module’s HCL code(main.tf)</strong> that describes how to use those variables to create a bunch of resources.</p><p><strong>XRC</strong> or claim is a little like a <strong>tfvars or locals.tf </strong>file providing inputs to the module.</p><p>The primary focus of this blog is to help you to get started with writing the manifest to build your infrastructure.<strong> </strong>Instead of boring you with the definitions and comparisons, Lets Get to the Main Event :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*ExL2kI8K7XhEWVpxvXpqkQ.jpeg" /></figure><p><strong>Prerequisites</strong> :</p><ol><li>The base EKS Cluster from which you are going to create resources using crossplane should be created along with VPC,SG etc. If you have the VPC and SG in place, you can use this to create a cluster using the EKSCTL Command or through the console itself: <a href="https://eksctl.io/usage/creating-and-managing-clusters/">https://eksctl.io/usage/creating-and-managing-clusters/</a></li><li>Kubectl installed.</li></ol><p><strong>How do i install Crossplane in my EKS Cluster?</strong></p><p>Assuming that you have your VPC, SG and EKS cluster created already. Kindly follow the steps below to install the Crossplane using HELM Charts in your EKS cluster.</p><pre><strong>#Create the namespace and install the components using helm<br></strong>kubectl create namespace crossplane-system<br><br>helm repo add crossplane-stable https://charts.crossplane.io/stable<br>helm repo update<br><br>helm install crossplane --namespace crossplane-system crossplane-stable/crossplane</pre><p><strong>What are all are required to Create a AWS resource using Crossplane ?</strong></p><ol><li><em>Provider Manifest(</em><a href="https://doc.crds.dev/github.com/crossplane/provider-aws"><em>AWS</em></a><em>, </em><a href="https://github.com/crossplane-contrib/provider-terraform"><em>Terraform</em></a><em> etc)</em></li><li><em>Secrets Manifest(AWS creds and github keys)</em></li><li><em>ProviderConfig Manifest(Injecting AWS and Github secrets for crossplane to create resource)</em></li><li><em>Resource Manifest (Template for creating a specific resource)</em></li></ol><p>Now , There are few possibilities/ways with Crossplane to achieve the endgame which is creating an S3 bucket from your EKS Cluster in AWS environment.</p><p><strong>1.0 Using a Simple Crossplane Manifest .</strong></p><p><a href="https://github.com/arun12cool/tf/tree/main/crossplane-default/">tf/crossplane-default at main · arun12cool/tf</a></p><p><strong>2.0 By Injecting Existing Terraform S3 module to Crossplane Manifest.</strong></p><p><a href="https://github.com/arun12cool/tf/tree/main/crossplane-terraform">tf/crossplane-terraform at main · arun12cool/tf</a></p><p><strong>3.0</strong> <strong>Using a Custom Resource Definition as per our needs , basically like a module for different teams which can be claimed through an XRC(Claim).</strong></p><p><a href="https://github.com/arun12cool/tf/tree/main/crossplane-Composition">tf/crossplane-Composition at main · arun12cool/tf</a></p><p>Now that we have seen the ways to achieve our goal, we can go through one by one.</p><p><strong><em>NOTE : You can make use of the following command to describe or to get the events of the resources that you are going to create hence forth.</em></strong></p><pre>Kubectl Describe &lt;objectname&gt; &lt;name-of-the-resource&gt;</pre><p><strong>1.0. What are all are required to Create a AWS resource using simple/direct crossplane manifest?</strong></p><ul><li><strong>AWS Provider</strong> <strong>Manifest</strong>: This will Install all the CRD’s ( Custom Resources Definitions ) required to create resources on the cloud. Ex: rdsinstances.database.aws.crossplane.io,ec2.aws.crossplane.io/v1alpha1<strong>,</strong> etc. <br>You will have to run the following AWS manifest alone to install AWS and Terraform Modules:</li></ul><p>Run the “<strong>Kubectl apply -f aws-terraform-provider.yaml”</strong></p><p><a href="https://github.com/arun12cool/tf/blob/main/aws-terraform-provider.yaml">tf/aws-terraform-provider.yaml at main · arun12cool/tf</a></p><ul><li><strong>Secrets</strong> : We should create a secret for the AWS creds and all the required credentials like Github etc through a manifest.</li></ul><p><strong>For #AWS and GIT Secrets:</strong></p><pre><strong>###Generate the configuration files with the AWS Credentials.</strong> AWS_PROFILE=default &amp;&amp; echo -e &quot;[default]\naws_access_key_id = $<strong>(</strong>aws configure get aws_access_key_id --profile $AWS_PROFILE<strong>)</strong>\naws_secret_access_key <strong>=</strong> $(aws configure get aws_secret_access_key --profile $AWS_PROFILE)&quot; &gt; aws-creds.ini</pre><pre><strong>###Create a Kubernetes secret with the configuration file generated. </strong>kubectl create secret generic aws-secret-creds -n crossplane-system --from-file=creds=./aws-creds.ini</pre><pre><strong>Or </strong></pre><pre>Use the manifest for creating the secret : Run the <strong>Kubectl apply -f secret.yaml</strong></pre><pre>```<br>---<br>apiVersion: v1</pre><pre>kind: Secret</pre><pre>metadata:</pre><pre>name: aws-creds</pre><pre>namespace: opm-pi</pre><pre>type: Opaque</pre><pre>stringData:</pre><pre>credentials: |</pre><pre>[default]</pre><pre>aws_access_key_id = &lt;access_key&gt;</pre><pre>aws_secret_access_key = &lt;secret_key&gt;</pre><pre>---<br>apiVersion: v1</pre><pre>kind: Secret</pre><pre>metadata:</pre><pre>name: git-credentials</pre><pre>namespace: opm-pi</pre><pre>type: Opaque</pre><pre>stringData:</pre><pre>creds: |</pre><pre>https://&lt;username&gt;:&lt;password&gt;@github.com</pre><pre>```</pre><ul><li><strong>ProviderConfig Manifest: </strong>This will inject secret required for the Crossplane to create resources in the Cloud.</li></ul><pre><strong>###Once the secret is created let us now create the Provider config.</strong></pre><pre>kubectl apply -f <a href="https://github.com/arun12cool/tf/blob/main/providerconfig.yaml">providerconfig.yaml</a></pre><p><a href="https://github.com/arun12cool/tf/blob/main/providerconfig.yaml">tf/providerconfig.yaml at main · arun12cool/tf</a></p><ul><li><strong>Resource Manifest</strong> : For creating the S3 resource in the Cloud using Crossplane.</li></ul><p><a href="https://github.com/arun12cool/tf/blob/main/crossplane-default/s3.yaml">tf/s3.yaml at main · arun12cool/tf</a></p><p>Run the</p><p>```</p><p><strong>Kubectl apply -f s3.yaml</strong></p><p><strong>```</strong></p><p>Tada ………You should be able to see the S3 bucket in the AWS Console now which is created via Crossplane from your EKS cluster.</p><p><strong>2.0. By Injecting Existing Terraform S3 module to Crossplane Manifest.</strong></p><p>There are two ways to do this :<br>1. By Injecting the Terraform s3 resource module as an <strong>Inline</strong> to the Crossplane Manifest.</p><p>2. By Injecting the Terraform s3 resource module which is in a Github repo as a <strong>Remote Source</strong> to the Crossplane Manifest.</p><ul><li><strong>By Injecting the Terraform s3 resource module as an Inline to the Crossplane Manifest.</strong></li></ul><p>As we have already installed the Required components like <strong>AWS &amp; Terraform Provider, Secrets and ProviderConfig</strong> in the previous steps. We can now directly run the Inline template using “<strong>Kubectl apply -f inline.yaml”</strong> Command.</p><p><a href="https://github.com/arun12cool/tf/blob/main/crossplane-terraform/inline.yaml">tf/inline.yaml at main · arun12cool/tf</a></p><p>Now you should see the resources in the Console.</p><p><strong>Note : I</strong>n the Above manifest, you could see two things :</p><p><strong>*. writeConnectionSecretToRef</strong> : Some Crossplane resources support writing connection details — things like URLs, usernames, endpoints, and passwords to a Kubernetes Secret. You can specify the secret to write by setting the spec.writeConnectionSecretToRef field. Note that while all managed resources have a writeConnectionSecretToRef field, not all managed resources actually have connection details to write — many will write an empty Secret. Which managed resources have connection details and what connection details they have is currently undocumented.</p><p><strong>*. providerConfigRef</strong> : This name should match the name given in the <em>ProviderConfig.yaml.</em></p><p><strong>2. By Injecting the Terraform s3 resource module which is in a Github repo as a Remote Source to the Crossplane Manifest.</strong></p><p>As we have already installed the Required components like <strong>AWS &amp; Terraform Provider, Secrets and ProviderConfig</strong> in the previous steps.</p><p><strong><em>Note : We should have the terraform s3 module under the /tf directory and a main.tf inside that /tf directory for the crossplane to pick up the modules. The folder name /tf should not be changed but can have a directory before that.</em></strong></p><p>Once the modules are created under /tf directory , you can push it to the github repo , we can source the same as per the file below to run the Remote template using “<strong>Kubectl apply -f remote.yaml”</strong> Command. Make sure the /tf path is mentioned in the source for crossplane to pick it up.</p><p><a href="https://github.com/arun12cool/tf/blob/main/crossplane-terraform/remote.yaml">tf/remote.yaml at main · arun12cool/tf</a></p><p>Now you should see the resources in the Console.</p><p>I guess by now should have got the idea on how to create resource using default crossplane manifest and using the remote TF github module repository.</p><p>Now there is one last way to write a module using Compostion , Definition and Claim.</p><p><strong>3.0</strong> <strong>Using a Custom Resource Definition as per our needs , basically like a module for different teams which can be claimed through an XRC(Claim).</strong></p><p>This is a challenging one to understand in the first go but you can do it .</p><p><strong>Repo</strong> :</p><p><a href="https://github.com/arun12cool/tf/tree/main/crossplane-Composition">tf/crossplane-Composition at main · arun12cool/tf</a></p><p>I hope you recall the crossplane terms/object which we discussed initially. We are gonna use that now.</p><p>This will be useful, if you the devops/SRE team needs to handle the creation of resources instead of the developer themselves.</p><p>We can basically create a definition-XRD, a custom resource definition and share it to customer/developer to Claim the resource . We can showcase the definition with them asking them to provide the set of required input values to the variables mentioned in the definition by using a XRC- Claim and get those resources created.</p><p>We can create resources the inline way and also using the remote way through github repos.</p><p>For inline, you can refer this :</p><p><a href="https://crossplane.io/docs/v1.6/concepts/composition.html">https://crossplane.io/docs/v1.6/concepts/composition.html</a></p><p>Now, we shall go with Remote github repos which has the terraform templates in place under<strong> /tf </strong>:</p><p>In the <strong>Definition.yaml</strong> :</p><p><a href="https://github.com/arun12cool/tf/blob/main/crossplane-Composition/definition.yaml">tf/definition.yaml at main · arun12cool/tf</a></p><p>You basically have to write a schema/definition of what is expected by the composition to create the resource. Basically the required variables for the terraform module which create S3 resource in the above mentioned format.</p><p>Once that is done, you can create a <strong>Composition.yaml</strong> file which basically has the info on how to incorporate those variables in the definition files to create the resource when it is claimed by the developer. It uses something called <strong>Patches </strong>to patch the variables from the claim to the composition.</p><p>In the <strong>Composition.yaml</strong> :</p><p><a href="https://github.com/arun12cool/tf/blob/main/crossplane-Composition/composition.tf">tf/composition.tf at main · arun12cool/tf</a></p><p><strong>Note :</strong></p><p><strong>Labels and compositeTypeRef </strong>Parameters in the composition file should match the definition.yaml files name and kind parameters and that is how it will be referenced while creating a particular resource using this method.</p><p>Lables format must in plurals + group name as in the definition.yaml file and for compositeTypeRef the kind and apiversion(groupname+version name) parameter should match as in the definition file<strong>.</strong></p><p>Now that we have the Definition.yaml and composition.yaml ready, we can apply the same using</p><pre>Kubectl apply -f &lt;filename&gt; command.</pre><p>Once these are created, you can use the claim.yaml to with the required input variables and values as required by the definition to claim the resource, by claiming means creating those resource based on your claim values.</p><p><a href="https://github.com/arun12cool/tf/blob/main/crossplane-Composition/claim.yaml">tf/claim.yaml at main · arun12cool/tf</a></p><p>Once you have claimed it, you can check the Terraform workspace using the command to check if the resource have been created successfully.</p><pre>Kubectl get workspace &lt;workspace name&gt; -n namespace-name</pre><p>Tada ………Now you should your buckets in the S3 console in AWS.</p><p><strong>Finally integrating this with ArgoCD :</strong></p><p>Install the Argocd plugin your EKS cluster by following the steps below :</p><p><a href="https://www.arthurkoziel.com/setting-up-argocd-with-helm/">Setting up Argo CD with Helm</a></p><p><strong>Accessing the Web UI<br></strong>The Helm chart doesn’t install an Ingress by default, so to access the Argo CD Web UI we have to port-forward to the service:</p><pre>kubectl port-forward svc/argo-cd-argocd-server 8080:443</pre><pre>We can then visit <a href="http://localhost:8080/">http://localhost:8080</a> to access it.</pre><p>If you don’t want to have localhost, then expose that argocd pod using the following command :</p><p>kubectl expose pod argocd-server --type=LoadBalancer --name=argocd-test</p><p>This will create a ELB and you can access the LB URL to go the argocd UI.</p><p><strong>The default username is “admin”. The password is auto-generated and defaults to the pod name of the Argo CD server pod</strong>. We can get it with:</p><pre>kubectl get pods -l app.kubernetes.io/name=argocd-server -o name | cut -d’/’ -f 2</pre><p>Once you have accessed it, You can create a new app in the UI and add the URL and Path as per the manifest below.</p><p>OR</p><p>You can apply the following manifest to run the <strong>Inline and Remote Crossplane manifest to create an S3 Bucket.</strong></p><pre><a href="https://github.com/arun12cool/tf/blob/main/crossplane-argocd/argo.yaml">https://github.com/arun12cool/tf/blob/main/crossplane-argocd/argo.yaml</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4Cowb-C5uqa3thspl8z-A.png" /><figcaption>Argocd-UI</figcaption></figure><p>You should see the above in the Argocd UI and this shows that the resources has been created, you can check the same in the S3 dashboard in the AWS Console.</p><p>Now you can change the name of the bucket in the <a href="https://github.com/arun12cool/tf/blob/main/crossplane-terraform/inline.yaml">https://github.com/arun12cool/tf/blob/main/crossplane-terraform/inline.yaml</a> repo and then wait for few seconds or hit refresh to check the update bucket.</p><p>You can also manage Argocd as an App so that it auto-upgrades the argocd app automatically, instead of you manually managing Argocd : <a href="https://github.com/arun12cool/tf/blob/main/crossplane-argocd/argocd-app.yaml">https://github.com/arun12cool/tf/blob/main/crossplane-argocd/argocd-app.yaml</a></p><p>Haa…That was a lengthy blog… But i am hopeful that its worth and you can have an understanding of Crossplane and hope this helps you to get started with it.</p><p>I have not mentioned the issues and errors that i had faced as this is already a big read. However, you can always reach out to me via <a href="https://www.linkedin.com/in/arunkrish29/">Linkedin</a> or via a chat and i will be happy to help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3c2bd7a61d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integration Testing using Terraform Test]]></title>
            <link>https://iamarunkrish.medium.com/integration-testing-using-terraform-test-6af26b03767a?source=rss-fe5bda89d1e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6af26b03767a</guid>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[testing-framework]]></category>
            <dc:creator><![CDATA[Arunkumar Krishnakumar]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 13:46:05 GMT</pubDate>
            <atom:updated>2022-03-23T09:06:32.084Z</atom:updated>
            <content:encoded><![CDATA[<p>Everyone have been asking if we can write test cases to verify if the resources created using terraform templates can be tested to confirm if we are getting the desired output before even deploying it in production.</p><p>I say, <strong>Yes :) You are into the right page.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Y-rEql0QPl20XnRdKZ6D4A.jpeg" /></figure><p>Trust me, its hard to get answers for this in Google !!! :)</p><p><strong>PRE-REQUISITES :</strong></p><pre>1) Terraform CLI v0.15.0<br>2) Docker Desktop<br>3) Kubectl<br>4) Helm<br>5) A Kubernetes Cluster</pre><p>Current extension to Terraform for this experimental feature consists of the following parts:</p><ol><li>Temporary experimental provider “<strong>terraform.io/builtin/test”</strong></li><li>A new “<strong>terraform test”</strong> command for more conveniently running multiple tests in a single action.</li><li>An experimental convention of placing test configurations in <strong>subfolders of a tests directory within your module</strong>, which terraform test will then discover and run.</li></ol><h3>TESTS FOR A TERRAFORM MODULE:</h3><p>To get started create a subfolder called <strong>tests/</strong> in the same directory where you keep your module’s <strong>.tf and/or .tf.json </strong>source files. In that directory, make another directory which will serve as your first test suite, with a directory name that concisely describes what the suite is aiming to test.</p><pre>So an example of a typical directory structure with the addition of a test suite called defaults would look like:</pre><pre>Lets say, the following files are there under the directory &quot;Helm&quot; :</pre><pre>main.tf<br>outputs.tf<br>providers.tf<br>variables.tf<br>versions.tf<br>tests/<br>  defaults/<br>    test_helm.tf</pre><p>The <strong>tests/defaults/test_helm.tf</strong> file contains a call to the main module with a suitable set of arguments and also one or more resources that will serve as the temporary syntax for defining test assertions.</p><p><strong>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</strong></p><p><strong>Note :</strong> This whole testing plays with one rule :</p><p><strong>what you got? </strong>versus <strong>what you want ?</strong></p><p>You basically have to set the <strong>what you want ? </strong>as a variable or locals and <strong>what you got? </strong>should be taken from the terraform Output</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>Here are few sample tests which I had created for testing the feasibilities of :</p><pre><strong>Helm<br>Docker<br>AWS Resource S3 <br>EKS Namespace</strong></pre><p>As long you create resources using terraform , the testing framework will work as it all needs is an output.</p><p><strong>Refer the repo for more : </strong><a href="https://github.com/arun12cool/terraform-test/tree/main/terraform-integration-test"><strong>https://github.com/arun12cool/terraform-test/tree/main/terraform-integration-test</strong></a></p><p><strong>Example :<br>Helm Resource — Helm.tf :</strong></p><pre>provider &quot;helm&quot; {</pre><pre>kubernetes {</pre><pre>config_path = &quot;~/.kube/config&quot;</pre><pre>}</pre><pre>}</pre><pre><em>### First Chart #####</em></pre><pre>resource &quot;null_resource&quot; &quot;helm_test&quot; {</pre><pre>provisioner &quot;local-exec&quot; {</pre><pre>command = &lt;&lt;-EOT</pre><pre>helm repo add bitnami https://charts.bitnami.com/bitnami</pre><pre>EOT</pre><pre>}</pre><pre>}</pre><pre>resource &quot;helm_release&quot; &quot;example&quot; {</pre><pre>name  = &quot;redis&quot;</pre><pre>chart = &quot;https://charts.bitnami.com/bitnami/redis-10.7.16.tgz&quot;</pre><pre>depends_on = [null_resource.helm_test]</pre><pre>}</pre><pre>output &quot;chart1&quot; {</pre><pre>value = helm_release.example.chart</pre><pre>}</pre><pre>output &quot;chart_name1&quot; {</pre><pre>value = helm_release.example.name</pre><pre>}</pre><pre>output &quot;chart_status1&quot; {</pre><pre>value = helm_release.example.status</pre><pre>}</pre><p>Then, under tests/defaults/test_helm.tf :</p><pre>terraform {</pre><pre>required_providers {</pre><pre>test = {</pre><pre>source = &quot;terraform.io/builtin/test&quot;</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>variable &quot;test_region&quot; {</pre><pre>type    = string</pre><pre>default = &quot;us-west-2&quot;</pre><pre>}</pre><pre>provider &quot;aws&quot; {</pre><pre>region = var.test_region</pre><pre>}</pre><pre>provider &quot;kubernetes&quot; {</pre><pre>config_path = &quot;~/.kube/config&quot;</pre><pre>}</pre><pre>module &quot;helm&quot; {</pre><pre>source = &quot;../..&quot;</pre><pre>}</pre><pre>locals {</pre><pre>chart1 = &quot;https://charts.bitnami.com/bitnami/redis-10.7.16.tgz&quot;</pre><pre>chart_name1 = &quot;redis&quot;</pre><pre>chart_status1 = &quot;deployed&quot;</pre><pre>}</pre><pre><em>#### Chart 1 #####################</em></pre><pre>resource &quot;test_assertions&quot; &quot;helm1&quot; {</pre><pre>component = &quot;helm1&quot;</pre><pre>equal &quot;name&quot; {</pre><pre>description = &quot;Check chart name&quot;</pre><pre>got         = module.helm.chart1 # Takes terraform output</pre><pre>want        = local.chart1</pre><pre>}</pre><pre>check &quot;name_prefix&quot; {</pre><pre>description = &quot;Check for prefix&quot;</pre><pre>condition   = can(regex(&quot;^helm&quot;, module.helm.chart1))</pre><pre>}</pre><pre>}</pre><pre>resource &quot;test_assertions&quot; &quot;helm_name&quot; {</pre><pre>component = &quot;name&quot;</pre><pre>equal &quot;name&quot; {</pre><pre>description = &quot;Check name&quot;</pre><pre>got         = module.helm.chart_name</pre><pre>want        = local.chart_name</pre><pre>}</pre><pre>}</pre><pre>resource &quot;test_assertions&quot; &quot;helm_status&quot; {</pre><pre>component = &quot;status&quot;</pre><pre>equal &quot;status&quot; {</pre><pre>description = &quot;Check name&quot;</pre><pre>got         = module.helm.chart_status</pre><pre>want        = local.chart_status</pre><pre>}</pre><pre>}</pre><p>You can also create additional directories alongside the defaults/ directory to define additional test suites that pass different variable values into the main module, and then include assertions that verify that the result has changed in the expected way.</p><h3>FOR RUNNING YOUR TESTS :</h3><p>To check all our test suites we can just run terraform test and that would get us output of testing results (errors or success).</p><p>The current experimental command expects to be run from your main module directory and not the specific test suite directory containing test cases files</p><p>Because these test suites are integration tests rather than unit tests, you will need to set up any credentials files or environment variables needed by the providers your module uses before running terraform test. When run the test command will, for each suite:</p><ol><li>Install the providers and any external modules the test configuration depends on.</li><li>Create an execution plan to create the objects declared in the module.</li><li>Apply that execution plan to create the objects in the real remote system.</li><li>Collect all of the test results from the apply step, which would also have “created” the test_assertions resources.</li><li>Destroy all of the objects recorded in the temporary test state, as if running terraform destroy against the test configuration.</li></ol><p><strong>Output of Failed case :</strong></p><pre>$terraform test<br>╷<br>│ Warning: The &quot;terraform test&quot; command is experimental<br>│<br>│ We&#39;d like to invite adventurous module authors to write integration tests for their modules using this command, but all of the behaviors of this command are currently experimental and may change based on feedback.<br>│<br>│ For more information on the testing experiment, including ongoing research goals and avenues for feedback, see:<br>│     <a href="https://www.terraform.io/docs/language/modules/testing-experiment.html">https://www.terraform.io/docs/language/modules/testing-experiment.html</a><br>╵<br>─── Failed: defaults.name.name (Check name) ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<br>wrong value<br>    got:  &quot;arun-chart&quot;<br>    want: &quot;redis&quot;</pre><pre>─── Failed: defaults.helm1.name (Check my name) ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<br>wrong value<br>    got:  &quot;helm-demo-ms-app&quot;<br>    want: &quot;<a href="https://charts.bitnami.com/bitnami/redis-10.7.16.tgz">https://charts.bitnami.com/bitnami/redis-10.7.16.tgz</a>&quot;</pre><pre>─── Failed: defaults.helm1.name_prefix (Check for prefix) ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<br>condition failed<br>─────────────────────────────────</pre><p><strong>Output of Successful case :</strong></p><pre>$terraform test<br><br>│ Warning: The &quot;terraform test&quot; command is experimental<br>│<br>│ We&#39;d like to invite adventurous module authors to write integration tests for their modules using this command, but all of the behaviours of this command are currently experimental and may change based on feedback.<br>│<br>│ For more information on the testing experiment, including ongoing research goals and avenues for feedback, see:<br>│     https://www.terraform.io/docs/language/modules/testing-experiment.html<br>╵<br>╷<br>│ Warning: Backend configuration ignored<br><br>Success! All of the test assertions passed.</pre><p>Likewise , you can create an S3 resource, an EKS Namespace resource or a Docker resource and take the outputs of all those and compare it with the test assertions for the desired output.</p><p><strong>Known Limitations :</strong></p><ol><li>It supports TF version greater than 0.15.0.</li></ol><p>2. <strong>Unable to perform terraform destroy :</strong></p><p>If in case you are going to test it in a complex module, you may be getting an error stating that the destroy action has not happened properly. In that case, mostly it would have been destroyed and I would also recommend you to verify the resources in the real world infrastructure and to confirm if its not there to avoid incurring resource charges. You can also get into the tests directory and see if you are able to properly run terraform init/plan/apply/destroy to verify the same. If its runs successfully, then you are good to go and can ignore the error.</p><p><strong>3. False positive test cases :</strong></p><p>Usually if you have any issues while running “terraform init/plan/apply/destroy” , the tests cases are skipped and returns successful along with unable to do terraform action error. So ensure that the “terraform init/plan/apply/destroy” in the tests directory works fine.</p><p><strong>Disclaimer :</strong></p><p>All it does in the backend is running a terraform init/plan/apply — takes the test related outputs and destroys the resources using terraform destroy and the temporary state file.</p><p>Also , to delete/destroy your resources via Terraform manually, please do follow the steps given in the URL below to individually delete a resource or to destroy all the resources.</p><p><a href="https://spacelift.io/blog/how-to-destroy-terraform-resources">Destroy Command - How to Destroy Resources from Terraform</a></p><p>You can reach out to me via Linkedin if you have any queries further.</p><p><a href="https://www.linkedin.com/in/arunkrish29/">Arun Kumar (He/Him/His) - Staff Software Engineer - Cloud Devops - GE Digital | LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6af26b03767a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>