<?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
     <title>BigBinary Blog</title>
     <link href="https://www.bigbinary.com/feed.xml" rel="self"/>
     <link href="https://www.bigbinary.com/"/>
     <updated>2026-10-05T12:08:12+00:00</updated>
     <id>https://www.bigbinary.com/</id>
     <entry>
       <title><![CDATA[Grafana Loki and Kubernetes Event exporter]]></title>
       <author><name>Vishal Yadav</name></author>
      <link href="https://www.bigbinary.com/blog/k8s-event-exporter-and-grafana-loki-integration"/>
      <updated>2024-05-07T12:00:00+00:00</updated>
      <id>https://www.bigbinary.com/blog/k8s-event-exporter-and-grafana-loki-integration</id>
      <content type="html"><![CDATA[<p>In the previous<a href="https://www.bigbinary.com/blog/prometheus-and-grafana-integration">blog</a>, wediscussed integrating <a href="https://prometheus.io/">Prometheus</a> and<a href="https://grafana.com/">Grafana</a> in the Kubernetes Cluster. In this blog, we'llexplore how to integrate the<a href="https://github.com/resmoio/kubernetes-event-exporter">Kubernetes Event exporter</a>&amp; <a href="https://grafana.com/oss/loki/">Grafana Loki</a> into your Kubernetes Clusterusing a helm chart.</p><p>Additionally, youll also learn how to add Grafana Loki as a data source to yourGrafana Dashboard. This will help you visualize the Kubernetes events.</p><p>Furthermore, we'll delve into the specifics of setting up the Event exporter andGrafana Loki, ensuring you understand each step of the process. From downloadingand configuring the necessary helm charts to understanding the Grafana Lokidashboard, we'll cover it all.</p><p>By the end of this blog, you'll be able to fully utilize Grafana Loki andKubernetes Event Exporter, gaining insights from your Kubernetes events.</p><h2>How Kubernetes event exporter can help us in monitoring health</h2><p>Objects in Kubernetes, such as Pod, Deployment, Ingress, Service publish eventsto indicate status updates or problems. Most of the time, these events areoverlooked and their 1-hour lifespan might cause missing important updates. Theyare also not searchable and cannot be aggregated.</p><p>For instance, they can alert you to changes in the state of pods, errors inscheduling, and resource constraints. Therefore, exporting these events andvisualizing them can be crucial for maintaining the health of your cluster.</p><p>Kubernetes event exporter allows exporting the often missed Kubernetes events tovarious outputs so that they can be used for observability or alerting purposes.We can have multiple receivers to export the events from the Kubernetes cluster.</p><ul><li><a href="https://www.opsgenie.com/">Opsgenie</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#webhookshttp">Webhooks/HTTP</a></li><li><a href="https://www.elastic.co/">Elasticsearch</a></li><li><a href="https://opensearch.org/">OpenSearch</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#slack">Slack</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#kinesis">Kinesis</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#firehose">Firehose</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#sns">SNS</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#sqs">SQS</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#file">File</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#stdout">Stdout</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#kafka">Kafka</a></li><li><a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter.html">OpsCenter</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#customizing-payload">Customize Payload</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#pubsub">Pubsub</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#teams">Teams</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#syslog">Syslog</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#bigquery">Bigquery</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#pipe">Pipe</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#aws-eventbridge">Event Bridge</a></li><li><a href="https://github.com/resmoio/kubernetes-event-exporter#loki">Grafana Loki</a></li></ul><h2>Setting up Grafana Loki &amp; Kubernetes event exporter using Helm chart</h2><p>We will once again use <a href="https://artifacthub.io/">ArtifactHub</a>, which provides ahelm chart for installing Grafana Loki onto a Kubernetes Cluster. If you needinstructions on how to install Helm on your system, you can refer to this blog.</p><p>In this blog post, we will install a Helm<a href="https://artifacthub.io/packages/helm/grafana/loki">chart</a> that sets up Loki inscalable mode, with separate read-and-write components that can be independentlyscaled. Alternatively, we can install Loki in monolithic mode, where the HelmChart installation runs the Grafana Loki <em>single binary</em> within a Kubernetescluster. You can learn more about this<a href="https://grafana.com/docs/loki/latest/setup/install/helm/install-monolithic/#install-the-monolithic-helm-chart">here</a>.</p><h3>1. Create S3 buckets</h3><ul><li><p>grafana-loki-chunks-bucket</p></li><li><p>grafana-loki-admin-bucket</p></li><li><p>grafana-loki-ruler-bucket</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/loki-s3-buckets.png" alt="The four Grafana Loki buckets listed in the AWS S3 console"></p></li></ul><h3>2. Create a policy for Grafana Loki</h3><p>Create a new policy under IAM on Amazon AWS using the below snippet.</p><pre><code>{    &quot;Version&quot;: &quot;2012-10-17&quot;,    &quot;Statement&quot;: [        {            &quot;Sid&quot;: &quot;LokiStorage&quot;,            &quot;Effect&quot;: &quot;Allow&quot;,            &quot;Action&quot;: [                &quot;s3:ListBucket&quot;,                &quot;s3:PutObject&quot;,                &quot;s3:GetObject&quot;,                &quot;s3:DeleteObject&quot;            ],            &quot;Resource&quot;: [                &quot;arn:aws:s3:::grafana-loki-chunks-bucket&quot;,                &quot;arn:aws:s3:::grafana-loki-chunks-bucket/*&quot;,                &quot;arn:aws:s3:::grafana-loki-admin-bucket&quot;,                &quot;arn:aws:s3:::grafana-loki-admin-bucket/*&quot;,                &quot;arn:aws:s3:::grafana-loki-ruler-bucket&quot;,                &quot;arn:aws:s3:::grafana-loki-ruler-bucket/*&quot;            ]        }    ]}</code></pre><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/grafana-loki-policy.png" alt="Terminal output confirming the Grafana Loki IAM policy was created"></p><h3>3. Create a Role with the above permission</h3><p>Create a role with a custom trust policy &amp; use the below snippet</p><pre><code>{    &quot;Version&quot;: &quot;2012-10-17&quot;,    &quot;Statement&quot;: [        {            &quot;Effect&quot;: &quot;Allow&quot;,            &quot;Principal&quot;: {                &quot;Federated&quot;: &quot;arn:aws:iam::account_id:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/open_id&quot;            },            &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,            &quot;Condition&quot;: {                &quot;StringEquals&quot;: {                    &quot;oidc.eks.us-east-1.amazonaws.com/id/open_id:aud&quot;: &quot;sts.amazonaws.com&quot;,                    &quot;oidc.eks.us-east-1.amazonaws.com/id/open_id:sub&quot;: &quot;system:serviceaccount:default:grafana-loki-access-s3-role-sa&quot;                }            }        }    ]}</code></pre><p>Note: Please update the account_id and open_id in the above given snippet.</p><p><strong>grafana-loki-access-s3-role-sa</strong>is the service account name that we willmention in the Loki values.</p><h3>4. Add Grafana using the helm chart</h3><p>To get this Helm chart, run this command:</p><pre><code class="language-jsx">helm repo add grafana https://grafana.github.io/helm-chartshelm repo update</code></pre><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/chart-add-output.png" alt="Terminal output from adding and updating the Grafana Helm chart repository"></p><p>We have downloaded the latest version of the Grafana.</p><h3>5. Install grafana/loki stack using the helm chart</h3><p>Create a <strong>loki-values yaml</strong> file with the below snippet</p><pre><code>loki:  readinessProbe: {}  auth_enabled: false  storage:    bucketNames:      chunks: grafana-loki-chunks-bucket      ruler: grafana-loki-rules-bucket      admin: grafana-loki-admin-bucket    type: s3    s3:      endpoint: null      region: us-east-1      secretAccessKey: null      accessKeyId: null      s3ForcePathStyle: false      insecure: falsemonitoring:  lokiCanary:      enabled: false  selfMonitoring:    enabled: falsetest:  enabled: falseserviceAccount:  create: true  name: grafana-loki-access-s3-role-sa  imagePullSecrets: []  annotations:    eks.amazonaws.com/role-arn: arn:aws:iam::account_id:role/loki-role  automountServiceAccountToken: true</code></pre><p>To install Loki using the Helm Chart on Kubernetes Cluster, runthis<code>helm install</code>command:</p><pre><code class="language-jsx">helm install my-loki grafana/loki --values loki-values.yaml</code></pre><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/chart-installation-output.png" alt="Terminal output from installing the Loki Helm chart"></p><p>We have successfully installed Loki on the Kubernetes Cluster.</p><p>Run the followingcommand to view all the resources created by the Loki HelmChart in your Kubernetes cluster:</p><pre><code class="language-jsx">kubectl get all -l app.kubernetes.io/name=loki</code></pre><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/all-resources-output.png" alt="Output of kubectl get all for the Loki release, listing its pods, services and deployments"></p><p>Helm chart created the following components:</p><ul><li><strong>Loki read and write:</strong> Loki is installed in scalable mode by default, whichincludes a read-and-write component. These components can be independentlyscaled out.</li><li><strong>Gateway:</strong> Inspired by Grafanas<a href="https://github.com/grafana/loki/blob/main/production/ksonnet/loki">Tanka setup</a>,the chart installs a gateway component by default. This NGINX componentexposes Lokis API and automatically proxies requests to the appropriate Lokicomponents (read or write, or a single instance in the case of filesystemstorage). The gateway must be enabled to provide an Ingress since the Ingressonly exposes the gateway. If enabled, Grafana and log shipping agents, such asPromtail, should be configured to use the gateway. If NetworkPolicies areenabled, they become more restrictive when the gateway is active.</li><li><strong>Caching:</strong> In-memory caching is enabled by default. If this type of cachingis unsuitable for your deployment, consider setting up memcache.</li></ul><p>Run this command to view all the Kubernetes Services for Prometheus &amp; Grafana:</p><pre><code class="language-jsx">kubectl get service -l app.kubernetes.io/name=loki</code></pre><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/all-services-output.png" alt="Output of kubectl get service for the Loki release, listing its services"></p><p>Listed services for Loki are:</p><ul><li>loki-backend</li><li>loki-backend-headless</li><li>loki-gateway</li><li>loki-memberlist</li><li>loki-read</li><li>loki-read-headless</li><li>loki-write</li><li>loki-write-headless</li><li>query-scheduler-discovery</li></ul><p>The <code>loki-gateway</code> service will be used to add Loki as a Datasource intoGrafana.</p><h3>6. Adding Loki data source in Grafana</h3><p>On the main page of Grafana, click on &quot;<strong>Home</strong>&quot;. Under &quot;<strong>Connections</strong>&quot;, youwill find the &quot;<strong>Data sources</strong>&quot; option.</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/grafana-dashboard.webp" alt="The Grafana home page, with the Data sources option listed under Connections"></p><p>On the Data Sources page, click on the &quot;Add new data source&quot; button.</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/data-sources-page.png" alt="The Grafana Data sources page with the Add new data source button"></p><p>In the search bar, type &quot;Loki&quot; and search for it.</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/add-data-source.png" alt="Search results for Loki on the Add data source page"></p><p>Clicking on &quot;Loki&quot; will redirect you to the dedicated page for the Loki datasource.</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/loki-data-source.png" alt="The dedicated settings page for the Loki data source in Grafana"></p><p>To read the metrics from Loki, we will use the <code>loki-gateway</code> service. Add theURL of the service as <code>http://loki-gateway</code>.</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/loki-form.png" alt="The Loki data source form with the connection URL set to http://loki-gateway"></p><p>After clicking on the &quot;Save &amp; test&quot; button, you will receive a toastr messageshown in the image below. This message is received because no clients have beencreated for Loki yet.</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/loki-addon-output.png" alt="A Grafana toast reporting that no clients exist yet for the Loki data source"></p><h3>7. Install Kubernetes event exporter using the helm chart</h3><p>Create an <strong>event-exporter-values yaml</strong> file with the below snippet</p><pre><code class="language-jsx">config:  leaderElection: {}  logLevel: debug  logFormat: pretty  metricsNamePrefix: event_exporter_  receivers:    - name: &quot;dump&quot;      file:        path: &quot;/dev/stdout&quot;        layout: {}    - name: &quot;loki&quot;      loki:        url: &quot;http://loki-gateway/loki/api/v1/push&quot;        streamLabels:          source: kubernetes-event-exporter          container: kubernetes-event-exporter  route:    routes:      - match:          - receiver: &quot;dump&quot;          - receiver: &quot;loki&quot;</code></pre><p>With the use of the above snippet, run this command to install the Kubernetesevent exporter in your Kubernetes Cluster.</p><pre><code class="language-jsx">helm repo add bitnami [https://charts.bitnami.com/bitnami](https://charts.bitnami.com/bitnami)helm install event-exporter bitnami/kubernetes-event-exporter --values event-exporter.yaml</code></pre><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/event-exporter-installation-output.png" alt="Terminal output from installing the kubernetes-event-exporter Helm chart"></p><p>To view all the resources created by the above helm chart, run this command:</p><pre><code class="language-jsx">kubectl get all -l app.kubernetes.io/name=kubernetes-event-exporter</code></pre><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/event-exporter-all-resources.png" alt="Output of kubectl get all for the event exporter release, listing its pod and deployment"></p><p>To view the logs of the event exporter POD, run this command:</p><pre><code class="language-jsx">kubectl logs -f pod/kubernetes-event-exporter-586455bbdd-sqlqc</code></pre><p>Note: Replace <strong>kubernetes-event-exporter-586455bbdd-sqlqc</strong> with your pod name.</p><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/event-exporter-logs.webp" alt="event-exporter-logs"></p><p>As you can see in the above image, the event exporter is working and runningfine. Event logs are being sent to both the receivers that wed configure in thevalues YAML file.</p><p>Once the POD is created &amp; running, we can go back to the Loki data source under<strong>Connections</strong> &gt; <strong>Data Sources</strong> page.</p><p>Again click on the Save &amp; test button &amp; this time youll receive a successtoastr message.</p><p>Output:</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/loki-data-source-added-output.png" alt="loki-data-source-added-output"></p><h3>8. Kubernetes event exporter dashboard</h3><p>We will import this<a href="https://grafana.com/grafana/dashboards/17882-kubernetes-event-exporter/">dashboard</a>into Grafana to monitor and track the events received from the Kubernetescluster. You can go through this blog if you want to learn how to import anexisting dashboard into Grafana.</p><p>After successfully importing the dashboard, you can view all the events from thecluster, as shown in the image below. Additionally, you can filter the eventsbased on any value within any interval.</p><p>Kubernetes Event Exporter</p><p><img src="/blog/images/images_used_in_blog/2024/k8s-event-exporter-and-grafana-loki-integration/event-exporter-dashboard.png" alt="Kubernetes Event Exporter"></p><h2>Conclusion</h2><p>In this blog post, we discussed the process of setting up Grafana Loki andKubernetes Event exporter. We covered various steps, such as creating a policyfor Grafana Loki, creating a role with the necessary permissions, and addingGrafana using the Helm chart, installing the Loki stack, and adding Loki as adata source in Grafana, installing Kubernetes event exporter using the Helmchart, and finally, setting up the Kubernetes event exporter dashboard inGrafana.</p><p>By following the steps outlined in this blog post, you can effectively monitorand track events from your Kubernetes cluster using Grafana Loki and KubernetesEvent exporter. This setup provides valuable insights and helps introubleshooting and analyzing events in your cluster.</p><p>If you have any questions or feedback, please feel free to reach out. Happymonitoring!</p>]]></content>
    </entry>
     </feed>