<?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 Apurv Kiri on Medium]]></title>
        <description><![CDATA[Stories by Apurv Kiri on Medium]]></description>
        <link>https://medium.com/@kiriappu?source=rss-a7b5aee2f1db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zXQAkz5pkyrU8mcK</url>
            <title>Stories by Apurv Kiri on Medium</title>
            <link>https://medium.com/@kiriappu?source=rss-a7b5aee2f1db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 21:25:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kiriappu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kubernetes — Automated Dependency Updates with Renovate]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-automated-dependency-updates-with-renovate-e4a9f48e58b8?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4a9f48e58b8</guid>
            <category><![CDATA[flux-cd]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitops]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Tue, 27 Oct 2026 20:25:33 GMT</pubDate>
            <atom:updated>2026-10-28T10:16:17.262Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is part of our ongoing series of posts for Kubernetes. In this post, we will automate dependency updates for our GitOps repository using <strong>Renovate</strong>, an open-source tool that finds outdated dependencies and raises pull requests to update them.</p><p>All components in our cluster are pinned to a specific version: Helm charts in HelmRelease, Flux itself in gotk-components.yaml, and actions in our GitHub workflows. This is what GitOps expects, but nothing tells us when these versions become outdated. We hadn&#39;t touched our cluster for a while, and by the time we came back, every Helm chart had a newer release available. Checking release pages manually for each of them is error-prone and time-consuming.</p><p>Renovate addresses this challenge by scanning the repository, looking up newer versions of each dependency, and raising a pull request per update with release notes attached. We stay in control by reviewing and merging, and FluxCD takes care of rolling out the change. Let’s dive into setting up Renovate as a self-hosted GitHub Actions workflow.</p><h3>1. Create a Token for Renovate</h3><p>Renovate needs a token to access the repository, push update branches and open pull requests. Let’s create a fine-grained personal access token that only has access to our GitOps repository:</p><ul><li>Repository access: <strong>Only select repositories</strong> → k8s-gitops</li><li>Read and write permission for Contents, Pull requests, Issues and Workflows</li><li>Read-only access to Metadata (added automatically)</li></ul><p>Workflows permission is needed so Renovate can update action versions in .github/workflows, and Issues is used for the Dependency Dashboard we&#39;ll see later.</p><p>Next, save the token as a repository secret. gh asks for the value, so the token never ends up in shell history:</p><pre>gh secret set RENOVATE_TOKEN -R kiriapurv/k8s-gitops</pre><blockquote><strong><em>Important:</em></strong><em> Don’t forget to give the token access to the repository itself, not just the permissions. With </em><em>Public repositories selected, Renovate fails on a private repository with </em><em>platform-unknown-error, and only the debug log shows the actual problem: </em><em>Could not resolve to a Repository with the name &#39;kiriapurv/k8s-gitops&#39;.</em></blockquote><h3>2. Setup Renovate Workflow</h3><p>Let’s schedule weekly Renovate runs by creating .github/workflows/renovate.yaml:</p><pre>name: renovate</pre><pre>on:<br>  workflow_dispatch:<br>    inputs:<br>      logLevel:<br>        description: Renovate log level<br>        type: choice<br>        options: [info, debug]<br>        default: info<br>  schedule:<br>    - cron: &quot;0 3 * * 1&quot;</pre><pre>permissions:<br>  contents: read</pre><pre>jobs:<br>  renovate:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Self-hosted Renovate<br>        uses: renovatebot/github-action@2804199d260ad00c1fae0e9e842888369391c776 # v46.3.10<br>        with:<br>          token: ${{ secrets.RENOVATE_TOKEN }}<br>        env:<br>          RENOVATE_REPOSITORIES: ${{ github.repository }}<br>          RENOVATE_GIT_AUTHOR: &quot;Renovate Bot &lt;3841024+kiriapurv@users.noreply.github.com&gt;&quot;<br>          LOG_LEVEL: ${{ inputs.logLevel || &#39;info&#39; }}</pre><p>This configuration:</p><ul><li>Runs every Monday at 03:00 UTC, and on demand through workflow_dispatch with an optional debug log level for troubleshooting</li><li>Pins the Renovate action to a full commit SHA instead of a tag, as this step gets a token with write access</li><li>Restricts Renovate to the current repository with RENOVATE_REPOSITORIES</li><li>Sets RENOVATE_GIT_AUTHOR so commits are made with our account instead of Renovate&#39;s default Mend address</li></ul><h3>3. Configure Renovate</h3><p>Next, let’s tell Renovate what to look for by creating renovate.json in the root of the repository:</p><pre>{<br>  &quot;$schema&quot;: &quot;https://docs.renovatebot.com/renovate-schema.json&quot;,<br>  &quot;extends&quot;: [<br>    &quot;config:recommended&quot;,<br>    &quot;helpers:pinGitHubActionDigests&quot;<br>  ],<br>  &quot;timezone&quot;: &quot;Asia/Kolkata&quot;,<br>  &quot;flux&quot;: {<br>    &quot;managerFilePatterns&quot;: [<br>      &quot;/cluster/.+\\.ya?ml$/&quot;,<br>      &quot;/apps/.+\\.ya?ml$/&quot;<br>    ]<br>  },<br>  &quot;packageRules&quot;: [<br>    {<br>      &quot;description&quot;: &quot;Sample app image tags are managed by Flux image automation&quot;,<br>      &quot;matchPackageNames&quot;: [<br>        &quot;ghcr.io/kiriapurv/**&quot;<br>      ],<br>      &quot;enabled&quot;: false<br>    }<br>  ]<br>}</pre><p>This configuration includes several important customizations:</p><ul><li>config:recommended gives us Renovate&#39;s sensible defaults, like the Dependency Dashboard and PR rate limiting</li><li>helpers:pinGitHubActionDigests pins GitHub Actions to commit digests and keeps those digests updated</li><li>flux.managerFilePatterns is the most important setting for our layout. By default, Renovate&#39;s flux manager only looks at gotk-components.yaml, so it wouldn&#39;t find the HelmRelease definitions in cluster/default/</li><li>The packageRules entry stops updates for our sample application image, since Flux image automation already handles it as set up in <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-3">Kubernetes GitOps with FluxCD - Part 3 - Automated Image Updates</a></li></ul><p>Before committing, let’s validate the configuration with Renovate’s own validator:</p><pre>docker run --rm -v &quot;$PWD&quot;:/usr/src/app -w /usr/src/app renovate/renovate:44.190.1 renovate-config-validator --strict renovate.json</pre><pre> INFO: Validating renovate.json as global config<br> INFO: Config validated successfully against 1 file(s)</pre><p>Now let’s commit and push these changes to our GitOps repository.</p><h3>4. Validate Setup</h3><p>Let’s run the workflow manually right away instead of waiting for Monday:</p><pre>gh workflow run renovate.yaml -R kiriapurv/k8s-gitops</pre><p>Once the run is done, the workflow log shows what Renovate found:</p><pre> INFO: Renovate started<br> INFO: Repository started (repository=kiriapurv/k8s-gitops)<br> INFO: Dependency extraction complete (repository=kiriapurv/k8s-gitops, baseBranch=main)<br>       &quot;stats&quot;: {<br>         &quot;managers&quot;: {<br>           &quot;flux&quot;: {&quot;fileCount&quot;: 9, &quot;depCount&quot;: 9},<br>           &quot;github-actions&quot;: {&quot;fileCount&quot;: 2, &quot;depCount&quot;: 7}<br>         &quot;total&quot;: {&quot;fileCount&quot;: 11, &quot;depCount&quot;: 16}<br> INFO: Branch created (repository=kiriapurv/k8s-gitops, branch=renovate/pin-dependencies)<br> INFO: PR created (repository=kiriapurv/k8s-gitops, branch=renovate/pin-dependencies)<br>       &quot;prTitle&quot;: &quot;Pin dependencies&quot;,<br> INFO: Branch created (repository=kiriapurv/k8s-gitops, branch=renovate/fluxcd-flux2-2.x)<br> INFO: PR created (repository=kiriapurv/k8s-gitops, branch=renovate/fluxcd-flux2-2.x)<br>       &quot;prTitle&quot;: &quot;Update dependency fluxcd/flux2 to v2.10.0&quot;,<br> INFO: Repository finished (repository=kiriapurv/k8s-gitops)<br>       &quot;cloned&quot;: true,<br>       &quot;durationMs&quot;: 41762,<br>       &quot;result&quot;: &quot;done&quot;,</pre><p>Renovate detected 16 dependencies in 11 files and already opened two pull requests. The rest of the updates are listed in the <strong>Dependency Dashboard</strong>, an issue created and maintained by Renovate itself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*_6I5c5TeHb88ujJ-.png" /></figure><p>All Helm charts in our cluster had an update available:</p><pre>Chart                  Current  Available<br>cilium                 1.17.1   1.20.4<br>cert-manager           1.17.1   v1.21.3<br>ingress-nginx          4.11.3   4.15.1<br>kube-prometheus-stack  69.5.2   69.8.2, 92.14.1<br>descheduler            0.32.2   0.37.0<br>reflector              9.0.318  9.1.45, 10.0.69<br>reloader               1.3.0    2.2.19</pre><p>These updates are listed under <strong>Rate-Limited</strong> because config:recommended allows at most two new pull requests per hour, so a stale repository isn&#39;t flooded with PRs. Ticking a checkbox on the dashboard lifts the limit for that one update. Major versions, like kube-prometheus-stack 92, get a separate branch, so minor and major upgrades can be reviewed separately.</p><h3>5. Rolling Out an Update</h3><p>To show the full flow, we’ll upgrade Reflector, which we configured in <a href="https://apurv.me/posts/kubernetes-replicate-secrets-with-reflector">Kubernetes — Replicate Secrets with Reflector</a>. First, let’s check which version is running now:</p><pre>kubectl get pods -l app.kubernetes.io/name=reflector -o jsonpath=&#39;{range .items[*]}{.metadata.name}{&quot;  &quot;}{.spec.containers[0].image}{&quot;\n&quot;}{end}&#39;</pre><pre>reflector-dcc5cf554-4wl95  docker.io/emberstack/kubernetes-reflector:9.0.318</pre><p>After ticking Update Helm release reflector to v9.1.45 on the dashboard and running the workflow again, Renovate creates a pull request with the release notes. The only line that changes:</p><pre>   chart:<br>     spec:<br>       chart: reflector<br>-      version: &quot;9.0.318&quot;<br>+      version: &quot;9.1.45&quot;<br>       interval: 10m<br>       sourceRef:<br>         kind: HelmRepository</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*AOIIJj-ELj-HqdcF.png" /></figure><p>Once the pull request is merged, FluxCD picks up the change. Instead of waiting for the next polling interval, let’s trigger the reconciliation:</p><pre>flux reconcile source git flux-system</pre><pre>◎ waiting for GitRepository reconciliation<br>✔ fetched revision main@sha1:0f4e575ef86d2bb51fce04a0301141cf8cd1a74a</pre><pre>flux reconcile helmrelease reflector -n default</pre><pre>✔ HelmRelease annotated<br>◎ waiting for HelmRelease reconciliation<br>✔ applied revision 9.1.45</pre><p>Now let’s check if our release was upgraded:</p><pre>flux get helmrelease reflector -n default</pre><pre>NAME     	REVISION	SUSPENDED	READY	MESSAGE<br>reflector	9.1.45  	False    	True 	Helm upgrade succeeded for release default/reflector.v2 with chart reflector@9.1.45</pre><pre>kubectl get pods -l app.kubernetes.io/name=reflector</pre><pre>NAME                         READY   STATUS    RESTARTS   AGE<br>reflector-556f7cbb75-mfvvz   1/1     Running   0          43s</pre><p>The new pod runs docker.io/emberstack/kubernetes-reflector:9.1.45, and the GitHub registry secret is still replicated to all namespaces:</p><pre>kubectl get secrets -A --field-selector metadata.name=github-registry-secret</pre><pre>NAMESPACE         NAME                     TYPE                             DATA   AGE<br>cert-manager      github-registry-secret   kubernetes.io/dockerconfigjson   1      602d<br>cilium-secrets    github-registry-secret   kubernetes.io/dockerconfigjson   1      596d<br>default           github-registry-secret   kubernetes.io/dockerconfigjson   1      609d<br>flux-system       github-registry-secret   kubernetes.io/dockerconfigjson   1      602d<br>ingress-nginx     github-registry-secret   kubernetes.io/dockerconfigjson   1      596d<br>kube-node-lease   github-registry-secret   kubernetes.io/dockerconfigjson   1      602d<br>kube-public       github-registry-secret   kubernetes.io/dockerconfigjson   1      602d<br>kube-system       github-registry-secret   kubernetes.io/dockerconfigjson   1      602d<br>monitoring        github-registry-secret   kubernetes.io/dockerconfigjson   1      602d<br>reloader          github-registry-secret   kubernetes.io/dockerconfigjson   1      601d</pre><p>The update went from pull request to running pod without touching the cluster directly.</p><h3>6. Retiring the Custom Flux Update Workflow</h3><p>In <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-7">Kubernetes GitOps with FluxCD — Part 7 — Resource Optimization and Automated Version Management with Github Actions</a>, we created a GitHub Actions workflow to regenerate gotk-components.yaml every month. Renovate&#39;s flux manager does this automatically: the Update dependency fluxcd/flux2 to v2.10.0 pull request regenerates cluster/default/flux-system/gotk-components.yaml for the new Flux version.</p><p>Since both would now conflict over the same file, we removed .github/workflows/update-flux.yaml and closed its pending pull request. Renovate saw that the workflow was gone and automatically closed its own Pin dependencies pull request, which only changed that file.</p><blockquote><strong><em>Note:</em></strong><em> We are holding back the Flux </em><em>v2.10.0 update and the major chart upgrades for now. They need a newer Kubernetes version, so we&#39;ll upgrade K3s first in an upcoming post.</em></blockquote><h3>What next ?</h3><p>Future posts will keep bringing the cluster up to date, including:</p><ul><li>Automated K3s upgrades with System Upgrade Controller</li><li>Migrating from ingress-nginx to Gateway API</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Renovate Documentation — <a href="https://docs.renovatebot.com/">https://docs.renovatebot.com/</a></li><li>Renovate Flux Manager — <a href="https://docs.renovatebot.com/modules/manager/flux/">https://docs.renovatebot.com/modules/manager/flux/</a></li><li>Renovate GitHub Action — <a href="https://github.com/renovatebot/github-action">https://github.com/renovatebot/github-action</a></li><li>FluxCD Documentation — <a href="https://fluxcd.io/flux/">https://fluxcd.io/flux/</a></li></ul><p><em>Originally published at </em><a href="https://apurv.me/posts/kubernetes-automated-dependency-updates-with-renovate/"><em>apurv.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4a9f48e58b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes GitOps with FluxCD — Part 3 — Automated Image Updates]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-gitops-with-fluxcd-part-3-automated-image-updates-86396e09cd14?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/86396e09cd14</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[flux-cd]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Tue, 25 Mar 2025 10:01:48 GMT</pubDate>
            <atom:updated>2025-03-25T10:01:48.589Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes GitOps with FluxCD — Part 3 — Automated Image Updates</h3><p>In our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/">previous post</a>, we explored how to manage secrets in FluxCD with SOPS. Building on our GitOps foundation from part 1 and secure secrets handling from part 2, this article will focus on image update automation — a powerful FluxCD feature that automatically updates your deployments when new container images are available, maintaining GitOps principles while eliminating manual image version updates.</p><h3>1. Setup image repository</h3><p>To demonstrate image automation, we’ll create a sample application using Quarkus, a Kubernetes-native Java framework.</p><p>First, let’s create a GitHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/0*h-acKQumFLA3nx9o.png" /></figure><p>Let’s implement a simple REST controller for our sample application.</p><pre>package com.kiriyard;<br>import jakarta.ws.rs.GET;<br>import jakarta.ws.rs.Path;<br>import jakarta.ws.rs.Produces;<br>import jakarta.ws.rs.core.MediaType;<br>@Path(&quot;/&quot;)<br>public class K8SampleApplication {<br>    private static final int VERSION = 1;<br>    @GET<br>    @Produces(MediaType.TEXT_PLAIN)<br>    public String index() {<br>        return &quot;Greetings From K8S App : Version %d&quot;.formatted(VERSION);<br>    }<br>}</pre><p>Now, let’s create a GitHub Action workflow that builds and publishes this image to the GitHub Container Registry.</p><pre>name: Build K8S App Image<br>on:<br>  push:<br>    branches:<br>      - main<br>jobs:<br>  build-image:<br>    runs-on: ubuntu-latest<br>    permissions:<br>      contents: read<br>      checks: write<br>      id-token: write<br>      packages: write<br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v4<br>      - name: Login to GitHub Container Registry<br>        uses: docker/login-action@v3<br>        with:<br>          registry: ghcr.io<br>          username: ${{ github.actor }}<br>          password: ${{ secrets.GITHUB_TOKEN }}<br>      - name: Set up JDK 21<br>        uses: actions/setup-java@v4<br>        with:<br>          distribution: temurin<br>          java-version: 21<br>          cache: &#39;maven&#39;<br>      - name: Generate build ID<br>        id: prep<br>        run: |<br>          branch=${GITHUB_REF##*/}<br>          sha=${GITHUB_SHA::8}<br>          ts=$(date +%s)<br>          echo &quot;BUILD_ID=${branch}-${sha}-${ts}&quot; &gt;&gt; $GITHUB_OUTPUT          <br>      - name: Build and push Docker image<br>        run: |<br>          ./mvnw install \<br>            -Dquarkus.container-image.build=true \<br>            -Dquarkus.container-image.registry=ghcr.io \<br>            -Dquarkus.container-image.group=&quot;&quot; \<br>            -Dquarkus.container-image.name=${{ github.repository }} \<br>            -Dquarkus.container-image.tag=${{ steps.prep.outputs.BUILD_ID }} \<br>            -Dquarkus.container-image.push=true</pre><p>After pushing our changes, we can verify the image has been created in the GitHub Container Registry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/0*m2NevcQV-j6GF4Ot.png" /></figure><p>We’ll note the full image path for future reference: ghcr.io/kiriapurv/k8s-sample-app:main-3cbb3902-1740556397</p><h3>2. Setup private repository pull secrets</h3><p>Since we’re using a private container registry, we need to configure GitHub authentication credentials as Kubernetes pull secrets for our deployment.</p><p>We’ll generate a Personal Access Token (PAT) and configure a Kubernetes secret using SOPS, following the encryption approach we established in our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/">previous post</a>.</p><p>First, let’s create the secret YAML manifest:</p><pre>kubectl create secret docker-registry github-registry-secret \<br>  --docker-server=ghcr.io \<br>  --docker-username=** \<br>  --docker-password=** \<br>  --namespace=default \<br>  --dry-run=client -o yaml &gt; github-registry-secret.yaml</pre><p>Now, let’s encrypt this secret using SOPS:</p><pre>sops encrypt --in-place github-registry-secret.yaml</pre><p>After pushing these changes to our Git repository, we’ll wait for FluxCD to perform reconciliation:</p><pre>flux get kustomizations flux-system --watch<br><br>NAME            REVISION                SUSPENDED       READY   MESSAGE                              <br>flux-system     main@sha1:893edbfc      False           True    Applied revision: main@sha1:893edbfc<br>flux-system     main@sha1:893edbfc      False   Unknown Reconciliation in progress<br>flux-system     main@sha1:893edbfc      False   Unknown Reconciliation in progress<br>flux-system     main@sha1:893edbfc      False   Unknown Reconciliation in progress<br>flux-system     main@sha1:893edbfc      False   Unknown Reconciliation in progress<br>flux-system     main@sha1:893edbfc      False   True    Applied revision: main@sha1:c2636b99<br>flux-system     main@sha1:c2636b99      False   True    Applied revision: main@sha1:c2636b99</pre><p>Let’s verify that our secret has been successfully created in the cluster:</p><pre>kubectl get secrets<br><br>NAME                     TYPE                             DATA   AGE<br>github-registry-secret   kubernetes.io/dockerconfigjson   1      65s<br>samplesecret             Opaque                           1      20h</pre><h3>3. Create deployment</h3><p>Now let’s create a Kubernetes deployment using our container image.</p><p>First, let’s create apps/sample-app/deployment.yaml</p><pre>apiVersion: apps/v1<br>metadata:<br>  name: sample-app<br>  namespace: default<br>kind: Deployment<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: sample-app<br>  template:<br>    metadata:<br>      labels:<br>        app: sample-app<br>    spec:<br>      imagePullSecrets:<br>        - name: github-registry-secret<br>      containers:<br>      - name: sample-app<br>        image: ghcr.io/kiriapurv/k8s-sample-app:main-3cbb3902-1740556397<br>        imagePullPolicy: Always<br>        ports:<br>        - containerPort: 8080<br>        resources:<br>          requests:<br>            memory: &quot;128Mi&quot;<br>            cpu: &quot;50m&quot;<br>          limits:<br>            memory: &quot;128Mi&quot;<br>            cpu: &quot;50m&quot;</pre><p>Next, create a Kustomization file to manage our resources at apps/sample-app/kustomization.yaml</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>resources:<br>  - deployment.yaml</pre><p>Finally, create a FluxCD Kustomization to deploy our application at cluster/default/sample-app.yaml</p><pre>apiVersion: kustomize.toolkit.fluxcd.io/v1<br>kind: Kustomization<br>metadata:<br>  name: sample-app<br>  namespace: flux-system<br>spec:<br>  interval: 5m<br>  path: ./apps/sample-app<br>  prune: true<br>  retryInterval: 2m<br>  sourceRef:<br>    kind: GitRepository<br>    name: flux-system<br>  targetNamespace: default<br>  timeout: 3m<br>  wait: true</pre><p>After pushing these changes, let’s monitor the FluxCD reconciliation process:</p><pre>flux get kustomizations sample-app --watch</pre><pre>NAME            REVISION        SUSPENDED       READY   MESSAGE                    <br>sample-app                      False           Unknown Reconciliation in progress<br>sample-app              False   Unknown Reconciliation in progress<br>sample-app              False   True    Applied revision: main@sha1:939bb8b3<br>sample-app      main@sha1:939bb8b3      False   True    Applied revision: main@sha1:939bb8b3</pre><p>Let’s verify that our deployment has been created:</p><pre>kubectl get pods<br>NAME                                READY   STATUS    RESTARTS      AGE<br>nginx-deployment-854f6c9499-wxdjx   1/1     Running   1 (11m ago)   45h<br>sample-app-9477cc684-fs876          1/1     Running   0             48s</pre><p>To validate that our application is working correctly, let’s set up port forwarding and test the endpoint:</p><pre>kubectl port-forward deployments/sample-app 8080:8080 <br>Forwarding from 127.0.0.1:8080 -&gt; 8080<br>Forwarding from [::1]:8080 -&gt; 8080</pre><p>Let’s send a request to verify our application is responding:</p><pre>curl http://localhost:8080</pre><pre>Greetings From K8S App : Version 1</pre><p>Perfect! Our application is working as expected.</p><h3>4. Setup FluxCD Image Automation</h3><p>Now that we have our application deployed, we’ll configure FluxCD’s image automation capabilities. This requires three key components:</p><ol><li>An ImageRepository resource that monitors our container registry for new images</li><li>An ImagePolicy resource that defines the criteria for selecting new images</li><li>An ImageUpdateAutomation resource that configures the automation process</li></ol><p>We’ll configure ImageRepository and ImagePolicy in same cluster/default/sample-app.yaml</p><pre>apiVersion: kustomize.toolkit.fluxcd.io/v1<br>kind: Kustomization<br>metadata:<br>  name: sample-app<br>  namespace: flux-system<br>spec:<br>  interval: 5m<br>  path: ./apps/sample-app<br>  prune: true<br>  retryInterval: 2m<br>  sourceRef:<br>    kind: GitRepository<br>    name: flux-system<br>  targetNamespace: default<br>  timeout: 3m<br>  wait: true<br>---<br>apiVersion: image.toolkit.fluxcd.io/v1beta2<br>kind: ImageRepository<br>metadata:<br>  name: sample-app<br>  namespace: default<br>spec:<br>  image: ghcr.io/kiriapurv/k8s-sample-app<br>  interval: 5m<br>  secretRef:<br>    name: github-registry-secret<br>---<br>apiVersion: image.toolkit.fluxcd.io/v1beta2<br>kind: ImagePolicy<br>metadata:<br>  name: sample-app-main-policy<br>  namespace: default<br>spec:<br>  imageRepositoryRef:<br>    name: sample-app<br>  filterTags:<br>    pattern: &#39;^main-[a-fA-F0-9]+-(?P&lt;ts&gt;.*)&#39;<br>    extract: &#39;$ts&#39;<br>  policy:<br>    numerical:<br>      order: asc</pre><h3>Understanding the ImagePolicy Configuration</h3><p>The ImagePolicy resource is crucial for defining how FluxCD selects the latest version of an image. Let’s break down its key components:</p><h4>Tag Filtering with filterTags</h4><p>The filterTags section uses regular expressions to identify and extract meaningful information from image tags:</p><ul><li>pattern: Defines a regex pattern to match against image tags. In our case, &#39;^main-[a-fA-F0-9]+-(?P&lt;ts&gt;.*)&#39; means:</li><li>^main-: The tag must start with “main-”</li><li>[a-fA-F0-9]+: Followed by one or more hexadecimal characters (our Git commit SHA)</li><li>(?P&lt;ts&gt;.*): Captures the remaining part of the tag as a named group “ts” (timestamp)</li><li>extract: Specifies which part of the pattern to extract for version comparison. The &#39;$ts&#39; refers to the named capture group &quot;ts&quot; from our pattern, which contains the Unix timestamp.</li></ul><p>This extraction is essential because the FluxCD automation needs to know which part of the tag contains the version information to compare.</p><h4>Version Selection with policy</h4><p>The policy section defines how FluxCD determines which image version is the “latest”:</p><ul><li>numerical: Indicates we’re dealing with numeric versioning (as opposed to semantic versioning)</li><li>order: asc: Specifies that higher numbers are considered newer (ascending order)</li></ul><p>In our case, we’re using Unix timestamps in our image tags, which naturally increase over time. By setting order: asc, we ensure that FluxCD selects the image with the most recent timestamp.</p><p>More details on sortable image tag is available in official documentation — <a href="https://fluxcd.io/flux/guides/sortable-image-tags/">https://fluxcd.io/flux/guides/sortable-image-tags/</a></p><p>Next, we need to annotate our deployment manifest to indicate which image policy should be applied. Let’s update</p><p>We’ll update apps/sample-app/deployment.yaml</p><pre>apiVersion: apps/v1<br>metadata:<br>  name: sample-app<br>  namespace: default<br>kind: Deployment<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: sample-app<br>  template:<br>    metadata:<br>      labels:<br>        app: sample-app<br>    spec:<br>      imagePullSecrets:<br>        - name: github-registry-secret<br>      containers:<br>      - name: sample-app<br>        image: ghcr.io/kiriapurv/k8s-sample-app:main-3cbb3902-1740556397 # {&quot;$imagepolicy&quot;: &quot;default:sample-app-main-policy&quot;}<br>        imagePullPolicy: Always<br>        ports:<br>        - containerPort: 8080<br>        resources:<br>          requests:<br>            memory: &quot;128Mi&quot;<br>            cpu: &quot;50m&quot;<br>          limits:<br>            memory: &quot;128Mi&quot;<br>            cpu: &quot;50m&quot;</pre><p>Note that we’ve added a special comment annotation after the image value: # {“$imagepolicy”: “default:sample-app-main-policy”}.</p><p>This tells FluxCD which policy to use when determining image updates.</p><p>Finally, we need to create an ImageUpdateAutomation resource to orchestrate the update process.</p><p>Let’s create cluster/default/image-update-automation.yaml:</p><pre>apiVersion: image.toolkit.fluxcd.io/v1beta2<br>kind: ImageUpdateAutomation<br>metadata:<br>  name: default-image-update<br>  namespace: default<br>spec:<br>  interval: 30m<br>  sourceRef:<br>    kind: GitRepository<br>    name: flux-system<br>    namespace: flux-system<br>  git:<br>    checkout:<br>      ref:<br>        branch: main<br>    commit:<br>      author:<br>        email: fluxcdbot@users.noreply.github.com<br>        name: fluxcdbot<br>      messageTemplate: &#39;{{range .Changed.Changes}}{{print .OldValue}} -&gt; {{println .NewValue}}{{end}}&#39;<br>    push:<br>      branch: main<br>  update:<br>    path: ./<br>    strategy: Setters</pre><p>This configuration tells FluxCD to:</p><ul><li>Check for updates every 30 minutes</li><li>Commit changes using the FluxCD bot identity</li><li>Use a message template that shows which images were updated</li><li>Push changes to the main branch</li><li>Use the “Setters” strategy to update image references throughout the repository</li></ul><p>Let’s push these changes and monitor FluxCD events to verify our automation is working:</p><pre>flux events -n default --watch<br>LAST SEEN               TYPE    REASON                  OBJECT                                  MESSAGE                                             <br>31s (x24 over 2m38s)    Warning DependencyNotReady      ImagePolicy/sample-app-main-policy      referenced ImageRepository has not been scanned yet<br>30s (x2 over 30s)       Normal  Succeeded       ImagePolicy/sample-app-main-policy      Latest image tag for &#39;ghcr.io/kiriapurv/k8s-sample-app&#39; resolved to main-3cbb3902-1740556397<br>30s     Normal  Succeeded       ImageRepository/sample-app      successful scan: found 1 tags</pre><p>Let’s confirm that our image resources are properly configured:</p><pre>flux get -n default images all<br>NAME                            LAST SCAN                       SUSPENDED       READY   MESSAGE                       <br>imagerepository/sample-app      2025-02-26T14:08:00+05:30       False           True    successful scan: found 1 tags</pre><pre>NAME                                    LATEST IMAGE                                                    READY   MESSAGE                                                                                      <br>imagepolicy/sample-app-main-policy      ghcr.io/kiriapurv/k8s-sample-app:main-3cbb3902-1740556397       True    Latest image tag for &#39;ghcr.io/kiriapurv/k8s-sample-app&#39; resolved to main-3cbb3902-1740556397</pre><h3>5. Updating Image</h3><p>Now let’s test our automation by updating our application code and pushing the change.</p><p>We’ll increment the version number in our controller class:</p><pre>package com.kiriyard;<br>import jakarta.ws.rs.GET;<br>import jakarta.ws.rs.Path;<br>import jakarta.ws.rs.Produces;<br>import jakarta.ws.rs.core.MediaType;<br>@Path(&quot;/&quot;)<br>public class K8SampleApplication {<br>-    private static final int VERSION = 1;<br>+    private static final int VERSION = 2;<br>    @GET<br>    @Produces(MediaType.TEXT_PLAIN)<br>    public String index() {<br>        return &quot;Greetings From K8S App : Version %d&quot;.formatted(VERSION);<br>    }<br>}</pre><p>After committing and pushing this change, GitHub Actions will build a new container image. Once the image is published, FluxCD should detect it, update our Git repository, and then apply the changes to our cluster. Let’s monitor the FluxCD events:</p><pre>flux -n default events </pre><pre>6s                      Normal  Succeeded               ImageUpdateAutomation/default-image-update      pushed commit &#39;91fce99&#39; to branch &#39;main&#39;                                                                                                   <br>                                                                                                        ghcr.io/kiriapurv/k8s-sample-app:main-3cbb3902-1740556397 -&gt; ghcr.io/kiriapurv/k8s-sample-app:main-29e96d2a-1740565130</pre><p>We can also verify the changes in our Git repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*rxJerbCRMcBOj4lk.png" /></figure><p>Now let’s check if the deployment in our cluster has been updated:</p><pre>kubectl -n default describe pod sample-app-649d676845-gcpwk <br>Name:             sample-app-649d676845-gcpwk<br>Namespace:        default<br>Priority:         0<br>Service Account:  default<br>Node:             192.168.1.19/192.168.1.19<br>Start Time:       Wed, 26 Feb 2025 16:18:50 +0530<br>Labels:           app=sample-app<br>                  pod-template-hash=649d676845<br>Annotations:      &lt;none&gt;<br>Status:           Running<br>IP:               10.42.0.15<br>IPs:<br>  IP:           10.42.0.15<br>Controlled By:  ReplicaSet/sample-app-649d676845<br>Containers:<br>  sample-app:<br>    Container ID:   containerd://c505519d6dd3d013fa2be3275e2b5085df4486a4c3ebe75a50688b37e49eb7ff<br>    Image:          ghcr.io/kiriapurv/k8s-sample-app:main-29e96d2a-1740565130<br>    Image ID:       ghcr.io/kiriapurv/k8s-sample-app@sha256:8447a6a128b96474ee620dfc692c15d7c22309f973663917191d2b87b8f3db72<br>    Port:           8080/TCP<br>    Host Port:      0/TCP<br>    State:          Running<br>      Started:      Wed, 26 Feb 2025 16:18:57 +0530<br>    Ready:          True<br>    Restart Count:  0<br>    Limits:<br>      cpu:     50m<br>      memory:  128Mi<br>    Requests:<br>      cpu:        50m<br>      memory:     128Mi<br>    Environment:  &lt;none&gt;<br>    Mounts:<br>      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-l2rxk (ro)<br>Conditions:<br>  Type                        Status<br>  PodReadyToStartContainers   True <br>  Initialized                 True <br>  Ready                       True <br>  ContainersReady             True <br>  PodScheduled                True <br>Volumes:<br>  kube-api-access-l2rxk:<br>    Type:                    Projected (a volume that contains injected data from multiple sources)<br>    TokenExpirationSeconds:  3607<br>    ConfigMapName:           kube-root-ca.crt<br>    ConfigMapOptional:       &lt;nil&gt;<br>    DownwardAPI:             true<br>QoS Class:                   Guaranteed<br>Node-Selectors:              &lt;none&gt;<br>Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s<br>                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s<br>Events:<br>  Type    Reason     Age    From               Message<br>  ----    ------     ----   ----               -------<br>  Normal  Scheduled  4m42s  default-scheduler  Successfully assigned default/sample-app-649d676845-gcpwk to 192.168.1.19<br>  Normal  Pulling    4m41s  kubelet            Pulling image &quot;ghcr.io/kiriapurv/k8s-sample-app:main-29e96d2a-1740565130&quot;<br>  Normal  Pulled     4m35s  kubelet            Successfully pulled image &quot;ghcr.io/kiriapurv/k8s-sample-app:main-29e96d2a-1740565130&quot; in 5.3s (5.3s including waiting). Image size: 166698164 bytes.<br>  Normal  Created    4m35s  kubelet            Created container sample-app<br>  Normal  Started    4m35s  kubelet            Started container sample-app</pre><p>As we can see, the pod is now running with the new image tag: main-29e96d2a-1740565130.</p><p>Finally, let’s test our application to confirm the version has been updated:</p><pre>curl http://localhost:8080</pre><pre>Greetings From K8S App : Version 2</pre><p>Success! Our application has been automatically updated to version 2, demonstrating the complete GitOps-based image automation flow with FluxCD.</p><h3>What next ?</h3><p>Future posts will explore advanced GitOps patterns with FluxCD, including:</p><ul><li>Helm chart automation</li><li>Notification and alerting configuration</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Official FluxCD Documentation — <a href="https://fluxcd.io/flux/guides/image-update/">https://fluxcd.io/flux/guides/image-update/</a></li><li>GitOps Working Group — <a href="https://opengitops.dev/">https://opengitops.dev</a></li><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li><li>Quarkus Container Image Guide — <a href="https://quarkus.io/guides/container-image">https://quarkus.io/guides/container-image</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86396e09cd14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes GitOps with FluxCD — Part 2 — Secret Management using SOPS]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-gitops-with-fluxcd-part-2-secret-management-using-sops-334324a6bd31?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/334324a6bd31</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[mozilla-sops]]></category>
            <category><![CDATA[gitops]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Thu, 20 Mar 2025 10:03:16 GMT</pubDate>
            <atom:updated>2025-03-20T10:03:16.158Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes GitOps with FluxCD — Part 2 — Secret Management using SOPS</h3><p>In Kubernetes-based GitOps workflows, securely managing sensitive information presents a unique challenge. While GitOps principles encourage storing all cluster configurations in Git repositories, committing plaintext secrets creates significant security risks. SOPS (Secrets OPerationS) offers an elegant solution to this problem when integrated with FluxCD.</p><p>In our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-1/">previous post</a>, we explored how to perform the initial setup of FluxCD in a Kubernetes cluster. Building on that foundation, we’ll now address one of the most critical aspects of GitOps implementation: <strong>Secret Management</strong>.</p><p>SOPS, developed by Mozilla, enables encrypting specific values within YAML, JSON, and other configuration formats while keeping the file structure intact. When combined with FluxCD’s native support for decryption, this allows teams to safely store encrypted secrets directly in their Git repositories alongside other infrastructure definitions. The secrets are only decrypted at runtime within the Kubernetes cluster, maintaining security while preserving the GitOps workflow.</p><p>This article explores how to implement a robust secret management strategy using SOPS and FluxCD. We’ll cover the setup process, encryption workflows, integration with different key management systems, and best practices for maintaining secure GitOps operations in production environments.</p><h3>1. Install SOPS and GPG</h3><p>Your installation method may differ depending on your operating system. Below is the command for openSUSE Tumbleweed:</p><pre>sudo zypper in sops gpg2</pre><p>For other distributions:</p><ul><li>Ubuntu/Debian: sudo apt install sops gnupg2</li><li>macOS: brew install sops gnupg</li><li>Arch Linux: sudo pacman -S sops gnupg</li></ul><h3>2. Generate Keypair</h3><p>Next, we’ll generate a GPG keypair that will be used for encryption and decryption:</p><pre>export KEY_NAME=&quot;cluster.local&quot;<br>export KEY_COMMENT=&quot;For Flux Secrets&quot;</pre><pre>gpg --batch --full-generate-key &lt;&lt;EOF<br>%no-protection<br>Key-Type: 1<br>Key-Length: 4096<br>Subkey-Type: 1<br>Subkey-Length: 4096<br>Expire-Date: 0<br>Name-Comment: ${KEY_COMMENT}<br>Name-Real: ${KEY_NAME}<br>EOF</pre><p>This creates a 4096-bit RSA key with no expiration date. The output will look similar to:</p><pre>gpg: directory &#39;/home/apurv/.gnupg/openpgp-revocs.d&#39; created<br>gpg: revocation certificate stored as &#39;/home/apurv/.gnupg/openpgp-revocs.d/A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4.rev&#39;</pre><p>Now retrieve the key fingerprint, which we’ll need for subsequent steps:</p><pre>gpg --list-secret-keys &quot;${KEY_NAME}&quot;</pre><pre>gpg: checking the trustdb<br>gpg: marginals needed: 3  completes needed: 1  trust model: pgp<br>gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u<br>sec   rsa4096 2025-02-25 [SCEAR]<br>      A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4<br>uid           [ultimate] cluster.local (For Flux Secrets)<br>ssb   rsa4096 2025-02-25 [SEA]<br>      8B514FAAC98DF16F61EE487A45E294E6CACB03D4</pre><p>Take note of the fingerprint (in this example: A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4).</p><h3>3. Store Private Key as Kubernetes Secret</h3><p>Now we’ll export the private key and store it as a Kubernetes secret that FluxCD can access:</p><pre>gpg --export-secret-keys --armor &quot;A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4&quot; | kubectl create secret generic sops-gpg \<br>--namespace=flux-system \<br>--from-file=sops.asc=/dev/stdin</pre><pre>secret/sops-gpg created</pre><p>Let’s verify the secret was created properly:</p><pre>apurv@oxygen:~&gt; kubectl -n flux-system get secrets</pre><pre>NAME          TYPE     DATA   AGE<br>flux-system   Opaque   3      25h<br>sops-gpg      Opaque   1      38s</pre><p>Since the local key is unprotected (we used %no-protection for demonstration purposes), we should delete it from our local machine:</p><pre>gpg --delete-secret-keys &quot;A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4&quot;</pre><h3>4. Configure In-Cluster Secrets Decryption</h3><p>For production environments, the recommended approach is to store secrets in a separate repository with restricted access. However, for this tutorial, we’ll patch the existing cluster manifest to add support for the decryption provider.</p><p>Edit cluster/default/flux-system/kustomization.yaml</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>resources:<br> - gotk-components.yaml<br> - gotk-sync.yaml<br>+patches:<br>+  - patch: |-<br>+      apiVersion: kustomize.toolkit.fluxcd.io/v1<br>+      kind: Kustomization<br>+      metadata:<br>+        name: flux-system<br>+        namespace: flux-system<br>+      spec:<br>+        decryption:<br>+          provider: sops<br>+          secretRef:<br>+            name: sops-gpg</pre><p>This patch configures FluxCD to use SOPS for decryption, referencing our previously created GPG key secret.<br> Let’s commit and push our changes, then verify the deployment:</p><pre>git commit -m &quot;Configured SOPS decryption for main cluster repo&quot; &amp;&amp; git push origin</pre><pre>flux get kustomizations flux-system --watch</pre><pre>NAME            REVISION                SUSPENDED       READY   MESSAGE                              <br>flux-system     main@sha1:c35e4e45      False           True    Applied revision: main@sha1:c35e4e45</pre><h3>5. Export Public Key and Configure SOPS</h3><p>We’ll export the public key to the cluster directory:</p><pre>gpg --export --armor &quot;A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4&quot; &gt; ./cluster/default/.sops.pub.asc</pre><p>Next, create a SOPS configuration file to specify which parts of the YAML files should be encrypted:</p><pre>cat &lt;&lt;EOF &gt; ./cluster/default/.sops.yaml<br>creation_rules:<br>  - path_regex: .*.yaml<br>    encrypted_regex: ^(data|stringData)$<br>    pgp: A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4<br>EOF</pre><p>This configuration tells SOPS to only encrypt the data and stringData sections of YAML files, leaving metadata intact for Kubernetes to process.<br> Commit these configuration files:</p><pre>git add . &amp;&amp; git commit -m &quot;Added SOPS public key and config&quot;</pre><h3>6. Validate the Setup</h3><p>Let’s verify our setup by creating a sample secret and ensuring it works properly:</p><p>Create ./cluster/default/samplesecret.yaml:</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: samplesecret<br>  namespace: default<br>type: Opaque<br>stringData:<br>  message: This is a secret message</pre><p>Now encrypt this file with SOPS:</p><pre>sops --encrypt --in-place samplesecret.yaml</pre><p>After encryption the yaml file looks like below.</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>    name: samplesecret<br>    namespace: default<br>type: Opaque<br>stringData:<br>    message: ENC[AES256_GCM,data:H0iMCWDGpqRSQZtjSXTbMlXaRvXQRxqs,iv:/r5ylcoqWd1wnOp1p9ksDUEs+kkPkdQz31I66LXrpxo=,tag:r2m9+dyo9tnBz+ty42cfrA==,type:str]<br>sops:<br>    kms: []<br>    gcp_kms: []<br>    azure_kv: []<br>    hc_vault: []<br>    age: []<br>    lastmodified: &quot;2025-02-25T12:00:11Z&quot;<br>    mac: ENC[AES256_GCM,data:AuJ9hHq2+Yars67Rw8QhkpjCu8iwqGVsWDJ2/1oEx430yaGSCNXXcZnntek9rsI3xuEzyVwTJcXIE/1yW1bCvPPdWUOel+dY+mLkLSUxio238FbDoGI8mv+7FLpDe4Tn9GZdBbaMyGF6FwXXfQJ8021tLSqK6IJQN8nW2XbT0L0=,iv:KkmRa+HzZ0lI0vsEdqX+ZY6HIpudA/0ABny6OruwuQ8=,tag:6gaSJssqOEQk53DvXCZT0Q==,type:str]<br>    pgp:<br>        - created_at: &quot;2025-02-25T12:00:11Z&quot;<br>          enc: |-<br>            -----BEGIN PGP MESSAGE-----</pre><pre>            hQIMA0XilObKywPUARAArblXLVn7VaJ+Sw2jNqptBPoPaDq7CA4V2LqUoGQUdIiX<br>            6pHZoZmfWCpvXAUTqLQ1xEnZ32XHl+lwEVxLzV6OckkYcZKxMGz1lHZGmK7QghtV<br>            Gm32lFvXVOnMfI9uZ96WH9WW+8Dng3VgyBAK/putNG+N3NLkeXa3vrWaaNaHY/Dj<br>            aBPK1FqzFAYLbFlGjadA1+1xpFfA4JnE5dLX5HTDIo9DKldJWxxqY6cGo6jTg1lO<br>            j+vmLHQicdKrApbMqdq1KyRLWTU21B0cRlfIIK37rX9xESXjUlwPmF27sew2KPsx<br>            iuLyofDu/fVD9kFUC/Zkrmog0IgBWaKuUniOBT1KkcPJoJ5AX9m3qyTGjTGNwvVU<br>            DWATppNCqnO2NhN2D13sOxL5/BSkJT4HZgdj8oIiQQjv0QwLW6nwlEHcmveiX6aK<br>            CRUOR51gp+ja+fAlZnevYUpJMJZFz4TX1LTVXqUd8dJeXePaAsCPzO38Ywrpe83D<br>            Z9n9ABYawCohwSb+Nd1/eoU0RBZwRfcD0PumTbWj8mbSMn6cPHJuAY1j1WZKH1/y<br>            PM583Vv1zA4NlUJwhAiqI/X0kl22+Qh4tq+tdrhPVLw7P+m7diHG2pyd6jKDZ/K9<br>            D3tY+eeQWcM3EV0hRBN7yA87Rs07lCy0m72PqAtD07qoUbO6jLXipIuE7TgPuZ3U<br>            aAEJAhBexKkWWprEJjk+jpt4h8aXyG7wUAeafCWr2kIWz0/kOSnG0STCjuL1kDbu<br>            +Ysah6EqMijU1sQBJv9Jn5oQ9eTAiHwN2Brh8F1nCPT+E6Ih6lbiJSLAD8duEa7V<br>            Nsgo8cYB0ebx<br>            =R3G0<br>            -----END PGP MESSAGE-----<br>          fp: A2E9A640A0E47EB72E6A4F0517B6FD7A7486D6E4<br>    encrypted_regex: ^(data|stringData)$<br>    version: 3.9.4</pre><p>Lets push these changes.</p><pre>git add samplesecret.yaml &amp;&amp; git commit -m &quot;Added sample secret&quot;<br>git push origin</pre><p>Let’s verify that the secret is created in the cluster:</p><pre>kubectl get secrets<br>NAME           TYPE     DATA   AGE<br>samplesecret   Opaque   1      52s</pre><p>Verify the content of the secret:</p><pre>kubectl get secret samplesecret -o jsonpath=&#39;{.data.message}&#39; | base64 --decode</pre><pre>This is a secret message</pre><h3>What next ?</h3><p>Future posts will explore advanced GitOps patterns with FluxCD, including:</p><ul><li>Helm chart automation</li><li>Image update automation</li><li>Notification and alerting configuration</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Official FluxCD Documentation <a href="https://fluxcd.io/flux/guides/mozilla-sops/">Manage Kubernetes secrets with SOPS</a></li><li>Mozilla SOPS — <a href="https://getsops.io/">https://getsops.io/</a></li><li>GitOps Working Group — <a href="https://opengitops.dev/">https://opengitops.dev</a></li><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=334324a6bd31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes GitOps with FluxCD — Part 1 — Initial Setup]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-gitops-with-fluxcd-part-1-initial-setup-c0e1bfae4acc?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0e1bfae4acc</guid>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[flux-cd]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 10:02:04 GMT</pubDate>
            <atom:updated>2025-03-18T10:02:04.706Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes GitOps with FluxCD — Part 1 — Initial Setup</h3><p>GitOps practice enables us to define our infrastructure as code in a declarative manner. It serves as an audited single source of truth for our cloud/cluster state, providing benefits like:</p><ul><li>Version control and audit trails for infrastructure changes</li><li>Automated reconciliation between desired and actual states</li><li>Improved security through encrypted credentials and access control</li><li>Simplified rollback capabilities</li><li>Enhanced collaboration through Git workflows</li></ul><p>FluxCD is a CNCF graduated project that enables GitOps practices in the Kubernetes ecosystem. It automates the deployment, monitoring, and reconciliation of cluster resources based on Git repositories.</p><p>This post covers the initial setup and core functionality of FluxCD in a Kubernetes cluster.</p><h3>1. Setup Git dependencies</h3><p>Lets start by creating git repository in Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/0*n16tJ02Z--1ic3UL.png" /></figure><p>Next, we need to generate a fine-grained access token that FluxCD will use to interact with our repository. These tokens provide more granular control over repository permissions compared to classic personal access tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/0*0Lifdn4LpXt2o8JM.png" /></figure><p>We’ll keep Read and write permission for Administration, Contents access and Read-only for Metadata access limited to repository we created above and permissions as recommeded by official FluxCD documentation for this initial setup.</p><h3>2. Setup Flux CLI</h3><p>Lets start by installing FluxCD cli</p><pre>sudo zypper in flux2-cli</pre><p>Next step is to export github token and user details variables.</p><pre>export GITHUB_TOKEN=******<br>export GITHUB_USER=*****</pre><p>For this post we are using locally VM hosted k3s cluster, lets check if we have access to same with kubectl.</p><pre># 1. Point to specific cluster we are setting up<br>export KUBECONFIG=~/.kube/local.config<br># 2. Check for access and version<br>kubectl version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tnp8WZigyLDusLOL.png" /></figure><p>Let’s check same with Flux cli if it has access as well.</p><pre>flux check --pre</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PY2aZXd9itDqXJMn.png" /></figure><h3>3. Bootstrap FluxCD</h3><p>We are going to install all components including extra for image automation.</p><pre>flux bootstrap github \<br>    --owner=$GITHUB_USER \<br>    --repository=k8s-gitops \<br>    --branch=main \<br>    --path=./cluster/default \<br>    --read-write-key \<br>    --components source-controller,kustomize-controller,helm-controller,notification-controller \<br>    --components-extra image-reflector-controller,image-automation-controller \<br>    --personal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AIynuH7UVl2dKh-w.png" /></figure><p>Lets verify Flux setup step by step.</p><ol><li>Bootstrap has created one deployment key in Github repository and stored as flux-system/flux-secret</li></ol><p>Let’s verify deployment key in Github</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SAnRtdMcaaRx6R3d.png" /></figure><p>Let’s verify secret with kubectl -n flux-system get secrets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qF2BbcOe5jOc95ZD.png" /></figure><ol><li>Flux has initialized the repository with initial commit having definition of components at cluster/default as specified bootstrap command.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/0*HTAapXdmTSzNMyWZ.png" /></figure><ol><li>FluxCD reconclided with Git repository and installed the components in flux-system namespace, lets verify same with kubectl</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sTwZ9ILyCDK-hTUp.png" /></figure><h3>4. Verify installation</h3><p>Lets verify our installation by creating a sample deployment.</p><p>apps/nginx/deployment.yaml</p><pre>apiVersion: apps/v1<br>metadata:<br>  name: nginx-deployment<br>  namespace: default<br>kind: Deployment<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:latest<br>        ports:<br>        - containerPort: 80<br>        resources:<br>          requests:<br>            memory: &quot;64Mi&quot;<br>            cpu: &quot;50m&quot;<br>          limits:<br>            memory: &quot;64Mi&quot;<br>            cpu: &quot;50m&quot;</pre><p>apps/nginx/kustomization.yaml</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>resources:<br>  - deployment.yaml</pre><p>cluster/default/nginx.yaml</p><pre>apiVersion: kustomize.toolkit.fluxcd.io/v1<br>kind: Kustomization<br>metadata:<br>  name: nginx<br>  namespace: flux-system<br>spec:<br>  interval: 5m<br>  path: ./apps/nginx<br>  prune: true<br>  retryInterval: 2m<br>  sourceRef:<br>    kind: GitRepository<br>    name: flux-system<br>  targetNamespace: default<br>  timeout: 3m<br>  wait: true</pre><p>The Kustomization resource has several important fields:</p><ul><li>interval: How often Flux should reconcile this resource (5m = 5 minutes)</li><li>path: Directory containing the Kubernetes manifests</li><li>prune: Whether Flux should delete resources that are no longer defined in Git</li><li>retryInterval: How long to wait between retries if reconciliation fails</li><li>wait: Whether Flux should wait for resources to be ready before completing reconciliation</li><li>timeout: Maximum time to wait for reconciliation</li></ul><p>Lets push these changes and wait for reconciliation to finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iAbT9m9TpnckflNa.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6_lvy7psJJKs5T-T.png" /></figure><p>Lets verify if nginx is deployed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uwS0Y1TOdG0CMLqJ.png" /></figure><h3>5. What if</h3><p>One of the core goals of GitOps is ensuring that our cluster’s state always matches the resources defined in our git repository. This continuous reconciliation process is what makes GitOps powerful for maintaining system consistency.</p><p>To demonstrate this functionality, we’ll delete our nginx deployment using kubectl and observe how Flux’s reconciliation process automatically restores it to the desired state defined in Git. This showcases the “self-healing” capability of the GitOps approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BS4t1ztRRaTaU8sA.png" /></figure><p>In screen above:</p><ol><li>First step is to verify the deployment with kubectl get deployments to check if nginx is up and running</li><li>Second step is to delete deployment with kubectl delete deployment/nginx-deployment</li><li>3rd step to confirm nginx deployment is deleted with kubectl get deployment</li><li>4th step is to watch over FluxCD reconciliation to kick in</li><li>5th step to verify that nginx is re-deployed post Flux’s reconciliation</li></ol><h3>What next ?</h3><p>Future posts will explore advanced GitOps patterns with FluxCD, including:</p><ul><li>Helm chart automation</li><li>Image update automation</li><li>Notification and alerting configuration</li><li>Secrets management with SOPS</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Official FluxCD Documentation — <a href="https://fluxcd.io/flux/">https://fluxcd.io/flux/</a></li><li>GitOps Working Group — <a href="https://opengitops.dev/">https://opengitops.dev</a></li><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0e1bfae4acc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes GitOps with FluxCD — Part 7 — Resource Optimization and Automated Version Management…]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-gitops-with-fluxcd-part-7-resource-optimization-and-automated-version-management-bd324679ae6f?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd324679ae6f</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[flux-cd]]></category>
            <category><![CDATA[gitops]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 20:25:34 GMT</pubDate>
            <atom:updated>2026-11-20T10:01:04.313Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes GitOps with FluxCD — Part 7 — Resource Optimization and Automated Version Management with Github Actions</h3><p>In our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-6/">previous post</a>, we set up push based reconciliation using webhooks. Building on what we’ve learned so far — <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-1/">basic FluxCD setup</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/">SOPS-based secret management</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-3/">image update automation</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-4/">Helm chart automation</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-5/">alerts</a> and <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-6/">push based reconciliation</a> — this article focuses on critical day-two operational concerns: optimizing FluxCD resource allocation and establishing automated version management through Github Actions.</p><h3>1. Sizing FluxCD Containers</h3><p>By default, FluxCD components are provisioned with the following resource configurations for CPU and memory:</p><pre>kubectl -n flux-system get pods -o json | jq -r &#39;[&quot;container&quot;, &quot;cpu_requests&quot;, &quot;cpu_limits&quot;, &quot;memory_requests&quot;, &quot;memory_limits&quot;], (.items[].spec.containers[] | [.image, .resources.requests.cpu, .resources.limits.cpu, .resources.requests.memory, .resources.limits.memory]) | @csv&#39; | column -t -s,<br> <br> <br>&quot;container&quot;                                           &quot;cpu_requests&quot;  &quot;cpu_limits&quot;  &quot;memory_requests&quot;  &quot;memory_limits&quot;<br>&quot;ghcr.io/fluxcd/helm-controller:v1.2.0&quot;               &quot;100m&quot;          &quot;1&quot;           &quot;64Mi&quot;             &quot;1Gi&quot;<br>&quot;ghcr.io/fluxcd/image-automation-controller:v0.40.0&quot;  &quot;100m&quot;          &quot;1&quot;           &quot;64Mi&quot;             &quot;1Gi&quot;<br>&quot;ghcr.io/fluxcd/image-reflector-controller:v0.34.0&quot;   &quot;100m&quot;          &quot;1&quot;           &quot;64Mi&quot;             &quot;1Gi&quot;<br>&quot;ghcr.io/fluxcd/kustomize-controller:v1.5.0&quot;          &quot;100m&quot;          &quot;1&quot;           &quot;64Mi&quot;             &quot;1Gi&quot;<br>&quot;ghcr.io/fluxcd/notification-controller:v1.5.0&quot;       &quot;100m&quot;          &quot;1&quot;           &quot;64Mi&quot;             &quot;1Gi&quot;<br>&quot;ghcr.io/fluxcd/source-controller:v1.5.0&quot;             &quot;50m&quot;           &quot;1&quot;           &quot;64Mi&quot;             &quot;1Gi&quot;</pre><p>For our environment with a smaller cluster footprint, these default limits are unnecessarily generous and could lead to resource contention. We’ll refine these allocations by modifying cluster/default/flux-system/kustomization.yaml to better align with our actual resource capacity and workload requirements:</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>resources:<br>  - gotk-components.yaml<br>  - gotk-sync.yaml<br>  - webhook-receiver.yaml<br>  - ingress.yaml<br>patches:<br>  - patch: |-<br>      apiVersion: kustomize.toolkit.fluxcd.io/v1<br>      kind: Kustomization<br>      metadata:<br>        name: flux-system<br>        namespace: flux-system<br>      spec:<br>        decryption:<br>          provider: sops<br>          secretRef:<br>            name: sops-gpg<br>+ - patch: |<br>+     - op: add<br>+       path: /spec/template/spec/nodeSelector<br>+     - op: replace<br>+       path: /spec/template/spec/containers/0/resources/limits/cpu<br>+       value: &quot;100m&quot;<br>+     - op: replace<br>+       path: /spec/template/spec/containers/0/resources/limits/memory<br>+       value: &quot;128Mi&quot;<br>+   target:<br>+     kind: Deployment</pre><p>After committing these changes, we can verify the resource adjustments have been properly applied:</p><pre>kubectl -n flux-system get pods -o json | jq -r &#39;[&quot;container&quot;, &quot;cpu_requests&quot;, &quot;cpu_limits&quot;, &quot;memory_requests&quot;, &quot;memory_limits&quot;], (.items[].spec.containers[] | [.image, .resources.requests.cpu, .resources.limits.cpu, .resources.requests.memory, .resources.limits.memory]) | @csv&#39; | column -t -s,<br> <br>&quot;container&quot;                                           &quot;cpu_requests&quot;  &quot;cpu_limits&quot;  &quot;memory_requests&quot;  &quot;memory_limits&quot;<br>&quot;ghcr.io/fluxcd/helm-controller:v1.2.0&quot;               &quot;100m&quot;          &quot;100m&quot;        &quot;64Mi&quot;             &quot;128Mi&quot;<br>&quot;ghcr.io/fluxcd/image-automation-controller:v0.40.0&quot;  &quot;100m&quot;          &quot;100m&quot;        &quot;64Mi&quot;             &quot;128Mi&quot;<br>&quot;ghcr.io/fluxcd/image-reflector-controller:v0.34.0&quot;   &quot;100m&quot;          &quot;100m&quot;        &quot;64Mi&quot;             &quot;128Mi&quot;<br>&quot;ghcr.io/fluxcd/kustomize-controller:v1.5.0&quot;          &quot;100m&quot;          &quot;100m&quot;        &quot;64Mi&quot;             &quot;128Mi&quot;<br>&quot;ghcr.io/fluxcd/notification-controller:v1.5.0&quot;       &quot;100m&quot;          &quot;100m&quot;        &quot;64Mi&quot;             &quot;128Mi&quot;<br>&quot;ghcr.io/fluxcd/source-controller:v1.5.0&quot;             &quot;50m&quot;           &quot;100m&quot;        &quot;64Mi&quot;             &quot;128Mi&quot;</pre><p>The output confirms our resource constraints have been successfully applied to all FluxCD components, optimizing our cluster’s resource utilization while maintaining operational integrity.</p><h3>2. Flux Version Updates with Github Actions</h3><p>Maintaining current versions of infrastructure components is a critical operational responsibility. We can leverage Github Actions to automate the monitoring and updating of FluxCD components by implementing a workflow that periodically checks for new releases and creates pull requests when updates are available.</p><p>Let’s establish this automation by creating .github/workflows/update-flux.yaml</p><pre>name: update-flux<br> <br>on:<br>  workflow_dispatch:<br>  schedule:<br>    - cron: &quot;0 0 1 * *&quot;<br> <br>permissions:<br>  contents: write<br>  pull-requests: write<br> <br>jobs:<br>  components:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Check out code<br>        uses: actions/checkout@v4<br>      - name: Setup Flux CLI<br>        uses: fluxcd/flux2/action@main<br>      - name: Check for updates<br>        id: update<br>        run: |<br>          flux install \<br>            --components=&quot;source-controller,kustomize-controller,helm-controller,notification-controller&quot; \<br>            --components-extra=&quot;image-reflector-controller,image-automation-controller&quot; \<br>            --export &gt; ./cluster/default/flux-system/gotk-components.yaml<br> <br>          VERSION=&quot;$(flux -v)&quot;<br>          echo &quot;flux_version=$VERSION&quot; &gt;&gt; $GITHUB_OUTPUT                    <br>      - name: Create Pull Request<br>        uses: peter-evans/create-pull-request@v7<br>        with:<br>            branch: update-flux<br>            commit-message: Update to ${{ steps.update.outputs.flux_version }}<br>            title: Update to ${{ steps.update.outputs.flux_version }}<br>            body: |<br>              ${{ steps.update.outputs.flux_version }}</pre><p>This workflow will execute either on-demand through manual triggering or automatically on the first day of each month. When new versions of FluxCD components are detected, it generates a pull request with the updated manifests, facilitating a controlled review and deployment process.</p><blockquote><strong><em>Important:</em></strong><em> Ensure that the </em><em>--components and </em><em>--components-extra flags precisely match those used during your initial FluxCD installation as documented in </em><a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-1/"><em>Kubernetes GitOps with FluxCD - Part 1 - Initial Setup</em></a><em>.</em></blockquote><p>After pushing these changes to our repository, we can verify the workflow’s effectiveness by manually triggering it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nSHWHvoJ7OXUFrTT.png" /></figure><p>As demonstrated in the screenshot, the workflow has successfully detected and proposed an update to FluxCD version 2.5.1, creating a pull request that can be reviewed and merged through our standard governance process.</p><h3>References</h3><ul><li>Official FluxCD Documentation — <a href="https://fluxcd.io/flux/flux-gh-action/">https://fluxcd.io/flux/flux-gh-action/</a></li><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li></ul><p><em>Originally published at </em><a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-7/"><em>apurv.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd324679ae6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes GitOps with FluxCD — Part 6 — Push-based Reconciliation with Webhook Receivers]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-gitops-with-fluxcd-part-6-push-based-reconciliation-with-webhook-receivers-7cacc0c3e7ec?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/7cacc0c3e7ec</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[webhooks]]></category>
            <category><![CDATA[flux-cd]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 20:25:18 GMT</pubDate>
            <atom:updated>2026-11-17T10:01:03.148Z</atom:updated>
            <content:encoded><![CDATA[<p>In our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-5/">previous post</a>, we set up Discord alerts to get notifications about our cluster’s status. Building on what we’ve learned so far — <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-1/">basic FluxCD setup</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/">SOPS-based secret management</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-3/">image update automation</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-4/">Helm chart automation</a>, and <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-5/">alerts</a> — this article focuses on <strong>webhook receivers</strong>.</p><p>By default, FluxCD polls Git repositories at the configured frequency to detect changes. With webhook receivers, your Git provider can notify FluxCD immediately when changes occur, ensuring the reconciliation process doesn’t have to wait for the next scheduled polling interval. This significantly expedites deployments and enhances overall cluster efficiency.</p><p>Let’s configure webhook receivers for our Kubernetes cluster.</p><h3>1. Setup Webhook Secret</h3><p>First, we’ll generate a cryptographically secure random secret which will be configured in both the FluxCD webhook receiver and GitHub webhooks.</p><p>We’ll create cluster/default/github-webhook-token.yaml</p><pre>TOKEN=$(openssl rand 24 | sha256sum -b | awk &#39;{print $1}&#39;)<br> <br>kubectl create secret generic github-webhook-token \<br>  --namespace=flux-system \<br>  --from-literal=token=$TOKEN \<br>  --dry-run=client -o yaml &gt; github-webhook-token.yaml</pre><p>Take note of the TOKEN variable (e.g., using echo $TOKEN) which we’ll later configure in GitHub.</p><p>The generated YAML file would look like:</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: github-webhook-token<br>  namespace: flux-system<br>data:<br>  token: &lt;base64 encoded token&gt;</pre><p>Now let’s encrypt this secret with SOPS and publish changes to our Git repository.</p><p>Let’s confirm if the secret is created:</p><pre>kubectl -n flux-system get secrets <br> <br>NAME                     TYPE     DATA   AGE<br>discord-webhook-secret   Opaque   1      3d20h<br>flux-system              Opaque   3      4d21h<br>github-webhook-token     Opaque   1      9s<br>sops-gpg                 Opaque   1      5d21h</pre><p>As we can see, the token secret has been successfully created.</p><blockquote><strong><em>Note:</em></strong><em> For detailed instructions on secret management, refer to </em><a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/"><em>Kubernetes GitOps with FluxCD — Part 2 — Secret Management using SOPS</em></a><em>.</em></blockquote><h3>2. Setup FluxCD Webhook Receiver</h3><p>The next step is to configure the webhook receiver in FluxCD.</p><p>Let’s define it for our cluster’s flux-system repository.</p><p>Create cluster/default/flux-system/webhook-receiver.yaml</p><pre>apiVersion: notification.toolkit.fluxcd.io/v1<br>kind: Receiver<br>metadata:<br>  name: flux-system<br>  namespace: flux-system<br>spec:<br>  type: github<br>  events:<br>    - &quot;ping&quot;<br>    - &quot;push&quot;<br>  secretRef:<br>    name: github-webhook-token<br>  resources:<br>    - kind: GitRepository<br>      name: flux-system</pre><p>Modify cluster/default/flux-system/kustomization.yaml:</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>resources:<br>  - gotk-components.yaml<br>  - gotk-sync.yaml<br>+ - webhook-receiver.yaml<br>patches:<br>  - patch: |-<br>      apiVersion: kustomize.toolkit.fluxcd.io/v1<br>      kind: Kustomization<br>      metadata:<br>        name: flux-system<br>        namespace: flux-system<br>      spec:<br>        decryption:<br>          provider: sops<br>          secretRef:<br>            name: sops-gpg</pre><p>Let’s push these changes and observe if the webhook receiver is registered:</p><pre>flux get receivers <br> <br>NAME            SUSPENDED       READY   MESSAGE                                                                                               <br>flux-system     False           True    Receiver initialized for path: /hook/2524a3ab747c79f26105e00e224d9d212558c1145ad3192ee59e1d6529f0bf0</pre><p>Take note of the path, which we’ll configure in GitHub.</p><p>As we can see, the receiver is successfully initialized and the webhook path is configured.</p><h3>3. Setup Ingress</h3><p>So far we have configured the receiver, but GitHub webhooks require a public endpoint for our webhook receiver. Let’s configure an ingress for the flux webhook receiver service.</p><p>Create cluster/default/flux-system/ingress.yaml:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: webhook-receiver<br>  namespace: flux-system<br>  annotations:<br>    external-dns.alpha.kubernetes.io/target: &quot;XXXXXX&quot;<br>    cert-manager.io/cluster-issuer: &quot;cluster-issuer&quot;<br>spec:<br>  tls:<br>  - hosts:<br>    - flux-wh.XXXXX<br>    secretName: flux-ingress-cert<br>  rules:<br>  - host: flux-wh.XXXX<br>    http:<br>      paths:<br>      - pathType: Prefix<br>        path: /<br>        backend:<br>          service:<br>            name: webhook-receiver<br>            port:<br>              number: 80<br>---<br>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: allow-acme-issuer<br>  namespace: flux-system<br>spec:<br>  podSelector:<br>    matchLabels:<br>      acme.cert-manager.io/http01-solver: &quot;true&quot;<br>    ingress:<br>    - from:<br>      - namespaceSelector: {}<br>    policyTypes:<br>      - Ingress</pre><p>Since the flux-system namespace implements strict NetworkPolicies, we need to allow our ACME resolver to be reachable through ingress. Hence, we’ve configured an additional NetworkPolicy.</p><blockquote><strong><em>Note:</em></strong><em> For detailed instructions on automated DNS configuration refer to </em><a href="https://apurv.me/posts/kubernetes-setup-external-dns/"><em>Kubernetes — Setup External DNS</em></a><em>, and TLS management refer to </em><a href="https://apurv.me/posts/kubernetes-setup-cert-manager-automated-tls-management/"><em>Kubernetes — Setup Cert Manager for Automated TLS Management</em></a><em>.</em></blockquote><p>Modify cluster/default/flux-system/kustomization.yaml:</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>resources:<br>  - gotk-components.yaml<br>  - gotk-sync.yaml<br>  - webhook-receiver.yaml<br>+ - ingress.yaml<br>patches:<br>  - patch: |-<br>      apiVersion: kustomize.toolkit.fluxcd.io/v1<br>      kind: Kustomization<br>      metadata:<br>        name: flux-system<br>        namespace: flux-system<br>      spec:<br>        decryption:<br>          provider: sops<br>          secretRef:<br>            name: sops-gpg</pre><p>Let’s push these changes and verify if the ingress is operational:</p><pre>kubectl -n flux-system get ingress<br> <br>NAME               CLASS   HOSTS                   ADDRESS                     PORTS     AGE<br>webhook-receiver   nginx   flux-wh.XXX   192.168.1.19,192.168.1.24   80, 443   69m</pre><p>As we can see, the ingress is up and running. Now let’s check if our domain is reachable:</p><pre>curl https://flux-wh.XXX<br> <br>404 page not found</pre><p>We can successfully reach our webhook endpoint. The 404 response is expected since we’re not hitting a specific webhook path.</p><h3>4. Setup Github Webhooks</h3><p>Now let’s use the secret token, endpoint, and webhook path we’ve configured to set up a webhook in GitHub:</p><h3>5. Verify Setup</h3><p>Let’s modify our sample app and increase the CPU limits in apps/sample-app/deployment.yaml:</p><pre>apiVersion: apps/v1<br>metadata:<br>  name: sample-app<br>  namespace: default<br>kind: Deployment<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: sample-app<br>  template:<br>    metadata:<br>      labels:<br>        app: sample-app<br>    spec:<br>      imagePullSecrets:<br>        - name: github-registry-secret<br>      containers:<br>        - name: sample-app<br>          image: ghcr.io/kiriapurv/k8s-sample-app:main-29e96d2a-1740565130 # {&quot;$imagepolicy&quot;: &quot;default:sample-app-main-policy&quot;}<br>          imagePullPolicy: Always<br>          ports:<br>            - containerPort: 8080<br>          resources:<br>            requests:<br>              memory: &quot;128Mi&quot;<br>              cpu: &quot;50m&quot;<br>            limits:<br>              memory: &quot;128Mi&quot;<br>-             cpu: &quot;50m&quot;<br>+             cpu: &quot;150m&quot;</pre><p>Let’s push our changes and verify if the webhook is working:</p><p>The webhook has been delivered successfully, and reconciliation has been triggered immediately, demonstrating the push-based model in action.</p><h3>6. Setup Image Repository</h3><p>We can follow similar steps to set up a webhook for the image repository of our sample app. This ensures that the automated image updates we implemented in <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-3/">Kubernetes GitOps with FluxCD — Part 3 — Automated Image Updates</a> can be instantly reconciled.</p><p>For the image repository, here’s the YAML configuration:</p><pre>apiVersion: notification.toolkit.fluxcd.io/v1<br>kind: Receiver<br>metadata:<br>  name: sample-app<br>  namespace: default<br>spec:<br>  type: github<br>  events:<br>    - &quot;ping&quot;<br>    - &quot;package&quot;<br>  secretRef:<br>    name: github-webhook-token<br>  resources:<br>    - kind: ImageRepository<br>      name: sample-app</pre><p>This configuration listens for package events, which are triggered when new container images are published to the GitHub Container Registry.</p><h3>What next ?</h3><p>Future posts will explore advanced GitOps patterns with FluxCD, including:</p><ul><li>Miscellaneous FluxCD Configurations</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Official FluxCD Documentation — <a href="https://fluxcd.io/flux/guides/webhook-receivers/">https://fluxcd.io/flux/guides/webhook-receivers/</a></li><li>GitHub Webhooks Documentation — <a href="https://docs.github.com/en/developers/webhooks-and-events/webhooks/about-webhooks">https://docs.github.com/en/developers/webhooks-and-events/webhooks/about-webhooks</a></li><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li></ul><p><em>Originally published at </em><a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-6/"><em>apurv.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7cacc0c3e7ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes — Setup Cert Manager for Automated TLS Management]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-setup-cert-manager-for-automated-tls-management-2a40e997fd24?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a40e997fd24</guid>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[cert-manager]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Fri, 28 Feb 2025 20:26:09 GMT</pubDate>
            <atom:updated>2026-11-13T10:01:03.508Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is part of our ongoing series on Kubernetes infrastructure management. In this installment, we’re focusing on setting up Cert Manager, a critical component for automating TLS certificate management. Although we’re working on a local Kubernetes cluster, we’ve implemented prerequisites in <a href="https://apurv.me/posts/kubernetes-routing-external-traffic-to-local-cluster/">Kubernetes — Routing external traffic to local Kubernetes cluster</a> to enable access to our internal cluster via public IP address, as well as configuring DNS automation with <a href="https://apurv.me/posts/kubernetes-setup-external-dns/">Kubernetes — Setup External DNS</a>.</p><h3>1. Setup Cert Manager</h3><p>Let’s configure Cert Manager by creating cluster/default/cert-manager.yaml. This declarative configuration establishes:</p><ul><li>A dedicated Cert Manager namespace</li><li>The Jetstack Helm Repository reference</li><li>The Cert Manager Helm Release with appropriate configuration</li></ul><pre>---<br>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: cert-manager<br>---<br>apiVersion: source.toolkit.fluxcd.io/v1<br>kind: HelmRepository<br>metadata:<br>  name: jetstack<br>  namespace: cert-manager<br>spec:<br>  interval: 10m<br>  url: https://charts.jetstack.io<br>---<br>apiVersion: helm.toolkit.fluxcd.io/v2<br>kind: HelmRelease<br>metadata:<br>  name: cert-manager<br>  namespace: cert-manager<br>spec:<br>  releaseName: cert-manager<br>  interval: 10m<br>  chart:<br>    spec:<br>      chart: cert-manager<br>      version: &quot;1.16&quot;<br>      interval: 10m<br>      sourceRef:<br>        kind: HelmRepository<br>        name: jetstack<br>        namespace: cert-manager<br>  values:<br>    crds:<br>      enabled: true<br>    prometheus:<br>      enabled: true<br>      podmonitor:<br>        enabled: true</pre><p>Next, we’ll define a ClusterIssuer that integrates with Let’s Encrypt to provide our certificates. Create this in cluster/default/cluster-issuer.yaml</p><pre>apiVersion: cert-manager.io/v1<br>kind: ClusterIssuer<br>metadata:<br>  name: cluster-issuer<br>  namespace: cert-manager<br>spec:<br>  acme:<br>    # The ACME server URL<br>    server: https://acme-v02.api.letsencrypt.org/directory<br>    # Email address used for ACME registration<br>    email: ****<br>    # Name of a secret used to store the ACME account private key<br>    privateKeySecretRef:<br>      name: letsencrypt-default<br>    solvers:<br>    - http01:<br>        ingress:<br>          ingressClassName: traefik</pre><p>After applying these configurations, let’s verify that the necessary secret keys have been generated and check for any potential errors:</p><pre>kubectl -n cert-manager get secrets<br> <br>NAME                                 TYPE                 DATA   AGE<br>cert-manager-webhook-ca              Opaque               3      5m31s<br>letsencrypt-default                  Opaque               1      3m39s<br>sh.helm.release.v1.cert-manager.v1   helm.sh/release.v1   1      6m1s</pre><p>We can confirm that the secret has been successfully generated. Now, let’s examine the logs for further diagnostics:</p><pre>kubectl -n cert-manager logs pods/cert-manager-84d588f4c6-gj6d4<br> <br>I0228 12:33:21.941719       1 setup.go:113] &quot;generating acme account private key&quot; logger=&quot;cert-manager.controller&quot; resource_name=&quot;cluster-issuer&quot; resource_namespace=&quot;&quot; resource_kind=&quot;ClusterIssuer&quot; resource_version=&quot;v1&quot; related_resource_name=&quot;letsencrypt-default&quot; related_resource_namespace=&quot;cert-manager&quot; related_resource_kind=&quot;Secret&quot;<br>I0228 12:33:22.042104       1 setup.go:225] &quot;ACME server URL host and ACME private key registration host differ. Re-checking ACME account registration&quot; logger=&quot;cert-manager.controller&quot; resource_name=&quot;cluster-issuer&quot; resource_namespace=&quot;&quot; resource_kind=&quot;ClusterIssuer&quot; resource_version=&quot;v1&quot; related_resource_name=&quot;letsencrypt-default&quot; related_resource_namespace=&quot;cert-manager&quot; related_resource_kind=&quot;Secret&quot;<br>I0228 12:33:23.515859       1 setup.go:315] &quot;verified existing registration with ACME server&quot; logger=&quot;cert-manager.controller&quot; resource_name=&quot;cluster-issuer&quot; resource_namespace=&quot;&quot; resource_kind=&quot;ClusterIssuer&quot; resource_version=&quot;v1&quot; related_resource_name=&quot;letsencrypt-default&quot; related_resource_namespace=&quot;cert-manager&quot; related_resource_kind=&quot;Secret&quot;<br>I0228 12:33:23.516047       1 conditions.go:96] Setting lastTransitionTime for Issuer &quot;cluster-issuer&quot; condition &quot;Ready&quot; to 2025-02-28 12:33:23.515998646 +0000 UTC m=+120.676709968<br>I0228 12:33:23.526676       1 setup.go:208] &quot;skipping re-verifying ACME account as cached registration details look sufficient&quot; logger=&quot;cert-manager.controller&quot; resource_name=&quot;cluster-issuer&quot; resource_namespace=&quot;&quot; resource_kind=&quot;ClusterIssuer&quot; resource_version=&quot;v1&quot; related_resource_name=&quot;letsencrypt-default&quot; related_resource_namespace=&quot;cert-manager&quot; related_resource_kind=&quot;Secret&quot;<br>I0228 12:33:27.046621       1 setup.go:208] &quot;skipping re-verifying ACME account as cached registration details look sufficient&quot; logger=&quot;cert-manager.controller&quot; resource_name=&quot;cluster-issuer&quot; resource_namespace=&quot;&quot; resource_kind=&quot;ClusterIssuer&quot; resource_version=&quot;v1&quot; related_resource_name=&quot;letsencrypt-default&quot; related_resource_namespace=&quot;cert-manager&quot; related_resource_kind=&quot;Secret&quot;</pre><p>The logs indicate that our configuration is functioning correctly, with the ACME account successfully registered with Let’s Encrypt.</p><h3>2. Validate Setup</h3><p>To validate our Cert Manager implementation, let’s enhance our existing sample application from the <a href="https://apurv.me/posts/kubernetes-setup-external-dns/">Kubernetes — Setup External DNS</a> guide by adding TLS configuration. We’ll modify apps/sample-app/ingress.yaml:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: sample-app-ingress<br>  namespace: default<br>  annotations:<br>    cert-manager.io/cluster-issuer: &quot;cluster-issuer&quot;<br>    external-dns.alpha.kubernetes.io/target: &quot;******&quot;<br>spec:<br>  tls:<br>  - hosts:<br>    - sample-app.**<br>    secretName: sample-app-tls<br>  rules:<br>    - host: sample-app.***<br>      http:<br>        paths:<br>          - pathType: Prefix<br>            backend:<br>              service:<br>                name: sample-app-service<br>                port:<br>                  number: 80<br>            path: /</pre><p>After committing these changes, let’s verify that HTTPS access to our application is working correctly:</p><pre>curl https://sample-app.***<br> <br>Greetings From K8S App : Version 2</pre><p>Now, let’s perform a deeper inspection of the certificate to ensure it’s properly issued and configured:</p><pre>openssl s_client -showcerts -connect sample-app.***:443<br> <br>Connecting to 15.235.210.126<br>CONNECTED(00000003)<br>depth=2 C=US, O=Internet Security Research Group, CN=ISRG Root X1<br>verify return:1<br>depth=1 C=US, O=Let&#39;s Encrypt, CN=R11<br>verify return:1<br>depth=0 CN=sample-app.***.email<br>verify return:1<br>---<br>Certificate chain<br> 0 s:CN=sample-app.***.email<br>   i:C=US, O=Let&#39;s Encrypt, CN=R11<br>   a:PKEY: rsaEncryption, 2048 (bit); sigalg: RSA-SHA256<br>   v:NotBefore: Feb 28 11:44:22 2025 GMT; NotAfter: May 29 11:44:21 2025 GMT</pre><p>The output confirms that SSL/TLS requests are working correctly, with a valid certificate issued by Let’s Encrypt that will remain valid for approximately 90 days.</p><h3>3. Monitoring in Grafana</h3><p>In our previous post <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-4/">Kubernetes GitOps with FluxCD — Part 4 — Helm Chart Automation — Kube Prometheus Stack</a> we deployed the Kube Prometheus Stack which can automatically collect metrics from Cert Manager since we configured our Helm release with podmonitor enabled. Let’s now establish comprehensive certificate monitoring by integrating a specialized Grafana dashboard from the <a href="https://gitlab.com/uneeq-oss/cert-manager-mixin/">Cert Manager Mixin</a> project.</p><p>We’ll begin by downloading the pre-configured dashboard JSON:</p><pre>curl --output cert-manager.json https://gitlab.com/uneeq-oss/cert-manager-mixin/-/raw/master/dashboards/cert-manager.json?ref_type=heads</pre><p>Next, we’ll create a ConfigMap with the grafana_dashboard: 1 label, which will trigger automatic dashboard integration. Create dashboards/kustomization.yaml:</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>namespace: monitoring<br>configMapGenerator:<br>  - name: monitoring-grafana-dashboards<br>    files:<br>      - cert-manager.json<br>    options:<br>      labels:<br>        grafana_dashboard: &quot;1&quot;</pre><p>Finally, we’ll define a Flux Kustomization to manage this dashboard resource by creating cluster/default/dashboards.yaml</p><pre>apiVersion: kustomize.toolkit.fluxcd.io/v1<br>kind: Kustomization<br>metadata:<br>  name: dashboards<br>  namespace: monitoring<br>spec:<br>  interval: 5m<br>  path: ./dashboards<br>  prune: true<br>  retryInterval: 2m<br>  sourceRef:<br>    kind: GitRepository<br>    name: flux-system<br>    namespace: flux-system<br>  targetNamespace: monitoring<br>  timeout: 3m<br>  wait: true</pre><p>After committing these changes, let’s verify that the ConfigMap has been generated successfully:</p><pre>kubectl -n monitoring get configmaps <br> <br>NAME                                                      DATA   AGE<br>monitoring-grafana-dashboards-9dbtc2728b                  1      37s</pre><p>To access and validate the Grafana dashboard, we’ll establish a port-forward to the Grafana service:</p><pre>kubectl -n monitoring port-forward service/kube-prometheus-stack-grafana 3000:80<br> <br>Forwarding from 127.0.0.1:3000 -&gt; 3000<br>Forwarding from [::1]:3000 -&gt; 3000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aGuptiLycIKjpelj.png" /></figure><p>The dashboard allows us to comprehensively monitor certificate lifecycle events, including issuance, renewal schedules, and potential validation errors — enabling proactive certificate management.</p><h3>What next ?</h3><p>Future posts will explore advanced Kubernetes and GitOps patterns with FluxCD, including:</p><ul><li>Push based reconciliation triggers with Webhook receivers for FluxCD</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li><li>Cert Manager Documentation — <a href="https://cert-manager.io/">https://cert-manager.io/</a></li><li>Cert Manager Mixin — <a href="https://gitlab.com/uneeq-oss/cert-manager-mixin">https://gitlab.com/uneeq-oss/cert-manager-mixin</a></li><li>FluxCD Documentation — <a href="https://fluxcd.io/docs/">https://fluxcd.io/docs/</a></li></ul><p><em>Originally published at </em><a href="https://apurv.me/posts/kubernetes-setup-cert-manager-automated-tls-management/"><em>apurv.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a40e997fd24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes — Routing external traffic to local Kubernetes cluster]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-routing-external-traffic-to-local-kubernetes-cluster-fda1287d0a2b?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/fda1287d0a2b</guid>
            <category><![CDATA[wireguard]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[homelab]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Thu, 27 Feb 2025 20:26:09 GMT</pubDate>
            <atom:updated>2026-11-06T10:01:03.752Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is part of our ongoing DevOps series focused on Kubernetes and GitOps practices. So far, we’ve explored various aspects of DevOps with FluxCD, and our upcoming posts will cover application deployment strategies in Kubernetes.</p><p>A significant challenge when working with a local Kubernetes environment (like our K3s setup) is the lack of public network access, which is automatically handled in managed Kubernetes offerings from cloud providers. For locally hosted clusters, establishing secure public connectivity is essential for many real-world scenarios.</p><p>This post addresses this specific challenge: <strong>how to expose services from your local Kubernetes cluster to the internet</strong>. The solution we’ll implement involves a public-facing cloud server with HAProxy for Layer 4 load balancing, connected to our local cluster nodes through an encrypted Wireguard tunnel. This networking foundation will enable several advanced configurations in future posts, including:</p><ul><li>Exposing applications to the public internet through Ingress</li><li>Setting up automatic DNS management with external-dns</li><li>Implementing automated TLS certificate provisioning with cert-manager</li><li>Configuring authentication and access control for your exposed services</li></ul><p><strong>Note</strong>: This setup is primarily intended for homelab or self-hosted Kubernetes environments. If you’re using a managed Kubernetes service like GKE, EKS, or AKS, this specific configuration is unnecessary as these platforms provide their own load balancing and ingress solutions.</p><h3>1. Setup Wireguard on Server</h3><p>First, install the Wireguard package:</p><pre>apt install -y wireguard</pre><p>Generate a cryptographic key pair:</p><pre>wg genkey | tee /etc/wireguard/privatekey | wg pubkey &gt; /etc/wireguard/publickey</pre><p>Configure the wg0 interface by creating /etc/wireguard/wg0.conf</p><pre>[Interface]<br>PrivateKey = ***<br>Address = 10.0.0.1/24<br>ListenPort = 51820<br>SaveConfig = true<br> <br>[Peer]<br>PublicKey = ***<br>AllowedIPs = 10.0.0.2/32<br>PersistentKeepalive = 25<br> <br>[Peer]<br>PublicKey = ***<br>AllowedIPs = 10.0.0.2/32<br>PersistentKeepalive = 25</pre><p>Activate and enable the Wireguard service:</p><pre>systemctl enable --now wg-quick@wg0.service</pre><p>Verify that the interface is operational:</p><pre>ip link list<br> <br>1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000<br>    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00<br>2: ens3: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000<br>    link/ether fa:16:3e:d7:81:4e brd ff:ff:ff:ff:ff:ff<br>    altname enp0s3<br>3: wg0: &lt;POINTOPOINT,NOARP,UP,LOWER_UP&gt; mtu 1420 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000<br>    link/none</pre><p>As we can see, the wg0 interface is successfully established.</p><h3>2. Setup Wireguard on Kubernetes Nodes</h3><p>For our Kubernetes nodes, we’re using MicroOS with K3s. Install the Wireguard tools:</p><pre>transactional-update pkg in wireguard-tools</pre><p>Generate key pairs and configure the wg0 interface by creating /etc/wireguard/wg0.conf on each node:</p><p>On Node 1:</p><pre>[Interface]<br>PrivateKey = ***<br>Address = 10.0.0.2/24<br> <br>[Peer]<br>PublicKey = ***<br>Endpoint = ***:51820<br>AllowedIPs = 0.0.0.0/0<br>PersistentKeepalive = 25</pre><p>On Node 2:</p><pre>[Interface]<br>PrivateKey = ***<br>Address = 10.0.0.2/24<br> <br>[Peer]<br>PublicKey = ***<br>Endpoint = ***:51820<br>AllowedIPs = 0.0.0.0/0<br>PersistentKeepalive = 25</pre><p>Enable and start the Wireguard interface:</p><pre>systemctl enable --now wg-quick@wg0.service</pre><p>Verify connectivity from each node to the server:</p><pre>ping 10.0.0.1<br> <br>PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.<br>64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=138 ms<br>64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=67.4 ms<br>64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=68.0 ms</pre><p>Verify connectivity from the server to each node:</p><pre>ping 10.0.0.2<br> <br>PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.<br>64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=71.6 ms<br>64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=68.7 ms<br>64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=68.1 ms</pre><pre>ping 10.0.0.3<br> <br>PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.<br>64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=81.8 ms<br>64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=78.9 ms<br>64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=77.9 ms</pre><h3>3. Configure HAProxy Layer 4 LoadBalancer</h3><p>Install HAProxy on the server:</p><pre>apt install -y haproxy</pre><p>Configure HAProxy by editing /etc/haproxy/haproxy.cfg</p><pre>frontend http_frontend<br>    bind *:80<br>    mode tcp<br>    option tcplog<br>    default_backend http_backend<br> <br>backend http_backend<br>    mode tcp<br>    balance roundrobin<br>    option tcp-check<br>    server node1 10.0.0.2:80 check<br>    server node2 10.0.0.3:80 check<br> <br>frontend https_frontend<br>    bind *:443<br>    mode tcp<br>    option tcplog<br>    default_backend https_backend<br> <br>backend https_backend<br>    mode tcp<br>    balance roundrobin<br>    option tcp-check<br>    server node1 10.0.0.2:443 check<br>    server node2 10.0.0.3:443 check</pre><p>Restart HAProxy to apply the configuration:</p><pre>systemctl restart haproxy</pre><p>Verify that traffic is properly forwarded by sending a request to the server’s public IP address from our local machine:</p><pre>curl http://$PUBLIC_IP<br> <br>404 page not found</pre><p>The “404 page not found” response confirms that traffic is successfully reaching our Kubernetes cluster. This error is expected and actually indicates success, as the request is properly reaching the Kubernetes ingress controller, which doesn’t have any routes configured yet.</p><h3>Conclusion</h3><p>We have successfully set up a secure tunnel between our public-facing server and our local Kubernetes cluster nodes using Wireguard. The HAProxy configuration routes all HTTP and HTTPS traffic to our cluster nodes in a load-balanced manner. This setup allows us to expose services from our local Kubernetes cluster to the internet with minimal configuration.</p><p>This foundation is critical for the GitOps-driven application deployments we’ll be implementing in upcoming posts in this series. With this networking infrastructure in place, we can now focus on automating application deployments with FluxCD while ensuring they’re securely accessible from the internet. Stay tuned for our next post on configuring Push based deployments with FluxCD, configuring external-dns and cert-manager to work with this setup.</p><p><em>Originally published at </em><a href="https://apurv.me/posts/kubernetes-routing-external-traffic-to-local-cluster/"><em>apurv.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fda1287d0a2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes — Setup External DNS]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-setup-external-dns-c0bd9df72559?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0bd9df72559</guid>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Thu, 27 Feb 2025 20:25:54 GMT</pubDate>
            <atom:updated>2026-11-10T10:01:03.228Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is part of our ongoing series of posts for Kubernetes. In this post we are focusing on setting up External DNS, a critical component for automating DNS record management. Although we are working on a local Kubernetes cluster, we have implemented prerequisites in <a href="https://apurv.me/posts/kubernetes-routing-external-traffic-to-local-cluster/">Kubernetes — Routing external traffic to local Kubernetes cluster</a> to enable access to our internal cluster via public ip.</p><p>We are using Cloudflare as our DNS Provider and implementing this solution using declarative GitOps principles with Flux.</p><h3>1. Setup Cloudflare API Key</h3><p>First, let’s generate an API key from Cloudflare by navigating to Manage Account &gt; Account API Tokens in the Cloudflare dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZjnP4QotoX_zouwN.png" /></figure><p>We’ll choose Edit DNS template and generate token for a specific zone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LuEcQjxIJAD6Y1je.png" /></figure><h3>2. Setup Kubernetes Secret</h3><p>Now we’ll configure a Kubernetes secret by creating cluster/default/cloudflare-token.yaml</p><blockquote><strong><em>Note:</em></strong><em> If you’re unfamiliar with YAML path conventions and definitions, please refer to our guide on GitOps with FluxCD: </em><a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-1/"><em>Kubernetes GitOps with FluxCD — Part 1 — Initial Setup</em></a><em>.</em></blockquote><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: cloudflare-token<br>  namespace: kube-system<br>type: Opaque<br>stringData:<br>  CF_API_TOKEN: ***<br>  CF_API_EMAIL: ***</pre><p>Let’s encrypt this sensitive data with SOPS and commit the changes to our Git repository.</p><blockquote><strong><em>Note:</em></strong><em> For detailed instructions on secret management, refer to </em><a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/"><em>Kubernetes GitOps with FluxCD — Part 2 — Secret Management using SOPS</em></a><em>.</em></blockquote><h3>4. Setup External DNS</h3><p>Now we’ll configure the External DNS deployment by creating cluster/default/external-dns.yaml</p><pre>---<br>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  name: external-dns<br>  namespace: kube-system<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRole<br>metadata:<br>  name: external-dns<br>rules:<br>- apiGroups: [&quot;&quot;]<br>  resources: [&quot;services&quot;,&quot;endpoints&quot;,&quot;pods&quot;]<br>  verbs: [&quot;get&quot;,&quot;watch&quot;,&quot;list&quot;]<br>- apiGroups: [&quot;extensions&quot;,&quot;networking.k8s.io&quot;]<br>  resources: [&quot;ingresses&quot;]<br>  verbs: [&quot;get&quot;,&quot;watch&quot;,&quot;list&quot;]<br>- apiGroups: [&quot;&quot;]<br>  resources: [&quot;nodes&quot;]<br>  verbs: [&quot;list&quot;,&quot;watch&quot;]<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRoleBinding<br>metadata:<br>  name: external-dns-viewer<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: external-dns<br>subjects:<br>- kind: ServiceAccount<br>  name: external-dns<br>  namespace: kube-system<br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: external-dns<br>  namespace: kube-system<br>spec:<br>  strategy:<br>    type: Recreate<br>  selector:<br>    matchLabels:<br>      app: external-dns<br>  template:<br>    metadata:<br>      labels:<br>        app: external-dns<br>    spec:<br>      serviceAccountName: external-dns<br>      containers:<br>      - name: external-dns<br>        image: k8s.gcr.io/external-dns/external-dns:v0.14.2<br>        args:<br>        - --source=ingress<br>        - --domain-filter=***<br>        - --provider=cloudflare<br>        resources:<br>          requests:<br>            memory: &quot;64Mi&quot;<br>            cpu: &quot;20m&quot;<br>          limits:<br>            memory: &quot;256Mi&quot;<br>            cpu: &quot;200m&quot;<br>        env:<br>        - name: CF_API_TOKEN<br>          valueFrom:<br>            secretKeyRef:<br>              name: cloudflare-token<br>              key: CF_API_TOKEN<br>        - name: CF_API_EMAIL<br>          valueFrom:<br>            secretKeyRef:<br>              name: cloudflare-token<br>              key: CF_API_EMAIL</pre><h4>Explanation of External DNS Configuration</h4><p>This YAML manifest consists of four Kubernetes resources that work together to enable automatic DNS record management:</p><ol><li><strong>ServiceAccount</strong>:</li></ol><ul><li>Creates a dedicated service account named external-dns in the kube-system namespace</li><li>This provides an identity for the External DNS process to operate within the cluster</li></ul><ol><li><strong>ClusterRole</strong>:</li></ol><ul><li>Defines the permissions required by External DNS to function properly</li><li>Allows read-only access (get, watch, list) to:</li><li>Services, endpoints, and pods: To monitor for changes to service endpoints</li><li>Ingresses: To detect new or modified ingress resources</li><li>Nodes: To gather information about the cluster nodes</li></ul><ol><li><strong>ClusterRoleBinding</strong>:</li></ol><ul><li>Associates the previously defined external-dns ClusterRole with the external-dns ServiceAccount</li><li>This binding effectively grants the External DNS service the permissions it needs</li></ul><ol><li><strong>Deployment</strong>:</li></ol><ul><li>Creates the actual External DNS controller pod with specific configuration:</li><li>Uses the Recreate strategy to ensure clean upgrades</li><li>Deploys the official k8s.gcr.io/external-dns/external-dns:v0.14.2 image</li><li>Configures important command-line arguments:</li><li>--source=ingress: Instructs External DNS to watch for Ingress resources</li><li>--domain-filter=***: Limits DNS operations to a specific domain (redacted in the example)</li><li>--provider=cloudflare: Specifies Cloudflare as the DNS provider</li><li>Sets resource constraints to optimize performance:</li><li>Requests modest resources (64Mi memory, 20m CPU)</li><li>Sets reasonable limits (256Mi memory, 200m CPU)</li><li>Injects Cloudflare credentials from the previously created secret:</li><li>CF_API_TOKEN: Authentication token for Cloudflare API access</li><li>CF_API_EMAIL: Associated email for the Cloudflare account</li></ul><p>With this configuration, External DNS will continuously monitor the Kubernetes cluster for new or modified Ingress resources. When it detects changes, it automatically creates, updates, or deletes the corresponding DNS records in Cloudflare according to the annotations and specifications in those resources. This eliminates the need for manual DNS management and ensures that your services are always accessible via their correct domain names.</p><p>Let’s commit these changes to our Git repository and verify that External DNS is deployed successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HzjTw_G3wH3wGJHy.png" /></figure><p>As we can see from the notifications in Discord, External DNS has been configured successfully.</p><p>Let’s examine the pod status as well:</p><pre>kubectl -n kube-system get pods<br> <br>NAME                                      READY   STATUS      RESTARTS      AGE<br>coredns-ccb96694c-s67q5                   1/1     Running     4 (60m ago)   4d2h<br>external-dns-7cbfcc8d94-zwck7             1/1     Running     0             2m3s<br>helm-install-traefik-8q42l                0/1     Completed   1             4d2h<br>helm-install-traefik-crd-nq5tj            0/1     Completed   0             4d2h<br>local-path-provisioner-5cf85fd84d-pxdcv   1/1     Running     4 (60m ago)   4d2h<br>metrics-server-5985cbc9d7-qn4dr           1/1     Running     4 (60m ago)   4d2h<br>svclb-traefik-aadbbe88-gjtbx              2/2     Running     8 (60m ago)   4d2h<br>svclb-traefik-aadbbe88-vzd2t              2/2     Running     6 (60m ago)   4h10m<br>traefik-5d45fc8cc9-g97pg                  1/1     Running     4 (60m ago)   4d2h</pre><p>As confirmed, External DNS is up and running. Let’s verify the logs to ensure proper functionality:</p><pre>kubectl -n kube-system logs pod/external-dns-7cbfcc8d94-zwck7 <br> <br>time=&quot;2025-02-28T11:26:25Z&quot; level=info msg=&quot;Instantiating new Kubernetes client&quot;<br>time=&quot;2025-02-28T11:26:25Z&quot; level=info msg=&quot;Using inCluster-config based on serviceaccount-token&quot;<br>time=&quot;2025-02-28T11:26:25Z&quot; level=info msg=&quot;Created Kubernetes client https://10.43.0.1:443&quot;<br>time=&quot;2025-02-28T11:26:27Z&quot; level=info msg=&quot;All records are already up to date&quot;<br>time=&quot;2025-02-28T11:27:27Z&quot; level=info msg=&quot;All records are already up to date&quot;<br>time=&quot;2025-02-28T11:28:28Z&quot; level=info msg=&quot;All records are already up to date&quot;</pre><p>The logs indicate that External DNS is functioning properly.</p><h3>5. Verify Setup</h3><p>Now we’ll validate our setup by configuring an ingress for a sample application we created in <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-3/">Kubernetes GitOps with FluxCD — Part 3 — Automated Image Updates</a>.</p><p>First, let’s configure a service by creating apps/sample-app/service.yaml</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: sample-app-service<br>  namespace: default<br>spec:<br>  ports:<br>    - name: http<br>      protocol: TCP<br>      port: 80<br>      targetPort: 8080<br>  selector:<br>    app: sample-app</pre><p>Next, let’s configure the ingress by creating apps/sample-app/ingress.yaml</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: sample-app-ingress<br>  namespace: default<br>  annotations:<br>    external-dns.alpha.kubernetes.io/target: &quot;******&quot;<br>spec:<br>  rules:<br>    - host: sample-app.***<br>      http:<br>        paths:<br>          - pathType: Prefix<br>            backend:<br>              service:<br>                name: sample-app-service<br>                port:<br>                  number: 80<br>            path: /</pre><p>Since we’re working with a local cluster, we’ve implemented a solution to route external traffic to our cluster as detailed in <a href="https://apurv.me/posts/kubernetes-routing-external-traffic-to-local-cluster/">Kubernetes — Routing external traffic to local Kubernetes cluster</a>. The public IP of our external server is specified in the external-dns.alpha.kubernetes.io/target.</p><p>Now, let’s modify the kustomization file at apps/sample-app/kustomization.yaml</p><pre>apiVersion: kustomize.config.k8s.io/v1beta1<br>kind: Kustomization<br>resources:<br>   - deployment.yaml<br>+  - service.yaml<br>+  - ingress.yaml</pre><p>Let’s commit these changes and verify that External DNS has created the necessary DNS records:</p><pre>kubectl -n kube-system logs pod/external-dns-7cbfcc8d94-zwck7 <br> <br>time=&quot;2025-02-28T11:42:34Z&quot; level=info msg=&quot;Changing record.&quot; action=CREATE record=**** ttl=1 type=A zone=****<br>time=&quot;2025-02-28T11:42:35Z&quot; level=info msg=&quot;Changing record.&quot; action=CREATE record=**** ttl=1 type=TXT zone=****<br>time=&quot;2025-02-28T11:42:35Z&quot; level=info msg=&quot;Changing record.&quot; action=CREATE record=**** ttl=1 type=TXT zone=****</pre><p>The logs confirm that the DNS records have been successfully created.</p><p>Finally, let’s verify access to our application using curl:</p><pre>curl http://sample-app.**<br> <br>Greetings From K8S App : Version 2</pre><p>We have successfully configured External DNS, automating the creation and management of DNS records for our Kubernetes services.</p><h3>What next ?</h3><p>Future posts will explore advanced Kubernetes and GitOps patterns with FluxCD, including:</p><ul><li>Setting up Cert Manager</li><li>Push based reconciliation triggers with Webhook receivers for FluxCD</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li><li>External DNS Documentation — <a href="https://kubernetes-sigs.github.io/external-dns/latest/">https://kubernetes-sigs.github.io/external-dns/latest/</a></li><li>FluxCD Documentation — <a href="https://fluxcd.io/docs/">https://fluxcd.io/docs/</a></li></ul><p><em>Originally published at </em><a href="https://apurv.me/posts/kubernetes-setup-external-dns/"><em>apurv.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0bd9df72559" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes GitOps with FluxCD — Part 5 — Implementing Discord Alerts]]></title>
            <link>https://medium.com/@kiriappu/kubernetes-gitops-with-fluxcd-part-5-implementing-discord-alerts-8cad94a78047?source=rss-a7b5aee2f1db------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cad94a78047</guid>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[flux-cd]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[discord]]></category>
            <dc:creator><![CDATA[Apurv Kiri]]></dc:creator>
            <pubDate>Wed, 26 Feb 2025 20:26:09 GMT</pubDate>
            <atom:updated>2026-11-03T10:01:03.430Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-4/">previous post</a>, we explored how to setup helm chart automation with FluxCD, Building on our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-1/">foundation of basic Flux CD setup</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/">SOPS-based secret management</a>, <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-3/">image update automation</a> and <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-4/">Helm Chart Automation</a>, this article focuses on implementing <strong>FluxCD Alerts</strong> with Discord integration to enhance GitOps observability stack.</p><p>Alerts provide real-time notifications about the state of our GitOps operations, helping us respond promptly to issues and stay informed about successful reconciliations. Let’s dive into configuring in our Kubernetes cluster.</p><h3>1. Obtaining the Discord Webhook URL</h3><p>First, we need to acquire a Webhook URL from Discord:</p><ol><li>Navigate to your Discord server settings</li><li>Select “Integrations”</li><li>Click on “Webhooks”</li><li>Create a new webhook or use an existing one</li><li>Copy the generated webhook URL</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*MC33tegSTEtTJ4XD.png" /></figure><h3>2. Securely Store the Webhook URL</h3><p>Next, we’ll securely store the webhook URL as a Kubernetes secret by creating cluster/default/discord-webhook-secret.yaml:</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: discord-webhook-secret<br>  namespace: flux-system<br>type: Opaque<br>stringData:<br>  address: https://discordapp.com/api/webhooks/XXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</pre><p>Following our established security practices, we’ll encrypt this sensitive information with SOPS and commit the changes to our Git repository as detailed in our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-2/">SOPS-based secret management</a> post.</p><h3>3. Configuring Alert Resources</h3><p>With our webhook secured, we can now configure the alert resources. Create cluster/default/discord-alert.yaml with the following content:</p><pre>apiVersion: notification.toolkit.fluxcd.io/v1beta3<br>kind: Provider<br>metadata:<br>  name: discord<br>  namespace: flux-system<br>spec:<br>  type: discord<br>  secretRef:<br>    name: discord-webhook-secret<br>---<br>apiVersion: notification.toolkit.fluxcd.io/v1beta3<br>kind: Alert<br>metadata:<br>  name: discord-info-alert<br>  namespace: flux-system<br>spec:<br>  eventMetadata:<br>    cluster: &quot;default&quot;<br>  providerRef:<br>    name: discord<br>  eventSeverity: info<br>  eventSources:<br>    - kind: GitRepository<br>      name: &#39;*&#39;<br>    - kind: Kustomization<br>      name: &#39;*&#39;<br>    - kind: HelmRelease<br>      name: &#39;*&#39;<br>    - kind: ImageUpdateAutomation<br>      name: &#39;*&#39;</pre><p>This configuration creates two resources:</p><ul><li>A Provider that specifies Discord as our notification destination</li><li>An Alert that defines which events should trigger notifications</li></ul><p>As of the time of writing, FluxCD supports the following event sources (as referenced at <a href="https://pkg.go.dev/github.com/fluxcd/notification-controller/api/v1#CrossNamespaceObjectReference">https://pkg.go.dev/github.com/fluxcd/notification-controller/api/v1#CrossNamespaceObjectReference</a> )</p><ul><li>Bucket</li><li>GitRepository</li><li>Kustomization</li><li>HelmRelease</li><li>HelmChart</li><li>HelmRepository</li><li>ImageRepository</li><li>ImagePolicy</li><li>ImageUpdateAutomation</li><li>OCIRepository</li></ul><h3>4. Verifying the Configuration</h3><p>After committing these changes to Git and allowing FluxCD to reconcile them, let’s verify that our alerts are properly configured:</p><pre>flux get alerts<br> <br>NAME                    SUSPENDED       READY   MESSAGE        <br>discord-info-alert      False           True    Alert is Ready</pre><p>The READY status confirms that our alert configuration has been successfully applied.</p><h3>5. Testing the Alert System</h3><p>To validate that our alerts are functioning as expected, let’s trigger an event by removing a previously created resource. In this case, we’ll delete the nginx deployment we created during our <a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-1/">initial FluxCD setup</a>.</p><pre>rm cluster/default/nginx.yaml</pre><p>After committing and pushing this change, we should observe a notification in our Discord channel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WN0pOWGrEeL4i04e.png" /></figure><p>Success! We have received the notification, confirming that our alert system is operational and correctly integrated with Discord.</p><h4>Best Practices for FluxCD Alerts</h4><p>When implementing alerts in your GitOps workflow, consider these best practices:</p><ul><li><strong>Filter by Severity:</strong> Configure different alerts for various severity levels (info, error, warning) to avoid alert fatigue</li><li><strong>Use Namespaces:</strong> Organize alerts by namespace to better manage notifications in larger clusters</li><li><strong>Integration Options:</strong> Beyond Discord, consider integrating with other platforms like Slack, Microsoft Teams, or PagerDuty for comprehensive coverage</li><li><strong>Alert Routing:</strong> Route critical alerts to urgent channels and informational alerts elsewhere</li></ul><h3>What next ?</h3><p>In forthcoming articles, we’ll explore more advanced GitOps patterns with FluxCD, including:</p><ul><li>Push based reconciliation triggers with Webhook receivers</li></ul><p>Stay tuned for each of these topics.</p><h3>References</h3><ul><li>Official FluxCD Documentation — <a href="https://fluxcd.io/flux/monitoring/alerts/">https://fluxcd.io/flux/monitoring/alerts/</a></li><li>GitOps Working Group — <a href="https://opengitops.dev/">https://opengitops.dev</a></li><li>Kubernetes Documentation — <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a></li><li>FluxCD Notification Controller API — <a href="https://pkg.go.dev/github.com/fluxcd/notification-controller/api/v1">https://pkg.go.dev/github.com/fluxcd/notification-controller/api/v1</a></li><li>Discord Webhook Documentation — <a href="https://discord.com/developers/docs/resources/webhook">https://discord.com/developers/docs/resources/webhook</a></li></ul><p><em>Originally published at </em><a href="https://apurv.me/posts/kubernetes-gitops-with-fluxcd-part-5/"><em>apurv.me</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cad94a78047" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>