<?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 Sagar H M on Medium]]></title>
        <description><![CDATA[Stories by Sagar H M on Medium]]></description>
        <link>https://medium.com/@sagarhm032000?source=rss-7bf7acbab9b4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*77kvgh6tbx7__BMp</url>
            <title>Stories by Sagar H M on Medium</title>
            <link>https://medium.com/@sagarhm032000?source=rss-7bf7acbab9b4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:42:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sagarhm032000/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[Multi-Master ETCd Backup and Restore.]]></title>
            <link>https://medium.com/@sagarhm032000/multi-master-etcd-backup-and-restore-ecc788455242?source=rss-7bf7acbab9b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecc788455242</guid>
            <category><![CDATA[etcd]]></category>
            <category><![CDATA[etcd-restore]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sagar H M]]></dc:creator>
            <pubDate>Sat, 02 Mar 2024 17:01:23 GMT</pubDate>
            <atom:updated>2024-03-14T03:29:17.093Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s dynamic business landscape, organizations of all sizes are constantly seeking ways to optimize costs while maintaining operational resilience. This drive for efficiency has led many small-scale to large-scale enterprises to transition from cloud-based solutions to on-premises infrastructure. While this shift offers greater control over costs and resources, it also brings about the need for robust disaster recovery. strategies, especially in the realm of Kubernetes cluster management.</p><p>Kubernetes has emerged as a leading platform for managing containerized applications, offering unparalleled automation, scalability, and resilience. However, as with any technology, there’s always a possibility of unexpected downtime or disasters that can impact critical operations.</p><p>Disruptions to your Kubernetes cluster can stem from various sources, such as hardware failures, software bugs, human errors, or even natural disasters. To mitigate the risks and ensure business continuity, a robust disaster recovery (DR) plan is essential.</p><p>In the realm of Kubernetes cluster management, the etcd datastore stands as the backbone, storing critical configuration data and cluster state information. The transition from cloud to on-premises infrastructure brings with it the need for a meticulous approach to etcd recovery in the event of disasters or data corruption. In this post, we look into the best practices and strategies for ensuring the integrity and resilience of the etcd datastore in on-premises Kubernetes environments.</p><h4>Prerequisite</h4><h4>1. ETCDctl CLI tool.</h4><p>Install the etcdctl binary on all control planes of the Kubernetes cluster for etcd backup and restore processes.</p><p>1.1. Download etcdctl Binary in all controle planes:</p><pre>wget https://github.com/etcd-io/etcd/releases/download/v3.5.11/etcd-v3.5.11-linux-amd64.tar.gz</pre><p>1.2. Extract the Tarball:</p><pre>tar xvf etcd-v3.5.11-linux-amd64.tar.gz</pre><p>1.3. Move etcdctl Binary to a Usable Location:</p><p>Move the etcdctl binary to a directory in your PATH, such as /usr/local/bin/</p><pre>sudo mv etcd-v3.5.11-linux-amd64/etcdctl /usr/local/bin/</pre><p>Verify Installation:</p><pre>etcdctl version</pre><h4>2. Back Up of the ETCD Snap shot.</h4><p>To view the member list table of etcd, you can use the etcdctl command-line tool. This tool allows you to interact with the etcd cluster, including viewing cluster status and member information.</p><pre>etcdctl --endpoints=https://127.0.0.1:2379 --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt endpoint status --cluster -w table</pre><p>To create a snapshot of the `etcd` datastore, you can use the `etcdctl` command-line tool to take snapshots for backup purposes. Replace “/path” with the actual valid path where the snapshot should be saved.</p><pre>etcdctl snapshot save /path/snapshot.db --cert=&quot;/etc/kubernetes/pki/etcd/server.crt&quot; --key=&quot;/etc/kubernetes/pki/etcd/server.key&quot; --cacert=&quot;/etc/kubernetes/pki/etcd/ca.crt&quot;</pre><p>To check the status of an etcd snapshot and verify its integrity.</p><pre>etcdctl snapshot status --write-out=table /path/snapshot.db</pre><h4>3. A Fresh Kubernetes cluster..</h4><p>A fresh cluster should have the same hostnames as the previous cluster, with the same number of control plane and worker nodes. Ensure that no CNI plugins are installed (like Flannel or IstioD). The nodes’ status should be “NotReady”.</p><p>Ensure to initialize the new cluster with the same Pod CIDR range as the old cluster.</p><h3><strong>Restoring Kubernetes Cluster from the ETCD Backup.</strong></h3><p>Before restoring etcd, it is crucial to ensure that all the api-server and etcd pods/services are not running or active. This prevents any conflicts or inconsistencies between the restored data and the live cluster.</p><pre>mv /etc/kubernetes/manifests /etc/kubernetes/manifests.bak</pre><p>Ensure that all static pods (kube-apiserver, control-plane, etcd, scheduler) are not in the running state on all control plane nodes.</p><pre>crictl  --runtime-endpoint unix:///run/containerd/containerd.sock  ps</pre><p>To remove all ETCD data from a fresh cluster that has been initialized, run the commands below on all control plane nodes. Ensure that the /var/lib/etcd directory is empty after running these commands.</p><pre>yes | rm -rf /var/lib/etcd</pre><p>These are the hostnames of controle planes used as per your environments.</p><p>Master 1 192.168.127.01</p><p>Master 2 192.168.127.02</p><p>Master 3 192.168.127.03</p><p><strong>In control plane Master1</strong></p><pre>ETCDCTL_API=3 etcdctl snapshot restore /path/snapshot.db \<br>--endpoints=https://192.168.127.01:2379 \<br>--name=Master1 \<br>--cert=/etc/kubernetes/pki/etcd/server.crt \<br>--key=/etc/kubernetes/pki/etcd/server.key \<br>--cacert=/etc/kubernetes/pki/etcd/ca.crt \<br>--initial-advertise-peer-urls=https://192.168.127.01:2380 \<br>--initial-cluster-token=etcd-cluster-0 \<br>--initial-cluster=Master1=https://192.168.127.01:2380,Master2=https://192.168.127.02:2380,Master3=https://192.168.127.03:2380 \<br>--data-dir=/var/lib/etcd \<br>--skip-hash-check=true</pre><p><strong>In controle plane</strong> Master2</p><pre>ETCDCTL_API=3 etcdctl snapshot restore /path/snapshot.db \<br>--endpoints=https://192.168.127.02:2379 \<br>--name=Master2 \<br>--cert=/etc/kubernetes/pki/etcd/server.crt \<br>--key=/etc/kubernetes/pki/etcd/server.key \<br>--cacert=/etc/kubernetes/pki/etcd/ca.crt \<br>--initial-advertise-peer-urls=https://192.168.127.02:2380 \<br>--initial-cluster-token=etcd-cluster-0 \<br>--initial-cluster=Master1=https://192.168.127.01:2380,Master2=https://192.168.127.02:2380,Master3=https://192.168.127.03:2380 \<br>--data-dir=/var/lib/etcd \<br>--skip-hash-check=true</pre><p><strong>In controle plane</strong> Master3</p><pre>ETCDCTL_API=3 etcdctl snapshot restore /path/snapshot.db \<br>--endpoints=https://192.168.127.03:2379 \<br>--name=Master3 \<br>--cert=/etc/kubernetes/pki/etcd/server.crt \<br>--key=/etc/kubernetes/pki/etcd/server.key \<br>--cacert=/etc/kubernetes/pki/etcd/ca.crt \<br>--initial-advertise-peer-urls=https://192.168.127.03:2380 \<br>--initial-cluster-token=etcd-cluster-0 \<br>--initial-cluster=Master1=https://192.168.127.01:2380,Master2=https://192.168.127.02:2380,Master3=https://192.168.127.03:2380 \<br>--data-dir=/var/lib/etcd \<br>--skip-hash-check=true</pre><p>Move the backup directory of /etc/kubernetes/manifests.bak to /etc/kubernetes/manifests on all control plane nodes. This action will cause the static pods to start up, as Kubelet recognizes the static path manifests. All new pods will come up with restored ETCD data.</p><pre>mv /etc/kubernetes/manifests.bak /etc/kubernetes/manifests</pre><h4>Restart the system services.</h4><p>Restart the system services like containerd and kubelet on all nodes of the cluster to initialize the CNI and start the pods. This will ensure that the CNI (Container Network Interface) is properly initialized and that the pods can start running on the nodes of the cluster.</p><pre>systemctl daemon-reload<br>systemctl restart containerd<br>systemctl restart kubelet</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecc788455242" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[kubernetes Monitoring with Prometheus]]></title>
            <link>https://medium.com/@sagarhm032000/kubernetes-monitoring-with-prometheus-28ff21792a44?source=rss-7bf7acbab9b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/28ff21792a44</guid>
            <dc:creator><![CDATA[Sagar H M]]></dc:creator>
            <pubDate>Sun, 03 Sep 2023 06:09:19 GMT</pubDate>
            <atom:updated>2023-09-03T15:21:05.357Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Observability</strong></p><p>In today’s fast-evolving digital landscape, modern software developments has become extremely complex. With hundreds of interconnected processes running on complex infrastructures, managing these systems can be a more challenging which can occur some errors, identifying and understanding them can be very difficult.</p><p><strong>Observability</strong> which helps<strong> </strong>to understand and moniter the state of system based upon the data generated by the system. observability which gives better insight into the internal working of the system which helps to detect and catch the problems easily.</p><h4>The components of observability can be broken into three categories:</h4><p><strong>Logging</strong> :Aggregating and storing the logged event messages written by programs</p><p><strong>Metrics</strong> :Collecting time series data, making it available in dashboards, and alerting upon it</p><p><strong>Tracing:</strong> Capturing data for requests that traverse multiple distinct workloads in the cluster</p><h3><strong>Prometheus</strong></h3><h4><strong>Introducation.</strong></h4><p>Prometheus is an open source metrics tool that has become the prevalent open source solution for Kubernetes-based platforms monitoring tool that collects metric data(numeric) and paired with Grafana for visualization.</p><p>Prometheus uses a scraping model where it collects metrics from targets who expose metrics at an http endpoint from which Prometheus can scrape them. The scraped metrics are stored in a time series database the use of labels in its data model ,which can be querried using the prometheus builtin querry language the Prometheus Query Language (PromQL).</p><h3>Why use Prometheus?</h3><p>Modern software developments has become extremely complex. With hundreds of loosly coupled interconnected distrubuted processes running on complex infrastructures, managing these systems can be a more challenging .In such infrastructure if any application/service crashes then it would become time consuming to debug the whole system manually . which can occur some errors, identifying and understanding them can be very difficult.To overcome this problem, we need a tool like Prometheus that constantly monitors whether services are running and alerts the maintainers even before a service/resource is down.</p><h3>Prometheus Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*stU0_9QN3L5H5AnH.png" /><figcaption>Prometheus Architecture (Image credit: <a href="https://prometheus.io/docs/introduction/overview/">prometheus.io</a>)</figcaption></figure><p>The major component of the prometheus is<strong> Prometheus server</strong>.</p><p><strong>The prometheus server contain Retrival , TSD and HTTP server.</strong></p><p><strong>Retrieval</strong> : It sends the Http pull request to the targets endpoints and collects the data (scrapes the metric data).</p><p><strong>TSDB :</strong> A time series database to store the metric data.</p><p><strong>Http Server : </strong>Exposes an HTTP API for other components to access the metrics stored by Prometheus. Provides a dashboard that is useful for executing metric queries and getting various status info to visualization .</p><p><strong>Exporters : </strong>Exporter which fetches metrics from targets and coverts to correct formate of prometheus expects expose that data at /metrics endpoints .</p><p><strong>Pushgateway : </strong>Its for short time lived jobs. A<strong> </strong>batch workload that shuts down when it has finished its work may not give the metrics to Prometheus server the chance to collect all metrics before it disappears, the batch workload can push its metrics to the Pushgateway which, in turn exposes those metrics for the Prometheus server to retrieve.</p><p><strong>Service discovery : </strong>service discovery which allows to discover the target endpoint to scrape the metrics.</p><p><strong>PromQL</strong> : It a powerful query language used for querying.It allows users to retrieve, filter, aggregate and transform metrics to gain insights into system performance and behavior. PromQL query expression which used to set the alert rule for the alerting system.</p><p><strong>Alert</strong>: Prometheus uses alerting rules to generate alerts from metrics. When an alert is triggered, the alert will usually be sent to a configured Alertmanager instance. Deploying Alertmanager and configuring Prometheus to send alerts.</p><p><strong>Alertmanager : </strong>processes alerts and routes them to receivers that constitute the communication medium to the on-call engineers.</p><h3>Kubernetes Monitoring with Prometheus part -1</h3><p>The Kube-Prometheus-Stack is a great tool for monitoring your kubernetes clusters. kube-prometheus-stack is a collection of Kubernetes manifests including the follow</p><ul><li>Prometheus operator</li><li>Prometheus</li><li>Alertmanager</li><li>Prometheus node-exporter</li><li>Prometheus Adapter</li><li>kube-state-metrics</li><li>Grafana</li><li>pre-configured to collect metrics from all Kubernetes component</li><li>delivers a default set of dashboards and alerting rules</li></ul><p><strong>Prometheus Operator</strong> : It is a Kubernetes operator that helps deploy and manage the various components of a Kubernetes metrics system for the platform itself as well as the tenant workloads.The Prometheus Operator uses several cus‐ tom resources that represent Prometheus servers.</p><p><strong>Alertmanager </strong>: This is a separate, distinct workload that processes alerts and routes them to receivers that constitute the communication medium to the on-call engineers</p><p><strong>Prometheus node-exporter </strong>: It is the node agent that usually runs as a Kubernetes DaemonSet and collects machine and operating system metrics.</p><p><strong>Prometheus Adapter </strong>: It is a part of the kube-prometheus stack. This enables autoscaling functionality for workloads.</p><p><strong>kube-state-metrics</strong> : It provides metrics related to a range of Kubernetes resources. It is essentially an exporter for information about resources collected from the Kubernetes API.</p><p><strong>Kubele</strong>t: Provides container and pod-level metrics, such as resource usage and container restarts.</p><p><strong>Grafana </strong>: It is an open source visualization layer that has become the default solution for viewing Prometheus metrics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28ff21792a44" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>