<?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 Naveen Singh on Medium]]></title>
        <description><![CDATA[Stories by Naveen Singh on Medium]]></description>
        <link>https://medium.com/@sunnykkc13?source=rss-e86ec26246b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*usuRF1uyijX9ikIDGmzAlA.jpeg</url>
            <title>Stories by Naveen Singh on Medium</title>
            <link>https://medium.com/@sunnykkc13?source=rss-e86ec26246b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 08:45:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sunnykkc13/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[EKS: Networking]]></title>
            <link>https://sunnykkc13.medium.com/eks-networking-24c735ec3a00?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/24c735ec3a00</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[ek]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Fri, 18 Sep 2026 06:45:00 GMT</pubDate>
            <atom:updated>2026-09-20T18:50:58.015Z</atom:updated>
            <content:encoded><![CDATA[<p>I was asked EKS networking in an interview and it made me realise how much I don’t know about the stack I’m daily working on. This blog will explain each part of the networking side.</p><h3>Cluster Creation:</h3><p>Whenever a cluster is created it will ask for a VPC and at least 2 subnets present in different availability zone (Choose the subnets in your VPC where the control plane may place elastic network interfaces (ENIs) to facilitate communication with your cluster).</p><h4>Add-On (Will discuss later):</h4><ul><li>AWS CNI plugin → This particular plugin allows the pod to pod communication, <strong><em>assigning IPs to pods</em></strong>, route traffic between nodes.</li><li>Kube-Proxy → I’m sure you must have heard about this component. Whenever a service (kubectl service) is created, kube proxy update ip tables on the worker node for the same.</li><li>CoreDNS → Assign DNS to each service.</li></ul><h4>Control Plane:</h4><p><strong><em>Control Plane is managed by AWS</em></strong>. When you create a cluster, Amazon EKS creates 2–4 <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html">elastic network interfaces</a> in the subnets that you specify. These network interfaces enable communication between your cluster and your VPC. Via these ENI the worker nodes (Kubelet) are able to connect to API-Server.</p><p>To find these ENIs: AWS Console → EC2 → Network &amp; Security → Network Interfaces → Filter “Description = Amazon EKS &lt;Cluster-Name&gt;”</p><h4>Worker Node:</h4><p>Here’s all the magic happens.</p><p>As soon as a worker node is created either by Nodegroup or Karpenter, a pod is placed “aws-node” by a daemonset “aws-node” found in kubectl get ds -n kube-system . <strong><em>This daemonset comes from AWS VPC CNI plugin</em></strong>.</p><p>aws-node pod contain one init container and two containers:</p><ul><li>aws-vpc-cni-init container → It copies aws-cni binary to host’s /opt/cni/bin/aws-cni</li><li>aws-node container → Install aws-cni, egress-cni and start IPAM (IP Address Management) daemon and copy a configuration file to host’s /etc/cni/net.d/ path. The configuration file contains CNI version, plugins details, capabilities and so on.</li><li>aws-eks-nodeagent container → It automatically detect health issues and trigger automatic node repair.</li></ul><h4><strong>AWS-CNI Plugin responsibilities and its Working:</strong></h4><p>Each pod running on this cluster will have a IP from your assigned VPC. The issue comes when you are running a large number of pods where available IPs from the VPC might get to 0. If it hits 0 all other pods to be scheduled will move to pending state. To resolve it, you can create another VPC of CIDR 192.168.0.0/16 , its associated subnets and assign the same to AWS CNI plugin in its configuration. It is also possible to assign security groups directly in configuration. That way your primary VPC will not get exhausted and pod will receive IPs.</p><p><strong>Note →</strong> <strong><em>aws-node pod shares host network that is the primary ENI (IPv4) attached to worker node.</em></strong></p><ol><li>aws-cni, egress-cni, and its configuration file get copied on the worker node.</li><li>Now aws-node container invokes IPAM daemon which basically attaches a secondary ENI (IPv4 from 192.168.0.0/16) to the worker node. <strong>It is necessary to understand working of IPAMD.</strong></li></ol><h4><strong>IPAM Working</strong></h4><ul><li>It is responsible for attaching a secondary ENI.</li><li>Create a warmpool (datastore) of available IPs for upcoming pods.</li><li>It checks for WARM_ENI_TARGET and WARM_PREFIX_TARGET environment variables for warmpool. It also checks for prefix delegation.</li><li>It calculates the maximum ip and max prefixes per ENI.</li><li>Update iptables for both ENIs.</li><li>Number of pods can be scheduled on the worker node based on IPs.</li></ul><p><strong>Networking context from Instance type</strong> → It is hardcoded how many ENIs can get attached to a node based on its instance type. Let’s take <strong>t2.large</strong> to understand it better:</p><ul><li><strong>Maximum number of network interfaces: 3</strong></li><li><strong>IPv4 addresses per interface: 12</strong></li></ul><p>Per ENI 12 IPs can get attached so total 3*12 = 36 IPs. Based on this almost 32 pods can set scheduled on this node.</p><p><strong>IPv4 Prefix Delegation → </strong>Instead of assigning a single IP to a ENI ( /32 ), a CIDR range is assigned (/28) which increases the IPs availability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*XnnYIhar9zOK279se8pDBQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*XC0thGiGDtAu3Duo5bDypA.jpeg" /></figure><p>When delegation is off then only 36 IPs can be assigned (3*12) and whenever a pod is scheduled to a node a aws api call is made to allocate free IP from the subnet and if ENI is filled then two extra api call for creating and attaching ENI also called. This might cause RateLimit issue. But when delegation is on then maths look like this</p><p>Per ENI → 12 CIDRs and per CIDR 16 IPs → total IPs = 12*16 = 192</p><p>All ENI combined = 192 * 3 = 576 (560 allocatable IPs)</p><p>This increase the IPs drastically and allow IPAM to create /28 CIDR warmpool hence reducing API calls.</p><p>But you will hardly see these many CIDRs get assigned to a node because kubelet has two limits — max-pod and — pod-per-core.</p><blockquote>So max pod calculation = min(maxPods, podPerCore, allocatable IPs)</blockquote><p><strong>IP allocation to Pod:</strong></p><ol><li>As kubelet receives the Pod to schedule on the node, it invokes container runtime (containerd). Containerd downloads the image and create pod network sandbox. It invokes aws-cni with ADD argument which then contacts IPAMD on gRPC protocol. IPAM checks for free IPs from warmpool and return it to aws-cni.</li><li>Once aws-cni receives the IP back from IPAM, it creates Veth pair where one end goes to pod renamed as eth0, IP assigned to pod and second end remains in host network namespace.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*6M1_3HTOoXLOgx6nGMyQ-Q.jpeg" /><figcaption>Pod IP allocation</figcaption></figure><p>So that’s a overview of AWS-CNI working. Let’s move to another plugin</p><h4>CoreDNS</h4><p>This plugin is responsible for creating local DNS. Wheneer a service is created, CoreDNS assign a internal domain name to it</p><blockquote>&lt;service-name&gt;.&lt;namespace&gt;.svc.cluster.local</blockquote><p>If some external DNS comes to CoreDNS, it forwards to VPC DNS resolver.</p><h4>Kube-proxy</h4><p>Kube Proxy runs on each node as pod (managed by daemonset). Whenever a service is created kubectl get service , kube proxy update the IP tables on each worker nodes so that pods can communicate to each other as it is not mandatory that related pods get scheduled on same node.</p><p><strong>Pod to Pod communication Flow</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*F_bZIdn5pg3Pzo_feBkOaA.jpeg" /></figure><p>It covers fairly everything I had on my plate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rd0Av07TNXYXifEU8nlQkg.png" /><figcaption>Network Flow</figcaption></figure><p>P.S. → If you have a requirement to attach a specific SG to your pod, AWS-CNI provide a way to do that</p><pre>cat &gt;my-security-group-policy.yaml &lt;&lt;EOF<br>apiVersion: vpcresources.k8s.aws/v1beta1<br>kind: SecurityGroupPolicy<br>metadata:<br>  name: my-security-group-policy<br>  namespace: my-namespace<br>spec:<br>  podSelector:<br>    matchLabels:<br>      role: my-role<br>  securityGroups:<br>    groupIds:<br>      - my_pod_security_group_id<br>EOF</pre><p>Topics left to cover:</p><ul><li>Trunk ENI and Branch ENI</li><li>Load Balancer Controller</li></ul><p>Resources:</p><ol><li><a href="https://docs.aws.amazon.com/eks/latest/userguide/managing-vpc-cni.html">https://docs.aws.amazon.com/eks/latest/userguide/managing-vpc-cni.html</a></li><li><a href="https://docs.aws.amazon.com/eks/latest/userguide/managing-coredns.html">https://docs.aws.amazon.com/eks/latest/userguide/managing-coredns.html</a></li><li><a href="https://docs.aws.amazon.com/eks/latest/userguide/managing-kube-proxy.html">https://docs.aws.amazon.com/eks/latest/userguide/managing-kube-proxy.html</a></li><li><a href="https://docs.aws.amazon.com/eks/latest/userguide/sg-pods-example-deployment.html">https://docs.aws.amazon.com/eks/latest/userguide/sg-pods-example-deployment.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24c735ec3a00" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make grep Faster: Optimise Your Searches with LC_ALL]]></title>
            <link>https://sunnykkc13.medium.com/make-grep-faster-optimise-your-searches-with-lc-all-6dffbcc1e73c?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dffbcc1e73c</guid>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Tue, 25 Mar 2025 02:31:26 GMT</pubDate>
            <atom:updated>2025-03-25T04:52:28.056Z</atom:updated>
            <content:encoded><![CDATA[<p>In Linux, when searching for a particular pattern or string the most used command is grep. Grep supports regular expression as well.</p><p>But in my case the grep was quite slow as the file I was scanning was too big and had too many lines, no wonder grep took its sweet time. So, o, I started looking for a more efficient way to search and then came across locale and how changing it can make grep faster.</p><p>Locale defines how text is encoded and processed. Let’s check the current encoding method:</p><pre>naveen@redskull:~$ locale<br>LANG=en_US.UTF-8<br>LANGUAGE=<br>LC_CTYPE=&quot;en_US.UTF-8&quot;<br>LC_NUMERIC=&quot;en_US.UTF-8&quot;<br>LC_TIME=&quot;en_US.UTF-8&quot;<br>LC_COLLATE=&quot;en_US.UTF-8&quot;<br>LC_MONETARY=&quot;en_US.UTF-8&quot;<br>LC_MESSAGES=&quot;en_US.UTF-8&quot;<br>LC_PAPER=&quot;en_US.UTF-8&quot;<br>LC_NAME=&quot;en_US.UTF-8&quot;<br>LC_ADDRESS=&quot;en_US.UTF-8&quot;<br>LC_TELEPHONE=&quot;en_US.UTF-8&quot;<br>LC_MEASUREMENT=&quot;en_US.UTF-8&quot;<br>LC_IDENTIFICATION=&quot;en_US.UTF-8&quot;<br>LC_ALL=en_US.UTF-8<br>naveen@redskull:~$</pre><h3>Understanding en_US.UTF-8 Locale</h3><p>en_US.UTF-8 is a locale setting in Unix-like systems that defines how text processing, character encoding, and formatting are handled.</p><h4>Breaking It Down</h4><ol><li><strong>en_US (English - United States)</strong></li></ol><ul><li>Specifies the language (en for English) and country (US for the United States).</li><li>Affects things like date formats, currency symbols, and sorting order.</li></ul><ol><li><strong>UTF-8 (Unicode Transformation Format - 8 bit)</strong></li></ol><ul><li>A variable-length character encoding standard that supports almost all characters from different languages.</li><li>Each character can be <strong>1 to 4 bytes long</strong> (ASCII characters remain 1 byte, while special characters like é or ₹ use more).</li><li><strong>Backward compatible with ASCII</strong>, meaning regular English text works without issues.</li></ul><h4>Why Use en_US.UTF-8?</h4><p>✅ <strong>Supports Multi-Language Text</strong> — Can handle symbols, emojis, and special characters.<br> ✅ <strong>Standard Encoding for Modern Systems</strong> — Avoids encoding issues like â€™ instead of &#39;.<br> ✅ <strong>Better Sorting &amp; Searching</strong> – Handles case-insensitive searches correctly (Résumé ≈ resume).</p><blockquote>Even this blog is encoded in UTF-8 so that it able to support é and those green tick emoji.</blockquote><h3>LC_ALL=C</h3><p>What I was searching is end_pos_log 74159832 in MySQL bin-log file which does not contain any international letter, only English characters. So, here:</p><ul><li>a fixed string was getting searched</li><li>only English characters were getting searched</li></ul><p>Then, I switched the locale temporarily to <strong>LC_ALL=C </strong>which only check ASCII character and ignore other international letters. Example</p><pre>naveen@redskull:~$ echo -e &quot;résumé\nresume\ncafé\ncafe\nnaïve\nnaive&quot; &gt; example.txt<br>naveen@redskull:~$ cat example.txt <br>résumé<br>resume<br>café<br>cafe<br>naïve<br>naive<br><br>naveen@redskull:~$ file example.txt <br>example.txt: Unicode text, UTF-8 text<br>naveen@redskull:~$ cat &gt; ascii_example.txt<br>naveen<br>naveen@redskull:~$ file ascii_example.txt <br>ascii_example.txt: ASCII text<br>naveen@redskull:~$<br></pre><p>Now, grep will ignore <strong>é</strong> and <strong>ï</strong></p><p>Just for your information here’s the ASCII table.</p><pre>Dec  Char                           Dec  Char     Dec  Char     Dec  Char<br>---------                           ---------     ---------     ----------<br>  0  NUL (null)                      32  SPACE     64  @         96  `<br>  1  SOH (start of heading)          33  !         65  A         97  a<br>  2  STX (start of text)             34  &quot;         66  B         98  b<br>  3  ETX (end of text)               35  #         67  C         99  c<br>  4  EOT (end of transmission)       36  $         68  D        100  d<br>  5  ENQ (enquiry)                   37  %         69  E        101  e<br>  6  ACK (acknowledge)               38  &amp;         70  F        102  f<br>  7  BEL (bell)                      39  &#39;         71  G        103  g<br>  8  BS  (backspace)                 40  (         72  H        104  h<br>  9  TAB (horizontal tab)            41  )         73  I        105  i<br> 10  LF  (NL line feed, new line)    42  *         74  J        106  j<br> 11  VT  (vertical tab)              43  +         75  K        107  k<br> 12  FF  (NP form feed, new page)    44  ,         76  L        108  l<br> 13  CR  (carriage return)           45  -         77  M        109  m<br> 14  SO  (shift out)                 46  .         78  N        110  n<br> 15  SI  (shift in)                  47  /         79  O        111  o<br> 16  DLE (data link escape)          48  0         80  P        112  p<br> 17  DC1 (device control 1)          49  1         81  Q        113  q<br> 18  DC2 (device control 2)          50  2         82  R        114  r<br> 19  DC3 (device control 3)          51  3         83  S        115  s<br> 20  DC4 (device control 4)          52  4         84  T        116  t<br> 21  NAK (negative acknowledge)      53  5         85  U        117  u<br> 22  SYN (synchronous idle)          54  6         86  V        118  v<br> 23  ETB (end of trans. block)       55  7         87  W        119  w<br> 24  CAN (cancel)                    56  8         88  X        120  x<br> 25  EM  (end of medium)             57  9         89  Y        121  y<br> 26  SUB (substitute)                58  :         90  Z        122  z<br> 27  ESC (escape)                    59  ;         91  [        123  {<br> 28  FS  (file separator)            60  &lt;         92  \        124  |<br> 29  GS  (group separator)           61  =         93  ]        125  }<br> 30  RS  (record separator)          62  &gt;         94  ^        126  ~<br> 31  US  (unit separator)            63  ?         95  _        127  DEL</pre><h4>How to use LC_ALL=C</h4><pre># just before grep command write<br><br>LC_ALL=C grep &#39;resume&#39; example.txt<br># it will temporarily change the locale not permanently</pre><p>Now, I have neglected international letters it gave grep a boost. Second thing I did is to use -F parameter. It takes the pattern as a fixed string not as a regex. Example:</p><pre>naveen@redskull:~$ grep &quot;r.sum.&quot; example.txt <br>résumé<br>resume<br>naveen@redskull:~$ grep &quot;na.ve&quot; example.txt <br>naïve<br>naive<br>naveen@redskull:~$ grep -F &quot;na.ve&quot; example.txt</pre><ul><li>-F → instead of taking . as regex it is searching for “na.ve” string which is not present in this file.</li></ul><h3>The final command</h3><pre>LC_ALL=C grep -F &quot;string&quot; file.txt <br><br># to compare performance<br>time grep &quot;search_term&quot; large_file.txt<br>time LC_ALL=C grep &quot;search_term&quot; large_file.txt</pre><p>Thank you for reading !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dffbcc1e73c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TLS Certificates]]></title>
            <link>https://sunnykkc13.medium.com/tls-certificates-153a85037a25?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/153a85037a25</guid>
            <category><![CDATA[tls-certificate]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Fri, 30 Aug 2024 10:28:24 GMT</pubDate>
            <atom:updated>2024-08-30T10:28:24.255Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever you accessed any website using HTTPS protocol then you must observed that browser shows a lock or a toggle icon that means the current website is secure and uses HTTPS. But what secure means here?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*VH9OzzwWxrrRjlKFSpTfwQ.png" /><figcaption>A Lock before website</figcaption></figure><h4>The beginning</h4><p>Suppose you are accessing <a href="https://mail.google.com/">mail.google.com</a> to login to your mail. Here you provide your credentials in plain text such as</p><ul><li>username: demo</li><li>password: demopassword</li></ul><p>Now your cred is not encrypted that means if there is any hacker, he can steal your cred that is not good.</p><p>To resolve this there are two methods to encrypt the data:</p><ul><li><strong>Symmetric Key encryption (Same key to encrypt and decrypt):</strong> In this user will encrypt the cred using a key and sends to server but server also needs the key to decrypt the cred and user needs to send the key along with cred. However hacker can also have the key with cred and boom! you are exposed again. So, this is not option.</li><li><strong>Asymmetric key encryption: </strong>In this method there are two keys that are called as public and private key. The speciality about this method is data can be encrypted using one key and decrypted using other one. Same key can not be used to encrypt and decrypt the data. <strong><em>So whenever you request any website, it sends its public key with response and then your data gets encrypted using it. Now even a hacker get the public key and encrypted cred, he will not be able to decrypt it as it requires private key of that public key.</em></strong></li><li>Let’s take a look what public and private key looks like</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*ODD5X26GWUR1IK7hQFqUXA.png" /><figcaption>Generating Asymmetric key pair</figcaption></figure><ul><li>id_rsa → your private key</li><li>id_rsa.pub → your public key</li><li>Data encrypted using public key can only be decrypted using private key and vice-versa.</li></ul><blockquote>Now, we understood the methods so does the hacker. Here’s comes another method to fraud you called phishing.</blockquote><p>I saw multiple intelligent person access <a href="https://mail.google.com/">https://mail.google.com</a> using gmail.com or search gmail or search engine.</p><ul><li>Now, hacker can use this to create a clone of the gmail and generate a key pair and somehow he’s able to fool you and you send your cred to hacker’s server.</li></ul><blockquote>To tackle this, certificates were introduced.</blockquote><p>Websites need SSL certificates to keep user data secure, verify ownership of the website, prevent attackers from creating a fake version of the site, and convey trust to users.</p><p><strong>So how it is different from our asymmetric encryption?</strong></p><p>For certificates instead of using ssh-keygen , openssl is used.</p><ul><li>Generate a key using openssl command. It contain both private and public key. I have run some additional command just for your knowledge.</li><li>openssl genrsa -out demodoamin.key 2048</li><li>Then this key is used to generate Certificate Signing Request (CSR) which will be send to an authority who will sign this certificate and mark this as valid.</li><li>openssl req -new -key demodoamin.key -out demodomain.csr</li></ul><pre># First we need a private key<br># genrsa is a algo<br># 2048 means length of key<br><br>&gt; openssl genrsa -out demodoamin.key 2048<br><br>root@2e8ce08eb302:/# openssl genrsa -out demodoamin.key 2048<br>Generating RSA private key, 2048 bit long modulus (2 primes)<br>..................................+++++<br>......+++++<br>e is 65537 (0x010001)<br>root@2e8ce08eb302:/# cat demodoamin.key <br>-----BEGIN RSA PRIVATE KEY-----<br>MIIEpAIBAAKCAQEAlp50GD6j4Ekq55U7Htmr6GGv/JuqBBrW63V04eOOLqVULdX7<br>XVcGLIzvy6D3N4udrY8WLkdj1LQPVljqwIqMlNKBXek3U3TWZ6m773tSHDt8KPZZ<br>6/AMZScxU+8/3uSte2lgbrj0bx0POqFDJJPOFun55WTJc0rVkozJCjeFnhHofdjE<br>uFYGt/6TRC2FvRC7bq1Yxh2SUU1P7nal2N6roFUwuUbwFJUA6UeN4+l5TN/+CwK1<br>MnGKFhamuGrttxfTxdzfeKgdap/A9fXQlU/xQ+4deKAzQD+Cl9Zyn1fLt1pVMbSo<br>AZw6B70zlqpPz8yOu5A4Suw1pcM/8St/SpCLBwIDAQABAoIBAGqYF1d1NWssvQWK<br>Mn4B1MywHelrjSY8jG+0/5RCBET00p9hufRz+zWaRLba4zrXPy8ufacg9QD6sYQN<br>h43eP+GvHMkGnRYeMQLKN+wjXZgHbTZcKoV0rIEF/L4HKy+mrTQS/qE9mhfs+/Ml<br>X6xKQmcrDaUP8BX9FysRIdJuOs0Dj5IfxCnDEZ57DT0hZ6sbFoqFTF1sr1CwbR3L<br>5o8s1WaM8qp3R2S0dVCUEP4mo64cmhCftvE+wqMZcmeZLZOeEngo8Ci32c52KLyH<br>OPNyVeY8jrLsZPQWcKar50L26D+u3TyDuGO1fMDC7R6UaG3GH21EmCXKeilm30T5<br>6QBdASkCgYEAxTvl+N5zHWXyv3NmJE6zDONr6VUp3J1iaJKVlisIB5f1l4YnA3rP<br>KJ2eSpp5bJoh4yOuR/qb5jFNSIk03vjvGYx4n/5uwejFGOBP3l+N6fgqipd2Lj0c<br>jvrtWtRobKr1FKRkvgF/XGY9Hpk3bO07A+gMB7zzrUkR6edEmEiCQusCgYEAw375<br>xuFyYhsx+Wb/4oS10bSR6QgnJyjcVr8p8b2pIoKNGwQe9Yaau2Ja8vGdCNMsczKm<br>bqiusJKg24Vg3xPYhH7+60/9IDFlg94IsWE3hpbMj1KEgzJJlu3I4xOhp9Bz/sS7<br>1PaXoMFBev+owEQF+DQ8BoFAHYb7osswOqS+OVUCgYEArZjp8mFA6ug3f8D/bweB<br>2t80tNvLi61O14HlfZYEbEKY3DQslIh8W2BX2YwbQbZsCzL1i88Nds+AGU8CpRpv<br>wIn+Bbx5Gd1Z1WphgfWSwBM4xmFHmK0bPNGpJh/8hWD3c6K6NO62fcpTE2KCATLQ<br>lcChDhKGW8gLp1dx7aMsW98CgYEAhk5ViyyXSI8mZhE8+oHx54AGPfI788s+lNoA<br>FvQVnn/SMR1Dp6ox40pO8VjMaaOqhfnmHWAFo4kYubeINbmMpnoY59CsNdG5zD5d<br>+n6vhudS4aPvJbMGm4oA2QBDruamygCeilBfGzGpqra5WF1jPIGmO1HQmniBp/Wv<br>zJohlYECgYBX3vI4u77JED7r+cgD8HZoBwU+1HiOZBNi0u7AQVp7lsNwY3KVyUlS<br>x3CXeAV9U6jhC3Nxv/viNzuldEptDz6MiH5VpO1B7X+IYtkyxj7ldSL9ioimVCaZ<br>29iomU0z85PS6I9UXplgNgXmBEviLcpdaxFG6khvEGvjtQ7pYOkM7w==<br>-----END RSA PRIVATE KEY-----<br>root@2e8ce08eb302:/#<br><br># To check the content of the key<br>root@2e8ce08eb302:/# openssl rsa -text -in demodoamin.key -noout<br><br>#The private key file contains both the private key and the public key. <br># You can extract your public key from your private key file if needed.<br><br>root@2e8ce08eb302:/# openssl rsa -in demodoamin.key -pubout -out demodomain_public.key<br>writing RSA key<br>root@2e8ce08eb302:/# cat demodomain_public.key <br>-----BEGIN PUBLIC KEY-----<br>MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlp50GD6j4Ekq55U7Htmr<br>6GGv/JuqBBrW63V04eOOLqVULdX7XVcGLIzvy6D3N4udrY8WLkdj1LQPVljqwIqM<br>lNKBXek3U3TWZ6m773tSHDt8KPZZ6/AMZScxU+8/3uSte2lgbrj0bx0POqFDJJPO<br>Fun55WTJc0rVkozJCjeFnhHofdjEuFYGt/6TRC2FvRC7bq1Yxh2SUU1P7nal2N6r<br>oFUwuUbwFJUA6UeN4+l5TN/+CwK1MnGKFhamuGrttxfTxdzfeKgdap/A9fXQlU/x<br>Q+4deKAzQD+Cl9Zyn1fLt1pVMbSoAZw6B70zlqpPz8yOu5A4Suw1pcM/8St/SpCL<br>BwIDAQAB<br>-----END PUBLIC KEY-----<br>root@2e8ce08eb302:/#<br><br></pre><pre>root@2e8ce08eb302:/# openssl req -new -key demodoamin.key -out demodomain.csr<br>You are about to be asked to enter information that will be incorporated<br>into your certificate request.<br>What you are about to enter is what is called a Distinguished Name or a DN.<br>There are quite a few fields but you can leave some blank<br>For some fields there will be a default value,<br>If you enter &#39;.&#39;, the field will be left blank.<br>-----<br>Country Name (2 letter code) [AU]:IN<br>State or Province Name (full name) [Some-State]:IN<br>Locality Name (eg, city) []:Noida<br>Organization Name (eg, company) [Internet Widgits Pty Ltd]:demodomain<br>Organizational Unit Name (eg, section) []:demodomain<br>Common Name (e.g. server FQDN or YOUR name) []:demodomain.com<br>Email Address []:ceo@demodomain.com<br><br>Please enter the following &#39;extra&#39; attributes<br>to be sent with your certificate request<br>A challenge password []:<br>An optional company name []:<br>root@2e8ce08eb302:/# <br>root@2e8ce08eb302:/# cat demodomain.csr <br>-----BEGIN CERTIFICATE REQUEST-----<br>MIIC1jCCAb4CAQAwgZAxCzAJBgNVBAYTAklOMQswCQYDVQQIDAJJTjEOMAwGA1UE<br>BwwFTm9pZGExEzARBgNVBAoMCmRlbW9kb21haW4xEzARBgNVBAsMCmRlbW9kb21h<br>aW4xFzAVBgNVBAMMDmRlbW9kb21haW4uY29tMSEwHwYJKoZIhvcNAQkBFhJjZW9A<br>ZGVtb2RvbWFpbi5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCW<br>nnQYPqPgSSrnlTse2avoYa/8m6oEGtbrdXTh444upVQt1ftdVwYsjO/LoPc3i52t<br>jxYuR2PUtA9WWOrAioyU0oFd6TdTdNZnqbvve1IcO3wo9lnr8AxlJzFT7z/e5K17<br>aWBuuPRvHQ86oUMkk84W6fnlZMlzStWSjMkKN4WeEeh92MS4Vga3/pNELYW9ELtu<br>rVjGHZJRTU/udqXY3qugVTC5RvAUlQDpR43j6XlM3/4LArUycYoWFqa4au23F9PF<br>3N94qB1qn8D19dCVT/FD7h14oDNAP4KX1nKfV8u3WlUxtKgBnDoHvTOWqk/PzI67<br>kDhK7DWlwz/xK39KkIsHAgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAQEAMl+QgndH<br>jV2FvpUe1f9pCFLK5VYEEz8oxZKkvGg/2YpZZInHpnuWHYHJWntNVW0gMV63fGTI<br>fMEQ3lG+AFwBa7xn98niculfaHoEivh9nJXY0qojSOLdTyaK7eb4WRA7yneJr+9r<br>YzlstJgUzsZQIHEO+RumEqixdfznDAJxZIIg7h5g9WTumjF+DLpdyBHHzS5QTFoz<br>4IPqXLY2c1Ht2AkhsmwVVZwntYdhovyVvT4W95Iguxvt9i804Of+uk6rsK1A3s4K<br>09nNimYk774VL2v0DMKVbdd3AKYvIE0ixnabjtNzrNXNB1TN8s2syVatEYVYvCF6<br>RL0THuwmST/lEA==<br>-----END CERTIFICATE REQUEST-----<br>root@2e8ce08eb302:/#</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*7NdoB-mb9vgujGOHm8v7Ug.png" /><figcaption>Credit — <a href="https://knowledge.digicert.com/general-information/openssl-quick-reference-guide">https://knowledge.digicert.com/general-information/openssl-quick-reference-guide</a></figcaption></figure><p>Now we have generated CSR, but who will sign it???</p><p>A <strong>certificate authority </strong>is a company or organization that acts to validate the identities of entities (such as websites, email addresses, companies, or individual persons) and bind them to cryptographic keys through the issuance of electronic documents known as digital certificates.</p><p>A digital certificate provides:</p><ul><li>Authentication, by serving as a credential to validate the identity of the entity that it is issued to.</li><li>Encryption, for secure communication over insecure networks such as the internet.</li><li>Integrity of documents signed with the certificate so that they cannot be altered by a third party in transit.</li></ul><p>A CA will validate and sign the CSR and then provide you the certificates means <strong>demodomain.crt</strong></p><p>Suppose your CSR has been signed by a CA and you got the certificate. But what if some one is impersonating as CA? CA signs the certificate using its private key to sign the certificates and your browser already have public key of most CA. It validates then the request becomes secure.</p><p>Note: → If certificate get expire then it also become unsecure. Here’s the example of one of the cert.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*yTtYd3FhnVkfznMIrwxAug.png" /></figure><ul><li>Here the CA is Cloudflare who signed this certificate and it is valid upto Jan 1, 2025.</li></ul><p>Thanks</p><p>Reference:</p><ul><li><a href="https://www.ssl.com/article/what-is-a-certificate-authority-ca/">https://www.ssl.com/article/what-is-a-certificate-authority-ca/</a></li><li><a href="https://knowledge.digicert.com/general-information/openssl-quick-reference-guide">https://knowledge.digicert.com/general-information/openssl-quick-reference-guide</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=153a85037a25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ansible Custom Facts]]></title>
            <link>https://sunnykkc13.medium.com/ansible-custom-facts-272bd79d9b85?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/272bd79d9b85</guid>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Thu, 30 May 2024 06:00:08 GMT</pubDate>
            <atom:updated>2024-05-30T06:00:08.755Z</atom:updated>
            <content:encoded><![CDATA[<h4>Ansible is an open source IT automation engine that automates provisioning, configuration management, application deployment, orchestration, and many other IT processes.</h4><p>In Layman term, <em>Ansible is a configuration management tool that can configure numbers of machine at a time regardless of their distribution families such as RedHat, Debian, Arch and so on</em>.</p><p>let’s say I have to install nginx on 100s of machine and machines are of different type such as Rocky Linux, Ubuntu, FreeBSD, Manjaro and so on. Now to install, all I have to run this:</p><pre>ansible nginx_target_hosts -m service -a &quot;name=nginx state=started&quot;</pre><p>or</p><pre>- hosts: nginx_target_hosts<br>  tasks:<br>    - name: install nginx<br>      service:<br>        name: nginx<br>        state: started</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cK91WU_zB9YkGbGb-scteA.png" /><figcaption>Image 1</figcaption></figure><p>Wait wait wait! Different distribution has different type of package manager but how a single task is able to install on all of them??? In the above image there is a task called <strong><em>“Gathering Facts”</em></strong> which is not introduced by us in our YAML file. <strong>So what are Facts ?</strong></p><blockquote>FACTS</blockquote><p>Facts are the different type of information about the target node which include hardware, network, O.S., Python, host name and so on. To check</p><pre>ansible localhost -m setup</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*tt3o4DUHRdqngDg23I0wjg.png" /><figcaption>Image 2</figcaption></figure><blockquote>CUSTOM FACTS</blockquote><p>While I was working on task where I had to configure around 600 machine and while doing that I ran into an issue, that is</p><ul><li>Every machine had a specific file containing numbers of variables that serves as inventory to ansible. Variables value can be different for different machines which stopped me to configure the machine remotely.</li><li>Organisation didn’t want to change it.</li><li><strong>That’s where I got a chance to create our own facts.</strong></li></ul><p>Let me give you a beautiful example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*XBEIQE11ZNM7-PzP6z-jLw.png" /><figcaption>Image 3</figcaption></figure><p>Image 3, these are the variables I wanted to add into facts. Here’s the file from which I got this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*PZba-jncMpqOhYk7Ti6YSA.png" /><figcaption>Image 4</figcaption></figure><blockquote>How to do it?</blockquote><p>There are two ways: <strong>First</strong></p><ol><li>Updated Ansible core python scripts → <a href="https://github.com/navsin189/ansible_custom_facts?tab=readme-ov-file#changes-for-custom-facts">https://github.com/navsin189/ansible_custom_facts?tab=readme-ov-file#changes-for-custom-facts</a></li><li>I have created <strong>lib/ansible/module_utils/facts/other/personal.py</strong></li><li>then updated <strong>lib/ansible/module_utils/facts/default_collectors.py</strong></li><li>But here’s the catch → “I don’t like this method”.</li></ol><p><strong>Second and the easiest one:</strong></p><p>In your target or managed nodes</p><pre>sudo mkdir -p /etc/ansible/facts.d<br>sudo touch /etc/ansible/facts.d/myfacts.fact<br><br>-- Via Ansible<br>ansible target_host_group -m file -a &quot;path=/etc/ansible/facts.d state=directory become=root&quot;<br>ansible target_host_group -m file -a &quot;path=/etc/ansible/facts.d/myfacts.fact state=touch become=root&quot;</pre><p>Here’s mine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*QnIFxtgWTb4pKWLr_4SXRg.png" /><figcaption>/etc/ansible/facts.d</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*PGoewzKGx4hsQs4OqYmmow.png" /><figcaption>here’s the custom facts</figcaption></figure><p>By default ansible search for custom facts under /etc/ansible/facts.d/*.fact but it can be changed under ansible.cfg by mentioning fact_path=your_path under [defaults]</p><p>So, create your own facts and enjoy.</p><blockquote>Thanks for reading!!!!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=272bd79d9b85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins Master Slave Setup]]></title>
            <link>https://sunnykkc13.medium.com/jenkins-master-slave-setup-d468fba5a3b5?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d468fba5a3b5</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 09:48:53 GMT</pubDate>
            <atom:updated>2023-10-19T09:48:53.896Z</atom:updated>
            <content:encoded><![CDATA[<p>Due to increasing demand of Continuous integration and Continuous delivery (CI/CD), most of us has heard the name of three most popular tools that are</p><ul><li>Jenkins</li><li>Git Lab</li><li>GitHub Actions</li></ul><p>In this article, I’m going to cover Jenkins with its setup and master slave configuration.</p><h3>Introduction</h3><p><a href="https://www.jenkins.io/doc/book/">Jenkins</a> is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. In layman term, Jenkins run jobs or tasks when mentioned condition meet. Example, as soon as there is a push on your GitHub repository it should clone it on the server, test and deploy the changes.</p><h3>Installation</h3><p>I’m using Ubuntu 22.04 as my operating system but Jenkins is available for different platform and the installation process is mentioned <a href="https://www.jenkins.io/doc/book/installing/">here</a>.</p><pre>sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \<br>  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key<br>echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \<br>  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \<br>  /etc/apt/sources.list.d/jenkins.list &gt; /dev/null<br>sudo apt-get update<br>sudo apt-get install jenkins</pre><p>After installation check the status of Jenkins using</p><pre>sudo systemctl status jenkins # it should be up and running, else<br>sudo systemctl start jenkins # to start Jenkins<br><br>jenkins --version # mine is 2.414.2</pre><p>By default it runs on port 8080. As soon as you land on this port with your machine’s IP, the Jenkins homepage would show up and ask you to follow some steps (changing password, installing plugins) with mentioned instruction.</p><p><strong>Note: While asking for plugin installation choose recommended one not the custom one if you are just starting with Jenkins.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymQqwsyQURzwVlJe4xYpjw.png" /><figcaption>Jenkins Homepage <strong>(image 1)</strong></figcaption></figure><p>After Jenkins has been configured, jobs can be run directly on the node where it is installed, but it is generally not a good idea to run jobs directly on the master node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RcHwKaZNV0Vd0XW5d7kEdw.png" /><figcaption>Jenkins Nodes <strong>(Image 2)</strong></figcaption></figure><h4>Master Slave Configuration</h4><p>Let’s add a worker node(machine/server) where our jobs will run and leave master as it is.</p><ul><li>The Jenkins on master can connect to worker node using i) SSH with username and password ii) SSH with keys.</li><li>We are going to use SSH with keys.</li></ul><p><strong>Steps</strong></p><ul><li>Launch a machine(VM/EC2).</li><li>Create SSH keys</li></ul><pre># My username is worker1<br>ssh-keygen -t ed25519 # with rsa type it was not working hence I had to use ed25519<br><br>cd .ssh &amp;&amp; touch authorized_keys<br>cat id_ed25519.pub &gt;&gt; authorized_keys<br><br># create a directory where jenmins can create its workspace<br># and store info about jobs<br><br>sudo mkdir /opt/jenkins<br>sudo chown worker1:worker1 -R /opt/jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*f9-pXRSJgxalV0cE6D5mFQ.png" /></figure><ul><li>Go to Jenkins UI</li><li>Dashboard → Manage Jenkins → Nodes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpI5LtXfLA4xZvtpiJglFA.png" /><figcaption><strong>Image 3</strong></figcaption></figure><ul><li>Open Nodes → New Node (Image 2)</li><li>Enter Name of node → click on Permanent Agent</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*CuR6EWu47cp3by5XjUQIrw.png" /><figcaption>Setup Node’s name <strong>(Image 4.1)</strong></figcaption></figure><ul><li>Click on <strong>Create</strong></li><li>There would be bunch of text field in which we would change some.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fi-z5Tveyg2T-mt3TBAAiw.png" /><figcaption>Setup Worker Node <strong>(Image 4.2)</strong></figcaption></figure><ul><li><strong>Name</strong> → Unique name to identify the agent.</li><li><strong>Description</strong> → mention what kind of jobs is going to run here</li><li><strong>Number of Executors</strong> → Number of jobs that can run in parallel(concurrent jobs)</li><li><strong>Remote Directory</strong> → Directory on worker node where Jenkins will create the workspace and run the jobs.</li><li><strong>Labels</strong> → This one is quite important as jobs identify the nodes via labels. We will see a example on this.</li><li><strong>Usage</strong> → There are two options here i) Use this node as much as possible ii) Only build jobs with label expression matching this node. The first one allow the jobs to be executed on this node in which wither no worker nodes are allowed or label matching to this node’s label whereas the second option allow only those jobs in which the label are mentioned as “first-worker”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*iF6MzwP5klhiidquE6jjbA.png" /><figcaption>Setup Worker Node <strong>(Image 4.3)</strong></figcaption></figure><ul><li><strong>Launch Method</strong> → Here “Launch agents via SSH” needs to be selected as we are going to use SSH with keys.</li><li><strong>Host</strong> → IP or DNS of the machine going to be the worker node.</li><li><strong>Credentials</strong> → Currently in your case, you don’t have any credentials for authentication, so to setup that <strong>click on ADD then select Jenkins. Please check the image 4.4 below this</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NfoHmyivMnSSX96x2FCZTQ.png" /><figcaption>Setup Worker Node <strong>(Image 4.4)</strong></figcaption></figure><ul><li><strong>Kind</strong> → It should be SSH username with Private key</li><li>Domain and Scope can be global as in image.</li><li><strong>ID</strong> → Unique identifier for cred.</li><li><strong>username</strong> → username used while SSH</li><li><strong>private key</strong> → Earlier we generated ssh keys and by default the name of the file is “<strong><em>id_ed25519 and id_ed25519.pub</em></strong>” . id_ed25519 is a private key, copy the value and paste it under private key section (Image 4.5). <strong>There should be no new line after the key.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WY1R8v87KuD4PKSYzAVKzA.png" /><figcaption>Setup Worker Node <strong>(Image 4.5)</strong></figcaption></figure><ul><li>Click on Add then select the Credential(Image 4.3) from drop down.</li><li>Match the other option from the image.</li></ul><p>Click on <strong>SAVE</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_PV0DpRX8UmeRiLeLcjtdw.png" /><figcaption>Worker Node successfully connected (Image 5)</figcaption></figure><ul><li>If it doesn’t get connected, click on the node’s name then check the logs from left panel.</li><li>Check the failure cause. The two main reason are i) authentication failed ii) Jenkins is not able to write into root working directory (/opt/jenkins)</li><li>For authentication one, you can try to make that node offline for a minute then enable it again. It should resolve then else check the permission of keys.</li><li>For directory, change the owner and group.</li></ul><h4>Run the Job on Worker Node</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*nooPcgWjiAsLt-JWS10dqg.png" /><figcaption>Create Job (Image 6)</figcaption></figure><ul><li>click on new item</li><li>Enter item name that is job name and select Freestyle project</li><li>After that while configuring click on “Restrict where this project can be run” and enter the worker node’s label.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*kHwfZRXVjQUde4wN1O22Lg.png" /><figcaption>Enter label’s name(Image 7)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*p2gCORuX1FIUk9QU3SQcKQ.png" /><figcaption>Shell execution(Image 8)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*sFuxX_TJ8zaLGbF0DQPvBw.png" /><figcaption>Job Output (Image 9)</figcaption></figure><ul><li>Here, the job is running on mentioned node.</li></ul><h4>Summary</h4><p>Jenkins is a CI/CD tool that offers master slave setup so that jobs can be distributed according to the resource needed and doesn’t take down the master itself.</p><blockquote>Try creating more nodes and run multiple jobs at a time.</blockquote><blockquote>Thanks for reading!!!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d468fba5a3b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alert and Alert Manager in Prometheus]]></title>
            <link>https://sunnykkc13.medium.com/alert-and-alert-manager-in-prometheus-6a64ad4b8d78?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a64ad4b8d78</guid>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 13:13:32 GMT</pubDate>
            <atom:updated>2023-10-13T13:20:04.559Z</atom:updated>
            <content:encoded><![CDATA[<p>Exporters in Prometheus and Dashboards in Grafana was covered in <a href="https://sunnykkc13.medium.com/prometheus-with-grafana-monitoring-a-application-0b4b2082f055">earlier post</a>. Now we know that Prometheus scrape the metrics exposed by exporters from targets mentioned in its config file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pN6HalIHfSfRukmv" /></figure><p>Let’s understand what monitoring means from DevOps and SRE perspective</p><ul><li>Monitoring means to visualize the health of project, environment, servers, and services.</li><li>If something bad happen, fix it to keep the server alive.</li><li>But no one monitor the dashboard 24x7 so how we going to know something bad happen and there’s a downtime.</li><li>For this alerts are created. Alerts are basically a expression with some conditions such as</li></ul><pre># monitoring<br>apache_up # this metric show the status of Apache web server on PromQL<br># 1 means up <br># 0 means down<br><br># alerts<br>if (apache_up != 1){<br>  printf(&quot;Apache is Down&quot;)<br>  # printf(&quot;Hey! guys I lost my job due to recession&quot;)<br>}<br># the syntax is not like this but I&#39;m giving an example of how it works</pre><h3>Alerts</h3><p>on <a href="http://localhost:9090/">http://localhost:9090</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OdS5g1I9Iz-MSphKLxS1Xg.png" /><figcaption>apache_up <strong>(image 1)</strong></figcaption></figure><p>The above image shows the value of apache_up metric where 1 means UP and 0 means down. Suppose, if apache goes down means by backend server goes down hence customer will face downtime. So let’s create alert for this but before that visit <a href="http://localhost:9090/alerts">http://localhost:9090/alerts</a></p><p>Steps:</p><ul><li>create a new directory named “<strong><em>alerts” </em></strong>under /etc/prometheus. Then a file named <strong><em>alerts.yml under alerts directory.</em></strong></li><li>change the owner and group to prometheus for both of them.</li></ul><pre># sudo vim /etc/prometheus/alerts/alerts.yml<br># insert the below lines<br><br>groups: # alerts need to be bundled under a group<br>  - name: My life My alerts My rules # name of the group<br>    rules: # under this you can create list of alerts<br>      - alert: Apache is Down # name of the alert<br>        expr: apache_up == 0 # if expression matches, there would be an alert<br>        for: 2m # time to wait before sending an alert<br>        labels: # labels is just like tags , you can provide your own<br>          severity: Critical<br>        annotations:<br>          summary: &quot;Apache Down on [{{ $labels.instance }}]&quot;<br>          description: &quot;Apache Down on [{{ $labels.instance }}] for job [{{ $labels.job }}]&quot;<br>        <br># close the editor</pre><p>Let’s understand the above YAML file</p><ul><li>groups → Take it as WhatsApp groups. There can be 100s of groups in which one group name is “My life My alerts My rules”.</li><li>Rules → Under “My life My alerts My rules” group there are multiple member and one of them is “Apache is Down” who only message when “apache_up == 0” but before sending the message he waits for 2 minute and check for the condition. After 2 minute he messages with a summary and a description along with some labels so his message can be identified easily. Here, the summary and description has some variables which values are dynamic(check the image 1) and get it from metrics.</li></ul><p>Now we have our alert, let’s tell the Prometheus to read this file</p><pre># sudo vim /etc/prometheus/prometheus.yml<br><br># you will see a variable named<br>rule_files:<br>  - &quot;alerts/alerts.yml&quot;<br>#sudo systemctl restart prometheus<br><br># it may ask to do sudo systemctl daemon-reload</pre><p>Again open <a href="http://localhost:9090/alerts">http://localhost:9090/alerts</a> but before that take a look at my alerts/alerts.yml file</p><pre>groups:<br>  - name: Apache Down Rule<br>    rules: <br>      - alert: Apache is Down <br>        expr: apache_up == 0 <br>        for: 2m <br>        labels: <br>          severity: Critical<br>        annotations:<br>          summary: &quot;Apache Down on [{{ $labels.instance }}]&quot;<br>          description: &quot;Apache Down on [{{ $labels.instance }}] for job [{{ $labels.job }}]&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*nAaIjIjOmTfuIn1IU2J_gA.png" /><figcaption><a href="http://localhost:9090/alerts">http://localhost:9090/alerts</a> <strong>(Image 2)</strong></figcaption></figure><p>From Image 2 or above image</p><ul><li><strong>Inactive</strong> → A green box that shows alerts that haven’t met the condition to get triggered.</li><li><strong>Pending</strong> → As soon as the alert’s expression matched it move to pending for 2 minutes.</li><li><strong>Firing</strong> → After 2 minutes the alerts transition to firing state.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VFylZ1K5exxQRBcYH2xOMQ.png" /><figcaption>For 2 minutes it’ll be here <strong>(Image 3)</strong></figcaption></figure><p>Check out the Labels column</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Io1RG5RWqZ6RsGYZIWtrAg.png" /><figcaption>Now in firing state <strong>(Image 4)</strong></figcaption></figure><p>I have created another one rule</p><pre>groups:<br>  - name: Apache Down Rule # I forgot rename it as Downtime Rule<br>    rules: <br>      - alert: Apache is Down <br>        expr: apache_up == 0 <br>        for: 2m <br>        labels: <br>          severity: Critical<br>        annotations:<br>          summary: &quot;Apache Down on [{{ $labels.instance }}]&quot;<br>          description: &quot;Apache Down on [{{ $labels.instance }}] for job [{{ $labels.job }}]&quot;<br><br>      - alert: Target Down <br>        expr: up == 0 <br>        for: 2m <br>        labels: <br>          severity: Critical<br>        annotations:<br>          summary: &quot;job [{{ $labels.job }}] is down on [{{ $labels.instance }}]&quot;<br>          description: &quot;job [{{ $labels.job }}] is down on [{{ $labels.instance }}]&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MaWz5sfrFM2uVyTPYwk8Wg.png" /></figure><p>My custom exporter is not running and I stopped node-exporter too. <strong>We are getting alerts but how to notify the teams?</strong></p><h3>AlertManager</h3><p><a href="https://prometheus.io/docs/alerting/latest/alertmanager/#alertmanager"><strong>Alert Manager</strong></a> provides the ability to send notification via slack, Gmail, pagerduty, OpsGenie and others so that the alerts can be handled in real time.</p><p>Alert Manager needs to be setup separately.</p><pre>wget https://github.com/prometheus/alertmanager/releases/download/v0.26.0/alertmanager-0.26.0.linux-amd64.tar.gz<br><br>tar xvzf alertmanager-0.26.0.linux-amd64.tar.gz<br><br>cd alertmanager-0.26.0.linux-amd64<br><br>sudo mkdir /etc/alertmanager<br><br>sudo mv alertmanager /usr/bin<br>sudp mv * /etc/alertmanager<br><br>cat &lt;&lt;EOF | sudo tee /etc/systemd/system/alertmanager.service<br>[Unit]<br>Description=Prometheus Alert Manager<br>Documentation=https://prometheus.io/docs/alerting/latest/alertmanager/#alertmanager<br>After=network-online.target<br><br>[Service]<br>User=root<br>Group=root<br>Restart=on-failure<br>ExecStart=/usr/bin/alertmanager \<br>  --config.file=/etc/alertmanager/alertmanager.yml<br><br>[Install]<br>WantedBy=multi-user.target<br>EOF<br><br>sudo systemctl daemon-reload<br>sudo systemctl enable alertmanager<br>sudo systemctl start alertmanager<br><br># http://localhost:9093</pre><p>Alert manager runs on <a href="http://localhost:9093/">http://localhost:9093</a> but we haven’t configured Prometheus for alert manager. Let’s do that</p><pre># open /etc/prometheus/prometheus.yml from any text editor<br># and change the following<br>alerting:<br>  alertmanagers:<br>    - static_configs:<br>        targets:<br>          - localhost:9093<br># this config is already there just uncomment the line with URI and update it.</pre><ul><li>restart prometheus then go to <a href="http://localhost:9090/status">http://localhost:9090/status</a> and below you will the heading of alert manager with specified URI.</li></ul><p>As soon as the alert went into firing mode, I got this on my alert manager</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1pRw-FUEiar1nbj-qXYexA.png" /><figcaption>Alert manager dashboard <strong>(Image 5)</strong></figcaption></figure><p>Well, alert manager got the alert but it doesn’t know where to send it. Now we have to configure alert manager with required configuration.</p><p>Here’s the current configuration of alert manager:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*qyBohsKnzPoQGE4kmt-JWA.png" /><figcaption>Default Alert manger Cfg <strong>(Image 6)</strong></figcaption></figure><p>Configure it for Slack:</p><ul><li>go to your workspace → Tools &amp; settings → Manage Apps → Search for Web hook</li><li>Get the Webhook then open alertmanager.yml</li></ul><pre>global:<br>  resolve_timeout: 1m<br>  slack_api_url: &#39;https://hooks.slack.com/services/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&#39;<br>  group_interval: 30s<br>  repeat_inetrval: 4h<br>route:<br>  receiver: &#39;slack-notifications&#39;<br><br>receivers:<br>- name: &#39;slack-notifications&#39;<br>  slack_configs:<br>  - channel: &#39;#alerts&#39;<br>    send_resolved: true</pre><ul><li>sudo systemctl daemon-reload</li><li>sudo systemctl restart alertmanager</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*c0o3ECNH_2UrvSUcAloDbw.png" /><figcaption>Notification for Slack</figcaption></figure><p>Similarly for Gmail, Pagerduty, you can follow this blog.</p><ul><li><a href="https://grafana.com/blog/2020/02/25/step-by-step-guide-to-setting-up-prometheus-alertmanager-with-slack-pagerduty-and-gmail/#:~:text=Go%20to%20Slack%20%2D%3E%20Administration%20%2D%3E%20Manage%20apps.&amp;text=In%20the%20Manage%20apps%20directory,it%20to%20your%20Slack%20workspace.&amp;text=Next%2C%20specify%20in%20which%20channel,%23monitoring%2Dinfrastructure%20channel.)">How to setup Alertmanager with PagerDuty, Gmail and Slack.</a></li></ul><p>Alert manager also provides metrics at <a href="http://localhost:9093/metrics">http://localhost:9093/metrics</a> , you can add it as a target to Prometheus.</p><h3>Custom Alerts</h3><p>Sometime we have a long expression and need to run it frequently such as node exporter doesn’t provide metrics about how much memory is used so, to get that</p><pre>(node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Cached_bytes - node_memory_Shmem_bytes) / 1024^3<br># this expression provides used memory in GB</pre><p>Prometheus allow us to create custom metrics and then directly use in PromQL. But how?</p><pre># mkdir /etc/prometheus/rules &amp;&amp; touch /etc/prometheus/rules/rules.yml<br># sudo chown prometheus:prometheus -R /etc/prometheus/rules<br># open this file with any text editor<br>groups:<br>  - name: Used Memory<br>    rules:<br>      - record: memory_used_in_GB<br>        expr: (node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Cached_bytes - node_memory_Shmem_bytes) / 1024^3<br><br># add this file to prometheus.yml under rule_files<br># sudo systemctl daemon-reload<br># sudo systemctl restart prometheus</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_NXx--SM5En7h5RblHgkA.png" /></figure><p>Similarly for used disk space</p><pre>groups:<br>  - name: Used Memory<br>    rules:<br>      - record: memory_used_in_GB<br>        expr: (node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Cached_bytes - node_memory_Shmem_bytes) / 1024^3<br>  - name: used disk space in percentage<br>    rules:<br>      - record: node_filesystem_used_space_percentage<br>        expr: 100 - (100 * node_filesystem_free_bytes / node_filesystem_size_bytes)    </pre><h3>Summary</h3><p>Alert comes when the given expression matches and goes to alert manager after mentioned time. Then alert manager sends the notification to configured receivers. Prometheus allows to create custom metrics too.</p><blockquote>Give it a try with different receivers too</blockquote><blockquote>Thanks for reading!!!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a64ad4b8d78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prometheus with Grafana: Monitoring a Application on VMs and Kubernetes.]]></title>
            <link>https://sunnykkc13.medium.com/prometheus-with-grafana-monitoring-a-application-0b4b2082f055?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b4b2082f055</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Wed, 11 Oct 2023 20:52:08 GMT</pubDate>
            <atom:updated>2026-08-01T10:51:21.916Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://blog.devops.dev/prometheus-with-grafana-556efd23a9d6">earlier post</a> we discussed what is Prometheus and Grafana with its setup. Let’s talk about monitoring some servers, processes or any application.</p><h3>Setup</h3><p>Installed MySQL and Apache webserver for a Django application. Need to monitor these services for serve traffic and DB load.</p><pre>sudo apt-get install mysql-server apache2 -y</pre><p>Google whether there is an exporter for target resources are present or not. If not, then custom exporter needs to be deployed.</p><p>Now the Prometheus server is up and running, it must be configured to scrape the metrics for mentioned services. Prometheus generally works on PULL mechanism where it scrapes from exporters endpoint on HTTP protocol.</p><p>Exporter Used:</p><ul><li><strong><em>Node exporter</em></strong> → It scrapes all the system metrics such as CPU, Memory, network, uptime and so on.</li><li><strong><em>MySQL exporter</em></strong> → It scrapes all the MySQL metrics such as max connection, threads, used connection and so on.</li><li><strong><em>Apache exporter</em></strong> → It scrapes metrics for Apache web server.</li></ul><p><strong>Why so many exporters?</strong></p><p>Exporter just expose keywords that can be used in PromQL, so don’t be afraid.</p><blockquote>From previous blog install node exporter and then install setup MySQL exporter and Apache exporter.</blockquote><pre># Create user for mysql exporter<br>CREATE USER &#39;exporter&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;XXXXXXXX&#39; WITH MAX_USER_CONNECTIONS 3;<br>GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO &#39;exporter&#39;@&#39;localhost&#39;;<br><br>wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.0/mysqld_exporter-0.15.0.linux-amd64.tar.gz<br><br>tar xvzf mysqld_exporter-0.15.0.linux-amd64.tar.gz<br><br>cd mysqld_exporter-0.15.0.linux-amd64<br><br>sudo mv mysqld_exporter /usr/bin/<br><br>sudo mkdir -p /etc/mysqld_exporter<br><br>cd /etc/mysqld_exporter<br><br>cat &gt; my.cnf<br>[client]<br>user = exporter<br>password = XXXXXXXX<br><br><br><br>cat &lt;&lt;EOF | sudo tee /etc/systemd/system/mysqld-exporter.service<br>[Unit]<br>Description=Prometheus Server<br>Documentation=https://prometheus.io/docs/introduction/overview/<br>After=network-online.target<br><br>[Service]<br>User=root<br>Group=root<br>Restart=on-failure<br>ExecStart=/usr/bin/mysql_exporter \<br>  --config.my-cnf=/etc/mysqld_exporter/my.cnf<br><br>[Install]<br>WantedBy=multi-user.target<br>EOF<br><br>sudo systemctl daemon-reload<br>sudo systemctl enable mysqld-exporter.service<br>sudo systemctl start mysqld-exporter.service<br><br># it starts at port 9104<br># curl http://localhost:9104/metrics<br><br>wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.2/apache_exporter-1.0.2.linux-amd64.tar.gz<br>tar xvzf apache_exporter-1.0.2.linux-amd64.tar.gz<br>cd apache_exporter-1.0.2.linux-amd64<br><br>sudo useradd apache -g apache<br>sudo groupadd --system apache<br>chown apache:apache apache_exporter<br>sudo mv apache_exporter /usr/bin<br><br>cat &lt;&lt;EOF | sudo tee /etc/systemd/system/apache-exporter.service<br>[Unit]<br>Description=Apache Server Exporter<br>Documentation=https://github.com/Lusitaniae/apache_exporter<br>After=network-online.target<br><br>[Service]<br>User=apache<br>Group=apache<br>Restart=on-failure<br>ExecStart=/usr/bin/apache_exporter<br><br>[Install]<br>WantedBy=multi-user.target<br>EOF<br>sudo systemctl daemon-reload<br>sudo systemctl enable apache-exporter.service<br>sudo systemctl start apache-exporter.service<br><br># it starts at port 9117<br># curl http://localhost:9117/metrics</pre><h3>Updating Prometheus config file</h3><ul><li>I’m assuming that a single instance is running Prometheus server, MySQL, and Apache. All exporters are installed here too hence it can be accessed via localhost or 127.0.0.1</li><li>But if they are installed on different instance from Prometheus server than instead of localhost, either their IP or DNS should be mentioned.</li></ul><pre>- job_name: Prometheus<br>  static_configs:<br>    - targets: [&quot;localhost:9090&quot;,&quot;localhost:9100&quot;] # node exposes metrics on 9100<br>- job_name: MySQL<br>  static_configs:<br>    - targets: [&quot;localhost:9104&quot;] # mysql exposes metrics on 9100<br>- job_name: Apache server<br>  static_configs:<br>    - targets: [&quot;localhost:9117&quot;] # apache exposes metrics on 9117</pre><ul><li>If your applications are running on Kubernetes and Prometheus is setup via kube-prometheus-stack then update your values.yaml</li></ul><pre>prometheus:<br>  enabled: true<br>  prometheusSpec:<br>    additionalScrapeConfigs:<br>    - job_name: kubernetes_service<br>      kubernetes_sd_configs:<br>      - role: endpoints<br>      relabel_configs:<br>      - source_labels: [__meta_kubernetes_service_annotation_promtheus_io_scrape]<br>        regex: true<br>        action: keep<br>      - source_labels: [__meta_kubernetes_service_annotation_promtheus_io_path]<br>        regex: (.+)<br>        action: replace<br>        target_label: metric_path<br>      - source_labels: [__meta_kubernetes_service_annotation_promtheus_io_port]<br>        regex: (.+)<br>        action: replace<br>        target_label: metric_port<br>      - source_labels: [__meta_kubernetes_service_annotation_promtheus_io_scheme]<br>        regex: (https?)<br>        action: replace<br>        target_label: metric_path<br>    - job_name: kubernetes_pod<br>      kubernetes_sd_configs:<br>      - role: pod<br>      relabel_configs:<br>      - source_labels: [__meta_kubernetes_pod_annotation_promtheus_io_scrape]<br>        regex: true<br>        action: keep<br>      - source_labels: [__meta_kubernetes_pod_annotation_promtheus_io_path]<br>        regex: (.+)<br>        action: replace<br>        target_label: metric_path<br>      - source_labels: [__meta_kubernetes_pod_annotation_promtheus_io_port]<br>        regex: (.+)<br>        action: replace<br>        target_label: metric_port<br>      - source_labels: [__meta_kubernetes_pod_annotation_promtheus_io_scheme]<br>        regex: (https?)<br>        action: replace<br>        target_label: metric_path</pre><ul><li>then in your application deployment manifest add</li></ul><pre># update pod annotation<br># spec.template.spec.metadata.annotation<br>annotations:<br>  prometheus.io/scrape: true<br>  prometheus.io/port: &quot;8080&quot; # based on your application<br>  promtheus.io/path: &quot;/metrics&quot; # based on your application<br><br># For service add metadata.annotations<br></pre><p>This can be added on service kind if your application has any.</p><blockquote>Prometheus Operator has two modern Kind i) PodMonitor ii) ServiceMonitor. These kind work based on label match. Giving example of PodMonitor:</blockquote><pre>prometheus:<br>  enabled: true<br>  additionalPodMonitors:<br>  - name: go-app # in target health this is shown<br>    podTargetLabels: # here you mention which labels you want to use as a selector. I used only one.<br>    - monitoredBy<br>    selector:<br>      matchExpressions:<br>      - key: &quot;monitoredBy&quot;<br>        operator: Exists<br>    podMetricsEndpoints: # expose the port in container config with metrics name. You are free to use anything.<br>    - port: metrics<br>      path: /metrics<br>      interval: 15s<br><br># Similarly ServiceMonitor are used for services. I prefer annotations.</pre><h3>Setup Grafana</h3><p>Grafana provides the ability to visualize the metrics scrapped by Prometheus via graph, charts and so many other options. It also provides alerting features based on metrics.</p><ul><li>On K8S</li></ul><pre>helm repo add grafana-community https://grafana-community.github.io/helm-charts<br>helm repo update<br># helm install grafana grafana-community/grafana<br><br># If you want to use different database<br>cat &lt;&lt; EOF &gt; grafana-values.yaml<br>envRenderSecret:<br>  GF_DATABASE_TYPE: postgres<br>  GF_DATABASE_HOST: mydb.xxxxxx.us-east-1.rds.amazonaws.com:5432<br>  GF_DATABASE_NAME: grafana<br>  GF_DATABASE_USER: grafana<br>  GF_DATABASE_PASSWORD: strongest_password<br>  GF_DATABASE_SSL_MODE: require<br>EOF<br><br>helm install grafana grafana-community/grafana -f grafana-values.yaml<br><br># By default Grafana uses MySQLite3 for the same</pre><ul><li>On VM/ EC2</li></ul><pre><br>mysql&gt; CREATE USER &#39;grafana&#39;@&#39;localhost&#39; identified by &#39;grafana@password&#39;;<br>mysql&gt; create database grafana;<br>mysql&gt; grant all privileges on grafana.* to &#39;grafana&#39;@&#39;localhost&#39;;<br>mysql&gt; flush privileges;<br><br># https://grafana.com/docs/grafana/latest/setup-grafana/installation/<br># go to above link for another OS<br>sudo apt-get install -y apt-transport-https software-properties-common wget<br>sudo mkdir -p /etc/apt/keyrings/<br>wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg &gt; /dev/null<br>echo &quot;deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main&quot; | sudo tee -a /etc/apt/sources.list.d/grafana.list<br>echo &quot;deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com beta main&quot; | sudo tee -a /etc/apt/sources.list.d/grafana.list<br># Updates the list of available packages<br>sudo apt-get update<br># Installs the latest OSS release:<br>sudo apt-get install grafana -y<br><br>sudo vim /etc/grafana/grafana.ini<br># search for database setting and replace the current with below one<br>[database]<br>type = mysql<br>host = 127.0.0.1:3306<br>name = grafana # database name<br>user = grafana<br>password = grafana@password<br><br><br>sudo systemctl daemon-reload<br>sudo systemctl enable grafana-server<br>sudo systemctl start grafana-server</pre><h4>Grafana Dashboards (Screenshot attached in <a href="https://blog.devops.dev/prometheus-with-grafana-556efd23a9d6">earlier post</a>)</h4><ul><li>login to <a href="http://localhost:3000/">http://localhost:3000/</a></li><li>user → admin password → admin</li><li>create a new password</li><li>from left panel select Data Sources → New connection</li><li>Select Prometheus as data source and just enter the <strong><em>host = http://localhost:9090</em></strong> <em>(If Prometheus is on same server as Grafana else DNS or IP ) </em>then click on SAVE &amp; TEST button.</li><li>Again click on hamburger Icon and open left panel then click on Dashboard.</li></ul><h4>Import Grafana Dashboards</h4><p>The best thing about Grafana is it has already list of dashboards on its official site made by amazing guys for different type of data sources and exporters. Grafana has a option to import already built dashboards present at <a href="https://grafana.com/grafana/dashboards/">Grafana official site</a>.</p><p>Search for dashboard related to your need and just copy the ID of the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*JPilLHftPuOj01F-PFJeeA.png" /><figcaption><a href="https://grafana.com/grafana/dashboards/1860-node-exporter-full/">https://grafana.com/grafana/dashboards/1860-node-exporter-full/</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*VlWATSEhUSzz0aHppKQ-Yg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*PZ0V8NpUSwQbAwHenLaYQg.png" /></figure><ul><li>click on load</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*TC5hbsBGhUK48pwHTIT1ZQ.png" /></figure><ul><li>Click on Import and then a beautiful dashboard would get created</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9RVVeJyxt20DzSj2Gmx34g.png" /></figure><ul><li>datasource sets to default (prometheus)</li><li>Job shows prometheus. This is mentioned in prometheus.yml</li><li>host show targets mentioned in prometheus.yml</li><li>As you can see there are lots of panel in each dropdown.</li><li>I can say this is the best way to learn the query language too. Open any panel and try to see the query that is used to get the data. This way you will explore a lots of function, keywords and so on.</li></ul><p>Similarly if you import dashboard with ID <strong>7362 </strong>for MySQL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JrfXMFLgBpwQ2MLjW1VBGA.png" /></figure><ul><li>Try to import the existing one and change the queries according to your need.</li><li>Similarly I imported Apache Dashboard with ID <strong>3894</strong></li></ul><p>You know the best thing about these panels in dashboard you can copy it and paste it in another dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*-xzO8WCz-fvCXxIZa_xGlQ.png" /><figcaption>Click on panel’s menu</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*fz1OAT4JDmWN-H5D9nKTew.png" /><figcaption>Click to copy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*lHJTnykKtjfvRtF8c5289g.png" /><figcaption>Paste the copied panel</figcaption></figure><p>You can paste the panel in other dashboard.</p><p>I’m going to show you my application’s dashboard containing a sum of panels from all above dashboards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VtRLmrqAyOQ3jI_knVABhA.png" /></figure><p>If you click on panel’s menu then inspect, you will find the query used in that panel, panel’s json and other option too.</p><p>In queries binary and conditional operators can be implemented where PromQL already has a lots of predefined functions just like MS-Excel.</p><h3>Custom Exporter</h3><p>To monitor custom application whose exporters are not available yet, Prometheus SDKs are used and available for mostly all programming languages. Python’s example</p><pre>from prometheus_client import start_http_server, Gauge, REGISTRY, GC_COLLECTOR, PLATFORM_COLLECTOR, PROCESS_COLLECTOR<br>import time<br>import psutil<br><br>firefox_memory_percentage = Gauge(&quot;firefox_memory_percentage&quot;, &quot;Firefox Memory percentage&quot;)<br><br>def unregister():<br>    REGISTRY.unregister(GC_COLLECTOR)<br>    REGISTRY.unregister(PLATFORM_COLLECTOR)<br>    REGISTRY.unregister(PROCESS_COLLECTOR)<br><br>def process_request(t):<br>    for process in psutil.process_iter():<br>        if &#39;firefox&#39; in process.name():<br>            print(process.memory_percent())<br>            firefox_memory_percentage.set(process.memory_percent())<br>    time.sleep(t)<br><br><br>if __name__ == &#39;__main__&#39;:<br>    start_http_server(8888) # it exports the metrics on localhost:8888/<br>    unregister()<br>    while True:<br>        process_request(15)</pre><p>It exposes the metrics on <a href="http://localhost:8888/">http://localhost:8888/</a> (not on /metrics)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*mj7Ch_gSM8rFsg4MmfwAog.png" /><figcaption>Firefox used memory in percentage</figcaption></figure><p>There are four type of metric:</p><ul><li>Gauge: If metric values can be increased or decreased. Memory or CPU utilization as example.</li><li>Counter: If metric value always increase. HTTP traffic based on status code can be taken as example.</li><li>Summary: A <strong>Summary</strong> doesn’t store observations in buckets. Instead, it continuously calculates statistics such as the average and configured percentiles (for example, p50, p95, and p99) as the data arrives. Using the same store example, instead of remembering how many customers spent in each range, it simply tells you, “The average purchase was ₹120 and the 95th percentile was ₹450.” This makes summaries easy to use and doesn’t require predefined buckets, but the calculated percentiles cannot be combined across multiple application instances, making them less suitable for distributed systems like Kubernetes.</li><li>Histogram: A <strong>Histogram</strong> groups observations into predefined <strong>buckets</strong> (ranges) and counts how many values fall into each bucket. Imagine tracking how much customers spend in a store. Before opening, you create buckets like <strong>₹0–₹50</strong>, <strong>₹51–₹100</strong>, <strong>₹101–₹500</strong>, and <strong>₹500+</strong>. Every purchase is placed into the appropriate bucket, so at the end of the day you know how many customers spent within each range. Because the bucket counts are stored, Prometheus can later calculate averages, percentiles (p95, p99), and SLOs, and it can combine data from multiple application instances. The trade-off is that you must choose bucket boundaries in advance</li></ul><p>Update prometheus.yml</p><pre>- job_name: Custom Exporter<br>  metrics_path: &quot;/&quot;<br>  static_configs:<br>    - targets: [&quot;localhost:8888&quot;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*kU7oMZHDIASKeLny_LXQoQ.png" /><figcaption>Grafana panel</figcaption></figure><h4>Summary</h4><ul><li>Check for exporters publically according to the stacks.</li><li>Configure endpoints in Prometheus config file. In K8S, update values.yaml for the same.</li><li>Custom exporters and type of metrics.</li></ul><h4>Next Part</h4><ul><li><a href="https://sunnykkc13.medium.com/alert-and-alert-manager-in-prometheus-6a64ad4b8d78">Alerts in Prometheus</a></li></ul><blockquote>Thanks for reading!!!</blockquote><p>CHANGELOG:</p><ul><li>[August 01, 2026] — Added application monitoring deployed on K8S and changes in values.yaml for the same.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b4b2082f055" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why K8S removed support of Docker?]]></title>
            <link>https://sunnykkc13.medium.com/why-k8s-removed-support-of-docker-51db94cd994a?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/51db94cd994a</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Tue, 30 May 2023 07:22:23 GMT</pubDate>
            <atom:updated>2023-05-30T07:22:23.424Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3orif2yRVSOcd1VuN2%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3orif2yRVSOcd1VuN2%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExYjUwOTVpOWsxbmluaGtscGVkazBvbWxpdDUyc2J3N2QzeDZiZjFmZSZlcD12MV9naWZzX2dpZklkJmN0PWc%2F3orif2yRVSOcd1VuN2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="333" frameborder="0" scrolling="no"><a href="https://medium.com/media/e68a9bb6d5036b57532e87d78d85cc67/href">https://medium.com/media/e68a9bb6d5036b57532e87d78d85cc67/href</a></iframe><p><strong>Acronyms Used:</strong></p><ul><li>CT → Containerization Tool</li><li>OCI → Open Container Initiative</li><li>CRI → Container Runtime Interface</li><li>K8S → Kubernetes</li></ul><p>Back in 2014, when Kubernetes was introduced it only provided support for the legendary CT named “Docker”. In the same year a tool called <strong>libcontainer </strong>was launched and its objectives were to create processes into isolated environments and manage their lifecycle.</p><p>Moving forward more CT came up such as rkt, CRI-O, etc that made Kubernetes team to develop a “<strong>container runtime interface”</strong>(CRI) based on OCI that can support multiple CT. However, because Docker was introduced before K8S, it does not support this OCI. As a result, the K8S team produced <strong>dockershim</strong> — a solution to support Docker.</p><p><strong>What is a OCI?</strong></p><ul><li>When multiple CT were introduced community felt a need of a set of rules and standard that can be followed by all CT. Then OCI was introduced that has two specification (I) Runtime Specification (II) Image Specification.</li><li>Runtime Specification → this specification outlines how to run a “<a href="https://github.com/opencontainers/runtime-spec/blob/master/bundle.md">filesystem bundle</a>” that is unpacked on disk.</li><li>Image Specification → this specification is to enable the creation of interoperable tools for building, transporting, and preparing a container image to run.</li><li>At a high-level an OCI implementation would download an OCI Image then unpack that image into an OCI Runtime filesystem bundle. At this point the OCI Runtime Bundle would be run by an OCI Runtime.</li><li>The <em>libcontainer</em> project was donated to <em>OCI</em> and the first standardized runtime following the <em>runtime-spec</em> was created — <strong>runc</strong></li></ul><h4><strong>RUNC</strong></h4><ul><li><strong>runc</strong> is a low level container runtime supported by all CT and K8S CRI. Let’s take a look on the below image</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RRYWlN9ShzFS8uUm.png" /><figcaption>Credit → <a href="https://mkdev.me/posts/the-tool-that-really-runs-your-containers-deep-dive-into-runc-and-oci-specifications">KIRILL</a></figcaption></figure><ul><li>runc doesn’t support image spec that is runc run busybox:latest can not be executed instead it needs the filesystem bundle(<em>Filesystem bundle is what you get when you download the container image and unpack it</em>) and a config.json that describe how to unbundle the filesystem to create a container. <strong>Containerd and docker works on top of runc and resolve this image spec issue.</strong></li><li>runc also provides command to start, pause, stop and delete the container.</li></ul><p>— — —</p><p>The image shows that Docker uses Containerd as a daemon behind the hood and that supports the K8S OCI specifications. As a result, the K8S community disabled Docker shim and Docker support by default.</p><p><strong>Before Kubernetes v2.4</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nEFCmxEzunGW3A5HEjTQ2Q.jpeg" /></figure><p>Even if you install docker and Kubernetes &gt; V2.4, K8S will use Containerd as CRI.</p><h4>ContainerD</h4><ul><li>Containerd also comes with a CLI tool called ‘<strong>ctr’ </strong>which is mainly used for debugging purpose. It doesn’t have commands what Docker have and to resolve this another CLI tool called <strong>‘nerdctl’ </strong>was introduced which is capable of doing what docker can do.</li></ul><h4>K8S CRI</h4><ul><li>It also comes with a CLI tool called ‘<strong>crictl</strong>’ and has similar commands to docker. It needs to be installed separately.</li></ul><blockquote>Thanks for reading!!!</blockquote><h4>References</h4><ul><li><a href="https://mkdev.me/posts/the-tool-that-really-runs-your-containers-deep-dive-into-runc-and-oci-specifications">https://mkdev.me/posts/the-tool-that-really-runs-your-containers-deep-dive-into-runc-and-oci-specifications</a></li><li><a href="https://blog.quarkslab.com/digging-into-runtimes-runc.html">https://blog.quarkslab.com/digging-into-runtimes-runc.html</a></li><li><a href="https://github.com/opencontainers/image-spec">https://github.com/opencontainers/image-spec</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51db94cd994a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka Setup]]></title>
            <link>https://towardsdev.com/kafka-setup-91b33fb50c86?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/91b33fb50c86</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kafka-consumer]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[kafka-producer]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Tue, 04 Apr 2023 06:58:40 GMT</pubDate>
            <atom:updated>2023-04-06T13:35:13.380Z</atom:updated>
            <content:encoded><![CDATA[<p>Earlier we discussed about Kafka in this <a href="https://sunnykkc13.medium.com/introduction-to-kafka-2f274f922c17">blog</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0doZbF-SbaR6icsy.png" /></figure><p>Let’s start a practical implementation for better understanding.</p><p>Prerequisite</p><ul><li><a href="https://www.oracle.com/in/java/technologies/downloads/">Java</a> &gt; 8</li><li><a href="https://www.apache.org/dyn/closer.cgi?path=/kafka/3.4.0/kafka_2.13-3.4.0.tgz">Kafka Binary</a></li></ul><h4>Steps:</h4><ul><li>I’m using Rocky Linux hence I downloaded a java.rpm, you can download the suitable one. Also my hostname is <strong>controller</strong>.</li><li>Also I’m running all commands on a single machine.</li></ul><pre>wget https://download.oracle.com/java/20/latest/jdk-20_linux-x64_bin.rpm<br><br>rpm -ivh jdk-20_linux-x64_bin.rpm<br><br># to confirm<br>java --version<br>which java</pre><ul><li>Download Kafka</li></ul><pre>wget https://dlcdn.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz<br><br>tar xvf kafka_2.13-3.4.0.tgz<br><br>cd kafka_2.13-3.4.0</pre><ul><li><a href="https://www.openlogic.com/blog/using-kafka-zookeeper#:~:text=At%20a%20detailed%20level%2C%20ZooKeeper,a%20given%20topic%2Fpartition%20pair."><strong>Zookeeper</strong></a><strong> </strong>→ Zookeeper in Kafka used to track the cluster details such as number of broker, broker health, leader and followers of brokers. It also tracks when topics are created or deleted from the cluster and maintains a topic list. In general, <a href="https://dattell.com/data-architecture-blog/what-is-zookeeper-how-does-it-support-kafka/">ZooKeeper</a> provides an in-sync view of the Kafka cluster.</li><li>using Zookeeper we will start the server. But let’s read the initial config of zookeeper</li></ul><pre>cd kafka_2.13-3.4.0<br><br>cat config/zookeeper.properties<br><br>########## zookeeper config starts ##########<br><br># the directory where the snapshot is stored.<br>dataDir=/tmp/zookeeper<br># the port at which the clients will connect<br>clientPort=2181<br># disable the per-ip limit on the number of connections since this is a non-production config<br>maxClientCnxns=0<br># Disable the adminserver by default to avoid port conflicts.<br># Set the port to something non-conflicting if choosing to enable this<br>admin.enableServer=false<br># admin.serverPort=8080<br><br>########## zookeeper config ends ##########<br><br>bin/zookeeper-server-start.sh config/zookeeper.properties<br><br>########## above command output ##########<br>INFO clientPortAddress is 0.0.0.0:2181 (org.apache.zookeeper.server.quorum.QuorumPeerConfig)<br>INFO Starting server (org.apache.zookeeper.server.ZooKeeperServerMain)<br>INFO Server environment:host.name=controller<br>INFO binding to port 0.0.0.0/0.0.0.0:2181<br>########## above command output ##########</pre><ul><li>In config, client means the broker which will connect on port 2181</li><li>Now run the Kafka server but let’s go through the config of server first.</li></ul><pre>cd kafka_2.13-3.4.0<br><br>cat config/server.properties<br><br>########## server config starts ##########<br><br>############################# Server Basics #############################<br><br># The id of the broker. This must be set to a unique integer for each broker.<br>broker.id=0<br><br>############################# Socket Server Settings #############################<br>#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL<br><br># The number of threads that the server uses for receiving requests from the network and sending responses to the network<br>num.network.threads=3<br><br># The number of threads that the server uses for processing requests, which may include disk I/O<br>num.io.threads=8<br><br># The send buffer (SO_SNDBUF) used by the socket server<br>socket.send.buffer.bytes=102400<br><br># The receive buffer (SO_RCVBUF) used by the socket server<br>socket.receive.buffer.bytes=102400<br><br># The maximum size of a request that the socket server will accept (protection against OOM)<br>socket.request.max.bytes=104857600<br><br><br>############################# Log Basics #############################<br><br># A comma separated list of directories under which to store log files<br>log.dirs=/tmp/kafka-logs<br><br># The default number of log partitions per topic. More partitions allow greater<br># parallelism for consumption, but this will also result in more files across<br># the brokers.<br>num.partitions=1<br><br># The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.<br># This value is recommended to be increased for installations with data dirs located in RAID array.<br>num.recovery.threads.per.data.dir=1<br><br>############################# Internal Topic Settings  #############################<br># The replication factor for the group metadata internal topics &quot;__consumer_offsets&quot; and &quot;__transaction_state&quot;<br># For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.<br>offsets.topic.replication.factor=1<br>transaction.state.log.replication.factor=1<br>transaction.state.log.min.isr=1<br><br>############################# Log Retention Policy #############################<br><br># The following configurations control the disposal of log segments. The policy can<br># be set to delete segments after a period of time, or after a given size has accumulated.<br># A segment will be deleted whenever *either* of these criteria are met. Deletion always happens<br># from the end of the log.<br><br># The minimum age of a log file to be eligible for deletion due to age<br>log.retention.hours=168<br><br># A size-based retention policy for logs. Segments are pruned from the log unless the remaining<br># segments drop below log.retention.bytes. Functions independently of log.retention.hours.<br>#log.retention.bytes=1073741824<br><br># The maximum size of a log segment file. When this size is reached a new log segment will be created.<br>#log.segment.bytes=1073741824<br><br># The interval at which log segments are checked to see if they can be deleted according<br># to the retention policies<br>log.retention.check.interval.ms=300000<br><br>############################# Zookeeper #############################<br><br># Zookeeper connection string (see zookeeper docs for details).<br># This is a comma separated host:port pairs, each corresponding to a zk<br># server. e.g. &quot;127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002&quot;.<br># You can also append an optional chroot string to the urls to specify the<br># root directory for all kafka znodes.<br>zookeeper.connect=localhost:2181<br><br># Timeout in ms for connecting to zookeeper<br>zookeeper.connection.timeout.ms=18000<br><br><br>############################# Group Coordinator Settings #############################<br><br># The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.<br># The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.<br># The default value for this is 3 seconds.<br># We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.<br># However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.<br>group.initial.rebalance.delay.ms=0<br><br>########## server config ends ##########</pre><ul><li>Let’s understand this config:</li><li>Every broker should have a unique ID.</li><li>If hostname is not defined then output of java.net.InetAddress.getCanonicalHostName()</li><li>logs will be kept for 168 hours.</li><li>number of partition is 1</li></ul><pre>cd kafka_2.13-3.4.0<br><br># on another terminal<br>bin/kafka-server-start.sh config/server.properties<br>########## above command output ##########<br>INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)<br>INFO [ZooKeeperClient Kafka server] Initializing a new session to localhost:2181. (kafka.zookeeper.ZooKeeperClient)<br>INFO Client environment:zookeeper.version=3.6.3--6401e4ad2087061bc6b9f80dec2d69f2e3c8660a, built on 04/08/2021 16:35 GMT (org.apache.zookeeper.ZooKeeper)<br>INFO Client environment:host.name=controller (org.apache.zookeeper.ZooKeeper)<br>INFO Client environment:java.version=20 (org.apache.zookeeper.ZooKeeper)<br>INFO Opening socket connection to server localhost/[0:0:0:0:0:0:0:1]:2181. (org.apache.zookeeper.ClientCnxn)<br>INFO [ZooKeeperClient Kafka server] Waiting until connected. (kafka.zookeeper.ZooKeeperClient)<br>INFO Socket connection established, initiating session, client: /[0:0:0:0:0:0:0:1]:51170, server: localhost/[0:0:0:0:0:0:0:1]:2181 (org.apache.zookeeper.ClientCnxn)<br>INFO Session establishment complete on server localhost/[0:0:0:0:0:0:0:1]:2181, session id = 0x100000c442e0000, negotiated timeout = 18000 (org.apache.zookeeper.ClientCnxn)<br>INFO [ZooKeeperClient Kafka server] Connected. (kafka.zookeeper.ZooKeeperClient)<br>INFO Cluster ID = B1kRQTeKTT60m7Ly8I75Ew (kafka.server.KafkaServer)<br>INFO Registered broker 0 at path /brokers/ids/0 with addresses: PLAINTEXT://controller:9092, czxid (broker epoch): 25 (kafka.zk.KafkaZkClient)<br>INFO Awaiting socket connections on 0.0.0.0:9092<br>INFO [KafkaServer id=0] started (kafka.server.KafkaServer)<br>INFO [BrokerToControllerChannelManager broker=0 name=forwarding]: Recorded new controller, from now on will use node controller:9092 (id: 0 rack: null) (kafka.server.BrokerToControllerRequestThread)<br>INFO [BrokerToControllerChannelManager broker=0 name=alterPartition]: Recorded new controller, from now on will use node controller:9092 (id: 0 rack: null) (kafka.server.BrokerToControllerRequestThread)<br>########## above command output ##########</pre><ul><li>Check the last two line, it says recorded new controller where in the zookeeper side a log is introduced</li></ul><pre>INFO Creating new log file: log.32 (org.apache.zookeeper.server.persistence.FileTxnLog)</pre><ul><li><strong>Zookeeper and server are running in a single machine on port 2181 and 9092 respectively.</strong></li></ul><h4>Let’s start creating Topics</h4><ul><li>Open another terminal then create a topic</li></ul><pre># create a topic first<br>bin/kafka-topics.sh --create --topic myfirsttopic --bootstrap-server localhost:9092<br># on port 9092 broker is running<br><br># details of above created topic<br>bin/kafka-topics.sh --describe --topic myfirsttopic --bootstrap-server localhost:9092</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MjwNV9CedBjwPcHkBVg-GA.png" /><figcaption>output of created topic</figcaption></figure><ul><li>Write a event in above created topic</li></ul><pre># command line producer<br>bin/kafka-console-producer.sh --topic myfirsttopic --bootstrap-server localhost:9092</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WozlVoQsOFQ8XD5f5kr8IA.png" /><figcaption>write event</figcaption></figure><ul><li>Press CTRL + C to return to shell.</li><li>read the events</li></ul><pre># command line consumer<br>bin/kafka-console-consumer.sh --topic myfirsttopic --from-beginning --bootstrap-server localhost:9092</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4qmOuwo23QWDhLD83yDtHw.png" /><figcaption>read event</figcaption></figure><p>We learnt how to create topic, read and write the events. Now learn how to do it from python.</p><ul><li>Installed <a href="https://github.com/confluentinc/confluent-kafka-python">confluent-kafka</a></li><li>Created two python file called producer.py and consumer.py</li></ul><pre>pip install confluent-kafka</pre><ul><li>producer.py</li></ul><pre>from confluent_kafka import Producer<br><br>producer_obj = Producer({&#39;bootstrap.servers&#39;: &#39;localhost:9092&#39;})<br><br>def delivery_report(err, msg):<br>    &quot;&quot;&quot; Called once for each message produced to indicate delivery result.<br>        Triggered by poll() or flush(). &quot;&quot;&quot;<br>    if err is not None:<br>        print(&#39;Message delivery failed: {}&#39;.format(err))<br>    else:<br>        print(&#39;Message delivered to {} [{}]&#39;.format(msg.topic(), msg.partition()))<br><br>my_data_list = [&#39;kafka&#39;,&#39;k8s&#39;,&#39;git&#39;,&#39;ansible&#39;,&#39;terraform&#39;,&#39;vagrant&#39;]<br><br>for data in my_data_list:<br>    producer_obj.produce(&#39;myfirsttopic&#39;, data.encode(&#39;utf-8&#39;), callback=delivery_report)<br><br># Wait for any outstanding messages to be delivered and delivery report<br># callbacks to be triggered.<br>producer_obj.flush()</pre><ul><li>consumer.py</li></ul><pre>from confluent_kafka import Consumer<br><br>consumer_obj = Consumer({<br>    &#39;bootstrap.servers&#39;: &#39;localhost:9092&#39;,<br>    &#39;auto.offset.reset&#39;: &#39;earliest&#39;,<br>    &#39;group.id&#39;: &#39;mygroup&#39;,<br>})<br><br>consumer_obj.subscribe([&#39;myfirsttopic&#39;])<br>while True:<br>    msg = consumer_obj.poll(1.0)<br><br>    if msg is None:<br>        continue<br>    if msg.error():<br>        print(&quot;Consumer error: {}&quot;.format(msg.error()))<br>        continue<br><br>    print(&#39;Received message: {}&#39;.format(msg.value().decode(&#39;utf-8&#39;)))<br><br>consumer_obj.close()</pre><ul><li>Although this consumer script will show the event which were added after previous consumption. To check from beginning change the “auto.offset.reset” value.</li></ul><h3>To create a cluster</h3><ul><li>install zookeeper on a machine. Let’s call this one controller.</li><li>launch number of broker(instances) and update the server config for controller IP and port. You can also update the partition’s count.</li><li>Github Link for AWS Cluster → <a href="https://github.com/navsin189/kafka-aws-cluster.git">Click here</a></li></ul><h4>References</h4><ul><li><a href="https://kafka.apache.org/quickstart">https://kafka.apache.org/quickstart</a></li><li><a href="https://github.com/confluentinc/confluent-kafka-python">https://github.com/confluentinc/confluent-kafka-python</a></li></ul><blockquote>Thank you for reading!!!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91b33fb50c86" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/kafka-setup-91b33fb50c86">Kafka Setup</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Kafka]]></title>
            <link>https://sunnykkc13.medium.com/introduction-to-kafka-2f274f922c17?source=rss-e86ec26246b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f274f922c17</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Naveen Singh]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 05:37:15 GMT</pubDate>
            <atom:updated>2023-04-04T16:24:23.076Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever there are IPL or ICC tournament, the most appreciated persons are not the cricketers but the Disney+ Hotstar guys that made the streaming possible. But have you wondered how they are able to do so? also how they are able to show 5 min latency to free tier users? I did and then I heard about <strong>Kafka</strong>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F18496422&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fab-devilliers-gif-cricket-sports-ipl-gif-18496422&amp;image=https%3A%2F%2Fmedia.tenor.com%2FBvnWWFq1yl0AAAAd%2Fab-devilliers-gif.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e6015ae110bac336b47e80e80faa786/href">https://medium.com/media/2e6015ae110bac336b47e80e80faa786/href</a></iframe><p>Kafka developed by LinkedIn then donated to Apache Software Foundation is an open source software which provides a framework for storing, reading and analyzing streaming data.</p><p><strong>Simplified Version</strong>: <em>Kafka is a</em> <em>stream processing platform</em> that enables applications to publish, consume, and process high volumes of record streams in a fast and durable way. <strong><em>Kafka can be called as Central Nervous System for a architecture.</em></strong></p><h4>Why Stream Processing?</h4><p>Stream processing is a data management technique that involves ingesting a continuous data stream to <em>quickly analyze, filter, transform or enhance</em> the data in <strong><em>real time</em></strong>. Once processed, the data is passed off to an application, data store or another stream processing engine.</p><h4>What means Real Time?</h4><p><em>Real time</em> could mean five minutes for a weather analytics app, millionths of a second for an algorithmic trading app or a billionth of a second for a physics researcher.</p><h4>How it Works?</h4><ul><li>In layman term, Kafka take data from multiple sources, store in a queue, process the data then passed to application. Here Kafka will process the data without noticing whether application wants it or not but also maintains the order of data.</li></ul><h4>Terminologies</h4><ul><li><strong>Cluster → </strong>Kafka is a distributed system and designed to run on<strong> </strong>one or more Broker.</li><li><strong>Broker </strong>→ Computer, instance or container running the Kafka.</li><li><strong>Event</strong> →An <strong>event</strong> records the fact that “something happened” in the world or in your business (events are just data). Example → eating ice-cream, watching IPL, publishing new version of a app, etc.</li><li><strong>Source </strong>→ From where events are coming. Example → from IPL match, Daily Soaps, etc.</li><li>Here’s an example event:</li></ul><pre>Event key: &quot;India Vs England&quot;<br>Event value: &quot;India won by 6 wickets&quot;<br>Event timestamp: &quot;March 31, 2023 at 2:06 p.m.&quot;</pre><ul><li><strong>Producer → </strong>are those client applications that publish (write) events to Kafka.</li><li><strong>Topic </strong>→ where events get stored(similar to tables in MySQL DB). A Broker can have multiple Topic. Topic might also be considered as <strong>Logs</strong>.</li><li><strong>Partition → Partition </strong>breaks a topic into multiple parts(will discuss later).</li><li><strong>OFFSET</strong> → A unique number assigned to every events in each partition.</li><li><strong>Consumer → </strong>are those that subscribe to (read and process) these events.</li></ul><h4><strong>Architecture</strong></h4><p>Let’s understand the below image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aVYQShRryngQrrpH.png" /><figcaption><a href="https://kafka.apache.org/intro">Image 1</a></figcaption></figure><ul><li>Producers are application that send events to Kafka. Multiple producers can send the events at a time.</li><li>Kafka is running on a Broker(server) that has a <strong>persistent volume</strong> attached. Example → Kafka running on EC2 instance which has EBS volume attached. <strong><em>These upcoming events are stored in the disk in the form of Topics. Topics are nothing but similar to tables in SQL only having columns.</em></strong></li><li>As a SQL can have as much as tables that can be stored in the given disk size, <strong>this also goes for the topics in Kafka</strong>.</li><li><strong>Example</strong> → Let’s say a Kafka cluster have 2 broker with disk size 10TB and 20 TB respectively. So the maximum size a topic can be is 20TB that place a limit on Kafka scalability.</li><li><em>To resolve this </em><strong><em>Partitions </em></strong><em>were introduced</em>. Partitioning breaks a topic into small parts where each can live on different brokers in a cluster. This way reading and writing the events are much easier.</li><li>The partitioning is done on the basis of <strong>Partition key</strong><em>(don’t compare it to primary key of SQL) </em>which decide the partition number for upcoming events. <strong><em>Taking the above event as a example the partition key can be the name that is “India Vs England” or category like “win”. Kafka ensure that the events for this match will be in order even there is a partition. Similarly there will be an another partition named “Real Madrid Vs Barcelona” and so on.</em></strong></li><li>But what happen if the event <strong><em>does not contain the partition key</em></strong> then Kafka uses <strong>Round Robin</strong> mechanism to store the event across the partitions.</li><li>Kafka ensure that the events having same key will land in same partition and also in order.</li><li>Each events in partition gets a unique number called <strong>OFFSET.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/0*KmTN2vPS8dA209rt.png" /><figcaption><a href="https://www.analyticsvidhya.com/blog/2022/07/apache-kafka-architecture-and-use-cases-explained/">Image 2</a></figcaption></figure><ul><li><strong><em>In image 1, multiple producer can read and write to different partitions at a time. The colors are denoting the partition key and each color are getting stored in a particular partition.</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iE53t7RlknCCRcW4T6hWeg.png" /><figcaption><a href="https://www.youtube.com/watch?v=Ch5VhJzaoaI">Image </a>3</figcaption></figure><ul><li>The Kafka consumer works by issuing “fetch” requests to the brokers leading the partitions it wants to consume(pull mechanism). The consumer specifies its <strong>offset</strong> in the log with each request and receives back a chunk of log beginning from that position. The consumer thus has significant control over this position and can rewind it to re-consume data if need be.</li></ul><h4>Features of Kafka</h4><ul><li><strong>Fault Tolerant</strong> → Kafka replicates the partitions across the brokers in a cluster that ensure high availability and can be used if a broker die. After replication there is a <strong>leader</strong> of that partition on to which write operation happens and N-1 replicated partition(<strong>followers</strong>) used for read operations.</li><li>Durable → Kafka also store the events for N days(default is 1 week) mentioned in grace policies.</li></ul><h4>Kafka vs. RabbitMQ</h4><p>RabbitMQ is a very popular open source <a href="https://www.ibm.com/in-en/topics/message-brokers">message broker</a>, a type of middleware that enables applications, systems, and services to communicate with each other by translating messaging protocols between them.</p><p>Because Kafka began as a kind of message broker (and can, in theory, still be used as one) and because RabbitMQ supports a publish/subscribe messaging model (among others), Kafka and RabbitMQ are often compared as alternatives. But, the comparisons aren’t really practical, and they often dive into technical details that are beside the point when choosing between the two. For example, that Kafka topics can have multiple subscribers, whereas each RabbitMQ message can have only one; or that Kafka topics are durable, whereas RabbitMQ messages are deleted once consumed.</p><p>The bottom line is:</p><ul><li><em>Kafka is a</em> <em>stream processing platform</em> that enables applications to publish, consume, and process high volumes of record streams in a fast and durable way; and</li><li><em>RabbitMQ is a message broker</em> that enables applications that use different messaging protocols to send messages to, and receive messages from, one another.</li></ul><p><a href="https://sunnykkc13.medium.com/kafka-setup-91b33fb50c86">Here’s the practical implementation</a></p><p><em>Thanks for reading!!!</em></p><h4>References:</h4><ul><li><a href="https://kafka.apache.org/intro">https://kafka.apache.org/intro</a></li><li><a href="https://youtube.com/playlist?list=PLa7VYi0yPIH2PelhRHoFR5iQgflg-y6JA">https://youtube.com/playlist?list=PLa7VYi0yPIH2PelhRHoFR5iQgflg-y6JA</a></li><li><a href="https://youtu.be/Ch5VhJzaoaI">https://youtu.be/Ch5VhJzaoaI</a></li><li><a href="https://www.ibm.com/in-en/topics/apache-kafka">https://www.ibm.com/in-en/topics/apache-kafka</a></li><li><a href="https://www.analyticsvidhya.com/blog/2022/07/apache-kafka-architecture-and-use-cases-explained/">https://www.analyticsvidhya.com/blog/2022/07/apache-kafka-architecture-and-use-cases-explained/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f274f922c17" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>