<?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 ADIL RAFIQ on Medium]]></title>
        <description><![CDATA[Stories by ADIL RAFIQ on Medium]]></description>
        <link>https://medium.com/@adrafiq-52?source=rss-48a91ae145fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jncFCyiavCLdtprAk4azww.jpeg</url>
            <title>Stories by ADIL RAFIQ on Medium</title>
            <link>https://medium.com/@adrafiq-52?source=rss-48a91ae145fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 21:35:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adrafiq-52/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[SRE Up to Speed. Data Collection. Part 1]]></title>
            <link>https://adrafiq-52.medium.com/sre-up-to-speed-data-collection-part-1-a869620d55f6?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/a869620d55f6</guid>
            <category><![CDATA[site-reliability-engineer]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[filesystem]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[process]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 10:07:32 GMT</pubDate>
            <atom:updated>2022-11-08T10:06:29.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dswUE0iv6MFxLau4-InsVA.jpeg" /></figure><p>As I jumped in SRE space two years back from Software Engineering. I realized quickly that I lacked the troubleshooting depth of a sysadmin. Had I known it earlier, I would have resolved incidents more efficiently, predictably and with certainty. My strengths were around software and system design. In cloud-native infrastructure space, the ideal contributor is best of both worlds. System admin and system design.</p><p>To overcome my lacking, I decided to identify first the most crucial system administration and troubleshooting techniques. Sharing my learning, here to save time for software engineers venturing in to infra/SRE space .</p><p>I have classified the skill set in three categories:</p><ol><li>Data Collection.</li><li>Data formatting and analysis.</li><li>Network and OS monitoring.</li></ol><h3>Data Collection</h3><blockquote>In case of failure, finding about current state of system. Its done by identifying the scope and then collecting all the data relevant to that scope. If required, bundle and transport it to local system.</blockquote><p>Lets define a failure. An un-desireable state of a system or an application, where Application is any user software and system is OS (Unix/Linux) for the scope of this article.</p><p>An operating system provides support for the application to run by managing its life-cycle. The life-cycle begins by reading some initial <strong>configurations</strong>, running a process which has <strong>state</strong> and writing the internals events to <strong>log</strong> files until the process exit with success or failure.</p><p>A UNIX/LINUX file system by design organizes the above mentioned items in individual file systems.</p><ol><li>Configurations in /etc</li><li>Logs in /var/log</li><li>State /proc</li></ol><h4><strong>Configurations</strong></h4><p><strong>Host</strong></p><blockquote>The /etc hierarchy contains host specific configuration files. A &quot;configuration file&quot; is a local file used to control the operation of a program; it must be static and cannot be an executable binary.</blockquote><p>A configuration file can be a static text file of any format, from key value pairs to json.</p><p><strong>User</strong></p><p>The Xdg linux systems creates .config folder in home directory to put user specific configuration files into it. The ownership of the files belong to that specific user only.</p><h4>Logs</h4><p><strong>Host</strong></p><p>The directory <strong>/var/log</strong> contains miscellaneous log files. Most logs are written to this directory or an appropriate sub-directory.</p><p><em>Taken from loggly.com</em></p><p>Some of the most important Linux system logs include:</p><ul><li>/var/log/syslog and /var/log/messages store all global system activity data, including startup messages. Debian-based systems like Ubuntu store this in /var/log/syslog, while Red Hat-based systems like RHEL or CentOS use /var/log/messages.</li><li>/var/log/auth.log and /var/log/secure store all security-related events such as logins, root user actions, and output from pluggable authentication modules (PAM). Ubuntu and Debian use /var/log/auth.log, while Red Hat and CentOS use /var/log/secure.</li><li>/var/log/kern.log stores kernel events, errors, and warning logs, which are particularly helpful for troubleshooting custom kernels.</li><li>/var/log/cron stores information about scheduled tasks (cron jobs). Use this data to verify your cron jobs are running successfully.</li></ul><p>Application developers can choose to right there logs in standard output or a file. The path to file is usually provided in configuration.</p><h4>State</h4><blockquote>The proc filesystem is the de-facto standard Linux method for handling process and system information.</blockquote><p>For each process in the linux, there exist a corresponding directory in /proc file-system.</p><p>Expect list of all process and directories under /proc to nearly equal.</p><p>ls -l /proc | wc -l ≈ ps -ef | wc -l</p><p>The state of process are organized in distinctive files. A list of these files and there content is given below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*3fsTGKsTFeYz5FX3Q8FYwA.png" /><figcaption>Files under each process directory. Taken from kernel.org</figcaption></figure><p>More information <a href="https://www.kernel.org/doc/html/latest/filesystems/proc.html">here</a>.</p><p>The status file under the directory, contains information about status in readable form. Infact ps directly reads information from status.</p><h4><strong>Example (nginx)</strong></h4><p>Lets collect configuration, state and log data for an application. In our case nginx.</p><p><strong>Logs</strong></p><p>nginx write access and error logs under /nginxdirectory in var logs. Logs are rotated by keeping most recent logs in access.log and numeric suffix are added to older file with highest being oldest. eg access.log.2</p><p>Path for all access logs can be collected with</p><p>find /var/log/nginx | egrep &#39;(access.log)+&#39; will print something like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*wzOP_vw74UzlEOWV5-lufA.png" /></figure><p>You can pipe the output to zip and cp to your local machine for later analysis.</p><p><strong>State</strong></p><p>Lets see how many processes under nginx daemon are under sleep or running. We will find all process for nginx, and read the status file under them for state attribute and count them.</p><p>ps -ef | egrep &#39;(nginx)+&#39; | awk &#39;{$2=&quot;/proc/&quot;$2; print $2} | xargs -I{} find {} -maxdepth 1 -name status&#39; 2&gt;/dev/null | xargs cat | grep (State). | uniq -c</p><p>Should get us an output like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*71KLhAbRd-dVe4uxDd5Ofw.png" /></figure><p><strong>Configuration</strong></p><p>nginx organizes its configuration in files with .conf suffix.</p><p>find /etc/nginx/ -maxdepth 1 | egrep &#39;(.conf)$&#39;</p><p>should output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*0kM7vqpFI-zxyT9IaKI2sQ.png" /></figure><p>which as mentioned before you can read for analysis or archive and ship for later.</p><p><strong>Conclusion</strong></p><p>A unix/linux file system organizes <strong>configuration, state </strong>and<strong> logs</strong> under /etc, /procand /var/logfile systems respectively. As an SRE, your heauristics should be to</p><ol><li>Read up by which naming convention your application organizes its configurations and logs.</li><li>Find those files or specific content in them by searching in respective filesystems using regular expressions and pattern matching to find specific content in them.</li></ol><p><a href="https://adrafiq-52.medium.com/sre-up-to-speed-part-1-regular-expression-9fc026d433ba">Part 2 </a>of data collection describes regular expressions in detail.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a869620d55f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SRE Up to Speed. Data Collection. Part 2. Regular Expression]]></title>
            <link>https://adrafiq-52.medium.com/sre-up-to-speed-part-1-regular-expression-9fc026d433ba?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fc026d433ba</guid>
            <category><![CDATA[site-reliability-engineer]]></category>
            <category><![CDATA[up-to-speed]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[regular-expressions]]></category>
            <category><![CDATA[sysadmin]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Sun, 30 Oct 2022 20:43:05 GMT</pubDate>
            <atom:updated>2022-11-04T10:08:00.522Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dswUE0iv6MFxLau4-InsVA.jpeg" /></figure><p>Continued from <a href="https://adrafiq-52.medium.com/sre-up-to-speed-data-collection-part-1-a869620d55f6">Part 1</a>, where I describe why every software engineer looking to become SRE, must know sysadmin skills.</p><p>I have classified the skill set in three categories:</p><ol><li>Data Collection.</li><li>Data formatting and analysis.</li><li>Network and OS monitoring.</li></ol><h3><strong>Data Collection</strong></h3><blockquote>In case of failure, finding about current state of system. Its done by identifying the scope and then collecting all the data relevant to that scope. If required, bundle and transport it to local system.</blockquote><p>Finding log files, state files, configurations or patterns in a any file. You can’t go far without regular expressions. <strong>awk, find, sed, grep</strong> all aid data collection and support regular expressions.</p><p><strong>Regular Expression</strong></p><blockquote>A sequence of characters that describes a pattern in text.</blockquote><p>Finding a pattern in text, is problem that exists since 1950s. For example,</p><p>For protocol handshake, the client sends an init request, and sever sends back an acknowledge. Both init and acknowledge have structured <em>pattern</em> without knowing which handshake wouldn&#39;t be possible.</p><p>To look for a pattern, you have to describe it to system. Describing large and dynamic pattern is cumbersome. That’s where regular expression comes in.</p><p>Think of regular expression as a combination of two things:</p><ol><li>Compression , where using a dictionary, large text is substituted with single characters or constructs. Hence packing in more information per character.</li><li>Templates to describe the occurrence of character dynamically.</li></ol><p>Here are the constructs:</p><p><strong>Meta Characters:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*bqSAGW7aBhIkR_HwKZXB2w.png" /></figure><p>* Matches any character occurrence 0 or n times. <strong>(Compression)</strong></p><p>For example: <em>access.log</em>, <em>access.1.log</em> could be represented as *.log</p><p>+ Matches any character occurrence at least 1 or n times. <strong>(Compression)</strong></p><p>For example: Finding networking ID in ip address that are not single digit.</p><p>++.* will match ip <em>192.168.11.11</em> but not 1.1.1.1</p><p>? Matches any character occurrence 0 or 1 time.</p><p>Finding plurals. table?will match both <em>table</em> and <em>tables</em>.</p><p>. Matches any character once</p><p>Defining occurrence of any character at least once. For example, collecting all files in log rotation except latest. access...log will match <em>access.1.log</em>, <em>access.2.log</em> but will skip <em>access.log</em></p><p><strong>Grouping</strong></p><p>Matching a sub-sequence described in parenthesis. Regular expression will treat all characters inside the parenthesis as single entity to match in the provided sequence.</p><p>(access) will match every text that have keyword <em>access</em> in them.</p><p>But you can also use operators in a group.</p><p>(access | error)will find all files that either have <em>access</em> or <em>error</em> in them.</p><p>Lastly, the can be used to match multiple successive occurrence as well.</p><p>(abc){2} will match abcabc.</p><p><strong>Brackets and Classes</strong></p><p>Instead of a wildcard *, if you want your character to match a specific range. You describe that <strong>range</strong> in brackets. A range can be described out of alpha(Lower and Upper case distinctively), numerical and special characters.</p><p>[abc] will match a or b or c.</p><p>(access).[12].log will match <em>access.1.log</em> and <em>access.2.log</em></p><p>Regex also has some built in shortcuts that can be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*75nKbFT0I-Oces_fw5kYKQ.png" /></figure><p>For example \w\s\w will match any sequence of two words separated by space. Where word is group of characters. For example <em>Hello World</em></p><p><strong>Back Reference</strong></p><p>Back reference is use to match a character or group, that previously exist in regular expression. An easier way to understand them is as if you were pushing each group into a stack, and each back reference pops out the last stacked item and match with it.</p><p>Imagine markup tags. <br>&lt;i&gt; Some Text &lt;/i&gt; , &lt;head&gt; Some Header &lt;/head&gt;</p><p>Here both i, and head occur twice. Instead of adding the group twice, we can refer its second occurrence back to first.</p><p>&lt;([a-z]*)&gt;+&lt;/\1&gt;<br>Here \1 is the back reference to ([a-z]*) group. Using back reference we can compress our regular expressions even further. Back references can be made to as many group or characters by incrementing the reference number. For example: &lt;div&gt;&lt;i&gt; Some Test &lt;/i&gt; &lt;/div&gt; can be matched with</p><p>&lt;([a-z]*)&gt;&lt;([a-z]*)&gt;+&lt;/\1&gt;&lt;/\2&gt; Here \1 refers to i and \2 refers to div.</p><p><strong>Anchor and Boundary</strong></p><p>Anchor $ after a character or group, matches any text that must end with it.</p><p>(.log)$ will match all files that end <em>.log. </em>It will skip<em> log.text</em></p><p>Boundry ^ before a character or group, matches any text that start with it.</p><p>^(apache)*(log)$ will match all text that must start with apache and end with log.</p><p><strong>Conclusion</strong></p><p>Now you’re equipped to quickly find files or logs that match a pattern. <br>The next step, is to know how a UNIX system organizes log, configuration and state-files. Stay tuned for part 2.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fc026d433ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How problem solving techniques reformed my learning capabilities]]></title>
            <link>https://adrafiq-52.medium.com/how-problem-solving-techniques-reformed-my-learning-capabilities-1a3226d15d5?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a3226d15d5</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Tue, 04 Oct 2022 06:57:43 GMT</pubDate>
            <atom:updated>2022-10-04T06:57:43.628Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Why read this article? If consciously reading, understanding and retaining a new concept, seems like the hardest thing in your life. Maybe you’re doing it wrong.</blockquote><h3><strong>Prologue</strong></h3><p>I am Adil. A software engineer and every few months or year, I take a sabbatical, learn from mistakes of past year along with skills of the coming years. If you were to ask me my learning process, the usual suspects are. A list of topics, set of books and a deadline. Already hard, but I made it work until it didn&#39;t consequently. Lets say you are learning to make a bridge with pillars and planks. Day 1 you learn what a pillar is. Day 2 you learn what a plank is. Day 3 when you are about to make the bridge by placing plank on pillars, you forgot what a pillar is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*MTmYwI5b8G3NVv0mfoynpQ.jpeg" /><figcaption>Grey Planks and Pink Pillars</figcaption></figure><blockquote>The best way to learn how a screwdriver works is to take an engine apart &amp; put it back together. The point is to do something else that forces you to use screwdrivers, so you see how they’re actually used. Far better than taking a class on screwdrivers. <br>Elon Musk</blockquote><p>That quote right there by Mr musk was my turning point. You will not understand the point of a notebook, unless you have ever felt the need to take a note.</p><h3>Journey</h3><p>Hindered by the lack of progress, I started working on memory and retaining techniques. Youtube shorts introduced me to memory trainer jim kwik.</p><h4><strong>Memory</strong></h4><blockquote>There is no good or bad memory, there is trained or untrained memory.<br>Jim Kwik</blockquote><p>There is plethora of techniques that jim described but I am going to discuss what has worked for me and more importantly has stuck with me after trying out so many.</p><p><strong>Documentary and Observatory Note taking</strong></p><p>Simply put, on your notebook, divide the page into two sections vertically. Name one <strong>Notes Made (documenting your learning) </strong>and other<strong> Notes Taken (Making active observations). <br></strong>Example. Some one is teaching you what Phillips head screwdriver is. Then your left side will be taking note of specifics being taught about the Phillips head, and on right your your own personal speculation of what a Phillips head screwdriver could be or do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dz7zWhrWfTB9_NB0l9HiXg.jpeg" /></figure><p>The observatory section is actually you getting hands on and trying to understand better the intent of a tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vYeib2_qSr_OcOsemcGVeA.jpeg" /><figcaption>Exhibit 1. My personal notes while learning regular expressions</figcaption></figure><p><strong>Problem Solving Techniques</strong></p><blockquote><em>A Problem Well Stated is Half Solved.<br>Charles Kettering</em></blockquote><p>Assuming that, What If I say</p><blockquote>A tool’s purpose is only understood in context of a problem well stated.</blockquote><p>If most of human inventions or ideas are to reduce effort, then to understand them the best place is to start at the problem.</p><p>Keeping in mind <a href="https://adrafiq-52.medium.com/what-most-engineers-dont-realize-about-problem-solving-3927e681e38a"><em>rephrasing goals and non goals</em>, <em>birds eye view and original intention</em></a><em>.</em> I add four more questions to my already partitioned notes section.</p><p><strong>Notes Made (Documenting)</strong></p><ol><li>What a concept/tool/idea is?</li><li>What it is’nt?</li></ol><p><strong>Notes Taken (Observartions)</strong></p><ol><li>What problem was its creator having?</li><li>Who uses it and how?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OFlKDZVej9gxCdALdpUD1w.jpeg" /></figure><p>So using this guide, One can go through the complete discovery process of a problem and the thought process that went into designing the tool. This helped me understand, retain and even extend the tool to suit my niche problem.</p><p><strong>Bonus</strong> <br>I am learning golang these days. If you want to know what problem its creators were facing with c++ that they decided to eventually create go. Watch these two videos</p><p><a href="https://www.youtube.com/watch?v=0ReKdcpNyQg">https://www.youtube.com/watch?v=0ReKdcpNyQg</a><br><a href="https://www.youtube.com/watch?v=4hxKEbWO5u0">https://www.youtube.com/watch?v=4hxKEbWO5u0</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a3226d15d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What most engineers don’t realize about problem solving]]></title>
            <link>https://adrafiq-52.medium.com/what-most-engineers-dont-realize-about-problem-solving-3927e681e38a?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/3927e681e38a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mindfulness]]></category>
            <category><![CDATA[mindset-shift]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Thu, 29 Sep 2022 08:52:10 GMT</pubDate>
            <atom:updated>2022-09-29T21:52:33.367Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2vyUgprhwmzOuz5C1sbkYg.jpeg" /></figure><blockquote>Why read this article? Your solutions are only good as your understanding of the problem. Improve your problem understanding.</blockquote><h3>Prologue</h3><p>I am adil rafique. A software engineer with interests in infrastructure and reliability engineer. And personal definition for my work is , If I am doing my job well, nobody should notice that I exist. <br>The one thing that’s common between you and me is, we have a set of complex problems that we’d like to solve to be productive at our work. Or in other words increase our productivity from mediocre to good by looking at the place we are least likely to i.e the problem statement</p><blockquote>A Problem Well Stated is Half Solved. <br>Charles Kettering</blockquote><p>Here are three techniques that I have helped me to qualify and scope the problem statement and its <strong>affectees</strong>. I would begin with a base problem statement, apply one of the technique and end up modifying, completely rewriting or the leaving the base statement intact until all of techniques are exhausted.</p><p><strong>Techniques</strong></p><ol><li>Rephrasing Goal.</li><li>Phrasing/Rephrasing Non-Goals.</li><li>Bird’s Eye View.</li><li>Reverse the problem.</li></ol><p><strong>Rephrasing Goal</strong></p><p>Simply put, Find alternative ways to arrive at the goal. <br>For example, If you are tasked to find the most recurring record in a collection. You can try alternatives like <strong>what is the most likely record to recur in the context of that database</strong><em>, </em><strong><em>is</em> the recurrence function of some other variable like specific time period</strong><em> </em>or<em> </em><strong>how does a database behave when it gets recurring records</strong><em>.</em></p><p><strong>Phrasing / Rephrasing Non-Goals</strong></p><p>Defining Non-Goals can significantly narrow down the scope of the problem. For that same example find the most recurring record in a collection. You can challenge and find out non-goals within context or with stake holders. Example of non-goals can be <strong>we are not concerned with the fastest search, we don’t need to count the recurrence.</strong></p><p><strong>Bird’s Eye View</strong></p><p>Identifying the right stakeholder can let you understand the problem and its scale better or will at least give you chance to inquire more from direct affectee. <br>Ask question like <strong>Who is the most likely to be affected by this problem </strong>or<strong> Who will be remain affected if this problem is’nt solved.</strong></p><p><strong>Reversing the problem</strong></p><p>In addition to finding the success factor, ask what is most likely to cause failure. For example, If we want to reduce the load time for request, we can ask <strong>What is most likely to contribute to load time.</strong></p><p>If our best solutions are a function of our understanding of problem, using better problem defining techniques is the way to effectiveness.</p><blockquote>“Give me six hours to chop down a tree and I will spend the first four sharpening the axe.” — <strong>Abraham Lincoln</strong></blockquote><p>I will give credit to Lucioano at <a href="http://litemind.com/">Litemind</a> for writing <a href="https://litemind.com/problem-definition/">this article</a> that introduced some of these techniques. Go read it further for more problem defining techniques that could help in your context.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3927e681e38a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Mesh (Resilience, Dynamic Routing, Load-Balancing)]]></title>
            <link>https://adrafiq-52.medium.com/service-mesh-resilience-dynamic-routing-load-balancing-3cdf6eac4259?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cdf6eac4259</guid>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[dynamic-routing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[resilience]]></category>
            <category><![CDATA[service-mesh]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Tue, 03 Nov 2020 09:04:24 GMT</pubDate>
            <atom:updated>2020-11-03T12:57:44.528Z</atom:updated>
            <content:encoded><![CDATA[<h3>Service Mesh (Resilience, Dynamic Routing, Load-Balancing)(Part 3)</h3><blockquote>This is a seven part series on service mesh. Starting with <strong>fundamentals</strong>, then <strong>hands-on with istio</strong>, resilience, dynamic-routing and load-balancing, <strong>API-Gateway</strong>, <strong>Security</strong>, <strong>obserability/tracing</strong>, and finally <strong>service-mesh at scale</strong>.</blockquote><p>We will be using the same example that we created in hands-on. <br>A Kubernetes cluster having istio installation and bookinfo example as our microservices. If you have missed it, I would suggest you go through the previous part where we get hands-on with Istio on GKE.</p><p>We will be using the following tools/concepts that Istio defines throughout the scope of this article.</p><p><strong>Destination Rule</strong>: <a href="https://istio.io/latest/docs/reference/config/networking/destination-rule/">DestinationRule</a> defines policies that apply to traffic intended for service after routing has occurred.</p><p><strong>Virtual Service</strong>: A <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/#TLSRoute">VirtualService</a> defines a set of traffic routing rules to apply when a host is addressed.</p><p><strong>Service Entries</strong>: <a href="https://istio.io/latest/docs/reference/config/networking/service-entry/">ServiceEntry</a> enables adding additional entries into Istio’s internal service registry, so that auto-discovered services in the mesh can access/route to these manually specified services.</p><p>Since we have our service mesh in place. We want it to provide us with the following:</p><ol><li>Resilience.</li><li>Dynamic-Routing.</li><li>Load-balancing and Canary Rollout.</li></ol><h3>Resilience:</h3><p>And what do we mean by resilience? That means in case of a failure, we need pre-programmed behaviors to mitigate the effects of those failures.</p><h4>Timeout</h4><p>We don&#39;t want our services to hang and wait indefinitely when the request is taking too long. It&#39;s not recommended to use the default timeout value because the actual time for operation only depends on the type of operation. We can dynamically create a timeout value in our mesh per service. Here is how we can add a timeout of 10s.</p><pre>Kubectl apply -f - &lt;&lt;EOF <br>apiVersion: networking.istio.io/v1alpha3 <br>kind: VirtualService <br>metadata:   <br> name: ratings <br> spec:   <br>  hosts:   <br>  - ratings   <br>  http:   <br>  - route:     <br>   - destination:         <br>      host: ratings         <br>      subset: v1     <br>   timeout: 10s<br>EOF</pre><h4>Retries</h4><p>We can have transient noise in our mesh, for example, deployments or restarts can make a service unavailable temporarily. It&#39;s highly likely the request to an such an upstream host fails, because of that. But since that transient noise is temporary our system should have retries built in to mitigate that. We can add request retries in our services so in situations like this the original request to service does not end in failure.</p><p>We create a virtual service for host ratings, the destination will be original but we add a retries spec with 3 attempts and 2s of timeout configuration.</p><pre>Kubectl apply -f - &lt;&lt;EOF<br>apiVersion: networking.istio.io/v1alpha3<br>kind: VirtualService<br>metadata:<br>  name: ratings<br>spec:<br>  hosts:<br>  - ratings<br>  http:<br>  - route:<br>    - destination:<br>        host: ratings<br>        subset: v1<br>    retries:<br>      attempts: 3<br>      perTryTimeout: 2s<br>EOF</pre><p><strong>Circuit Breaking</strong></p><p>For services that receive requests from too many hosts, can be overloaded. This overload can result in timeout or denial of service. We can create a connection pool for such scenarios and even add a circuit breaking limit. When the limit is reached, no new connection is accepted. <br>We create a destination rule for the host and define a connection pool in trafficPolicy. The connection pool is applied to all TCP upstream requests to reviews service.</p><pre>Kubectl apply -f - &lt;&lt;EOF<br>apiVersion: networking.istio.io/v1alpha3<br>kind: DestinationRule<br>metadata:<br>  name: reviews<br>spec:<br>  host: reviews<br>  subsets:<br>  - name: v1<br>    labels:<br>      version: v1<br>    trafficPolicy:<br>      connectionPool:<br>        tcp:<br>          maxConnections: 100<br>EOF</pre><h3>Dynamic Routing</h3><p>Using Istio’s destination rules and virtual service we can program the incoming traffic route based on their URL, origin, cookies, region, and headers. This can be applicable in many scenarios. For example, you want to redirect regional requests to closest clusters or if you are hosting multiple versions of API then you can redirect request based on URL usually as v1 or v2. One other example that comes to my mind, is when we hosted a dashboard in each of our clusters. But we wanted to access all of them from the same URL. So we created a virtual service in one of our cluster, that receives requests and routed it to other clusters based on URL.</p><pre>Kubctl apply -f - &lt;&lt;EOF <br>apiVersion: networking.istio.io/v1alpha3<br>kind: VirtualService<br>metadata:<br>  name: tracing-dashboard<br>  namespace: istio-system<br>spec:<br>  hosts:<br>  - &lt;Your host here&gt;<br>  gateways:<br>  - tracing-gateway<br>  http:<br>  - name: &quot;my-first-cluster&quot;<br>    match:<br>    - uri:<br>        prefix: /my-first-cluster<br>      route:<br>      - destination:<br>        host: &lt;Path to dashboard in my-first-cluster&gt;<br>  - name: &quot;my-second-cluster&quot;<br>    match:<br>    - uri:<br>        prefix: /my-second-cluster<br>      route:<br>      - destination:<br>        host: &lt;Path to dashboard in my-second-cluster&gt;<br>EOF</pre><p>Using <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRoute">virtual service</a>, we can create programmable behavior for incoming, outgoing, and internal traffic as well.</p><blockquote>To control routing for traffic bound to services outside the mesh, external services must first be added to Istio’s internal service registry using the ServiceEntry resource. VirtualServices can then be defined to control traffic bound to these external services.</blockquote><pre>kubectl apply -f - &lt;&lt;EOF <br>apiVersion: networking.istio.io/v1beta1<br>kind: ServiceEntry<br>metadata:<br>  name: external-svc-wikipedia<br>spec:<br>  hosts:<br>  - wikipedia.org<br>  location: MESH_EXTERNAL<br>  ports:<br>  - number: 80<br>    name: example-http<br>    protocol: HTTP<br>  resolution: DNS<br>---<br>apiVersion: networking.istio.io/v1alpha3<br>kind: VirtualService<br>metadata:<br>  name: my-wiki-rule<br>spec:<br>  hosts:<br>  - wikipedia.org<br>  http:<br>  - timeout: 5s<br>    route:<br>    - destination:<br>        host: wikipedia.org<br>EOF</pre><h3>Load-balancing and Canary Rollout</h3><p>Each service can have multiple instances of itself. How will we distribute requests so that no single instance is overload? Or we can have services with multiple versions or iterations running. <br>So to load-balance a service toward the instance with the least connections. We can use the following destination rule.</p><pre>kubectl apply -f - &lt;&lt;EOF  <br>apiVersion: networking.istio.io/v1beta1<br>kind: DestinationRule<br>metadata:<br>  name: bookinfo-ratings<br>spec:<br>  host: ratings.prod.svc.cluster.local<br>  trafficPolicy:<br>    loadBalancer:<br>      simple: LEAST_CONN<br>EOF</pre><pre># You can replace LEAST_CONN with ROUND_ROBIN. <a href="https://istio.io/latest/docs/reference/config/networking/destination-rule/#LoadBalancerSettings-SimpleLB">More Info</a></pre><p>Some organizations use canary rollouts. I.e when a new version of service is released, it is first waited to stabilize, then a small portion of traffic is shifted toward and monitored. When all checks pass, then gradually all traffic is shifted.</p><p>For example, we have three versions of reviews service in our bookinfo example. Here is how we can use Istio virtual service and destination rule to achieve that.</p><pre>kubectl apply -f - &lt;&lt;EOF<br>apiVersion: networking.istio.io/v1alpha3<br>kind: VirtualService<br>metadata:<br>  name: reviews<br>spec:<br>  hosts:<br>    - reviews<br>  http:<br>  - route:<br>    - destination:<br>        host: reviews<br>        subset: v1<br>      weight: 90<br>    - destination:<br>        host: reviews<br>        subset: v2<br>      weight: 10<br>---<br>apiVersion: networking.istio.io/v1alpha3<br>kind: DestinationRule<br>metadata:<br>  name: helloworld<br>spec:<br>  host: helloworld<br>  subsets:<br>  - name: v1<br>    labels:<br>      version: v1<br>  - name: v2<br>    labels:<br>      version: v2<br>EOF</pre><p>Here our destination rules create service version aka subsets using labels on pod. And our virtual services routes the traffic with weights 90% to v1 and 10% to v2. We can slowly increase the weighted traffic to v2 once the service stabilizes and complete the cycle of canary rollout.</p><h3>Summary</h3><p>Great!! We have now seen how an Istio can help us with operations that add resilience, dynamic routing, load balancing, and canary rollouts in our mesh. <br>Next Up, we cover API-Gateway and Edge in our service mesh.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cdf6eac4259" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Mesh(Getting Hands-On with Istio)(Part 2)]]></title>
            <link>https://adrafiq-52.medium.com/service-mesh-getting-hands-on-with-istio-part-2-808ac586567a?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/808ac586567a</guid>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[service-mesh]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[hands-on]]></category>
            <category><![CDATA[istio]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Tue, 03 Nov 2020 09:03:18 GMT</pubDate>
            <atom:updated>2022-11-09T10:40:46.138Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This is a seven part series on service mesh. Starting with fundamentals, then hands-on with istio, resilience dynamic-routing and canary rollouts, API-Gateway, Security, obserability/tracing, and finally service-mesh at scale</blockquote><p>In this article, we will use <a href="https://cloud.google.com/kubernetes-engine">GKE</a> and <a href="https://istio.io/latest/docs/examples/bookinfo/">Istio’s Bookinfo Service Example</a> as our microservices and install <a href="https://istio.io/">Istio Service Mesh</a> on our cluster. We will go through the installation procedure in detail, verify our install and lastly add microservices to our mesh.</p><h4>Istio</h4><p>Istio Greek for “Sail” was started as an open-source effort by google back in 2016 learning from the service mesh that they developed for google’s internal services. The project intended to create a service-mesh that can simultaneously work services deployed in various environments. Currently, Istio can work with kubernetes, consul, and virtual machines deployed on the cloud or on-premises. Like other service meshes available, Istio’s structure consists of two parts. A data plane and a control plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MhqvyVr5yKig0St8-E4yQQ.png" /></figure><p>The <strong>control plane</strong> in Istio consists of istiod.</p><p>istiod unifies the following services in itself:</p><ol><li><strong>Citadel</strong> that does authentication and certificate rotation for (mtls).</li><li><strong>Galley</strong> that provides configuration management.</li><li><strong>Pilot</strong> responsible for service-discovery.</li><li><strong>Side-car injector</strong> whose job is to inject sidecars alongside our services.</li></ol><p>The <strong>data-plane </strong>of istio uses a version of <a href="https://www.google.com/search?hl=en&amp;source=hp&amp;ei=L2afX5DjJImGjLsPk7uouAQ&amp;q=envoy+proxy&amp;oq=envoy+proxy&amp;gs_lcp=CgZwc3ktYWIQAzIFCAAQyQMyAggAMgIIADICCAAyAggAMgIIADICCAAyAggAMgIIADICCAA6CAgAELEDEMkDOgUIABCxAzoICAAQsQMQgwE6BQguELEDOggILhCxAxCDAToLCAAQsQMQgwEQyQM6AgguOgoIABDJAxBGEP8BOggILhDHARCvAToECAAQCjoKCAAQsQMQyQMQCjoHCAAQsQMQCjoMCAAQyQMQChBGEP8BOgoIABCxAxCDARAKOgoILhDHARCvARAKOhAILhDHARCvARDJAxAKEJMCOgcIABDJAxAKOg4ILhDHARCvARDJAxCTAlCAlk1YvP5sYI-AbWgIcAB4AIABxgOIAeIhkgEIMi0xNS4xLjGYAQCgAQGqAQdnd3Mtd2l6&amp;sclient=psy-ab&amp;ved=0ahUKEwjQtu_n3-LsAhUJA2MBHZMdCkcQ4dUDCAc&amp;uact=5">Envoy Proxy</a> that was developed by Lyft. Envoy is installed as sidecar to all services, and the job of the envoy is to mediate all the incoming and outgoing traffic. Istio uses envoy’s built-in feature for dynamic routing, circuit breaking, tls termination, and metrics to implement the administrator&#39;s configuration.</p><h4>Installing</h4><p>Pre-requisites:</p><ol><li>A Kubernetes cluster on GKE, with RBAC access.</li></ol><p>Download istio on your system, and set the env variable to access bin/istioctl in your terminal. Or navigate to the directory where istio is installed.</p><pre>curl -L https://istio.io/downloadIstio | sh -</pre><p>Out of the two ways available, we will be using istio-operator to install istio on our cluster. Istio-Operator is an effort by banzaicloud. It is essentially a controller, that reads a Kubernetes CRD of type Istio-Operator and creates istio-system namespace according to specs.</p><pre># Initialize istio-operator on your cluster</pre><pre>istioctl operator init</pre><pre># Create namespace istio-system</pre><pre>kubectl create ns istio-system</pre><pre># Apply the following manifest from this <a href="https://gist.github.com/adrafiq/f345dc54e2a50071c0556e6eb89443b4">gist</a>: </pre><pre>kubectl apply -f <a href="https://gist.github.com/adrafiq/f345dc54e2a50071c0556e6eb89443b4">istio-manifest.yaml</a></pre><pre># To check wether manifest was deployed correctly or for validation errors. View logs of istio-operator pod</pre><pre>kubectl logs -f --selector=name=istio-operator -n istio-operator</pre><pre>A succesfull deployment should display the following info at the end</pre><pre>2020-11-02T02:56:33.842590Z info end reconciling resources</pre><p>I have made further comments about the spec in the gist.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/428590d10849e6478a60a18aea3e6594/href">https://medium.com/media/428590d10849e6478a60a18aea3e6594/href</a></iframe><h4>Adding Services to Mesh</h4><p>Since our mesh was deployed and stabilized, we will now start adding microservices to our mesh. In Kubernetes, it&#39;s as easy as labeling a namespace. We will label all the namespaces that we want in our mesh and sidecar injector will automatically start to inject proxies into them.</p><pre># Label bookinfo namespace</pre><pre>kubectl label namespace bookinfo istio-injection=enabled</pre><pre># Restart all pods in the namespace</pre><pre>Kubectl delete pods --all -n bookinfo</pre><pre># Checking one of the pod to see if the side car is injected. </pre><pre>kubectl get pods --selector=app=productpage -n bookinfo -o jsonpath=&quot;{.items[*].spec.containers[*].image}&quot; <br>|\ tr -s &#39;[[:space:]]&#39; &#39;\n&#39;</pre><pre># And you should see two containers in the pod. </pre><pre>docker.io/istio/examples-bookinfo-productpage-v1:1.16.2<br>docker.io/istio/proxyv2:1.5.3</pre><pre># The proxyv2 is the envoy proxy and hence it is verified that sidecars are injected.</pre><p>Now we have successfully added services to our mesh.</p><h4>Exposing our services out of mesh</h4><p>All traffic inside mesh will come from ingress gateway. We will now expose our productpage service to traffic coming from ingress gateway.</p><pre># Create gateway and virtualservice that redirects traffic to product service </pre><pre>kubectl apply -f <a href="https://raw.githubusercontent.com/istio/istio/release-1.7/samples/bookinfo/networking/bookinfo-gateway.yaml">samples/bookinfo/networking/bookinfo-gateway.yaml</a></pre><pre># Determine Host Ip and Port<br>export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath=&#39;{.status.loadBalancer.ingress[0].ip}&#39;) </pre><pre>export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath=&#39;{.spec.ports[?(@.name==&quot;http2&quot;)].port}&#39;)</pre><pre># Create firewall rule for GCP <br>gcloud compute firewall-rules create allow-gateway-http --allow &quot;tcp:$INGRESS_PORT&quot;</pre><pre># Now you can verify external at<br>echo &quot;http://$INGRESS_HOST:INGRESS_PORT/productpage&quot; TaDa!!</pre><h3>Summary</h3><p>We have seen how istio is architectured with a data plane and control plane. Using istio-operator we have installed istio in our cluster and exposed our mesh to outside traffic.</p><p>From here we go to <a href="https://medium.com/@adrafiq-52/service-mesh-resilience-dynamic-routing-load-balancing-3cdf6eac4259">adding resilience and dynamic routing to our mesh</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=808ac586567a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Mesh (Why and When?)]]></title>
            <link>https://adrafiq-52.medium.com/service-mesh-why-and-when-fa9e90a1fbc1?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa9e90a1fbc1</guid>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[service-mesh]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[fundamentals]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Tue, 03 Nov 2020 09:02:26 GMT</pubDate>
            <atom:updated>2022-11-09T10:39:53.429Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This is a seven part series on service mesh. Starting with fundamentals, then hands-on with istio, resilience dynamic-routing and canary rollouts, API-Gateway, Security, obserability/tracing, and finally service-mesh at scale</blockquote><blockquote>This article briefly discusses the evolution of microservices, challenges of a microservice architecture, and how service mesh solves them.</blockquote><h4><strong>Microservices vs Monolith</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*uWP2W4D3szfBFIjD9vCFZA.jpeg" /><figcaption>Taken from <a href="https://www.experfy.com/blog/microservices-vs-monolith-which-architecture-is-the-best-choice-for-your-business/">experfy</a></figcaption></figure><p>A monolith service architecture has a single service that is responsible for all features of the application, whereas decoupling these features logically and creating atomic services responsible for them creates the microservice architecture.</p><p>The argument in favor of microservices doesn&#39;t get any clearer than this: <br><strong>Decentralization</strong>: Decentralized decision making, development, deployment, and testing. As compared to a monolith service, a microservice architecture enables different engineering teams to work simultaneously and makes the decision making of architecture, release, and testing locally.</p><p><strong>Easier to scale: </strong>Due to its modular nature, a microservice architecture is easier to scale. Adding more developers, infrastructure is easy.</p><p><strong>No Single Point of failure: </strong>Lastly, this point is true to only some extent. An architecture based on microservices, will not have a single point of failure. But in reality, most systems, do have services that have interdependencies. However, the effects can be mitigated if the system is designed with failure in mind, along with monitoring, fallback, and quick response in place.</p><h4><strong>Challenges of Microservices</strong></h4><p>A distributed system such as a microservice architecture comes with its own failure modes.</p><blockquote>A fallacy is an incorrect assumption. Developers new to microservices can be guilty of these fallacies. Coined by <a href="https://en.wikipedia.org/wiki/L._Peter_Deutsch">L. Peter Deutsch</a> as <a href="https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing">Fallacies of Distributed Computing</a>.</blockquote><pre>The <a href="https://en.wikipedia.org/wiki/Fallacy">fallacies</a> are: <br>1. The <a href="https://en.wikipedia.org/wiki/Computer_network">network</a> is reliable.<br>2. <a href="https://en.wikipedia.org/wiki/Latency_(engineering)">Latency</a> is zero.<br>3. <a href="https://en.wikipedia.org/wiki/Throughput">Bandwidth</a> is infinite.<br>4. The network is <a href="https://en.wikipedia.org/wiki/Computer_security">secure</a>.<br>5. <a href="https://en.wikipedia.org/wiki/Network_topology">Topology</a> doesn&#39;t change.<br>6. There is one <a href="https://en.wikipedia.org/wiki/Network_administrator">administrator</a>.<br>7. Transport cost is zero.<br>8. The network is homogeneous.</pre><p>If we analyze these fallacies, we either open ourselves to the following failures or have to make developers responsible for them:</p><ol><li>The responsibility of security is left on developers to establish protocols for communication between services.</li><li>Error handling for the network is not coded in applications.</li><li>Lack of a single authority.</li><li>Bottlenecks created by a lack of rate-limiting and caching.</li></ol><p>Hence, there arrives a need to decouple <strong>developments from operations</strong>. <br>What does that mean?</p><p>Application developers need to focus on business logic, whereas operations will be responsible for network communication between the distributed systems. i.e How the microservices will communicate. That is the solution that service mesh provides.</p><h4><strong>Service Mesh</strong></h4><blockquote>A service mesh provides a transparent and language-independent way to flexibly and easily automate networking, security, and observation functions. In essence, it decouples development and operations for services.<br> Taken from <a href="https://www.infoq.com/minibooks/service-mesh-cloud-native-comms/?useSponsorshipSuggestions=true&amp;utm_source=minibooks_about_ServiceMesh&amp;utm_medium=link&amp;utm_campaign=ServiceMesh#idp_register">InfoQ Magazine:Service Meshes</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*MVLkktz7NJggBRu-QFU0KQ.png" /></figure><p>A generic service mesh has two parts. A <strong>control plane</strong> and a <strong>data plane</strong>.</p><p>The <strong>data plane</strong> is responsible for communications i.e All intra-service communications go via them. A service mesh creates a data plane by injecting a proxy container aside your services. Normally called a sidecar, its job is to intercept incoming and outgoing requests. These requests are then routed or denied depending upon the policy and security configurations. In general, these sidecars are responsible for communication between services, security, monitoring, and load-balancing.</p><p>The <strong>control plane,</strong> however, generates the configurations that are used by data planes. These configurations other than defaults depend mostly on user input. And hence the control plane creates a single administration of the network. Let&#39;s say for a use-case. We want to rate-limit the traffic from Service B to Service A. We will create a rate-limiting configuration. The control plane will disperse each sidecar, their configurations. The sidecar with Service B will intercept the traffic and rate limit it accordingly.</p><p>Lucky for us, there is a variety of service mesh available. Starts with <a href="https://istio.io/">Istio</a>, <a href="https://www.consul.io/">consul</a>, <a href="https://openservicemesh.io/">open-service-mesh</a> and recent entrant <a href="https://www.nginx.com/products/nginx-service-mesh/">Nginx service mesh</a>.</p><h4>Service Mesh Features</h4><p>A service mesh like <a href="https://istio.io/">Istio</a> will add the following capabilities to your microservice architecture.</p><p><strong>Security:</strong></p><p>Adds authentication, authorization, and encryption to communication between services with flexible strategy. Apart from intra-services communication, edge traffic i.e external traffic flowing inside the mesh (Ingress) and outward the mesh (egress) is also secured.</p><p><strong>Systems Resilience:<br></strong>Create systems resilient to overloaded capacity by adding circuit breaking to services. Or add global rate-limiting for cases when a large number of clients are accessing a small number of hosts. Like databases.</p><p><strong>Dynamic Routing:</strong></p><p>Programmable routing with rules that can URL, cookies, headers. Common use-cases are creating edge API-Gateway, API versioning. Add load-balancing with weightage, traffic shifting, red/blue deployments, canary deployments.</p><p><strong>Full Stack Tracing and Observability:</strong></p><p>The ability to visualize all the nodes, including each service, be it front end or back end. With edges showing traffic, observability is equally good for debugging traffic issues and a good knowledgebase for new developers in your team. With distributed tracing, you can debug the latency issues.</p><blockquote>Distributed tracing enables users to track a request through mesh that is distributed across multiple services. This allows a deeper understanding about request latency, serialization and parallelism via visualization.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRZSBuEUUkFrrCpkxB26xg.png" /></figure><h4><strong>When do you need service-mesh</strong></h4><blockquote>In deciding whether or not a service mesh makes sense for you and your organization, start by asking yourself two questions: how complex is your service topology and how will you integrate a service mesh into your software development lifecycle (SDLC)?</blockquote><p>A service mesh won&#39;t add much value when you are starting and the topology is very simple. You can easily diagnose the bottlenecks when there are one or two services. Only when you start adding more services and increase the complexity of topology i.e (microservices that call each other and make two, three, or even four hops within a mesh to complete a request). Also, as we have already discussed, the service mesh data plane is as easy as installing the sidecars to your existing services. The deployment of service mesh will be easy, but you’ll add one step to your SDLC. That step will be rolling out occasionally new operations configurations when you roll out services.</p><h3>Summary</h3><p>Microservice architecture comes with its own failure modes. Decoupling development from operations can solve these problems and give a more robust SDLC. Service mesh provides a great way to handle these operations by providing security, resilience, authority, observability, and routing capabilities.</p><p>Follow on for getting <a href="https://medium.com/@adrafiq-52/service-mesh-getting-hands-on-with-istio-part-2-808ac586567a">hands-on with Google Istio Project</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa9e90a1fbc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Backup and Disaster Recovery]]></title>
            <link>https://adrafiq-52.medium.com/kubernetes-backup-and-disaster-recovery-88d6cb8c5bf7?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/88d6cb8c5bf7</guid>
            <category><![CDATA[disaster-recovery]]></category>
            <category><![CDATA[velero]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[backup]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Wed, 28 Oct 2020 10:53:05 GMT</pubDate>
            <atom:updated>2020-10-28T11:06:52.131Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This article borrows the <a href="https://www.youtube.com/watch?v=IPYeCltXpxw">why, what and how</a> methadology of communicating which was described by simon sinek. I find this model to be very contextual in teaching and context is what makes our brain tick.</blockquote><p>I have made an assumption, you roughly understand <a href="https://whatis.techtarget.com/definition/distributed-computing#:~:text=Distributed%20computing%20is%20a%20model,to%20improve%20efficiency%20and%20performance.">distributed computing</a>, <a href="https://hackernoon.com/what-is-containerization-83ae53a709a6">containerization</a>, <a href="https://www.redhat.com/en/topics/containers/what-is-container-orchestration">orchestration</a>, <a href="https://microservices.io/">microservices</a>. If not click the links.</p><h4>Overview of Kubernetes</h4><p>Kubernetes is a very powerful resource orchestration service. With the kube API and controllers acting as control plane, Kubernetes act as a non-terminating loop, whose sole job is to move cluster from current to the desired state. The desired state generally is described in <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/">CRDs</a>. Controllers read these CRD objects and provision/remove the resources, directly or via Kube system API. Platforms like helm have made it easier to create and share CRD’s dynamically.</p><h4>Why (Necessity is the mother of invention)</h4><p>Working at <a href="https://webveloper.com/">webveloper</a>, we were trying to do a tracing and observability project four our multi-cluster Kubernetes deploy. We had organized our infrastructure in form of either helm charts or crds. With repos representing our monitoring, logging, product, and service-mesh, etc. For the research of the project, I was fiddling with the mesh(istio in our case) CRD’s. Long story short, I altered one CRD that described API-Gateway, and then all hell broke loose. Soon we had our monitoring tell us, that product services were down. As a firefighting effort, we started creating all relevant CRDs from repos. But it took two infrastructure engineers nearly ten hours to make sure every single CRD was created and the cluster came back to the desired state. <strong>There couldn&#39;t be any bigger motivation now, to look for a backup and disaster recovery tooling. That&#39;s the why ! In case of disaster, reducing the time taken to restore the cluster to desired states in a matter of minutes instead of hours.</strong></p><h4>How To Do (Approaching Kubernetes backup)</h4><p>As described in the overview of Kubernetes, Kubernetes depend upon controllers to read the CRD’s (Resource definitions objects/specs) and provision resources accordingly. Hence approaching Kubernetes backup is as easy as taking a snapshot of all the CRD’s that are currently in the cluster. And in case of disaster, use that snapshot to create them again. Leaving the job of provisioning the resources to controllers. That data is stored in Kubernetes etcd (a key/value database). That is basically it.</p><h4>What to do (Velero by VMware)</h4><p>Fortunately, there is a very stable and relevant community effort, that was originated by engineers at VMware. Over several iterations, we have <a href="https://velero.io/">Velero (A Kubernetes backup and migration service)</a> in its current form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZiO1e1ipOeZOn7U2HWTJpw.png" /></figure><blockquote>Each Velero operation – on-demand backup, scheduled backup, restore – is a custom resource, defined with a Kubernetes <a href="https://kubernetes.io/docs/concepts/api-extension/custom-resources/#customresourcedefinitions">Custom Resource Definition (CRD)</a> and stored in <a href="https://github.com/coreos/etcd">etcd</a>. Velero also includes controllers that process the custom resources to perform backups, restores, and all related operations.</blockquote><p><strong>Setting Up</strong></p><p>We will be doing a hands-on of setting up velero, creating scheduled backups, and restore example. We will be using GCP as provider for cloud storage (backup-location), and GKE for our example cluster. <br>You can find docs for setting up with other providers here: <a href="https://velero.io/docs/v1.5/supported-providers/">https://velero.io/docs/v1.5/supported-providers/</a></p><pre>We will use istio <a href="https://istio.io/latest/docs/examples/bookinfo/"><strong>bookinfo microservice example</strong></a><strong> </strong>as our product services.</pre><pre>kubectl apply -f <a href="https://raw.githubusercontent.com/istio/istio/release-1.7/samples/bookinfo/platform/kube/bookinfo.yaml">samples/bookinfo/platform/kube/bookinfo.yaml</a></pre><p><strong>GCP Plugin</strong></p><p>We will be setting up an object store (etcd) plugin. That involves creating a bucket and creating necessary permissions to use that bucket.</p><pre>Make sure you have auth to your google cloud and your relevant project is selected in gcloud cmd. </pre><pre># Creating bucket</pre><pre>BUCKET=&lt;YOUR_BUCKET&gt;<br><br>gsutil mb gs://$BUCKET/</pre><pre># View config list and copy project name</pre><pre>gcloud config list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*GwwqVsooELI9p-Fz6GSVRw.png" /></figure><pre># Store the project value from the results in the environment variable $PROJECT_ID.</pre><pre>PROJECT_ID=$(gcloud config get-value project)</pre><pre># Create a service account:</pre><pre>gcloud iam service-accounts create velero \<br>    --display-name &quot;Velero service account&quot;</pre><pre># Set the $SERVICE_ACCOUNT_EMAIL variable to match its email value.</pre><pre>SERVICE_ACCOUNT_EMAIL=$(gcloud iam service-accounts list \<br>  --filter=&quot;displayName:Velero service account&quot; \<br>  --format &#39;value(email)&#39;)</pre><pre>Attach policies to give velero the necessary permissions to function:</pre><pre># Our permissions</pre><pre>ROLE_PERMISSIONS=(     <br>compute.disks.get     <br>compute.disks.create     <br>compute.disks.createSnapshot     <br>compute.snapshots.get     <br>compute.snapshots.create     <br>compute.snapshots.useReadOnly     <br>compute.snapshots.delete     <br>compute.zones.get )  </pre><pre># Creating a role with those permissions</pre><pre>gcloud iam roles create velero.server \     --project $PROJECT_ID \     --title &quot;Velero Server&quot; \     --permissions &quot;$(IFS=&quot;,&quot;; echo &quot;${ROLE_PERMISSIONS[*]}&quot;)&quot;  </pre><pre># Creating IAM policy for our account that uses the role we just created</pre><pre>gcloud projects add-iam-policy-binding $PROJECT_ID \     --member serviceAccount:$SERVICE_ACCOUNT_EMAIL \     --role projects/$PROJECT_ID/roles/velero.server  </pre><pre># Giving access to our bucket</pre><pre>gsutil iam ch serviceAccount:$SERVICE_ACCOUNT_EMAIL:objectAdmin gs://${BUCKET}</pre><pre># Create a service account key, specifying an output file (credentials-velero) in your local directory. Store it somewhere safe. </pre><pre>gcloud iam service-accounts keys create credentials-velero \ — iam-account $SERVICE_ACCOUNT_EMAIL</pre><p><strong>Installing and setting up Velero</strong></p><p>Download and install velero cmd from their <a href="https://velero.io/docs/v1.5/basic-install/">website</a>. Then once the cmd is ready.</p><pre># Install velero on server</pre><pre>velero install \<br>    --provider gcp \<br>    --plugins velero/velero-plugin-for-gcp:v1.1.0 \<br>    --bucket $BUCKET \<br>    --secret-file ./credentials-velero</pre><p><strong>Creating Scheduled Backups</strong></p><p>Here is how you can setup velero to create scheduled daily backups. Where the last argument is a CRON time. You can use <a href="https://crontab.guru/">crontab</a> to generate your desired value.</p><pre>velero schedule create daily-backup --schedule &quot;0 7 * * *&quot;</pre><p><strong>Disaster Recovery</strong></p><p>Suppose a disaster has occurred, follow these steps to restore your cluster.</p><pre># Update your backup storage location to read-only mode (this prevents backup objects from being created or deleted in the backup storage location during the restore process):</pre><pre># Get storage location name and copy the Name value.<br>velero backup-location get</pre><pre># Set the storage location access mode to read-only</pre><pre>kubectl patch backupstoragelocation &lt;STORAGE LOCATION NAME&gt; \     <br>--namespace velero \     <br>--type merge \     <br>--patch &#39;{&quot;spec&quot;:{&quot;accessMode&quot;:&quot;ReadOnly&quot;}}&#39;</pre><pre>## create a restore from the latest successful backup triggered by schedule &quot;daily-backup&quot;<br>  <br>velero restore create --from-schedule daily-backup</pre><pre># Once the restore jon is created, use the following command to monitor progress</pre><pre>velero restore describe &lt;Restore-Object-Name&gt;</pre><pre># Patching backup location access to allow read/write access</pre><pre>kubectl patch backupstoragelocation &lt;STORAGE LOCATION NAME&gt; \    <br>--namespace velero \    <br>--type merge \    <br>--patch &#39;{&quot;spec&quot;:{&quot;accessMode&quot;:&quot;ReadWrite&quot;}}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0duUMLgl77GbbYEM_wDqA.png" /></figure><p><strong>Manual Backup and Restore</strong></p><p>You can also create manual backups and restore them voluntarily.</p><pre># Creating a backup</pre><pre>velero backup create my-backup-1</pre><pre># Getting a list of backups available<br>velero backup get</pre><pre># Creating a restore job from backup name. <br>velero restore create --from-backup my-backup-1</pre><h3>Summary</h3><p>Having a Kubernetes backup, disaster recovery in place can help you reduce the time taken to restore your clusters from hours to two minutes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88d6cb8c5bf7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring in Kubernetes (Multi-Cluster environment)]]></title>
            <link>https://adrafiq-52.medium.com/monitoring-in-kubernetes-multi-cluster-environment-7f98b4f52832?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f98b4f52832</guid>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[multi-cluster]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Sun, 25 Oct 2020 03:06:20 GMT</pubDate>
            <atom:updated>2020-10-25T03:07:56.952Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This is the last article in three-part series on monitoring. If you haven&#39;t read the <a href="https://adrafiq-52.medium.com/monitor-this-kubernetes-6e9a3e563457">what, how and why of monitoring</a>, and <a href="https://adrafiq-52.medium.com/monitoring-in-kubernetes-hands-on-9a4d4a4ff1c5">monitoring in kubernetes (Hands-On)</a>. I would suggest giving them a read first.</blockquote><h4><strong>Establishing our environment:</strong></h4><p>We have a Kubernetes based multi-cluster infrastructure. They can be any region, environment (Stage, Production). They have cross-cluster communication established via any service mesh.</p><h4>Central Monitoring (Federation):</h4><p>In a multi-cluster environment, the best way to monitor or control our infrastructure is to establish a central command and control. Where we have a central cluster that has tooling installed to monitor our other clusters.</p><p>We have <a href="https://adrafiq-52.medium.com/monitor-this-kubernetes-6e9a3e563457">earlier</a> described monitoring as <strong>exporting</strong>, <strong>collecting,</strong> and <strong>visualizing</strong>. Prometheus provides the facility of Prometheus federation, wherein each Prometheus instance becomes an exporter, and the central Prometheus scrapes the Prometheus instances residing in each cluster. <br>So we install our monitoring tooling in monitoring namespace as we did in the <a href="https://adrafiq-52.medium.com/monitoring-in-kubernetes-hands-on-9a4d4a4ff1c5">hands-on</a>, in all of our clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*8_i6okZ9A3m2yrxH3mxw8g.jpeg" /></figure><h4>Setting Up Central Prometheus</h4><p>To begin, install monitoring tooling in other clusters as described in <a href="https://adrafiq-52.medium.com/monitoring-in-kubernetes-hands-on-9a4d4a4ff1c5">hands-on</a>.</p><p>Similarly, <a href="https://adrafiq-52.medium.com/monitoring-in-kubernetes-hands-on-9a4d4a4ff1c5">install grafana</a> in our central cluster, but we will use a different helm value file for <a href="https://gist.github.com/adrafiq/231c0d079ee1ece7f2b5df9f224906f2">prometheus-central</a>. The difference in central Prometheus is that we create scrape jobs to the Prometheus instances in our product clusters.</p><p>As described in the code snippet below. Notice, the labels field. This will help us in grafana to select metrics for each cluster via drop-down. We call them <a href="https://grafana.com/docs/grafana/latest/variables/">dashboard variables</a>. Use this <a href="https://gist.github.com/adrafiq/231c0d079ee1ece7f2b5df9f224906f2">gist</a> to get helm-values for central-prometheus.</p><pre>extraScrapeConfigs: |  <br># Prometheus Federation. Scrape metrics from prometheus cross-cluster   <br>  - job_name: &#39;my-first-cluster&#39;    <br>    scrape_timeout: 30s    <br>    honor_labels: true    <br>    metrics_path: &#39;/federate&#39;    <br>    params:      <br>     &#39;match[]&#39;:        <br>       - &#39;{job=&quot;prometheus&quot;}&#39;        <br>       - &#39;{job=&quot;prometheus-pushgateway&quot;}&#39;        <br>       - &#39;{job=&quot;prometheus-blackbox-exporter&quot;}&#39;        <br>       - &#39;{job=&quot;kubernetes-apiservers&quot;}&#39;        <br>       - &#39;{job=&quot;kubernetes-nodes&quot;}&#39;        <br>       - &#39;{job=&quot;kubernetes-nodes-cadvisor&quot;}&#39;        <br>       - &#39;{job=&quot;kubernetes-pods&quot;}&#39;        <br>       - &#39;{job=&quot;kubernetes-service-endpoints&quot;}&#39;        <br>       - &#39;{job=&quot;kubernetes-nodes-cadvisor&quot;}&#39;        <br>       - &#39;{job=&quot;kubernetes-pods&quot;}&#39;        <br>       - &#39;{__name__=~&quot;job:.*&quot;}&#39;    <br>   static_configs:      <br>   - targets:        <br>     - &#39;&lt;Link to prometheus in my-first-cluster&gt;&#39;        <br>     labels:          <br>       cluster: my-first-cluster</pre><p><strong>Installation Steps</strong></p><pre># Create monitoring namespace<br>kubectl create ns monitoring</pre><pre># Install grafana<br>helm install stable/grafana --name grafana --namespace monitoring -f <a href="https://gist.github.com/adrafiq/0a95756ed19c2e77475bf2fe68b6d932">grafana.yaml</a><br>## Import the kubernetes cost and microservice health dashboards as described in <a href="https://adrafiq-52.medium.com/monitoring-in-kubernetes-hands-on-9a4d4a4ff1c5">hands-on</a></pre><pre># Install Prometheus<br>helm install stable/prometheus --name my-first-cluster-prometheus --namespace monitoring -f <a href="https://gist.github.com/adrafiq/231c0d079ee1ece7f2b5df9f224906f2">prometheus-central.yaml</a></pre><h4>Configuring Grafana</h4><p>We will add, drop-down selector for our product clusters, such that selecting each option will populate the dashboard with metrics from that respective cluster.</p><p><strong>Steps:</strong></p><ol><li>Goto dashboard Settings -&gt; Variables. Click New.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bmPb_QkrfGfK73P7ogs6QA.png" /></figure><p>2. Enter <em>Name</em> : “cluster”, <em>Label</em> : “cluster”, <em>Data source </em>:<em> </em>“Prometheus”, Query : label_values(cluster), set Multi-value to true. <br>Here we enter Query as a function of label_values. Where label_values gets unique values from all our metrics. That is (my-first-cluster, my-second-cluster).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FsKAdMu-_aTV1mVjHJxoIg.png" /></figure><p>3. Move the precedence of cluster variable to top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBy0lM0TOGtE4Q0EOm5lyQ.png" /></figure><p>And finally, return to the dashboard and use the drop-down to select metrics from the respective cluster.</p><p><strong>Summary</strong></p><p>In a multi-cluster environment, there should be central monitoring and configuration cluster, that scrapes the metrics from all other clusters into one place.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f98b4f52832" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring in Kubernetes(Hands-On)]]></title>
            <link>https://adrafiq-52.medium.com/monitoring-in-kubernetes-hands-on-9a4d4a4ff1c5?source=rss-48a91ae145fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a4d4a4ff1c5</guid>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[alerts]]></category>
            <category><![CDATA[email]]></category>
            <dc:creator><![CDATA[ADIL RAFIQ]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 06:06:33 GMT</pubDate>
            <atom:updated>2020-10-25T23:02:08.842Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This is a three-part series. If you haven&#39;t read the <a href="https://adrafiq-52.medium.com/monitor-this-kubernetes-6e9a3e563457">why, what, and how of monitoring</a> I would suggest you read it first. This part focuses more on getting hands on.</blockquote><p><strong>Prerequisites</strong>:</p><p>We will install monitoring infrastructure on a Kubernetes cluster. And then create/import custom dashboards for our monitoring needs. We will cover cluster health, micro-service uptime. And follow up with creating smart alerts.<br>For this purpose, make sure you have a working Kubernetes cluster authorized for <strong>kubectl</strong> to use, and <strong>helm v2</strong> installation. We will use istio <a href="https://istio.io/latest/docs/examples/bookinfo/"><strong>bookinfo microservice example</strong></a><strong> </strong>as our product services. Optionally create a namespace by the name of monitoring.</p><h3><strong>Setting up the infrastructure:</strong></h3><p>As we discussed in the previous part, we can divide the monitoring process into three steps. Exporting, collecting, and visualizing.</p><p><strong>Step 1 (Exporters)</strong>:</p><p>For the scope of this article, we will install <a href="https://github.com/prometheus/blackbox_exporter">blackbox exporter</a>, which allows black box probing of endpoints http, https, DNS, tcp and icmp. This exporter will help us create scrape jobs of probing microservice health endpoints which will be later used to construct SLI. <br>Create a helm installation with the following values from <a href="https://gist.github.com/adrafiq/3d77b13b6bc0151ac739523acedb886d">gist</a>:</p><pre><br>helm install stable/prometheus-blackbox-exporter — name prometheus-blackbox  — namespace monitoring -f <a href="https://gist.github.com/adrafiq/3d77b13b6bc0151ac739523acedb886d">blackbox_exporter</a>.yaml</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/029e1d9c507d0b93f6994f321b5e682e/href">https://medium.com/media/029e1d9c507d0b93f6994f321b5e682e/href</a></iframe><p><strong>Step 2 (Collector)</strong>:</p><p>We will install Prometheus as a collector whose job is to scrape metrics from various exporters and store them in its time-series database. We will also create the scrape jobs configs in which we will describe extra scrape jobs for black box to probe bookinfo services.</p><pre>helm install stable/prometheus --name my-first-cluster-prometheus --namespace monitoring -f <a href="https://gist.github.com/adrafiq/8b8089dceca25a0ec4d96a8627767e2a">prometheus.yaml</a></pre><pre># Extra scrape job<br>extraScrapeConfigs: |  <br>  - job_name: &#39;prometheus-blackbox-exporter&#39;    <br>    metrics_path: /probe    <br>    params:      <br>    module: [http_2xx]    <br>    static_configs:      <br>    - targets:        <br>      - http://details.bookinfo.svc.cluster.local        <br>      - <a href="http://reviews.bookinfo.svc.cluster.local/">http://reviews.bookinfo.svc.cluster.local</a><br>    replacement: prometheus-blackbox-prometheus-blackbox-exporter:9115</pre><blockquote>Use the helm values from <a href="https://gist.github.com/adrafiq/8b8089dceca25a0ec4d96a8627767e2a"><strong>this gist</strong></a>.Still looking for a way to make long gist scrollable on medium. If you know, please do tell.</blockquote><p><strong>Step 3 (Visualizer):</strong></p><p>Lastly, we will install grafana in our monitoring namespace. Grafana will use the Prometheus server as data source to fetch and visualize metrics. Like above, we will use helm to install grafana with values in the <a href="https://gist.github.com/adrafiq/0a95756ed19c2e77475bf2fe68b6d932"><strong>following gist</strong></a>:</p><pre>helm install stable/grafana --name grafana --namespace monitoring -f <a href="https://gist.github.com/adrafiq/0a95756ed19c2e77475bf2fe68b6d932">grafana.yaml</a></pre><p>Important to define the data source as our Prometheus server in our values YAML file.</p><pre>datasources:  <br>  datasources.yaml:    <br>    apiVersion: 1    <br>    datasources:    <br>    - name: Prometheus      <br>      type: prometheus      <br>      url: http://my-first-cluster-prometheus-server.monitoring.svc.cluster.local      <br>      access: proxy      <br>      isDefault: true</pre><p>And that’s it. We have set up a minimal infrastructure for our monitoring.</p><p><strong>Dashboards</strong></p><p>We won&#39;t have time to cover promql and grafana diagrams in this article but surely other examples will follow. For now, we will use some of the pre-made dashboards that are available in the <a href="https://grafana.com/grafana/dashboards">grafana dashboards directory</a>. <br>To import a dashboard, first-run grafana locally by opening a <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/">port-forwarded session to the grafana pod</a>.</p><p>We will import two dashboards for <a href="https://grafana.com/grafana/dashboards/8670">kubernetes cluster cost</a> and <a href="https://grafana.com/grafana/dashboards/5345">microservice health</a>. These are the steps :</p><ol><li>Goto Home -&gt; Manage -&gt; Import (and add the dashboard id to import).</li><li>Select data source as Prometheus in form and click import.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4qy7SkwJsyS6kAcrLRxo0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QPxm2Qq2lVP2bf5e6fXeAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ezWAnDC6DzxobKH-9aJGsg.png" /></figure><p>There, we are done and have imported two dashboards.</p><p><strong>Cluster Health and Costs</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ipq9uDByxyxaVXUzfsYG0Q.png" /></figure><p><strong>Microservice Health Checks</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWwhXxjn6jgJkRvLXl4jTQ.png" /></figure><h3>Alerting</h3><p>Grafana uses <a href="https://grafana.com/docs/grafana/latest/alerting/notifications/#list-of-supported-notifiers">notification channels</a> to send <a href="https://grafana.com/docs/grafana/latest/alerting/create-alerts/"><em>alerts</em></a> of predefined conditions to users. Let&#39;s see a simple case of emailing, microservice health check alerts to a developer.</p><p><strong>Step 1</strong>:</p><p>Add email server (SMTP) configuration to grafana chart. I used SendGrid&#39;s API for this demonstration. Update the following YAML values accordingly.</p><pre>grafana.ini:<br> smtp:<br>  enabled: true<br>  host: smtp.sendgrid.net:465<br>  user: apikey<br>  password: &lt;Your Sendgrid API-KEY Here&gt;<br>                              ---<br>helm upgrade grafana stable/grafana --namespace monitoring -f grafana.yaml</pre><p><strong>Step 2</strong>:</p><p>From the sidebar, navigate to <strong>Alerts -&gt; Notification Channels</strong></p><p>Click the new channel button, add a name, enable <em>Disable Resolve Message</em>, <em>Send Reminders,</em> and add a test email in the <em>Email Addresses </em>field. Press the <em>send-test</em> button and you should receive a test email from grafana.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*oOwS2CLpJp4DR1IQ8pvXKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*KqeXOkxXBxGUJC1_7hIx0w.png" /></figure><p><strong>Step 3</strong>:</p><p>To create a microservice down alert we will first create a dashboard.</p><p>Added to it will be a chart that plots UP metric from the black-box exporter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fF9gFX0Ha-29Hd8p6SQu1Q.png" /></figure><p>In the chart edit pane, navigate to alert section. Add a <em>name</em>, set <em>Evaluate Every</em> (10s), <em>For</em> (15s). This means evaluate the health checks every 10s, and only fire the alert if there is an undesired value for 15s continuously. <br>Lastly, add condition of (When the value is below 1). Since UP is boolean metrics, below 1 will imply a service down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EdFdXhQ8UnueYnpaMcaoBQ.png" /></figure><p>Disable the deployment of either details or reviews service to mimic a failure</p><pre>kubectl scale deployment details-v1 --replicas=0 -n bookinfo</pre><p>And you should receive a mail for the alert. TA DA!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RzJIMrWoAcomNf80AAx7zg.png" /></figure><h3>Summary:</h3><p>During the course of this article, we have successfully set up monitoring in our clusters. Created and imported dashboards and finally created an alert that uses email notification channel.</p><p>For the third and last part of this series please goto. <a href="https://adrafiq-52.medium.com/monitoring-in-kubernetes-multi-cluster-environment-7f98b4f52832">Monitoring a multi-cluster environment</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a4d4a4ff1c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>