<?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 Zubair Haque on Medium]]></title>
        <description><![CDATA[Stories by Zubair Haque on Medium]]></description>
        <link>https://medium.com/@haque-zubair?source=rss-488c186c9d41------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mXsh4nm1VMhdDPBx1YXQbQ.jpeg</url>
            <title>Stories by Zubair Haque on Medium</title>
            <link>https://medium.com/@haque-zubair?source=rss-488c186c9d41------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:14:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@haque-zubair/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[Simplifying Observability with Loki and Fluent Bit]]></title>
            <link>https://haque-zubair.medium.com/simplifying-observability-with-loki-and-fluent-bit-206689a85e65?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/206689a85e65</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[loki]]></category>
            <category><![CDATA[logging-and-monitoring]]></category>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 15:39:48 GMT</pubDate>
            <atom:updated>2024-12-19T16:08:17.993Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*09hDwukdJhSwHUnVnJT30A.png" /></figure><p>Logging forms the backbone of understanding the heartbeat of our systems, especially when managing complex ETL data pipelines on a Kubernetes cluster. Our goal is always to ensure that every piece of data in the pipeline flows seamlessly across the platform. However, troubleshooting challenges do arise, and addressing them requires a structured approach. To uncover the root cause, we need to simplify and enhance observability within our cluster.</p><p>Our platform is running on an rke2 k8s cluster, deployed with the precision and repeatability of <strong>Helmfile</strong>. In this blog, I’ll share our approach to building a robust logging stack tailored to our ETL platform using loki and fluent-bit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=206689a85e65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing Multi-Environment Secrets with Helmfile]]></title>
            <link>https://haque-zubair.medium.com/managing-multi-environment-secrets-with-helmfile-e8517203bee9?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8517203bee9</guid>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Fri, 18 Oct 2024 14:01:06 GMT</pubDate>
            <atom:updated>2025-01-15T15:41:14.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*n3ctrOOXdeGOaTkUUZKGEg.png" /></figure><p>In our current infrastructure for our product platform, we use <a href="https://helmfile.readthedocs.io/en/latest/">helmfile</a> for deployments and <a href="https://github.com/getsops/sops">sops</a> to manage and encrypt secrets across multiple environments. Helmfile provides a streamlined, declarative approach to deploying Helm charts, while sops ensures sensitive data is securely encrypted and stored in version control. By integrating with AWS KMS, sops enables seamless decryption during deployments, maintaining security without hindering access for authorized DevOps engineers. This ensures encrypted secrets are managed efficiently across environments, keeping them secure while remaining accessible for day-to-day operations.</p><h3>Installing sops locally</h3><p><strong>Download the sops Binary:</strong> First, download the SOPS binary directly to your ~/bin directory. Use the following command:</p><pre>curl -L -o ~/bin/sops &quot;https://github.com/mozilla/sops/releases/download/3.9.0/sops-3.9.0.linux.amd64&quot;</pre><p><strong>Make the Binary Executable:</strong> After downloading sops, you need to make sure the binary is executable by running:</p><pre>chmod +x ~/bin/sops</pre><p><strong>Verify that everything was installed correctly</strong>: Check that sops is installed correctly and verify the version with the following command:</p><pre>sops --version</pre><h3>Configuring SOPS with AWS KMS</h3><p>Now that SOPS is installed, we’ll configure it to use AWS KMS. SOPS supports KMS across multiple AWS accounts by assuming roles, allowing administrators to establish trust between secure and less secure environments.</p><p>Log in to your AWS account and navigate to the <strong>KMS (Key Management Service)</strong> module. Start by creating a new KMS key by clicking on the <strong>Create key</strong> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlEZE-J_HAoo9fvZQovPpQ.png" /></figure><p>Choose the <strong>Symmetric</strong> key type (for encryption and decryption) and click <strong>Next</strong>. You can leave all other options as default. In the <strong>Regionality</strong> section, select whether this will be a <strong>Single-Region</strong> or <strong>Multi-Region</strong> key, depending on your current infrastructure setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3L6mdb-inpEKVGm-rnZUGA.png" /></figure><p>Add an <strong>Alias</strong> and a <strong>Description</strong> for your AWS KMS key, then click <strong>Next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oPY9jg6pXBxiZKBvx2mP_A.png" /></figure><p>Set the <strong>administrative</strong> and <strong>usage</strong> permissions (for encrypting/decrypting) the KMS key:</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8517203bee9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grafana and Prometheus Setup with Helmfile: A Guide to Monitoring in Production Environments]]></title>
            <link>https://haque-zubair.medium.com/grafana-and-prometheus-setup-with-helmfile-a-guide-to-monitoring-in-production-environments-0c3a0dd1f999?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c3a0dd1f999</guid>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Wed, 01 May 2024 15:17:42 GMT</pubDate>
            <atom:updated>2024-05-24T16:53:08.455Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cbvTDO1bcKNWorAydXvkxA.png" /></figure><p>In this post, we will explore the setup and deployment of a robust and comprehensive monitoring solution for production environments running on an rke2 kubernetes cluster. In today’s landscape monitoring is very crucial for maintaining the reliability and performance of production systems. I want to go through an effective way of implementing monitoring tools using Helmfile to streamline the process. Here are the key components in our setup:</p><ul><li><a href="https://artifacthub.io/packages/helm/grafana/grafana"><strong>Grafana Helm Chart:</strong></a> Is being used for visualizing and analyzing metrics from our Kubernetes cluster.</li><li><a href="https://artifacthub.io/packages/helm/prometheus-community/prometheus"><strong>Prometheus Helm Chart:</strong></a> Used for collecting Kubernetes metrics and providing the data to Grafana.</li><li><a href="https://artifacthub.io/packages/helm/aws-ebs-csi-driver/aws-ebs-csi-driver"><strong>AWS-EBS CSI Driver:</strong></a> To manage persistent storage efficiently within our Kubernetes environment.</li></ul><p>Before we delve into our monitoring setup, let’s get a better understanding of helmfile. <a href="https://helmfile.readthedocs.io/">helmfile</a> is a powerful tool, that helps you manage multiple Helm charts declaratively.</p><p>If you haven’t already, create a Helmfile — a YAML-based configuration file for managing Helm charts and releases. Helmfile simplifies Kubernetes deployments, providing a structured approach to defining environments, repositories, and releases. Once your Helmfile is set up, we’ll configure it to deploy Grafana, Prometheus, and the AWS EBS CSI Driver, empowering your Kubernetes cluster with a robust monitoring solution.</p><p>In our Helmfile, we start by defining environments to streamline the deployment process. Here, we have established a single environment, aptly named “dev”. Environments serve as logical groupings that allow us to manage our deployments more efficiently, accommodating variations between development, staging, and production setups. With the “dev” environment in place, we’re ready to proceed with configuring repositories and releases to bring our monitoring solution to life.</p><h4><strong>Prometheus</strong></h4><p>Prometheus is the monitoring tool that we will be integrating with Grafana, which will allow us to keep track of the health of our rke2 cluster. Prometheus will be gathering and storing metrics, enabling us to be responsiveness if the system is down or in need of maintenance. Prometheus will not only monitor our systems but can also interface with Grafana to manage alerts and incidents.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c3a0dd1f999" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scaling Apache Kafka with Strimzi and KEDA]]></title>
            <link>https://haque-zubair.medium.com/scaling-apache-kafka-with-strimzi-and-keda-1fcfc09ff239?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fcfc09ff239</guid>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Fri, 17 Nov 2023 15:00:25 GMT</pubDate>
            <atom:updated>2023-11-24T15:48:34.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhdQpzaK4Bxuq_IO9Ih5Xw.png" /></figure><p>Apache Kafka has become the backbone of many modern distributed systems, providing a robust and scalable way to stream data. As organizations begin to embrace Kubernetes for container orchestration, the need to seamlessly integrate Kafka into this dynamic environment becomes very important. Most organizations have a goal to create scalable Kafka deployments, we can use Strimzi to accomplish that task. Strimzi is an open-source tool that helps manage and maintain Kafka clusters. Strimzi offers several operators including:</p><ul><li><strong>Zookeeper</strong></li><li><strong>Kafka Connect</strong></li><li><strong>Kafka MirrorMaker</strong></li><li><strong>Kafka Exporter</strong></li></ul><p>This blog is not just about deployments by the way, it’s about leveraging the capabilities of Strimzi to orchestrate Kafka clusters. While we’re jumping into how to implement Strimzi with Kafka on Kubernetes, we will also go over how to effectively autoscale the deployments with KEDA (Kubernetes-based Event-Driven Autoscaling. KEDA will be an essential component that helps us achieve our goal of scalability, for our Kafka deployments.</p><h3>Installing the Strimzi Kafka Operator on Kubernetes</h3><p>To begin, let’s start our local Minikube cluster with the following command:</p><pre>$ minikube start --memory=4096</pre><p>Now that our Minikube cluster is up and running, let’s create a dedicated namespace, where we’ll orchestrate our Kafka deployment:</p><pre>$ kubectl create namespace kafka</pre><p>Step 1: Set Strimzi Version</p><pre>$ export STRIMZI_VERSION=0.38.0</pre><p>Step 2: Deploy the Strimzi Kafka Operator:</p><pre>$ curl -L https://github.com/strimzi/strimzi-kafka-operator/releases/download/${STRIMZI_VERSION}/strimzi-cluster-operator-${STRIMZI_VERSION}.yaml \<br>| sed &#39;s/namespace: .*/namespace: kafka/&#39; \<br>| kubectl apply -f - -n kafka</pre><p>Once that curl command is executed successfully &amp; applied to our kafka namespace, we will be able to use Strimzi. Let’s briefly summarize what was created:</p><p><strong>Strimzi Operator Setup:</strong></p><ul><li><strong>RBAC &amp; clusterroles created for security and confidentiality</strong></li><li><strong>A ConfigMap &amp; serviceaccount for the strimzi-cluster-operator is also created</strong></li></ul><p><strong>Security:</strong></p><ul><li><strong>We created secure roles and permissions to control everything for the Kafka broker</strong></li><li><strong>We are also safeguarding sensitive client data and interactions</strong></li></ul><p><strong>Connectivity:</strong></p><ul><li><strong>Strimzi incorporates a feature that enables the seamless creation and management of connections between various Kafka components through the implementation of bridges</strong></li></ul><p><strong>Deployment:</strong></p><ul><li><strong>We deployed and manage the Strimzi Kafka Operator. We also streamlined Kubernetes interactions, including client delegation &amp; ensuring smooth orchestration of Kafka clusters.</strong></li></ul><p>Now that we got our Strimzi Operator up and running in the kafka namespace, let’s check the health of our minikube cluster:</p><pre>$ kubectl get all -n kafka</pre><p>Our output should resemble something like this, showcasing the readiness and status of the Strimzi Operator deployment in the kafka namespace:</p><pre>NAME                                           READY   STATUS    RESTARTS   AGE<br>pod/strimzi-cluster-operator-95d88f6b5-ww5pv   1/1     Running   0          3m2s<br><br>NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE<br>deployment.apps/strimzi-cluster-operator   1/1     1            1           3m2s<br><br>NAME                                                 DESIRED   CURRENT   READY   AGE<br>replicaset.apps/strimzi-cluster-operator-95d88f6b5   1         1         1       3m2s</pre><p>In the next step, we’re going to deploy a Strimzi Kafka cluster with a single broker and Zookeeper node. This is going to include persistent storage configuration, which will help enable all of the Kafka operations and data durability.</p><pre>$ kubectl apply -f https://raw.githubusercontent.com/strimzi/strimzi-kafka-operator/${STRIMZI_VERSION}/examples/kafka/kafka-persistent-single.yaml -n kafka</pre><p>Let’s assess the status of our Kafka cluster:</p><pre>$ kubectl get kafka -n kafka</pre><p>The output should give us information about our cluster, such as the Kafka replica and the Zookeeper replica (indicating that the cluster is currently in a ready state):</p><pre>NAME         DESIRED KAFKA REPLICAS   DESIRED ZK REPLICAS   READY   WARNINGS<br>my-cluster   1     </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fcfc09ff239" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Argo Rollouts is a powerful Kubernetes controller that offers a wide range of deployment…]]></title>
            <link>https://haque-zubair.medium.com/argo-rollouts-is-a-powerful-kubernetes-controller-that-offers-a-wide-range-of-deployment-820b99534d51?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/820b99534d51</guid>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[argo-rollouts]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[deployment-pipelines]]></category>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Wed, 12 Jul 2023 15:58:49 GMT</pubDate>
            <atom:updated>2023-07-19T21:57:13.176Z</atom:updated>
            <content:encoded><![CDATA[<h3>Streamline Application Deployments with Argo Rollouts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rZ_Yfz9XNk8dDqf4s8kDhQ.jpeg" /></figure><p>Argo Rollouts is a powerful Kubernetes tool that offers us a wide range of deployment capabilities. It has useful features like blue-green, canary, and progressive rollouts. It has ultimately simplified the way we manage our Kubernetes cluster. Argo rollouts does an automated analysis of the software you’re about to release, checking the success and failure of the changes you are promoting to your customers. In today’s demo we will be performing a canary rollout with Istio:</p><ul><li>The <strong>Canary Rollout Strategy</strong> we demo today, is going to be deploying a new version of our software to only a subset of users. Hence, keeping the majority of our users on a stable version of our application. By directing a small percentage of the traffic to the <strong>canary</strong> version, we can easily identify any issues or performance problems before impacting a larger audience, allowing us to <strong>rollback</strong> if necessary.</li></ul><h3>Setting up your Kubernetes Cluster</h3><p>We’re going to be deploying this locally on Docker Desktop. Let’s go over some of the things you will need so you can follow along with this <a href="https://github.com/argocon22Workshop/ArgoCDRollouts/blob/main/docs/201_README.md">workshop</a> (all the steps and instructions are available in this link, clone this repository to get started).</p><h3>Prerequisites</h3><p>Make sure you go to Settings on Docker Desktop and Enable Kubernetes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Z88NjK8dniSNNPeZL7sYA.png" /></figure><p>We’re going to start by creating a namespace for argocd</p><pre>$ kubectl create namespace argocd</pre><p>The output should confirm that the command was successful and that the new namespace has been successfully created in the Kubernetes cluster. Now, we’re going to install <a href="https://argo-cd.readthedocs.io/en/stable/getting_started/">Argo CD</a> in our new namespace and that’s where all of the Argo CD services and application resources will live:</p><pre>$ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml</pre><p>Here’s a brief synopsis of what was actually installed</p><ul><li><strong>Custom resource definitions (CRDs):</strong> You’ve now installed the necessary resources ArgoCD needs.</li><li><strong>Service accounts:</strong> We now also have the various ServiceAccounts for our Argo CD components. Which includes the <a href="https://argocd-applicationset.readthedocs.io/en/stable/">ApplicationSet controller</a>, the <a href="https://argocd-notifications.readthedocs.io/en/stable/">Notifications controller,</a> and more.</li><li><strong>Roles and Cluster Roles:</strong> These roles will provide the cluster-level permissions needed for Argo CD to interact with various Kubernetes resources and perform operations within the cluster.</li><li><strong>Role Bindings and Cluster Role Bindings:</strong> This will associate the ServiceAccount’s with their respective Role or Cluster Role.</li><li><strong>Config Maps:</strong> We’ve also installed the config data for the various Argo CD components as well.</li><li><strong>Secrets:</strong> These secrets store sensitive information required by the Argo CD components and resources, which ensuring the handling of credentials, API keys, and other confidential data necessary to operate our cluster.</li><li><strong>Deployments and Stateful Sets:</strong> These are the running instances of the specific Argo CD components we will use for this workshop.</li><li><strong>Network policies:</strong> These policies establish specific network connectivity rules for our Argo CD components, ensuring that we have secure communication within the Kubernetes cluster.</li></ul><p>Now that we have Argo CD up and running, let’s check the status of the pods in our cluster, run the command:</p><pre>$ kubectl get pods -A</pre><p>This is going to provide us with insights in regards to the health and availability of our cluster:</p><pre>NAMESPACE     NAME                                                READY   STATUS    RESTARTS   AGE<br>argocd        argocd-application-controller-0                     1/1     Running   0          23s<br>argocd        argocd-applicationset-controller-7786cb7547-5zf5w   1/1     Running   0          23s<br>argocd        argocd-dex-server-58574dff5f-vc7vg                  1/1     Running   0          23s<br>argocd        argocd-notifications-controller-7764bb774d-wvhcv    1/1     Running   0          23s<br>argocd        argocd-redis-77bf5b886-sl2hf                        1/1     Running   0          23s<br>argocd        argocd-repo-server-5b9977b575-5czsr                 0/1     Running   0          23s<br>argocd        argocd-server-6485ccb9c9-plk7s                      0/1     Running   0          23s<br>kube-system   coredns-5d78c9869d-qqx6f                            1/1     Running   0          109s<br>kube-system   coredns-5d78c9869d-zhh6d                            1/1     Running   0          109s<br>kube-system   etcd-docker-desktop                                 1/1     Running   0          106s<br>kube-system   kube-apiserver-docker-desktop                       1/1     Running   0          116s<br>kube-system   kube-controller-manager-docker-desktop              1/1     Running   0          115s<br>kube-system   kube-proxy-k4ffh                                    1/1     Running   0          110s<br>kube-system   kube-scheduler-docker-desktop                       1/1     Running   0          109s<br>kube-system   storage-provisioner                                 1/1     Running   0          108s<br>kube-system   vpnkit-controller                                   1/1     Running   0          108s</pre><p>In the <strong>argocd</strong> namespace we have the following pods up and running:</p><ul><li><strong>argocd-application-controller</strong></li><li><strong>argocd-applicationset-controller</strong></li><li><strong>argocd-dex-server</strong></li><li><strong>notifications-controller</strong></li><li><strong>argocd-redis</strong></li><li><strong>argocd-repo-server</strong></li><li><strong>argocd-server</strong></li></ul><p>And in the <strong>kube-system</strong> namespace we have:</p><ul><li><strong>coredns</strong></li><li><strong>etcd-docker-desktop</strong></li><li><strong>kube-apiserver</strong></li><li><strong>kube-controller</strong></li><li><strong>kube-proxy</strong></li><li><strong>kube-scheduler</strong></li></ul><p>Now the next few commands we’re going to run, will utilize the <a href="https://formulae.brew.sh/formula/argocd"><strong>argocd CLI</strong></a> I’ve actually already installed the CLI and it’s a part of the workshop prerequisites link listed above. Before we get into the CLI commands we’re going to need to retrieve the admin password for Argo CD. The command we’re going to run will fetch the admin password stored in the <strong>argocd-initial-admin-secret,</strong> Which lives in the <strong>argocd</strong> namespace. The secret will get decoded, which is then going to allow us to access and manage Argo CD via the user interface:</p><pre>$ kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=&quot;{.data.password}&quot; | base64 -d</pre><p>Once you get the password, store it in a text file or notepad somewhere because we’re going to need to log into the user interface. I’m going to use the Argo CD CLI to enable port forwarding and login to the UI <strong>(note: we’re going to be adding that --port-forward-namespace flag to every CLI command we run):</strong></p><pre>$ argocd --port-forward --port-forward-namespace argocd login</pre><p>The above CLI command will prompt you for your credentials:</p><pre>Username: admin<br>Password: <br>&#39;admin:login&#39; logged in successfully<br>Context &#39;port-forward&#39; updated</pre><p>This is where you will need the admin password we decoded in the steps above. Once we have logged in successfully we’re going to create an app which will be a part of our Argo CD list of managed applications:</p><pre>$ argocd --port-forward-namespace argocd repo add &quot;https://github.com/argocon22Workshop/ArgoCDRollouts&quot;</pre><p>this is the same repo we have specified as our workshop project listed above in the Prerequisites section. The next thing we need to do is create an app with <strong>argocd app create </strong>command:</p><pre>$ argocd --port-forward-namespace argocd app sync argo-rollouts</pre><p>This command is asking the API server to sync our <strong>argo-rollouts</strong> application. The application controller is going to be scanning the state of the resources and then apply them to our cluster. The command then watches for the sync operation and reconciles the states whether is a fail or a success. We have now synced and applied the:</p><ul><li><strong>namespace</strong></li><li><strong>ServiceAccount</strong></li><li><strong>argo-rollouts-notification-secret</strong></li><li><strong>ClusterRole: so argo-rollouts can view edit &amp; modify the resources in the argo-rollouts app.</strong></li><li><strong>The CRDs for: analysistemplates.argoproj.io, experiments.argoproj.io and rollouts.argoproj.io</strong></li></ul><p>and a lot more.</p><h3>Istio</h3><p>We’re going to be using Istio for enabling traffic-routed canary deployments. It will provide us with granular control over pod counts and traffic percentages. Furthermore, it will allow us to safely test out new versions of our applications by gradually diverting a portion of the traffic to the canary pods while monitoring their performance with Prometheus. With Istio, we can easily implement canary deployments and minimize the impact of potential issues by controlling the distribution of traffic between different versions of our services.</p><p>First install the istioctl command line tool:</p><pre>$ brew install istioctl</pre><p>Then initiate the <a href="https://github.com/argocon22Workshop/ArgoCDRollouts/blob/main/docs/201_prereqs.md#13-install-istio">default install</a> of Istio via their CLI tool:</p><pre>$ istioctl install - set profile=demo -y - set values.global.tag=1.15.0<br><br>✔ Istio core installed<br><br>✔ Istiod installed<br><br>✔ Egress gateways installed<br><br>✔ Ingress gateways installed<br><br>✔ Installation complete Making this installation the default for injection and validation.</pre><p>This command initiates the installation process of Istio. The output will indicate the completion of the installation process, it shows we have installed of it’s core components:</p><ul><li><strong>Istiod (Istio control plane)</strong></li><li><strong>Egress gateways</strong></li><li><strong>Ingress gateways</strong></li></ul><p>The default installation allows Istio to be configured to automatically inject its sidecar proxies into application pods for enhanced observability, security, and control. So we’ve got Istio installed, we’re going to create a new namespace called <strong>argo-rollouts-istio</strong> using the command <strong>kubectl create namespace</strong> command:</p><pre>$ kubectl create namespace argo-rollouts-istio</pre><p>We need to enable Istio automatic sidecar injection into our new namespace, so it can be used by our application. Please note, you must add this label <strong>istio-injection=enabled </strong>(to your namespace to enable Istio’s sidecar injection):</p><pre>$ kubectl label namespace argo-rollouts-istio istio-injection=enabled</pre><h3>Prometheus</h3><p>We’re also using Prometheus to monitor our cluster, the command below is going to set up Prometheus and its relevant <strong>CRDs</strong> in our cluster. The <strong>CRDs</strong> will be installed in a separate namespace called <strong>monitoring:</strong></p><pre>$ kubectl apply --server-side -f manifests/prometheus/upstream/setup</pre><p>This command applies a set of resources and configurations for setting up monitoring in our Kubernetes cluster. Here’s a breakdown of what was configured:</p><ul><li>A few service accounts were created, for the <strong>alertmanager-main</strong>, <strong>blackbox-exporter</strong>, <strong>grafana</strong>, <strong>kube-state-metrics</strong>, <strong>node-exporter</strong>, <strong>prometheus-adapter</strong>, <strong>prometheus-k8s</strong>, and <strong>prometheus-operator</strong></li><li>Various Roles and Cluster Roles were created, which define the permissions for all of the ServiceAccounts listed above</li><li>Role bindings and Cluster Role bindings were created to associate each roles with it’s appropriate ServiceAccount</li><li>Multiple ConfigMaps were created, which contain the config for different components in our cluster and the dashboard</li><li>Secrets were created for <strong>alertmanager-main</strong> and <strong>grafana</strong>, which will house sensitive information</li><li>Services were created for <strong>alertmanager-main</strong>, <strong>blackbox-exporte</strong>r, <strong>grafana</strong>, <strong>kube-state-metrics</strong>, <strong>node-exporter</strong>, <strong>prometheus-adapter</strong>, <strong>prometheus-k8s</strong>, and <strong>prometheus-operator</strong></li><li>Deployments were created for the <strong>blackbox-exporter</strong>, <strong>grafana</strong>, <strong>kube-state-metrics</strong>, <strong>prometheus-adapter</strong>, and the <strong>prometheus-operator</strong></li><li>We also configured pod disruption budgets for <strong>alertmanager-main</strong>, <strong>prometheus-adapter</strong>, and <strong>prometheus-k8s</strong></li><li>An API service was created for <strong>v1beta1.metrics.k8s.io</strong></li><li>A daemonset was created for the <strong>node-exporter</strong></li><li>All of the various <strong>CRDs</strong> were created for our different monitoring components</li><li>Service monitors were created for various components, including: <strong>alertmanager-main</strong>, <strong>blackbox-exporter</strong>, <strong>grafana</strong>, <strong>kube-apiserver</strong>, <strong>kube-controller-manager</strong>, <strong>kube-scheduler</strong>, <strong>kube-state-metrics</strong>, <strong>kubelet</strong>, <strong>node-exporter</strong>, <strong>prometheus-adapter</strong>, <strong>prometheus-k8s</strong>, and <strong>prometheus-operator</strong></li><li>Network policies were created for the <strong>alertmanager-main</strong>, <strong>blackbox-exporter</strong>, <strong>grafana</strong>, <strong>kube-state-metrics</strong>, <strong>node-exporter</strong>, <strong>prometheus-adapter</strong>, <strong>prometheus-k8s</strong>, and <strong>prometheus-operator</strong></li><li>And last but not least, a gateway and virtual service were created for the Istio networking layer for <strong>prometheus</strong></li></ul><h3>Argo Rollouts: Canary Rollout Strategy</h3><p>In this section we’re going to use <strong>kustomize</strong> to build the Kubernetes manifest files located in the <strong>manifests/ArgoCD201-RolloutsDemoCanaryIstio </strong>directory. The resources that are being created are:</p><p><strong>service/istio-host-split-canary:</strong> We will create a service for the canary version of the application:</p><pre>apiVersion: v1<br>kind: Service <br>metadata: <br>  name: istio-host-split-canary <br>  labels: <br>    app: istio-host-split <br>spec:<br>  ports:<br>    - port: 80<br>      targetPort: http<br>      protocol: TCP<br>      name: http<br>  selector:<br>    app: istio-host-split</pre><p><strong>service/istio-host-split-stable:</strong> We will create a service for the stable version of the application:</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: istio-host-split-stable<br>spec:<br>  ports:<br>    - port: 80<br>      targetPort: http<br>      protocol: TCP<br>      name: http<br>  selector:<br>    app: istio-host-split</pre><p><strong>rollout.argoproj.io/istio-host-split:</strong> We’re going to create an Argo Rollout called <strong>istio-host-split</strong>, which defines the canary rollout strategy for the application:</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Rollout<br>metadata:<br>  name: istio-host-split<br>spec:<br>  replicas: 4<br>  strategy:<br>    canary:<br>      canaryService: istio-host-split-canary<br>      stableService: istio-host-split-stable<br>      trafficRouting:<br>        managedRoutes:<br>          - name: mirror-route<br>        istio:<br>          virtualService:<br>            name: istio-host-split-vsvc<br>            routes:<br>              - primary<br>      steps:<br>        - setWeight: 25<br>        - pause: {}<br>        - setWeight: 50<br>        - pause: {}<br>        - setWeight: 75<br>        - pause: {}<br>  selector:<br>    matchLabels:<br>      app: istio-host-split<br>  template:<br>    metadata:<br>      labels:<br>        app: istio-host-split<br>    spec:<br>      containers:<br>        - name: istio-host-split<br>          image: ghcr.io/argocon22workshop/rollouts-demo:blue<br>          ports:<br>            - name: http<br>              containerPort: 8080<br>              protocol: TCP<br>          resources:<br>            requests:<br>              memory: 16Mi<br>              cpu: 5m</pre><p><strong>gateway.networking.istio.io/istio-host-split-gateway:</strong> We’re also going to create an Istio Gateway resource for routing traffic to the canary and stable versions of our application:</p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: Gateway<br>metadata:<br>  name: istio-host-split-gateway<br>spec:<br>  selector:<br>    istio: ingressgateway<br>  servers:<br>    - port:<br>        number: 80<br>        name: http<br>        protocol: HTTP<br>      hosts:<br>        - &quot;*&quot;</pre><p><strong>virtualservice.networking.istio.io/istio-host-split-vsvc:</strong> Once we’ve created the Gateway resource, we’re going to create a Istio VirtualService resource for configuring all of the traffic splitting and routing rules between the canary and stable versions of our application:</p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: VirtualService<br>metadata:<br>  name: istio-host-split-vsvc<br>spec:<br>  hosts:<br>    - &quot;*&quot;<br>  gateways:<br>    - istio-host-split-gateway<br>  http:<br>    - name: primary<br>      route:<br>        - destination:<br>            host: istio-host-split-stable<br>          weight: 100<br>        - destination:<br>            host: istio-host-split-canary<br>          weight: 0</pre><p>In this next step, we will apply the manifests for our Argo Rollouts Demo with our <strong>canary rollout strategy</strong> using Istio:</p><pre>$ kustomize build manifests/ArgoCD201-RolloutsDemoCanaryIstio/ | kubectl apply -f -</pre><p>We have now enabled <strong>canary rollout strategy</strong> for our application using the traffic-routed canary strategy with Istio, which will allow us to have better control over pod counts and traffic percentages for a smooth and controlled deployment process:</p><pre>service/istio-host-split-canary created<br>service/istio-host-split-stable created<br>rollout.argoproj.io/istio-host-split created<br>gateway.networking.istio.io/istio-host-split-gateway created<br>virtualservice.networking.istio.io/istio-host-split-vsvc created</pre><p>Navigate to <a href="http://localhost/">http://localhost/</a> you should see our demo application up and running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_duqU4msSywgJoR8uG55g.gif" /></figure><h3>Argo Rollouts Dashboard</h3><p>We are now ready to look at the <strong>argo-rollouts dashboard</strong></p><pre>$ kubectl-argo-rollouts dashboard</pre><p>Go ahead and navigate to <a href="http://localhost:3100/rollouts">http://localhost:3100/rollouts</a> you should now be able to see that the <strong>argo-rollouts dashboard </strong>is up and running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*dKEGjLDXnNok8EOdeQTDFQ.png" /></figure><p>Now we’re going to patch the <strong>istio-host-split rollout</strong> in the <strong>argo-rollouts-istio</strong> namespace. Just for context, we’re updating the image of for our container within the rollout’s pod template to use the <strong>ghcr.io/argocon22workshop/rollouts-demo:red</strong> image. It will essentially trigger the rollout process to update the pod with the new image:</p><pre>$ kubectl -n argo-rollouts-istio patch rollout istio-host-split --type json --patch &#39;[{&quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/image&quot;, &quot;value&quot;: &quot;ghcr.io/argocon22workshop/rollouts-demo:red&quot; }]&#39;</pre><p>Once we have successfully patched our <strong>rollout</strong> the dashboard will now display two revisions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*iA1S-ctPRHRe9bMYuWgCuA.png" /></figure><p>In the <strong>rollout</strong> declared above, we had a configuration with the weight set to 25% for the first canary rollout, then we’re going to gradually increase it to 50% and then 75% in subsequent step. The pauses in between will allow time for the canary to stabilize before proceeding to the next weight increase. This gradual <strong>rollout</strong> strategy helps minimize the potential impact to users when new software version is released. Click the <strong>^PROMOTE </strong>button <strong>(notice our demo application should show be updating in real-time showing us that our changes are being successfully deployed).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nc0nrJpPdF_Kat5M8iBluw.png" /></figure><p>Our <strong>argo-rollouts dashboard </strong>should also be updated and indicate to us it is in a paused state and the updated Weight should now show at 50%</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*ZnA08jekolPGCD4kNffQ2g.png" /></figure><p>So we’re going to perform the same steps until we’re at 75% &amp; we have now successfully performed the gradual <strong>rollout</strong> of our <strong>canary</strong> deployment, we are now ready to proceed with the final step of promoting the remaining changes. By increasing the weight to 100%, we ensure that the new version is fully exposed to the production environment, allowing us to take advantage of the latest enhancements and features while being confident in its stability. The Argo Rollouts CRDs help minimize any potential disruptions to the users and provide a reliable and efficient deployment process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NHruxnX47tq2LJPvFZlgeA.png" /><figcaption>demo-application</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*AiR4mW9wMcf8LheM0joQwA.png" /></figure><h3>Rollbacks</h3><p>The rollback button in Argo Rollouts provides you with a powerful and essential mechanism to revert to a previous, known, and stable version of your deployment. It allows for quick and efficient recovery in case the new rollout introduces unexpected issues, bugs, or performance problems. Utilizing the rollback button can help maintain application reliability and user satisfaction by swiftly reverting to a reliable state without the need for a time-consuming and error-prone manual rollback process. It serves as a valuable safety net during the deployment lifecycle, enabling us to respond promptly to any unforeseen issues and keep our apps running smoothly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2UemP-tn2zLF_IAGoIAcQ.png" /></figure><p>Once we click the rollback button, it will rollback to the previous version with the weight of 25%</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OsTSt5M7Q6dqQ5Wbv0mtrw.png" /></figure><p>once we validate that our demo-app once it is rolled back to the previous version it is functioning as designed we can then click on the <strong>PROMOTE-FULL</strong> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4wzXHaA2yNOMCaA7kBT17w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mNARZBQGzkqHX4mB2NxT6w.png" /></figure><p>And now we have successfully rolled back to a previous version of our application. Thanks for taking the time to read this article, just a reminder all of the commands for this workshop are listed in this <a href="https://github.com/argocon22Workshop/ArgoCDRollouts/blob/main/docs/exercise-201/exercise3.md">link</a> here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=820b99534d51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplified Log Aggregation on AWS EKS with Flux, ELK Stack, and Fluentd]]></title>
            <link>https://haque-zubair.medium.com/simplified-log-aggregation-and-analysis-on-aws-eks-with-flux-elk-stack-and-fluentd-3bb925386ee3?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bb925386ee3</guid>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 00:30:05 GMT</pubDate>
            <atom:updated>2025-03-24T15:31:57.927Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eD3Kf2Sc6sftR8PkZTyq5Q.png" /></figure><p>In today’s world many of us are working on Microservices, ETL Data Pipelines and distributed Infrastructure Environments. Which basically means that efficient log management and analysis are critical for maintaining system reliability. In this article, we’ll explore how to leverage the ELK Stack, along with the Fluentd log collector, to simplify log aggregation and analysis on our AWS EKS cluster using the FluxCD.</p><p>To streamline log aggregation and analysis in our AWS Kubernetes cluster, we’ll be harnessing the power of the ELK Stack, Filebeat, and Fluentd. Let’s take a closer look at each component:</p><ul><li><strong>ELK Stack: </strong>Which comprises of Elasticsearch, Logstash, and Kibana. It’s going to provide us with scalable search capabilities, as well as processing and enriching the logs, and last but not least a UI for log visualization and analysis.</li><li><strong>Filebeat: </strong>is basically a lightweight log shipper that collects, filters, and sends logs to our ELK Stack, capturing and forwarding all of our logs.</li><li><strong>Fluentd: </strong>in this case Fluentd will act as our log collector, gathering logs from various sources and forwarding them to our ELK Stack.</li></ul><h3>Elastic Cloud on Kubernetes</h3><p>The Elastic Operator will ensures that all of the core components listed above are configured correctly across our AWS EKS cluster. Not to mention, it seamlessly integrates with FluxCD &amp; will allow us to efficiently visualize and analyze our log data. We’re going to be using the <a href="https://artifacthub.io/packages/helm/elastic/eck-operator">eck-operator</a> Helm Chart, so let’s start by creating a directory structure that looks like this:</p><pre>├── operators<br>│   └── base<br>│       ├── elastic-operator<br>│       │   ├── kustomization.yaml<br>│       │   ├── release.yaml<br>│       │   └── namespace.yaml</pre><p>We’re going to create a separate namespace for the Elastic Operator, optimizing the organization and management of our logging infrastructure. By isolating it in its dedicated namespace, we gain control and visibility over the associated resources.</p><pre>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: elastic-operator</pre><p>Ok, now the release.yaml is where we will declare</p><pre>apiVersion: helm.toolkit.fluxcd.io/v2beta1<br>kind: HelmRelease<br>metadata:<br>  name: elastic-operator<br>  namespace: elastic-operator<br>spec:<br>  interval: 5m<br>  chart:<br>    spec:<br>      chart: eck-operator<br>      version: &#39;2.8.0&#39;<br>      sourceRef:<br>        kind: HelmRepository<br>        name: elastic<br>        namespace: flux-system<br>      interval: 1m</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bb925386ee3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Define your CI/CD pipeline with Argo Workflows]]></title>
            <link>https://haque-zubair.medium.com/define-your-ci-cd-pipeline-with-argo-workflows-25aefb02fa63?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/25aefb02fa63</guid>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <category><![CDATA[argo-workflows]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 06:26:07 GMT</pubDate>
            <atom:updated>2023-06-12T18:35:09.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u9sLg4tom-zvX0qv6fq3Mw.png" /></figure><p>Argo Workflows is an open-source, container-native workflow engine for orchestrating your CI/CD jobs on Kubernetes. It’s implemented as a Kubernetes Custom Resource Definition (CRD), which enables contributors to create custom API objects to extend the capabilities of Kubernetes in a compliant manner.</p><h3>But why Argo Workflows?</h3><p>Argo Workflows is designed to run on top of Kubernetes, and not on other platforms such as VMs or cloud services. Let’s take a minute to highlight the benefits and drawbacks of using Kubernetes as a platform for running Argo Workflows.</p><p>Argo Workflows is implemented as a Kubernetes Custom Resource Definition (CRD), which enables you to:</p><ul><li>Define Kubernetes workflows using separate containers for each step in the workflow.</li><li>Model workflows with directed acyclic graphs (DAGs) to capture dependencies between multiple steps.</li><li>Run compute-intensive data processing or machine learning tasks quickly and easily.</li><li>Natively run CI/CD pipelines on Kubernetes without configuring a complex application development solution.</li></ul><h3>CI/CD using Argo Workflows</h3><p>Argo Workflows is the right fit for your needs if you require:</p><ul><li><strong>Resilience to handle container crashes and failures.</strong></li><li><strong>Autoscaling options that can manage large numbers of workflows simultaneously.</strong></li><li><strong>Comprehensive enterprise features such as Role-Based Access Control (RBAC) and Single Sign-On (SSO).</strong></li></ul><p>You may want to avoid using Argo Workflows if:</p><ul><li><strong>The complexity of YAML file maintenance may increase as the number of workflows and infrastructure requirements grow, although Argo offers tricks and templating features to manage this aspect.</strong></li><li><strong>Your team does not have experience with containers and Kubernetes.</strong></li><li><strong>You require maintaining a full enterprise setup, which involves managing a large number of configuration options.</strong></li></ul><h3>Understanding the Key Components of Argo Workflows</h3><p>The core concept of Argo Workflows involves defining and storing live Kubernetes CRD objects that will specify the workflow being executed in its proper state:</p><ul><li>The <strong>workflow.spec</strong> contains a list of templates and an <strong>entrypoint</strong> that serves as the primary function or first template to execute.</li></ul><p>Templates are defined as functions and can be of various types:</p><ul><li>such as <strong>containers</strong>, <strong>scripts</strong>, or <strong>resource templates</strong>.</li></ul><p>The container template is the most commonly used. The script template allows for a script to be defined and then executed. The resource template handles requests, while the suspend template pauses the workflow execution for a defined duration and can be resumed using the Argo UI. The Templates themselves use nested lists to run in sequence or parallel, which can be customized based on different settings.</p><h3>Installation</h3><p>To get started we’re going to need to download the Argo Workflows binary on your machine and save it:</p><pre>$ curl -sLO https://github.com/argoproj/argo-workflows/releases/download/v3.4.5/argo-darwin-amd64.gz</pre><p>Now we need to decompress the file, we downloaded from the command above:</p><pre>$ gunzip argo-darwin-amd64.gz</pre><p>Once, we have all of that done we need to modify the permissions of this file, allowing it to be run as a program. This will allow you to execute the argo commands directly from the command line:</p><pre>$ chmod +x argo-darwin-amd64</pre><p>Once we have done that, we need to move this file from the current directory to the <strong>/usr/local/bin</strong> directory:</p><pre>mv ./argo-darwin-amd64 /usr/local/bin/argo</pre><p>This will allow you to execute the argo command from anywhere in the terminal. To verify that Argo Workflows was installed successfully, run the following command:</p><pre>$ argo version</pre><p>The output will display the version number installed, indicating that everything is good to go.</p><h3>Running your sample application</h3><p>In this section, we will be deploying a workflow with a simple Python app using Argo Workflows. We’ll start by defining our build step, then finally creating a workflow to deploy and test the app. We’re going to be doing all of this on our local minikube cluster, on your local machine by running the following command:</p><pre>$ minikube start</pre><p>you should be in the default namespace in your minikube cluster, we should now be able to apply the following Kubernetes manifest file, which is going to create the various Kubernetes resources needed for Argo Workflows to do it’s magic:</p><pre>$ kubectl apply -n argo -f https://github.com/argoproj/argo-workflows/releases/download/v3.4.5/install.yaml</pre><p>We’ve got everything we need to get started now, our cluster now has:</p><ul><li>The necessary <strong>(CRDs)</strong> to create and run workflows.</li><li>An <strong>RBAC</strong> for secure and controlled access to Kubernetes resources.</li><li>A <strong>ConfigMap</strong> which is responsible for executing workflows.</li><li>We also set a<strong>PriorityClass</strong> to ensure that the <strong>Argo Workflow</strong> controller has a higher priority &amp; has the necessary resources to run in the cluster.</li></ul><p>A key thing to note here is <strong>Argo Workflows</strong> will define your CI/CD workflow using a YAML file to specify the following:</p><ul><li><strong>steps: You can add various build steps, there can be one or more.</strong></li><li><strong>dependencies: any dependencies you have which is needed to run your workflow can be added.</strong></li><li><strong>parameters: enables you to customize your workflow’s behavior, you can use input parameters &amp; pass those in to trigger workflows. Giving you the flexibility you need as well as making it reusable.</strong></li></ul><p>Now that we understand what <strong>Argo Workflows</strong> can do, we can start by creating and managing our workflows as code. Let’s create a Python 3 application workflow with three steps <strong>(deploying, testing, and building)</strong>. First, create a file named <strong>python-app.yaml </strong>inside our <strong>app</strong> directory and add the workflow definition:</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Workflow<br>metadata:<br>  name: python-app<br>spec:<br>  entrypoint: python-app<br>  templates:<br>  - name: python-app<br>    steps:<br>    - - name: build<br>        template: build<br>    - - name: test<br>        template: test<br>    - - name: deploy<br>        template: deploy<br>  - name: build<br>    container:<br>      image: python:3.11<br>      command: [python]<br>      args: [&quot;-c&quot;, &quot;print(&#39;build&#39;)&quot;]<br>  - name: test<br>    container:<br>      image: python:3.11<br>      command: [python]<br>      args: [&quot;-m&quot;, &quot;unittest&quot;, &quot;discover&quot;, &quot;-s&quot;, &quot;/app/tests&quot;]<br>      volumeMounts:<br>      - name: test-volume<br>        mountPath: /app/tests<br>    volumes:<br>    - name: test-volume<br>      hostPath:<br>        path: /path/to/tests<br>  - name: deploy<br>    container:<br>      image: python:3.11<br>      command: [python]<br>      args: [&quot;-c&quot;, &quot;print(&#39;deploy&#39;)&quot;]</pre><p>In this example, the Workflow CRD defines the CI/CD pipeline, and each step in the template has a specific purpose:</p><ul><li><strong>The build step builds the image with the latest changes, using a Python 3.11 image for this demo.</strong></li><li><strong>The test step mounts a volume with test files and runs unit tests with the Python unittest library.</strong></li><li><strong>The deploy step runs the Python container and prints deploy. Normally, this step would involve pushing the tested code to a container registry, like AWS ECR or Harbor, and then deploying it to the production environment.</strong></li></ul><p>To apply this file, you would use the kubectl apply command with the -f flag followed by the path to the YAML file. Here&#39;s an example command:</p><pre>$ kubectl apply -f python-app.yaml</pre><p>This will create an Argo Workflow with the name <strong>python-app</strong> along with their respective templates and steps. Now, let’s execute the <strong>argo get</strong> command to retrieve information about the workflow, including its status and logs:</p><pre>$ argo get python-app<br>Name:                python-app<br>Namespace:           default<br>ServiceAccount:      unset (will run with the default ServiceAccount)<br>Status:              Succeeded<br>Conditions:          <br> PodRunning          False<br> Completed           True<br>Created:             Mon Mar 20 16:23:06 -0500 (37 seconds ago)<br>Started:             Mon Mar 20 16:23:06 -0500 (37 seconds ago)<br>Finished:            Mon Mar 20 16:23:36 -0500 (7 seconds ago)<br>Duration:            30 seconds<br>Progress:            3/3<br>ResourcesDuration:   10s*(1 cpu),10s*(100Mi memory)<br><br>STEP           TEMPLATE    PODNAME                      DURATION  MESSAGE<br> ✔ python-app  python-app                                           <br> ├───✔ build   build       python-app-build-3831382643  4s          <br> ├───✔ test    test        python-app-test-461837862    4s          <br> └───✔ deploy  deploy      python-app-deploy-988129288  4s</pre><h3>Argo Workflows benefits</h3><p><strong>Argo Workflows</strong> is a powerful tool for managing and automating complex workflows in a containerized deployment environment. It offers several benefits, including:</p><ul><li><strong>Easy version control and modification of workflows as code.</strong></li><li><strong>Integration with Argo Events for triggering workflows based on events.</strong></li><li><strong>Automatic retries and error handling for reliable and robust workflow execution.</strong></li><li><strong>Seamless integration with Kubernetes and other container orchestration platforms</strong>.</li><li><strong>Support for parallel and sequential workflows, enabling faster and more efficient execution.</strong></li><li><strong>Extensive monitoring and logging capabilities, including integration with Prometheus and Grafana.</strong></li></ul><h3>Conclusion</h3><p>In conclusion, if your DevOps team is looking to simplify the management and automation of complex containerized workflows, Argo Workflows is an essential tool. However, when considering whether to use it or not, you should evaluate your team’s cloud and Kubernetes experience, size, and growth targets. It’s likely that you’ll end up somewhere in the middle. If you’re building platforms on top of Kubernetes, Argo Workflows and Tekton CD can be great tools for platform engineers to build abstractions and hide the pain of maintaining YAML files from dev teams.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25aefb02fa63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS API Gateway & Lambda with Terraform]]></title>
            <link>https://haque-zubair.medium.com/aws-lambda-api-gateway-with-terraform-bd143b1c56bb?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd143b1c56bb</guid>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[cloudwatch-logs]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 22:32:34 GMT</pubDate>
            <atom:updated>2023-03-09T15:03:13.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*ztE0X0xXc2lJKMgo7Xi4TQ.png" /><figcaption>Image from <a href="https://spacelift.io/blog/what-is-terraform">https://spacelift.io/blog/what-is-terraform</a></figcaption></figure><p>I attended a PI planning session with the product development team a short while ago. We were preparing for a new feature rollout, I was faced with the challenge of finding a reliable and cost-effective solution to build and deploy our R&amp;D project. After researching our options, we ultimately chose to use AWS SAM (Serverless Application Model). In this blog post, I will go over how to define, provision, and manage your infrastructure resources with Terraform. This should help you setup your AWS SAM environment and get you on your way to establishing your development process.</p><h3>Using Terraform</h3><p>I’ll go over how easy it is to manage &amp; deploy AWS resources such as API Gateway, S3 and Lambda functions. Pointing out key things like:</p><ol><li><strong>Using Declarative Infrastructure as Code (IaC):</strong> Terraform uses a declarative syntax to describe the desired state of your infrastructure.</li><li><strong>Resource management with Terraform:</strong> It allows you to create, modify, and delete AWS resources. It also supports versioning, which makes it easy if you want to do a roll back, going back to a previous configuration.</li><li><strong>State management:</strong> Terraform simplifies infrastructure management by using configuration files to define the desired state of your infrastructure and automatically making changes to bring it in line with that state, ensuring consistent and predictable configuration.</li></ol><h3>Creating a Lambda Function</h3><p>We’re going to start by creating a basic NodeJs lambda function, create a directory called handler &amp; in that directory create a file called handler.js</p><pre>&#39;use strict&#39;;<br><br>export async function handler(event) {<br>  return {<br>    statusCode: 200,<br>    headers: {<br>      &#39;Access-Control-Allow-Origin&#39;: &#39;*&#39;<br>    },<br>    body: JSON.stringify(<br>      {<br>        message: &#39;Your function executed successfully!&#39;<br>      },<br>      null,<br>      2<br>    ),<br>  };<br>}</pre><p>This handler function I created above, basically returns a JSON object with a message and status code of 200 when it is successfully invoked and executed.</p><h3>Terraform</h3><p>We’re going to start on writing our terraform code, create a directory called terraform &amp; in that directory create a provider.tf file. This file declares version constraints for the various different <a href="https://developer.hashicorp.com/terraform/language/providers">providers</a> we will use, such as the AWS provider the version of the Terraform CLI we’re going to use &amp; what region we’re going to create our S3 buckets and Lambda functions in:</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 4.21.0&quot;<br>    }<br>    random = {<br>      source  = &quot;hashicorp/random&quot;<br>      version = &quot;~&gt; 3.3.0&quot;<br>    }<br>    archive = {<br>      source  = &quot;hashicorp/archive&quot;<br>      version = &quot;~&gt; 2.2.0&quot;<br>    }<br>  }<br><br>  required_version = &quot;~&gt; 1.0&quot;<br>}<br><br>provider &quot;aws&quot; {<br>  region = &quot;us-east-2&quot;<br>}</pre><p>The next thing we’re going to do is, we’re going to create a zip archive of our Lambda function and upload it to S3. The reason we’re doing that is, our Lambda functions are implemented as packages of code, then those packages are uploaded to AWS. Example below in the handler-lambda-bucket.tf file:</p><pre>resource &quot;random_pet&quot; &quot;lambda_bucket_name&quot; {<br>  prefix = &quot;lambda&quot;<br>  length = 2<br>}<br><br>resource &quot;aws_s3_bucket&quot; &quot;lambda_bucket&quot; {<br>  bucket        = random_pet.lambda_bucket_name.id<br>  force_destroy = true<br>}<br><br>resource &quot;aws_s3_bucket_public_access_block&quot; &quot;lambda_bucket&quot; {<br>  bucket = aws_s3_bucket.lambda_bucket.id<br><br>  block_public_acls       = true<br>  block_public_policy     = true<br>  ignore_public_acls      = true<br>  restrict_public_buckets = true<br>}</pre><p>So now we have our new S3 bucket created. I want to take a moment to go over the aws_s3_bucket_public_access_block which is what we used to set up our permissions for our AWS S3 bucket. This particular Terraform <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block">resource</a> applies access restrictions using the following parameters:</p><p><em>(Note: this helped us ensure that the S3 bucket is not publicly accessible)</em></p><ul><li><strong>block_public_acls</strong></li><li><strong>block_public_policy</strong></li><li><strong>ignore_public_acls</strong></li><li><strong>restrict_public_buckets</strong></li></ul><p>keep in mind that all access to the bucket is controlled through AWS Identity and Access Management (IAM) policies, which can always be adjusted. Ok, so moving on to the next thing which is going to be creating a Lambda function that runs in response to an event trigger. The example is below which is created in thehandler-lambda.tf file:</p><pre>resource &quot;aws_iam_role&quot; &quot;handler_lambda_exec&quot; {<br>  name = &quot;handler-lambda&quot;<br><br>  assume_role_policy = &lt;&lt;POLICY<br>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: {<br>        &quot;Service&quot;: &quot;lambda.amazonaws.com&quot;<br>      },<br>      &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>    }<br>  ]<br>}<br>POLICY<br>}<br><br>resource &quot;aws_iam_role_policy_attachment&quot; &quot;handler_lambda_policy&quot; {<br>  role       = aws_iam_role.handler_lambda_exec.name<br>  policy_arn = &quot;arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole&quot;<br>}<br><br>resource &quot;aws_lambda_function&quot; &quot;handler&quot; {<br>  function_name = &quot;handler&quot;<br><br>  s3_bucket = aws_s3_bucket.lambda_bucket.id<br>  s3_key    = aws_s3_object.handler.key<br><br>  runtime = &quot;nodejs16.x&quot;<br>  handler = &quot;function.handler&quot;<br><br>  source_code_hash = data.archive_file.handler.output_base64sha256<br><br>  role = aws_iam_role.handler_lambda_exec.arn<br>}<br><br><br>resource &quot;aws_cloudwatch_log_group&quot; &quot;handler_lambda&quot; {<br>  name = &quot;/aws/lambda/${aws_lambda_function.handler.function_name}&quot;<br>}<br><br>data &quot;archive_file&quot; &quot;handler&quot; {<br>  type        = &quot;zip&quot;<br>  source_dir  = &quot;../${path.module}/handler&quot;<br>  output_path = &quot;../${path.module}/handler.zip&quot;<br>}<br><br>resource &quot;aws_s3_object&quot; &quot;handler&quot; {<br>  bucket  = aws_s3_bucket.lambda_bucket.id<br>  key    = &quot;handler.zip&quot;<br>  source = data.archive_file.handler.output_path<br>  etag = filemd5(data.archive_file.handler.output_path)<br>}</pre><ol><li><strong>aws_iam_role:</strong>We start off by creating an AWS IAM role for the Lambda function, which has a name and a policy. The policy we set in this configuration is the basic execution role for our Lambda function.</li><li><strong>aws_iam_role_policy_attachment:</strong>We also have a policy attachment for the AWS IAM role we created, this policy grants permissions that are necessary for the Lambda function to run, such as writing logs to our CloudWatch Logs.</li><li><strong>aws_lambda_function:</strong>The <strong>aws_lambda_function</strong>resource will create a Lambda function named “hello” with a specified runtime of NodeJS, it’s going to use the IAM role created above as the execution role. An important detail I wanted to point out is, on line 34 you’ll see there is a <strong>source_code_hash</strong>which is going to be the hash of the zip file that will be uploaded to the S3 bucket, terraform can detect if the zip file has changed, and if it has, it will update the Lambda function. Also, last but not least, we have the arn role on line 36 that will be used to execute the Lambda function when it is invoked.</li><li><strong>aws_cloudwatch_log_group: </strong>This Terraform<strong> </strong>resource creates a CloudWatch Logs group for our Lambda function.</li><li><strong>data_archive_file: </strong>This is the zip file that will be uploaded to our S3 bucket created above and our Lambda function has the permissions to access it.</li><li><strong>aws_s3_object: </strong>Uploads a zip archive of our source code.</li></ol><h3>AWS API Gateway</h3><p>The next step is to create an AWS API Gateway using Terraform. We’re going to use API Gateway version 2, which allows you to create and manage RESTful APIs. Create a file called api-gateway.tfand add the following:</p><pre>resource &quot;aws_apigatewayv2_api&quot; &quot;main&quot; {<br>  name          = &quot;main&quot;<br>  protocol_type = &quot;HTTP&quot;<br>}<br><br>resource &quot;aws_apigatewayv2_stage&quot; &quot;dev&quot; {<br>  api_id = aws_apigatewayv2_api.main.id<br><br>  name        = &quot;dev&quot;<br>  auto_deploy = true<br><br>  access_log_settings {<br>    destination_arn = aws_cloudwatch_log_group.main_api_gw.arn<br><br>    format = jsonencode({<br>      requestId               = &quot;$context.requestId&quot;<br>      sourceIp                = &quot;$context.identity.sourceIp&quot;<br>      requestTime             = &quot;$context.requestTime&quot;<br>      protocol                = &quot;$context.protocol&quot;<br>      httpMethod              = &quot;$context.httpMethod&quot;<br>      resourcePath            = &quot;$context.resourcePath&quot;<br>      routeKey                = &quot;$context.routeKey&quot;<br>      status                  = &quot;$context.status&quot;<br>      responseLength          = &quot;$context.responseLength&quot;<br>      integrationErrorMessage = &quot;$context.integrationErrorMessage&quot;<br>      }<br>    )<br>  }<br>}<br><br>resource &quot;aws_cloudwatch_log_group&quot; &quot;main_api_gw&quot; {<br>  name = &quot;/aws/api-gw/${aws_apigatewayv2_api.main.name}&quot;<br><br>  retention_in_days = 30<br>}</pre><p>So let’s take a look at this plan, as mentioned above it is sets up a basic infrastructure for a v2 API Gateway. You can add more configuration options and integrations with other AWS services, if needed but I am going to keep it pretty basic for this demo:</p><ul><li><strong>aws_apigatewayv2_api: </strong>The name of our API is called main, which I will show you on the AWS console once we apply our configuration.</li><li><strong>aws_apigatewayv2_stage: </strong>This<strong> </strong>Terraform resource represents the deployment for the API Gateway v2 API, which we have set to dev.</li><li>In API Gateway V2,</li><li><strong>aws_cloudwatch_log_group:</strong>The stage is set to auto-deploy and has an access log setting that writes to a CloudWatch log group called “main_api_gw”. The CloudWatch log group has a retention period of 30 days.</li></ul><p>Now, let’s write the Terraform for creating the API Gateway v2 route that invokes our Lambda function. The code will use the following three resources:</p><pre>resource &quot;aws_apigatewayv2_integration&quot; &quot;lambda_handler&quot; {<br>  api_id = aws_apigatewayv2_api.main.id<br><br>  integration_type = &quot;AWS_PROXY&quot;<br>  integration_uri  = aws_lambda_function.handler.invoke_arn<br>}<br><br>resource &quot;aws_apigatewayv2_route&quot; &quot;post_handler&quot; {<br>  api_id    = aws_apigatewayv2_api.main.id<br>  route_key = &quot;POST /handler&quot;<br><br>  target = &quot;integrations/${aws_apigatewayv2_integration.lambda_handler.id}&quot;<br>}<br><br>resource &quot;aws_lambda_permission&quot; &quot;api_gw&quot; {<br>  statement_id  = &quot;AllowExecutionFromAPIGateway&quot;<br>  action        = &quot;lambda:InvokeFunction&quot;<br>  function_name = aws_lambda_function.handler.function_name<br>  principal     = &quot;apigateway.amazonaws.com&quot;<br><br>  source_arn = &quot;${aws_apigatewayv2_api.main.execution_arn}/*/*&quot;<br>}</pre><ol><li><strong>aws_apigatewayv2_integration:</strong> resource specifies the integration between the API Gateway and the Lambda function.</li><li><strong>aws_apigatewayv2_route:</strong> resource defines the route for the API Gateway. The <strong>route_key</strong> specifies the HTTP method and path for the route, so this is a POST request and the endpoint is handler.</li><li><strong>aws_lambda_permission:</strong> resource allows the API Gateway to invoke the Lambda function.</li></ol><p>Before actually creating these resources, it’s a good practice to preview the changes that Terraform will make by generating a plan file.</p><pre>$ terraform plan</pre><p>The output of the <strong>terraform plan</strong> command will include information such as:</p><ul><li>The resources that Terraform will create, modify, or delete.</li><li>Any changes to resource attributes or dependencies.</li><li>Any errors or warnings that Terraform encounters while generating the plan.</li></ul><p>Once you have reviewed and approved the plan, you can run the <strong>terraform apply</strong> command to actually execute the plan and create the aws resources you defined in your code. To see your resources in the console, you’ll need to log in to your AWS account and navigate to the relevant modules:</p><ol><li><strong>API Gateway:</strong> you should be able to the see the <strong><em>main </em></strong>API.</li><li><strong>AWS Lambda:</strong> you should be able to see the <strong><em>handler</em></strong> Lambda function created above.</li></ol><p>To view an example of this code, you can clone and share my <a href="https://github.com/zhaque44/lambda-api-gateway-terraform">repo on Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd143b1c56bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real Time Monitoring with AWS ElastiCache]]></title>
            <link>https://haque-zubair.medium.com/real-time-monitoring-with-aws-elasticache-4edf7a4c020b?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/4edf7a4c020b</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[elasticache]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 22:45:43 GMT</pubDate>
            <atom:updated>2023-01-02T20:44:34.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*T5ymtoNDwmBukoW6tjmlKg.jpeg" /></figure><p><a href="https://aws.amazon.com/elasticache/">Amazon ElastiCache</a> is a managed in-memory data store and cache service provided by AWS. We want to build alerting around our AWS-EKS cluster which is using ElastiCache &amp; Redis. We’re doing this because, when an outage occurs we want to be notified right way so we can troubleshoot what went wrong with Redis and try to resolve it as soon as possible.</p><h3>Solution</h3><p>The best solution would be, to take a more proactive approach to monitoring and alerting. Our approach will be to send an alert when urgent issues have been detected, or when resource limits are about to be reached.</p><h3>Alerts &amp; Notifications</h3><p>It’s necessary to call attention to our metrics even when the system is performing adequately. We are looking to implement the following types of alerts to help mitigate our risk in terms of downtime. The best way to diagnose these issues is to set a priority on the kinds of alerts we are receiving from Grafana:</p><p><strong>soft-alerts (low to moderate severity): </strong>posting a message in your messaging application such as slack or gchat will give this message high visibility, but won&#39;t disrupt anyone in the middle of the work day. It will let us know for example, if we&#39;re about to run out of disk space or anything memory or CPU usage related. This is going to give us time to diagnose the situation before something more sever occurs.</p><p><strong>high-alerts (high severity): </strong>This will also be posted as a notification in the same chat room, this particular alert will require immediate attention. Recipients of this alert, will prioritize this alert and share findings. As well as, solve the issue and validate that things are functioning as designed.</p><h3>Integrate AWS CloudWatch with Grafana</h3><p>CloudWatch monitors all of our cloud resources, for us to get better metrics visualization of our environments. Let’s start by logging in to our AWS account and creating a user in the IAM module:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*GtHlBcf7DgmzeVNQwFp0Hg.png" /></figure><p>Select the checkbox to enable Programmatic Access:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*2goH0BRQ1-maRaFXGAXL-A.png" /></figure><p>Then you want to attach an existing policy, which is provided by AWS (<a href="https://docs.aws.amazon.com/grafana/latest/userguide/AMG-manage-permissions.html">Amazon Managed Grafana policy</a>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7G-qi4YZroqpzHuq1qYF9g.png" /></figure><p>Once you have done that, click the Next: Review button, then add your AWS access ID &amp; secret key. Once you have successfully created the grafana-cloudwatchuser, navigate to Access Management &gt; Policies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjX5MN26GFhBn4_dr1uEQA.png" /></figure><p>The same policy is attached to our grafana-cloudwatch user (navigate to the IAM &gt; Users module and select the grafana-cloudwatch user):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAM3KtIqeMLTMnwChyKjSg.png" /></figure><h3>Add AWS X-Ray Plugin</h3><p>The <a href="https://grafana.com/grafana/plugins/grafana-x-ray-datasource/">AWS X-Ray</a> plugin provides a holistic view of requests as they travel through your system. It helps with analyzing and debugging applications &amp; monitoring cloud performance metrics.</p><p>Grafana is going to need permissions granted via IAM, so click on the Add permissions button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*sK9MSIgXwsRIlcVdKlLWuQ.png" /></figure><p>Select the Attach existing policies directly, option and search for AWSXrayFullAccess. Once you have successfully added that existing policy, you’ll be able to see that policy on the Permissions tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*JG8lbMdvLvZAM7tOIsX8Tg.png" /></figure><p>Later on we will add this Data Source with Cloudwatch, you’ll be able to be see an option X-ray trace link which will integrate the plugin &amp; allow us to have Observability &amp; Traceability of our product platform.</p><h3>Add CloudWatch as a Data Source in Grafana</h3><p>Now we can add the CloudWatch Data Source in Grafana, Log in to Grafana and navigate to (Configuration &gt; Data sources):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*j8aHKAlcTD1VfK2rbibRCA.png" /></figure><p>Click on Add Data Source &amp; select the CloudWatch Data Source:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aURrzEVyYy2IbnjweesAJQ.png" /></figure><p>Fill out all of your Connection Details:</p><ul><li>Access &amp; secret key</li><li>ARN role</li><li>Default Region</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MPAlSHn1aRNArLKVPS5fyQ.png" /></figure><p>Once you have successfully filled out all of those details, when you scroll down you’ll see the X-ray trace link, I mentioned above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*V8XC7oAL8m4LfYsrFpIpew.png" /></figure><h3>Adding the AWS ElastiCache Redis Dashboard</h3><p>Now we can import the <a href="https://grafana.com/grafana/dashboards/969-aws-elasticache-redis/">AWS ElastiCache Dashboard</a> in Grafana, Click the Import button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*rG7sD8N9lY7T6BuOF7bZYQ.png" /></figure><p>We’re going to use the dashboard ID, for the ElastiCache Dashboard, which is <strong>969</strong> in this case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wL5_bs3KSPlnHgUUMwg7w.png" /></figure><p>Then go ahead and name your dashboard and click the Import button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MaE9NPW05GlRZpUTBT3a9w.png" /></figure><p>Grafana should now display the new Dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*de4O4UWROyLvGJVEbOFzlQ.png" /></figure><h3>Monitoring and Alerting</h3><p>There are quite a few CloudWatch metrics which offer good insight into current real-time performance. By implementing this dashboard we will be able to take corrective action before performance issues occur. We will be setting up alerting on the following Redis metrics:</p><ol><li>CPUUtilization</li><li>DatabaseMemoryUsagePercentage</li></ol><h4>CPUUtilization</h4><p>The CPUUtilization metric monitors your workload, this metric is reported to us as a percentage.</p><p><strong>soft-alert:</strong> If we set a soft-alert to notify us via webhook at 80%, when we utilized 79% of our CPU usage it will trigger a message which will be sent to us in our team chat room. This will be an eye-opener for us, basically notifying us that Redis is almost exhausted when it comes to processing requests.</p><p><strong>high-alert:</strong> For this particular alert, we’ll set our threshold at 90%, when we have reached 89% of CPU usage it triggers a webhook &amp; sends a message to our team chat room letting us know that an outage has occurred &amp; our website is down.</p><h4>DatabaseMemoryUsagePercentage</h4><p>The DatabaseMemoryUsagePercentage metric monitors the percentage of memory that is currently in use. This percentage is calculated by used_memory/maxmemory</p><p><strong>soft-alert:</strong> We’re going to set our soft-alert to notify us at 80%, when we have reached 79% of our memory usage it will trigger a webhook &amp; send us a message to our team chat room. This should indicate that something out of the ordinary is happening and we should investigate why this is occuring.</p><p><strong>high-alert:</strong> For this alert, we’ll set our threshold at 90%, when we have reached 89% of our memory usage and we’ll receive a message in our team chat room, at this point an outage has occurred &amp; is disruptive to our business.</p><h3>Customizing Alerts</h3><p>As mentioned above, we wanted to be notified via our chat messaging system when an outage occurs. I wanted these messages to be team specific, so I am going to create a notification channel on the sidebar, click on bell icon and select Notification channels:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*28BHptql4oRbHUwCeCG6WA.png" /></figure><p>Click on the New channel button and select the Type of notification channel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*vxZ65kaTWDHTsjoNG5c2Sw.png" /></figure><p>Here is where you can select Slack or Google Hangouts Chat:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9utP1nzHnfsiVMSUAVkacw.png" /></figure><p>fill out all of the relevant details:</p><ul><li>Name: gchat hangout space name</li><li>Url: incoming webhook url, which you can retrieve from gchat</li><li>Notification settings: customize them to your preference</li></ul><p>Once you have saved all of the details, go back to the dashboard and Edit the CPUUtilization panel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iZ42U-EAdkJBJrCBD1gEwg.png" /></figure><p>Select the Alert module and click on the Create Alert button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7hva2vJocTjSzT7iiFDmOQ.png" /></figure><p>Customize the Alert based on your preferred Rules and conditions, now scroll down to the Notifications section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mgwK6ci_5x1JSFfVBzxVFQ.png" /></figure><p>Click the <strong>+ </strong>button<strong> </strong>and add the Notification channel you just created in the step above, fill out the Message section and save the changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lKeHKDDoAwx5XY6TB0mpGQ.png" /></figure><p>That’s basically it, there are many out of the box Redis Grafana dashboards to choose from this one just happened to suit my use case the most.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4edf7a4c020b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skaffold: Local development with Kubernetes]]></title>
            <link>https://haque-zubair.medium.com/skaffold-local-development-with-kubernetes-e90fe3f7dfdf?source=rss-488c186c9d41------2</link>
            <guid isPermaLink="false">https://medium.com/p/e90fe3f7dfdf</guid>
            <dc:creator><![CDATA[Zubair Haque]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 13:54:57 GMT</pubDate>
            <atom:updated>2022-11-23T14:09:57.081Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*GvAr7fQzvt7GYPMBwTdvnA.jpeg" /></figure><p><strong>Skaffold</strong> is an amazing tool for doing local development with a kubernetes cluster. I’m able to locally test my changes, without having to re-deploy all the time. The productivity boost for our dev teams, is speeding up feature development and enabling a faster release cycle.</p><p>I started using <strong>Skaffold</strong> for all new projects in my current position, well for any new microservice in our ETL data pipeline and it works pretty well on a minikube cluster.</p><h3>Getting Started with tooling</h3><p>Let’s get our <a href="https://minikube.sigs.k8s.io/docs/start/"><strong><em>minikube</em></strong></a> cluster setup. Install <strong><em>minikube</em></strong> locally by using homebrew:</p><pre>$ brew install minikube</pre><p>Make sure it was installed successfully:</p><pre>$ minikube version</pre><p>Output:</p><pre><strong>minikube version: v1.27.1</strong></pre><pre><strong>commit: fe869b5d4da11ba318eb84a3ac00f336411de7ba</strong></pre><p>Start minikube:</p><pre>$ minikube start</pre><p>Use the minikube addon to enable the ingress <strong><em>nginx controller:</em></strong></p><pre>$ minikube addons enable ingress</pre><p>Install skaffold on your machine:</p><pre>$ brew install skaffold</pre><p>Validate that the install was successful:</p><pre>$ skaffold version</pre><p>The skaffold docs talk about their <a href="https://skaffold.dev/docs/pipeline-stages/init"><strong><em>init</em></strong></a> command, which is pretty easy to run:</p><pre>$ skaffold init </pre><p>So if your project has no kubernetes manifests yet, the init command tries to bootstrap your project for you. Now you can interact with all common cli tools such as <strong><em>kubectl &amp; kustomize</em></strong></p><h3>Getting started with our app</h3><p>For this skaffold demo, we’re going to create a basic NodeJS app. Add your package.json to the root directory of this project:</p><pre>{<br>  &quot;name&quot;: &quot;skaffold-nodejs-project&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;nodemon src&quot;<br>  },<br>  &quot;repository&quot;: {<br>    &quot;type&quot;: &quot;git&quot;,<br>    &quot;url&quot;: &quot;&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;body-parser&quot;: &quot;^1.19.0&quot;,<br>    &quot;cors&quot;: &quot;^2.8.5&quot;,<br>    &quot;express&quot;: &quot;^4.17.1&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;chai&quot;: &quot;^4.3.4&quot;,<br>    &quot;mocha&quot;: &quot;^9.0.2&quot;,<br>    &quot;nodemon&quot;: &quot;^2.0.12&quot;,<br>    &quot;supertest&quot;: &quot;^6.1.3&quot;<br>  }<br>}</pre><p>Now create a src directory and create a file called index.jsand add:</p><pre>const express = require(&#39;express&#39;);<br><br>const app = express();<br><br>app.get(&#39;/&#39;, (request, response) =&gt; {<br>  response.status(200).send({ message: &#39;Local Development: Hello World!&#39; });<br>});<br><br>app.listen(3000, () =&gt; {<br>  console.log(&#39;Server is running!&#39;);<br>});</pre><p>In the example above we have the following:</p><pre>request: we define a route handler to make a simple GET request. The app <br>will send back a 200 response and display:<br><br>&quot;Local Development: Hello World!&quot; <br><br>on the browser.</pre><p>our app will listen in on port 3000, here is a list of other places where you will need to make changes to accommodate for this:</p><pre>Dockerfile: we&#39;re going to EXPOSE port 3000 right before we run npm start<br>service.yaml: the Service manifest port will be set to 3000<br>deployment.yaml: the Deployment manifest will set the containerPort to 3000</pre><p>Create a <a href="https://github.com/zhaque44/skaffold-nodejs-project/blob/main/Dockerfile"><strong><em>Dockerfile</em></strong></a>, skaffold will use this Dockerfile to build your images:</p><pre>FROM node:16.18.0 AS build<br><br>WORKDIR /app<br><br>COPY package.json .<br><br>RUN npm install<br><br>COPY . .<br><br>EXPOSE 3000<br><br>CMD [ &quot;npm&quot;, &quot;run&quot;, &quot;start&quot; ]</pre><h3>Creating the Deployment Manifest File</h3><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: app<br>  labels:<br>    app: app<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: app<br>  template:<br>    metadata:<br>      labels:<br>        app: app<br>    spec:<br>      containers:<br>        - name: app<br>          image: express-app<br>          resources:<br>            limits:<br>              memory: 512Mi<br>              cpu: &quot;1&quot;<br>          ports:<br>            - containerPort: 3000</pre><h3>Creating the Service Manifest File</h3><p>Now we need to create a service manifest for your deployment &amp; that looks like this:</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: app-svc<br>spec:<br>  type: NodePort<br>  selector:<br>    app: app<br>  ports:<br>  - port: 3000<br>    targetPort: 3000</pre><h3>Add your skaffold.yaml file</h3><pre>apiVersion: skaffold/v2beta21<br>kind: Config<br><br>profiles:<br>  - name: dev<br>    activation:<br>      - command: dev<br>    build:<br>      artifacts:<br>        - image: express-app<br>          context: .<br>          sync:<br>            manual:<br>            - src: &#39;src/**/*.js&#39;<br>              dest: .</pre><p>If you look at the example above you’ll see that the manual sync rule must point out the src of where the files live and the dest field, which is the relative path of your image.</p><p>Bringing up your local cluster:</p><pre>skaffold dev --port-forward</pre><p>Now in this output, we can see:</p><pre>Listing files to watch...<br> - express-app<br>Generating tags...<br> - express-app -&gt; express-app:ca56ce4<br>Checking cache...<br> - express-app: Found Locally<br>Tags used in deployment:<br> - express-app -&gt; express-app:c1365267f7badf38c83efb341be2521a041ac566d5796fbf38ca6ac7348774d6<br>Starting deploy...<br> - deployment.apps/app created<br> - service/app-svc created</pre><p>that the deployment &amp; service was created. Now, when any js file changes, Skaffold will continuously apply the deployment.yaml file &amp; build your changes,</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e90fe3f7dfdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>