<?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 marjune on Medium]]></title>
        <description><![CDATA[Stories by marjune on Medium]]></description>
        <link>https://medium.com/@marjune?source=rss-af481dc98e1a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5rSpY26U0f7v4w5ULRAmBQ.jpeg</url>
            <title>Stories by marjune on Medium</title>
            <link>https://medium.com/@marjune?source=rss-af481dc98e1a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:33:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marjune/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[The relevance of A.A. Markov's “Markov Chain” in large language models (LLMs).]]></title>
            <link>https://medium.com/@marjune/the-relevance-of-a-a-markovs-markov-chain-in-large-language-models-llms-5787aaacc285?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5787aaacc285</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[markov-chains]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Fri, 03 Jul 2026 15:58:38 GMT</pubDate>
            <atom:updated>2026-07-03T15:58:38.655Z</atom:updated>
            <content:encoded><![CDATA[<p>With all the AI buzzwords flying around, the subject can seem pretty abstract, and I think most of us have only a rough idea. Worse, we’re too familiar with the terms, and it feels like we understand them.</p><p>I want to understand the fundamental ideas that led to AI breakthroughs. As we all know, humanity’s progress has come from collective ideas over time.</p><h3>A.A Markov (1913) — Markov chains.</h3><blockquote><a href="https://mathshistory.st-andrews.ac.uk/Biographies/Markov/"><strong>A A Markov</strong></a> was a Russian mathematician who is is best known for his work in probability and for stochastic processes especially Markov chains.</blockquote><p>“<em>Markov chain </em>” predicts what comes next based <strong>only on the current state, not the past</strong>, using <strong>probability</strong>. This is the foundation of the “<em>Generative Pre-trained Transformer</em>” (GPT).</p><p>In his study, “<a href="https://alpha60.de/research/markov/DavidLink_AnExampleOfStatistical_MarkovTrans_2007.pdf"><em>An Example of Statistical Investigation of the Text Eugene<br>Onegin Concerning the Connection of Samples in Chains</em></a><em>”. </em>Markov took the Russian novel <a href="https://www.gutenberg.org/files/23997/23997-h/23997-h.htm"><em>Onegin</em></a><em> </em>and extracted the 20,000 letters, which were counted by hand and labeled as consonants (<em>C</em>) or vowels (<em>V</em>), disregarding the letters themselves. It looks like this afterward;</p><blockquote>C <strong>V</strong> C C <strong>V</strong> C <strong>V</strong> C C C C C <strong>V</strong> C <strong>V</strong> <strong>V</strong> C C C C …</blockquote><p>After labeling them as <em>C</em> or <em>V, </em>he proceeded with tallying;</p><pre>Markov 1913 — Raw counts (Eugene Onegin, 20,000 letters)<br><br>Symbol  Meaning                          Count<br>N       total letters                    20,000<br>-       vowels                            8,638<br>-       consonants                       11,362<br>(VV)    vowel followed by vowel           1,104<br>(VC)    vowel followed by consonant       7,534<br>(CV)    consonant followed by vowel     ~ 7,534<br>(CC)    consonant followed by consonant   3,827<br>(VVV)   three vowels in a row               115<br>(CCC)   three consonants in a row           505</pre><p>Measuring the basic odds, he chopped the <strong>20,000 </strong>letters into <strong>200</strong> blocks, each containing <strong>100</strong> letters — about <strong>43 per 100</strong>, i.e., a <strong>~43%</strong> chance.<br>Back in the day, before computers, this was a pretty tedious job, as we can only imagine.</p><h4>First-order probabilities.</h4><pre>Markov 1913 — First-order probabilities (20,000 letters)<br><br>Var  Definition                               Formula                       Value<br>p    P(vowel)                                 8,638 / 20,000                0.432<br>q    P(consonant) = 1 - p                     11,362 / 20,000               0.568<br><br>p0   P(vowel | prev consonant)                CV / cons   = 7,534 / 11,361  0.663<br>p1   P(vowel | prev vowel)                    VV / vowels = 1,104 / 8,638   0.128<br><br>q0   P(consonant | prev consonant) = 1 - p0   -                             0.337<br>q1   P(consonant | prev vowel) = 1 - p1       -                             0.872</pre><blockquote><strong>The question is, given the current letter, what are the odds of what comes next?</strong></blockquote><p>Let’s start with these two variables:</p><p>p0 After a <em>consonant,</em> <strong>66% </strong>chance of getting a <em>vowel</em>. <br>p1 After a <em>vowel</em>, <strong>13% </strong>chance of getting another <em>vowel</em>.</p><p>The huge gap between <strong>66%</strong> and <strong>13% </strong>proves that the previous letter significantly changes the odds. The same scenario with q0 and q1 <strong>34%</strong> vs <strong>87%</strong> of getting a <em>consonant. </em>With all these gaps, it proves that letters are linked in a “chain”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dlOKL5lKDPaJEXAxsC45wg.png" /><figcaption>First order chain</figcaption></figure><h4>Second-order probabilities.</h4><pre>Second-order probabilities (his complex chain)<br>Var   Definition                      Formula                   Value<br>----  -----------------------------   ----------------------    -----<br>p1,1  P(vowel | prev two = V V)       VVV / VV = 115 / 1,104    0.104<br>q0,0  P(consonant | prev two = C C)   CCC / CC = 505 / 3,827    0.132</pre><blockquote><strong>How much does the probability change if we increase the order condition on two previous letters instead of one?</strong></blockquote><p>Turns out it&#39;s getting less likely; the chance of getting a vowel after two consecutive vowels has gone down to <strong>10%. </strong>A huge collapse: for two consonants, getting another consonant is now down to <strong>13%</strong> from the <strong>34% </strong>in the first order.</p><h3>More Statistics.</h3><blockquote>How much the counts bounce around their average?</blockquote><blockquote>From 20,000 letters into 200 blocks, each containing 100 letters — about 43 per 100, i.e., a ~43.2% chance.</blockquote><pre>Dispersion / variance results<br>Quantity                           Formula / source                Value<br>---------------------------------  -----------------------------   -----<br>mean vowels per 100 letters        100 * p                         43.2<br>dispersion coefficient (measured)  5,114 / 24,537.6                0.208 <br>theoretical - simple chain         (1+d)/(1-d) = 0.465 / 1.535     ~ 0.3<br>theoretical - complex chain        (his full dispersion formula)   0.195<br>independent-case reference         -                                  1<br>probable error                     0.67 * sqrt(5.11)               ~ 1.5<br></pre><p><strong>Variance</strong> is just a measure of how far these spread from their average (43.2).</p><h4>Dependence Parameters</h4><pre>Dependence parameters<br>Var      Definition                                    Formula                  Value<br>-------  -------------------------------------------   -----------------------  ------<br>delta    gap between the two conditional vowel-probs   p1 - p0 = 0.128 - 0.663  -0.535<br>epsilon  second-order correlation parameter            -24 / 872                -0.027<br>eta      second-order correlation parameter            -205 / 663               -0.309</pre><p>Dependence parameters suggest that memory has diminishing returns, as we can see from the negative values. Each extra letter of history helps less than the one before.</p><p>In simple terms, the probability of what comes next is the foundation of modern predictive text and AI language models.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5787aaacc285" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bit ON Bit OFF: Understanding File Modes in C Through Bitwise Operators | chmod | From…]]></title>
            <link>https://medium.com/@marjune/bit-on-bit-off-understanding-file-modes-in-c-through-bitwise-operators-chmod-from-fcdee0c9644b?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcdee0c9644b</guid>
            <category><![CDATA[c]]></category>
            <category><![CDATA[gnu]]></category>
            <category><![CDATA[chmod]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[bitwise-operator]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Mon, 14 Jul 2025 19:21:43 GMT</pubDate>
            <atom:updated>2025-07-14T19:21:43.789Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bit ON Bit OFF: Understanding File Modes in C Through Bitwise Operators | chmod | From GNU-coreutils | GNU-lib | Linux</h3><blockquote><a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chmod">chmod</a><br><a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chown">chown</a><br><a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#mkdir">mkdir</a><br>…..<br>……</blockquote><blockquote><a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chmod">https://wiki.gentoo.org/wiki/GNU_Coreutils</a></blockquote><p>For macOS, Linux, and other Unix-like system users, these commands are very familiar, directly interfacing in the terminal or indirectly via user interface.</p><p>The <a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chmod"><em>chmod</em></a><em> </em>command, for example, is responsible for setting permissions on files or directories. Adding/removing <em>read</em>, <em>write</em>, and <em>execute</em> capabilities for <em>users</em>, <em>groups, </em>and the rest(<em>others) </em>is just a <a href="https://en.wikipedia.org/wiki/Bitwise_operation"><strong><em>bitwise operation</em></strong></a><strong><em> (OR, AND, NOT).</em></strong></p><p>As pointed out in “<em>The UNIX Time Sharing System</em>” by Dennis Ritchie and Ken Thompson.</p><blockquote>3.5 Protection</blockquote><blockquote>Although the access control scheme in UNIX is quite simple, it has some unusual features. Each user of the system is assigned a unique user identification number. When a file is created, it is marked with the user ID of its owner. Also given for new files is a set of seven protection bits. Six of these specify independently read, write, and execute permission for the owner of the file and for all other users.</blockquote><h3>Understanding the code</h3><p>We’re going to explore the source code of <a href="https://wiki.gentoo.org/wiki/GNU_Coreutil"><em>GNU Coreutils</em></a><em> </em>at <a href="https://github.com/coreutils/coreutils">https://github.com/coreutils/coreutils</a> so we can learn more deeply.</p><p>Let’s examine the code for <a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chmod"><em>chmod</em></a><em> </em>at <a href="https://github.com/coreutils/coreutils/blob/master/src/chmod.c"><em>chmod.c.</em></a></p><pre>/* This is the usage of the command if we run chmod --help in the termnial */<br>void usage (int status) {}<br><br>/* The main function and entry point of the chmod */<br>int main (int argc, char **argv) {}</pre><p>There’s more in the <a href="https://github.com/coreutils/coreutils/blob/master/src/chmod.c"><em>chmod.c</em></a><em> </em>of course, and the specific thing we’re going to examine further is the core functionality that will calculate the permission mode using <a href="https://en.wikipedia.org/wiki/Bitwise_operation"><strong><em>bitwise operation</em></strong></a><strong><em>.</em></strong> It’s located in another repo (<a href="https://github.com/coreutils/gnulib">https://github.com/coreutils/gnulib</a>). In <a href="https://github.com/coreutils/gnulib/blob/master/lib/modechange.c"><em>lib/modechange.c</em></a><em> </em>is where the interesting part.</p><h4>Defined values</h4><p>Let’s take a look at pre-defined variables with octal values first, which are documented in <a href="https://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html"><em>sysstat.h.html</em></a>.</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;sys/stat.h&gt;<br><br>/* <br>  S_IRWXU : 00700<br>  S_IRUSR : 00400<br>  S_IWUSR : 00200<br>  S_IXUSR : 00100<br>  S_IRWXG : 00070<br>  S_IRGRP : 00040<br>  S_IWGRP : 00020<br>  S_IXGRP : 00010<br>  S_IRWXO : 00007<br>  S_IROTH : 00004<br>  S_IWOTH : 00002<br>  S_IXOTH : 00001<br>  S_ISUID : 04000<br>  S_ISGID : 02000<br>  S_ISVTX : 01000<br>*/<br>void print_S_I() {<br>   printf(&quot;S_IRWXU : %05o\n&quot;, S_IRWXU);<br>   printf(&quot;S_IRUSR : %05o\n&quot;, S_IRUSR);<br>   printf(&quot;S_IWUSR : %05o\n&quot;, S_IWUSR);<br>   printf(&quot;S_IXUSR : %05o\n&quot;, S_IXUSR);<br>   printf(&quot;S_IRWXG : %05o\n&quot;, S_IRWXG);<br>   printf(&quot;S_IRGRP : %05o\n&quot;, S_IRGRP);<br>   printf(&quot;S_IWGRP : %05o\n&quot;, S_IWGRP);<br>   printf(&quot;S_IXGRP : %05o\n&quot;, S_IXGRP);<br>   printf(&quot;S_IRWXO : %05o\n&quot;, S_IRWXO);<br>   printf(&quot;S_IROTH : %05o\n&quot;, S_IROTH);<br>   printf(&quot;S_IWOTH : %05o\n&quot;, S_IWOTH);<br>   printf(&quot;S_IXOTH : %05o\n&quot;, S_IXOTH);<br>   printf(&quot;S_ISUID : %05o\n&quot;, S_ISUID);<br>   printf(&quot;S_ISGID : %05o\n&quot;, S_ISGID);<br>   printf(&quot;S_ISVTX : %05o\n&quot;, S_ISVTX);<br>}<br><br>int main() {<br>    print_S_I();<br>    return 0;<br>}</pre><p>Based on <a href="https://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html"><em>sysstat.h.html</em></a></p><blockquote><strong>S_IRWXU</strong> read, write, execute/search by owner <br><strong>S_IRUSR</strong> read permission, owner <br><strong>S_IWUSR</strong> write permission, owner <br><strong>S_IXUSR</strong> execute/search permission, owner <br><strong>S_IRWXG</strong> read, write, execute/search by group <br><strong>S_IRGRP</strong> read permission, group <br><strong>S_IWGRP</strong> write permission, group <br><strong>S_IXGRP</strong> execute/search permission, group <br><strong>S_IRWXO</strong> read, write, execute/search by others <br><strong>S_IROTH</strong> read permission, others <br><strong>S_IWOTH</strong> write permission, others <br><strong>S_IXOTH</strong> execute/search permission, others <br><strong>S_ISUID</strong> set-user-ID on execution <br><strong>S_ISGID</strong> set-group-ID on execution <br><strong>S_ISVTX</strong> on directories, restricted deletion flag</blockquote><blockquote>The bits defined by <strong>S_IRUSR</strong>, <strong>S_IWUSR</strong>, <strong>S_IXUSR</strong>, <strong>S_IRGRP</strong>, <strong>S_IWGRP</strong>, <strong>S_IXGRP</strong>, <strong>S_IROTH</strong>, <strong>S_IWOTH</strong>, <strong>S_IXOTH</strong>, <strong>S_ISUID</strong>, <strong>S_ISGID</strong> and <strong>S_ISVTX</strong> are unique.</blockquote><blockquote><strong>S_IRWXU</strong> is the bitwise OR of <strong>S_IRUSR</strong>, <strong>S_IWUSR</strong> and <strong>S_IXUSR</strong>.</blockquote><blockquote><strong>S_IRWXG</strong> is the bitwise OR of <strong>S_IRGRP</strong>, <strong>S_IWGRP</strong> and <strong>S_IXGRP</strong>.</blockquote><blockquote><strong>S_IRWXO</strong> is the bitwise OR of <strong>S_IROTH</strong>, <strong>S_IWOTH</strong> and <strong>S_IXOTH</strong>.</blockquote><pre>READ:     S_IRUSR (00400) | S_IRGRP (00040) | S_IROTH (00004) = 00444<br>WRITE:    S_IWUSR (00200) | S_IWGRP (00020) | S_IWOTH (00002) = 00222<br>EXECUTE:  S_IXUSR (00100) | S_IXGRP (00010) | S_IXOTH (00001) = 00111</pre><p>Doing a bitwise OR operation with the power of 2 numbers, i.e., 1, 2, 4, 8, 16, 32, and so on, the consequence is addition because they are unique in their bit position.</p><p>Back to the <a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chmod"><em>chmod</em></a><em> </em>command, updating files with new permissions, e.g.,</p><p>Adding <em>read, write, </em>and <em>execute </em>permissions for others chmod o+rwx file_name</p><p>For the group, it will be chmod g+wrx file_name We can also combine the entire <em>user, group, </em>and <em>other </em>into one command, chmod ugo+wrx file_name</p><p>Removing permissions is - rather than +</p><h4>Mode Change</h4><p>In <a href="https://github.com/coreutils/gnulib/blob/master/lib/modechange.c"><em>lib/modechange.c</em></a>,<em> </em>which is used by the <a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chmod"><em>chmod</em></a><em> </em>command. We can test the <a href="https://github.com/coreutils/gnulib/blob/master/lib/modechange.c"><em>modechange.c</em></a><em> </em>by invoking two functions, mode_compile With a valid parameter, such as <a href="https://wiki.gentoo.org/wiki/GNU_Coreutils#chmod"><em>chmod</em></a><em>. </em>i.e.,</p><blockquote>Each MODE is of the form ‘[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0–7]+’.</blockquote><pre>#include &lt;sys/stat.h&gt;<br>#include &lt;modechange.h&gt;<br>#include &lt;stdbool.h&gt;<br>#include &lt;stdio.h&gt;<br><br>void test_mode_change() {<br><br>    mode_t oldmode = 0000; // as is this is the file without any permissions<br>    mode_t newmode;<br><br>    // adding read, write, and execute to owner/user, group, and others<br>    struct mode_change *change = mode_compile(&quot;ug+rwx&quot;); <br>    if (change) {<br>       newmode = mode_adjust(oldmode, 0, 0022, change, 0);<br>       printf(&quot;[OLD MODE]: %05o\n&quot;, oldmode);<br>       printf(&quot;[NEW MODE]: %05o\n&quot;, newmode);<br>       // [OLD MODE]: 00000<br>       // [NEW MODE]: 00770<br>    }<br>}<br><br>int main() {<br>    test_mode_change();<br>    return 0;<br>}</pre><h4>mode_compile</h4><ul><li>Read the parameter, <em>“ug+rwx” </em>which adding <em>read, write, </em>and <em>execute </em>permissions to the <em>user </em>and <em>group.</em></li><li>Calculate the affected <em>“ug” </em><em>user , </em>and<em> </em><em>group</em>. <strong>Bitwise OR</strong>;</li></ul><pre>-------------------------------------------------<br>| user              |   group           | ug    |<br>-------------------------------------------------<br>| S_ISUID | S_IRWXU | S_ISGID | S_IRWXG | 06770 |<br>-------------------------------------------------</pre><ul><li>Get the operator +</li><li>Calculate the rwx mode. <strong>Bitwise OR</strong>;</li></ul><pre>---------------------------------------------------------------------------------------------------<br>|            read             |          write              |       execute               | rwx   |<br>|-------------------------------------------------------------------------------------------------|<br>| S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH | S_IXUSR | S_IXGRP | S_IXOTH | 00777 |<br>---------------------------------------------------------------------------------------------------</pre><ul><li>Putting together the affected (ug) and modes (rwx). <strong>Bitwise AND</strong>. <br> ug &amp; rwx which is06770 &amp; 00777 = 0770 the actual mode for <em>“ug+rwx”</em>.</li><li>Return the mode_changestructure.</li></ul><pre>struct mode_change {<br>  char op          = +;                   /* One of &quot;=+-&quot;.  */<br>  char flag        = ;                    /* Special operations flag.  */<br>  mode_t affected  = 06770;               /* Set for u, g, o, or a.  */<br>  mode_t value     = 00777;               /* Bits to add/remove.  */<br>  mode_t mentioned = 00770;               /* Bits explicitly mentioned.  */<br>};</pre><h4>mode_adjust</h4><p>The mode_adjust function will finally adjust the mode_t oldmode = 0000; to mode_t newmode; based on the structure returned from modu_compile.</p><p>In case the operator is - it means removing the permissions, the bitwise operator then becomes <strong>NOT.</strong></p><p>This is the idea in <a href="https://github.com/coreutils/gnulib/blob/master/lib/modechange.c"><em>modechange.c</em></a><em> </em>while in <a href="https://github.com/coreutils/coreutils/blob/master/src/chmod.c"><em>chmod.c</em></a><em> </em>it involves traversing file hierarchies, depending on the options.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcdee0c9644b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Continuous Deployment with Jenkins Pipelines to MCP and LLM.]]></title>
            <link>https://medium.com/@marjune/from-continuous-deployment-with-jenkins-pipelines-to-mcp-and-llm-c1adcb7a46c9?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1adcb7a46c9</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[claude]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Thu, 26 Jun 2025 17:07:39 GMT</pubDate>
            <atom:updated>2025-06-26T17:07:39.569Z</atom:updated>
            <content:encoded><![CDATA[<p>With my progress in creating my own <a href="https://www.anthropic.com/news/model-context-protocol"><em>MCP (Model Context Protocol)</em></a> server to manage a Kubernetes cluster, my primary goal is to learn how to utilize LLM for tasks beyond code generation and public knowledge questions. As I discussed in my previous article,</p><blockquote><a href="https://medium.com/@marjune/how-i-built-a-personal-docker-based-mcp-to-manage-a-k8s-cluster-94c8aa28ab74">How I Built a Personal Docker-based MCP to manage a K8s cluster.</a></blockquote><p>I created a few simple tools to interface with a Kubernetes cluster. Moving forward, I want to add more capability where, instead of using a CI/CD pipeline to deploy my application, LLM will take care of the deployment on my behalf, based on certain standards, so that LLM will not assume how to proceed. Since LLM can perfectly reason out, I’ll communicate in a way that makes it seem like my intelligent assistant is handling the task, removing the technical overhead associated with operating tools like Jenkins or any other CI/CD.</p><h4>Application Deployment</h4><p>I created a pipeline before where I used Jenkins as my CI/CD tool for deployment,</p><blockquote><a href="https://medium.com/@marjune/blue-green-deployment-in-kubernetes-using-jenkins-declarative-pipeline-b5ad8e40f9c3">Blue/Green Deployment in Kubernetes using Jenkins Declarative Pipeline.</a></blockquote><p>With the same application as Blue/Green. I’ll add more tools to my <em>MCP, </em>like deployment from start to finish.</p><h4>MCP Tools</h4><blockquote><a href="https://github.com/mrjbtc/mcp-k8s/tree/main">https://github.com/mrjbtc/mcp-k8s/tree/main</a></blockquote><p>To help the LLM understand how to deploy my application, I created a tool that outputs a clear, step-by-step description of the deployment process.</p><p><a href="https://github.com/mrjbtc/mcp-k8s/blob/main/src/tools/deployment.py">mcp-k8s/src/tools/deployment.py at main · mrjbtc/mcp-k8s</a></p><pre>@mcp.tool(<br>    annotations={<br>        &quot;title&quot;: &quot;How to deploy blue green&quot;,<br>        &quot;readOnlyHint&quot;: True,<br>        &quot;destructiveHint&quot;: False,<br>        &quot;openWorldHint&quot;: False<br>    }<br>)<br>async def how_to_deploy_blue_green():<br> &quot;&quot;&quot; These are the steps on how to deploy Blue Green deployment &quot;&quot;&quot;<br> return &quot;&quot;&quot;<br>     1. Query the existing blue deployment to get the number of replicas it’s running. This ensures the green deployment will scale to match the current load.<br><br>     2. Update the svc-web-app-test service to point to the green deployment by modifying its selector to app=${GREEN-ENVIRONMENT} GREEN-ENVIRONMENT = web-app-a OR web-app-b. This will route traffic to the new version for pre-release validation.<br><br>     3. Update the image of the green deployment to the specified version/tag<br><br>     4. Scale the green deployment to match the replica count retrieved from the blue deployment (Step 1)<br><br>     5. Validate the green deployment by checking its health endpoint using the test service&#39;s IP=192.168.106.3 and NODE_PORT=30655 using the health check with the uri http://{IP}:{NODE_PORT} Monitor this endpoint for up to 3 minutes. If it doesn&#39;t consistently return HTTP 200 OK, abort the deployment.<br><br>     6. Ask for approval to continue the deployment.<br><br>     7. Once the health check passes, pause and wait for manual approval to proceed with production switch.<br><br>     8. Update the production service svc-web-app to point to the green deployment by modifying its selector to app=${GREEN-ENVIRONMENT} GREEN-ENVIRONMENT = web-app-a OR web-app-b<br><br>     9. Promote the green deployment to &quot;blue&quot; by updating the labels from green to blue.<br><br>     10. Update the existing blue deployment’s labels to indicate it is now the &quot;green&quot; (standby) environment.<br><br>     11. Finally, scale the old blue deployment down to zero replicas. Be careful to target the correct one (the previous production deployment, not the newly updated green).<br>    &quot;&quot;&quot;</pre><p>Other tools (<a href="https://github.com/mrjbtc/mcp-k8s/tree/main/src/tools"><em>https://github.com/mrjbtc/mcp-k8s/tree/main/src/tools</em></a>) are available that support all these steps.</p><pre><br>$ uv run python src/main.py <br>[mcp.run]<br>[available tools]:<br>get_deployments<br>describe_deployment<br>get_blue_green_deployment<br>set_image<br>scale_replicas<br>switch_blue_green_environment<br>how_to_deploy_blue_green<br>get_namespaces<br>get_pods<br>describe_pods<br>get_services<br>set_selector</pre><h4>Asking LLM to assist in deploying my application</h4><p>As everything is prepared and ready to proceed with deployment. I started by asking,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xVohCraREgKS3v8RwdRUiA.png" /></figure><p>Based on my first interaction with LLM, I instructed it to check my Blue/Green deployment in the web namespace, and it decided to invoke some of the tools available, which are get_deployments, and get_services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-tisFgMmtgF8b4ewctANA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ArgnZQ7E6YX3cTxCa7X99A.png" /></figure><p>It summarizes the information from the tools. I check the production service, which says in the <em>NodePort</em>:<strong>30654</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuExpa4YO1pjf3HTXCDalg.png" /></figure><p>And the production environment is serving <em>Version 1.</em></p><p>I then follow up with the question on how to proceed with the blue/green deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ojpie-orLZZ0ojKyx6jAVg.png" /></figure><p>Now, the how_to_deploy_blue_green tool is being invoked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EOmiubnf5wU-P36uUvHInQ.png" /></figure><p>Then I gave a green signal to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SOJuq3C9q1GXzNqmsQtKkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-WDHdDr_KNj_oEWB7lDxWQ.png" /></figure><p>As the LLM proceeds, some tools are executed more than once due to some errors, that’s why the model retried and re-construct the parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qOnO6nmKdPo0wwOjkUXIGQ.png" /></figure><p>After confirming the steps above, I can now access my test service, in <em>NodePort: </em><strong><em>30665.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXcS1maOYugF2vEMm06n-w.png" /></figure><p>The test service endpoint is now pointing to green environment which is serving newly deployed <em>Version 2.</em></p><p>And in the Blue environment still <em>Version 1</em> since I haven’t instructed my assistant to proceed the green to production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuExpa4YO1pjf3HTXCDalg.png" /></figure><p>After verifying that everything looks good. I tell my assistant to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nLG0ExWGUKJBbqSEMIza3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-Y1_DAV7roplQMXtCVYvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0k44qcAC5u4drspsaMp1Ew.png" /></figure><p>And there it is, deployment was successful. The production endpoint in <strong>30654 </strong>port is now pointing to the new version of the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CfMW-yO0KdSkVTZakbgKtw.png" /></figure><h4>Final Thoughts</h4><p>Deployment becomes effortless through a simple conversation.</p><p>If something goes wrong, I can instruct the LLM to initiate a rollback. Additionally, we can integrate more automated tests and allow the LLM to monitor system behavior post-deployment. Based on predefined criteria, it can autonomously decide whether a rollback is necessary.</p><p>As we continue developing MCP, a good rule of thumb is to design tools that are focused and narrowly scoped. Avoid relying on the LLM to generate or execute high-risk, destructive commands. Always consider RBAC(<em>Role-Based Access Control</em>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1adcb7a46c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Built a Personal Docker-based MCP to manage a K8s cluster.]]></title>
            <link>https://medium.com/@marjune/how-i-built-a-personal-docker-based-mcp-to-manage-a-k8s-cluster-94c8aa28ab74?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/94c8aa28ab74</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Tue, 03 Jun 2025 14:51:11 GMT</pubDate>
            <atom:updated>2025-06-10T19:14:12.322Z</atom:updated>
            <content:encoded><![CDATA[<p>Without a doubt, the intelligence of <a href="https://www.ibm.com/think/topics/large-language-models"><em>LLMs</em></a> is extraordinary; it can perfectly reason out things from acquired knowledge or different sources of context provided. As people build <a href="https://blogs.nvidia.com/blog/what-is-agentic-ai/"><em>Agentic AI</em></a><em> </em>to solve complex tasks and workflows, <a href="https://www.ibm.com/think/topics/large-language-models"><em>LLMs serve</em></a><em> </em>as the brain in navigating how things get done.</p><p>In my previous<em> </em><a href="https://medium.com/@marjune/how-i-use-ai-and-vector-database-augmenting-internal-knowledge-retrieval-ac099dcf468e"><em>article</em></a><em>, </em>I<em> </em>implemented<em> RAG (Retrieval Augmented Generation) </em>based on my internal context data that resides in a <em>vector database </em>and<em> </em><a href="https://ollama.com/"><em>Ollama</em></a>. It’s a straightforward use case.</p><h3>The Challenge</h3><p>To accomplish a complex task comprising multiple operations and data sources, <a href="https://www.ibm.com/think/topics/large-language-models"><em>LLMs</em></a><em> </em>require integration with tools for each action, e.g., <em>fetching data from an external API, writing files on our local machine, or executing commands.</em></p><h3>The Solution</h3><p><em>Antropic</em> <a href="https://modelcontextprotocol.io/introduction">introduced</a> <a href="https://www.anthropic.com/news/model-context-protocol"><em>MCP (Model Context Protocol)</em></a><em>,</em> a standard way of bridging the fragments between <a href="https://www.ibm.com/think/topics/large-language-models"><em>LLM</em></a> as a brain and different tools, APIs, functions, and applications. Abstracting the integration in a way of decoupling from whichever <a href="https://www.ibm.com/think/topics/large-language-models"><em>LLM</em></a><em> Models </em>we’re using, plug and play. As nicely explained in <a href="https://addyo.substack.com/p/mcp-what-it-is-and-why-it-matters"><strong><em>mcp-what-it-is-and-why-it-matters</em></strong></a><strong><em>.</em></strong></p><h3>Building my MPC</h3><p>Through my learning journey, I created an <a href="https://www.anthropic.com/news/model-context-protocol"><em>MCP</em></a> server using the <a href="https://github.com/modelcontextprotocol/python-sdk">python-sdk</a> to manage a Kubernetes cluster. I’m using the <a href="https://modelcontextprotocol.io/quickstart/server">Claude desktop</a> and built my <a href="https://www.anthropic.com/news/model-context-protocol"><em>MCP</em></a><em> </em>into a Docker image, which can be found in my <a href="https://github.com/mrjbtc/mcp-k8s"><em>GitHub repo</em></a>.</p><h4>Project Structure</h4><pre>|-- mcp-k8s<br>|   |-- Dockerfile<br>|   |-- README.md<br>|   |-- k8s-service-account.yaml<br>|   |-- requirements.txt<br>|   `-- src<br>|       |-- client<br>|       |   |-- __init__.py<br>|       |   `-- k8s_client.py<br>|       |-- k8s_resources<br>|       |   |-- __init__.py<br>|       |   |-- deployments.py<br>|       |   |-- namespaces.py<br>|       |   |-- pods.py<br>|       |   `-- services.py<br>|       |-- main.py<br>|       |-- models<br>|       |   |-- __init__.py<br>|       |   `-- response.py<br>|       |-- server<br>|       |   `-- __init__.py<br>|       |-- test.py<br>|       `-- tools<br>|           |-- __init__.py<br>|           |-- deployment.py<br>|           |-- namespace.py<br>|           |-- pod.py<br>|           `-- services.py</pre><h4>Dockerfile</h4><p>I added the <a href="https://kubernetes.io/docs/reference/kubectl/generated/kubectl_version/"><em>Kubectl</em></a> CLI to interact with the <em>Kubernetes</em> cluster and configured <a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/"><em>Kubeconfig</em></a> for authentication and access.</p><blockquote><a href="https://github.com/mrjbtc/mcp-k8s/blob/main/Dockerfile">Dockerfile</a></blockquote><pre>FROM python:3.11-slim<br><br>ARG USER=&quot;acrux&quot;<br>ARG SRC_CODE=&quot;src&quot;<br><br>RUN apt-get update -y<br>RUN apt-get install -y wget<br>RUN wget https://dl.k8s.io/v1.31.2/bin/linux/amd64/kubectl<br>RUN chmod +x kubectl<br>RUN mv kubectl /usr/local/bin/<br><br>RUN useradd -m ${USER}<br>USER ${USER}<br>RUN mkdir /home/${USER}/${SRC_CODE}<br><br>ENV PATH=&quot;/home/${USER}/.local/bin:$PATH&quot;<br>ENV PYTHONPATH=/home/${USER}/${SRC_CODE}<br><br>COPY --chown=${USER}:${USER} requirements.txt /home/${USER}/${SRC_CODE}/requirements.txt<br><br>RUN python -m ensurepip --default-pip &amp;&amp; \<br>    pip install --no-cache-dir --upgrade pip &amp;&amp; \<br>    pip install --no-cache-dir -r /home/${USER}/${SRC_CODE}/requirements.txt<br><br>COPY --chown=${USER}:${USER} ./${SRC_CODE}/ /home/${USER}/${SRC_CODE}/<br>COPY --chown=${USER}:${USER} kube-config /home/${USER}/.kube/config<br><br>WORKDIR /home/${USER}<br><br>CMD [&quot;/bin/bash&quot;]</pre><h4>Requirements.txt</h4><p>For <a href="https://github.com/mrjbtc/mcp-k8s/blob/main/requirements.txt"><em>requirements.txt</em></a>, just three packages are required,</p><pre>pydantic<br>mcp[cli]<br>uv</pre><h4>MCP-tools</h4><p>The available tools for the LLM to access are located in <a href="https://github.com/mrjbtc/mcp-k8s/tree/main/src/tools"><em>src/tools</em></a>.</p><pre>|-- mcp-k8s<br>|       `-- tools<br>|           |-- __init__.py<br>|           |-- deployment.py<br>|           |-- namespace.py<br>|           |-- pod.py<br>|           `-- services.py</pre><blockquote><a href="https://github.com/mrjbtc/mcp-k8s/blob/main/src/tools/services.py">src/tools/services.py</a></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63ab74a4b15e54f7dc8fdce93f83be58/href">https://medium.com/media/63ab74a4b15e54f7dc8fdce93f83be58/href</a></iframe><h4>Building the image</h4><p>Change directory to mcp-k8s and execute docker build . -t mcp:0.0.1</p><h4>Claude Desktop MCP config</h4><p>After the Docker image(mcp:0.0.1) is created. Following this <a href="https://modelcontextprotocol.io/quickstart/server#mac-os-linux">user guide, </a>updating claude_desktop_config.json with,</p><pre>{<br>  &quot;mcpServers&quot;: {<br>    &quot;k8s-mcp&quot;: {<br>       &quot;command&quot;: &quot;docker&quot;,<br>        &quot;args&quot;: [<br>          &quot;run&quot;,<br>          &quot;--rm&quot;,<br>          &quot;-i&quot;,<br>          &quot;mcp:0.0.1&quot;,<br>          &quot;uv&quot;,<br>          &quot;run&quot;,<br>          &quot;src/main.py&quot;<br>        ]<br>    }<br>  }<br>}</pre><p>Restarted the <em>Claude Desktop, </em>and under <em>Claude-&gt;Settings-&gt;Developer, </em>Docker is running. The tools should be ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*luRBxiCEbMitwYYWyJKTuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzxYMV139QvQHGvFxz2T8g.png" /></figure><h4>Asking Claude questions.</h4><p>Based on this question, <em>Claude </em>will invoke these tools get_namespaces, and get_deployments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcvPdIZRr-IDcza2ygnOJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UdJ89Zl-yWzFYx5gCyNv-w.png" /></figure><p>Sure enough, after invoking the tools, <em>Claude </em>analyzes the necessary information and summarizes it.</p><h4>Further Development</h4><p>Adding more tools that can perform more operations, such as deployment, analyzing errors, debugging, and more…</p><p>Developing more purpose-specific <em>Dockerized MCPs</em> and incorporating them into <em>Claude Desktop</em>.</p><pre>{<br>  &quot;mcpServers&quot;: {<br>    &quot;k8s-mcp&quot;: {<br>       &quot;command&quot;: &quot;docker&quot;,<br>        &quot;args&quot;: []<br>    },<br>    &quot;mcp-2&quot;: {<br>    },<br>    &quot;mcp-3&quot;: {<br>    }<br>  }<br>}</pre><p>Abstracting complex operations from different applications or technologies, such as <em>Kubernetes, </em>into natural language can be quite handy. <a href="https://blogs.nvidia.com/blog/what-is-agentic-ai/"><em>Agentic AI</em></a><em> </em>consists of MCPs connected to an LLM, enabling the completion of complex tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94c8aa28ab74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Use AI and Vector Database, Augmenting Internal Knowledge Retrieval.]]></title>
            <link>https://medium.com/@marjune/how-i-use-ai-and-vector-database-augmenting-internal-knowledge-retrieval-ac099dcf468e?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac099dcf468e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ollama]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[llm-applications]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 11:34:46 GMT</pubDate>
            <atom:updated>2025-03-28T19:39:07.997Z</atom:updated>
            <content:encoded><![CDATA[<p>With the rise of LLM models today, everyone is racing to create their <a href="https://blogs.nvidia.com/blog/what-is-agentic-ai/"><em>agentic AI</em></a> to solve specific problems. People bet that <a href="https://www.ibm.com/think/topics/agentic-workflows"><em>agentic workflows</em></a> are the next thing, removing much human intervention in performing a task and raising the bar of productivity.</p><p>I want to learn about LLMs, but before delving into their complexity, I want to start with a practical use case. In my previous work, I designed and developed a simple API and integrated it with <a href="https://api.slack.com/docs/apps"><em>slack-app</em></a>, and <a href="https://api.slack.com/interactivity/slash-commands"><em>slash-commands</em></a><em> </em>in Slack to automate something and retrieve information, minimizing manual efforts. Every time a user types a command in a message, e.g./some-commands It will invoke the API and return as a Slack message. I did it with <a href="https://aws.amazon.com/api-gateway/">API gateway</a> in AWS and AWS <a href="https://aws.amazon.com/lambda/">lambda</a>.</p><h3>RAG (Retrieval Augmented Generation).</h3><p>One use case of LLMs is to serve as a reasoning engine, processing provided context or data to generate meaningful insights relative to questions asked. This is particularly relevant in implementations of <a href="https://platform.openai.com/docs/guides/optimizing-llm-accuracy#retrieval-augmented-generation-rag"><em>RAG</em></a>, where LLMs leverage external knowledge to craft their responses<em>. </em>I could use them to extend the use case I mentioned above.</p><p>If we ask chatGPT with this prompt,</p><blockquote>Given this data {<strong>SOME DATA</strong>} please respond to this promt {<strong>Questions related to the data</strong>}.</blockquote><p>Sure enough, chatGPT’s augmented answer is based on the given data. The data can be files, articles, texts, or anything.</p><p>In any company or organization, regardless of the size, internal information, e.g., documentation, confluence, FAQ, SOP, any available information there is. Locating and reading them takes time and endless discussions with colleagues and new joiners to clarify processes, workflows, and technical details.</p><p>By storing the internal information or vocabulary as context and retrieving relevant data based on meaning during search, we can feed this information to an LLM to enhance its reasoning and response generation. This can be done using vector embeddings.</p><h3>Vector Embeddings.</h3><p>I found vector embeddings in the <a href="https://weaviate.io/blog"><em>Weaviate blog</em></a>,<em> </em>which nicely <a href="https://weaviate.io/blog/vector-embeddings-explained"><em>explained embeddings</em></a><em>.</em></p><blockquote>Vectors or vector embeddings are numeric representations of data that capture certain features of the data.</blockquote><p>Based on the numeric representations of our data, <a href="https://weaviate.io/blog/vector-search-explained"><em>vector search</em></a> can do all sorts of mathematical calculations to capture context or meaning in a vector space or the entire vocabulary. <strong>NLP</strong> (<strong>Natural Language Processing</strong>), which uses embeddings to capture meaning.</p><p>Weaviate is a vector database where we can store our vector data. Here are some articles about <a href="https://www.turing.com/kb/guide-on-word-embeddings-in-nlp"><em>guide-on-word-embeddings-in-nlp</em></a>, <a href="https://weaviate.io/blog/history-of-weaviate"><em>history-of-weaviate</em></a> detailing more about key ideas of the subject.</p><h3>Implementation.</h3><p>Given all the information above, it’s time to get into action. So, I need a vector database, and I use <a href="https://weaviate.io/platform"><em>Weaviate</em></a><em>. </em>For<em> </em>LLM, I use <a href="https://ollama.com/"><em>Ollama</em></a><em> </em>and deploy locally using Kubernetes.</p><p>I followed this simple <a href="https://weaviate.io/developers/weaviate/quickstart/local#32-retrieval-augmented-generation"><em>retrieval-augmented-generation</em></a><em> </em>example. High-level architecture diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4vQUbckObptWmzrNIK8glA.png" /><figcaption><a href="https://weaviate.io/developers/weaviate/quickstart/local#32-retrieval-augmented-generation">https://weaviate.io/developers/weaviate/quickstart/local#32-retrieval-augmented-generation</a></figcaption></figure><h3>Deploying in Kubernetes Locally.</h3><p>The diagram below shows where I deploy <a href="https://weaviate.io/platform"><em>Weaviate</em></a>, <a href="https://ollama.com/"><em>Ollama</em></a>, and a client to interact with the vector database, run a query, and send the results to LLM to augment the response relative to the query or question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*fewPYQDib3rc6Xpnoqmb-g.png" /></figure><h4>Namespace.</h4><pre><br>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: dev-ai</pre><h4>Weaviate Storage.</h4><pre><br># Storage Class<br>kind: StorageClass<br>apiVersion: storage.k8s.io/v1<br>metadata:<br>  name: local-storage<br>provisioner: kubernetes.io/no-provisioner<br>volumeBindingMode: WaitForFirstConsumer<br><br>---<br># PV<br>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: weaviate-pv-volume<br>  labels:<br>    type: local<br>spec:<br>  storageClassName: local-storage<br>  claimRef:<br>    name: weaviate-pv-claim<br>    namespace: dev-ai<br>  capacity:<br>    storage: 10Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  local:<br>    path: /mnt<br>  nodeAffinity:<br>    required:<br>      nodeSelectorTerms:<br>      - matchExpressions:<br>        - key: kubernetes.io/hostname<br>          operator: In<br>          values:<br>          - colima<br><br>---<br># PVC<br>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: weaviate-pv-claim<br>  namespace: dev-ai<br>spec:<br>  storageClassName: local-storage<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 3Gi<br></pre><h4>Weaviate Service and Deployment.</h4><p>So I’m using thiscr.weaviate.io/semitechnologies/weaviate:1.29.0 image provided by weaviate publicly.</p><p>Also, we are enabling <em>ENABLE_MODULES </em>with <em>“text2vec-ollama”, </em>where <em>Weaviate</em> uses this model to convert our data into vector embeddings. However, we can use any vectorizer model or <a href="https://weaviate.io/developers/weaviate/starter-guides/custom-vectors"><em>bring your own vectors</em></a><em>.</em></p><pre><br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: weaviate-service<br>  namespace: dev-ai<br>spec:<br>  selector:<br>    app: weaviate-server<br>  type: NodePort<br>  ports:<br>    - name: http<br>      port: 8080<br>      targetPort: 8080<br>      nodePort: 32001<br>    - name: gprc<br>      port: 50051<br>      targetPort: 50051<br>      nodePort: 32002<br>      <br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: weaviate-server<br>  namespace: dev-ai<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: weaviate-server<br>  strategy:<br>    type: Recreate<br>  template:<br>    metadata:<br>      labels:<br>        app: weaviate-server<br>    spec:<br>      containers:<br>        - name: weaviate<br>          image: cr.weaviate.io/semitechnologies/weaviate:1.29.0<br>          imagePullPolicy: IfNotPresent<br>          env:<br>            - name: ENABLE_MODULES<br>              value: &quot;text2vec-ollama&quot;<br>          ports:<br>            - name: p1<br>              containerPort: 8080<br>            - name: gprc<br>              containerPort: 50051<br>          volumeMounts:<br>            - name: weaviate-data<br>              mountPath: /var/lib/weaviate<br>      volumes:<br>        - name: weaviate-data<br>          persistentVolumeClaim:<br>              claimName: weaviate-pv-claim</pre><h4>Ollama LLM Service.</h4><blockquote><strong>Note:</strong> The example below dont have persistent volume unlike the weaviate service . So if the pod is being recreated then we have to pull and run the model again.</blockquote><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: ollama-generative-service<br>  namespace: dev-ai<br>spec:<br>  selector:<br>    app: ollama-generative<br>  type: NodePort<br>  ports:<br>    - port: 11434<br>      targetPort: 11434<br>      nodePort: 32004<br><br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: ollama-generative<br>  namespace: dev-ai<br>  labels:<br>    app: ollama-generative<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: ollama-generative<br>  strategy:<br>    type: Recreate<br>  template:<br>    metadata:<br>      labels:<br>        app: ollama-generative<br>    spec:<br>      containers:<br>      - name: ollama-generative<br>        image: ollama/ollama:latest<br>        #command: [&quot;ollama --version&quot;, &quot;ollama pull llama3.2&quot;, &quot;ollama run llama3.2&quot;]<br>        resources:<br>          requests:<br>            memory: &quot;10Gi&quot;<br>            cpu: &quot;500m&quot;<br>        ports:<br>        - name: http<br>          containerPort: 11434<br>        imagePullPolicy: IfNotPresent</pre><p>After deploying or applying the <em>Ollama </em>Service and Deployment<em> </em>object<em>, we </em>need to pull and run the <a href="https://ollama.com/library"><em>models</em></a> we want. I use <em>llama3.2 </em>model.</p><pre>kubectl exec --stdin --tty -n dev-ai {CONTAINER_NAME} -- bin/bash<br><br># Pull and run model<br>ollama pull llama3.2<br>ollama run llama3.2</pre><p>Testing <a href="https://weaviate.io/platform"><em>Weaviate</em></a> and <a href="https://ollama.com/"><em>Ollama</em></a><em> </em>Service. I’m using <a href="https://medium.com/@marjune/colima-kubernetes-making-containerized-applications-within-pods-accessible-54172c078458"><em>Colima to run Kubernetes</em></a> locally and exposing a <a href="https://kubernetes.io/docs/concepts/services-networking/service/">Service</a> outside the cluster through the <strong>address</strong> below.</p><pre>% colima list<br>PROFILE       STATUS     ARCH       CPUS    MEMORY    DISK     RUNTIME       ADDRESS<br>default       Running    aarch64    2       15GiB     60GiB    docker+k3s    192.168.106.2</pre><p>Get services under <em>dev-ai </em>namespace.</p><pre>% kubectl get service -n dev-ai -o wide<br>NAME                        TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)                          AGE   SELECTOR<br>ollama-generative-service   NodePort   10.43.83.61    &lt;none&gt;        11434:32004/TCP                  1d    app=ollama-generative<br>weaviate-service            NodePort   10.43.14.186   &lt;none&gt;        8080:32001/TCP,50051:32002/TCP   1d    app=weaviate-server</pre><p>Simple curl for <a href="https://weaviate.io/platform"><em>Weaviate</em></a> and <a href="https://ollama.com/"><em>Ollama</em></a><em> s</em>ervice outside the Kubernetes cluster.</p><pre># weaviate<br>curl -I 192.168.106.2:32001/v1/.well-known/ready<br>HTTP/1.1 200 OK<br><br># Ollama<br>curl 192.168.106.2:32004 <br>Ollama is running</pre><p>Both services are up and running.</p><blockquote><strong>Note:</strong> I tested it outside the Kubernetes cluster so I have to use the NodePort. Testing it within the cluster i.e run a pod as client then the <a href="https://weaviate.io/platform">Weaviate</a> and <a href="https://ollama.com/">Ollama</a> service can be directly invoke as follow,</blockquote><blockquote><strong>curl -I {WEAVIATE_SERVICE_NAME}:8080/v1/.well-known/ready</strong><br><strong>curl {OLLAMA_SERVICE_NAME}:11434</strong></blockquote><h3>Vectorizing Internal Data and RAG (Retrieval Augmented Generation) iImplementation.</h3><p>This implementation serves as a proof of concept for what I envision.</p><h4>Requirements.txt</h4><p>Packages required to install.</p><pre>weaviate-client<br>python-dotenv<br>ollama</pre><h4>Dockerfile.</h4><p>Building my docker file with docker build . -t cerevisiae:0.0.0-omega</p><pre>FROM python:3.11-slim<br><br>RUN pip install --upgrade pip<br>RUN apt-get -y update &amp;&amp; apt-get -y install vim &amp;&amp; \<br>    apt-get -y install curl<br><br>RUN useradd -m cerevisiae<br>USER cerevisiae<br>RUN mkdir /home/cerevisiae/app<br>WORKDIR /home/cerevisiae/app<br><br>ENV PATH=&quot;/home/cerevisiae/.local/bin:$PATH&quot;<br>ENV PYTHONPATH=/home/cerevisiae/app<br><br>COPY --chown=cerevisiae:cerevisiae requirements.txt .<br>COPY --chown=cerevisiae:cerevisiae ./src/ .<br><br>RUN python -m ensurepip --default-pip &amp;&amp; \<br>    pip install --no-cache-dir --upgrade pip &amp;&amp; \<br>    pip install --no-cache-dir -r requirements.txt<br><br>CMD [&quot;/bin/sh&quot;]</pre><h4>Pod client.</h4><p>Creating a pod for my client to test RAG.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  namespace: dev-ai<br>  name: cerevisiae<br>  labels:<br>    app: cerevisiae<br>spec:<br>  containers:<br>  - name: cerevisiae<br>    image: cerevisiae:0.0.0-omega<br>    command:<br>        - &quot;/bin/sh&quot;<br>        - &quot;-c&quot;<br>        - &quot;while true; do sleep 6000; done&quot;<br>    imagePullPolicy: IfNotPresent</pre><h4>Internal Data.</h4><p>I needed something to serve as my internal data, so I used this <a href="https://www.nba.com/news/history-this-date-in-nba-jan">https://www.nba.com/news/history-this-date-in-nba-jan</a> and formatted it as <em>history_this_date_in_nba_jan.json</em></p><pre>[<br>  {<br>    &quot;when&quot;: &quot;Jan. 1, 1974&quot;,<br>    &quot;text&quot;: &quot;Ernie DiGregorio of Buffalo handed out 25 assists in the Braves’ 120-119 win over Portland, establishing a single-game record for assists by a rookie. Seattle’s Nate McMillan tied DiGregorio’s mark in a game against the Los Angeles Clippers on February 23, 1987.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  },<br>  {<br>    &quot;when&quot;: &quot;Jan. 1, 1979&quot;,<br>    &quot;text&quot;: &quot;John Y. Brown attended his first game as owner of the Boston Celtics. Brown, the former owner of the Buffalo Braves, and Irving H. Levin, who had owned the Celtics, decided to “trade” franchises in June of 1978. This unprecedented maneuver brought about the eventual relocation of the Buffalo Braves and the name change to the San Diego Clippers before the 1978-79 season.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  },<br>  {<br>    &quot;when&quot;: &quot;Jan. 1, 2012&quot;,<br>    &quot;text&quot;: &quot;All-Star Jimmy Butler made his Chicago Bulls’ debut in in a 104-64 win over the Memphis Grizzlies.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  },<br>  {<br>    &quot;when&quot;: &quot;Jan. 1, 2020&quot;,<br>    &quot;text&quot;: &quot;NBA Commissioner Emeritus David Stern dies at 77 after a nearly month-long battle with a brain hemorrhage. Stern had been involved with the NBA for nearly two decades before he became its fourth commissioner on Feb. 1, 1984. By the time he left his position in 2014, a league that fought for a foothold before him had grown to a more than $5 billion a year industry and made NBA basketball perhaps the world’s most popular sport.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  },<br>  {<br>    &quot;when&quot;: &quot;Jan. 2, 1987&quot;,<br>    &quot;text&quot;: &quot;The Indiana Pacers beat the Los Angeles Clippers 116-106 to give Coach Jack Ramsay his 800th NBA victory, at the time one of only two coaches (along with Red Auerbach) to reach that plateau.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  },<br>  {<br>    &quot;when&quot;: &quot;Jan. 2, 2000&quot;,<br>    &quot;text&quot;: &quot;19,600 fans watched the Miami Heat defeat the Orlando Magic, 111-103 in the first game at the Heat’s new American Airlines Arena.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  },<br>  {<br>    &quot;when&quot;: &quot;Jan. 2, 2021&quot;,<br>    &quot;text&quot;: &quot;Phoenix Suns legend and Hall of Famer Paul Westphal dies at age 70 in Arizona. A five-time All-Star, Westphal played in the NBA from 1972-84. After winning a championship with the Celtics, he made the finals in 1976 with Phoenix and, after his playing career ended, Westphal was the Suns coach. He guided Phoenix to the 1993 Finals and was also the coach of Seattle and Sacramento.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  },<br>  {<br>    &quot;when&quot;: &quot;Jaunary 2, 2023&quot;,<br>    &quot;text&quot;: &quot;Cleveland Cavaliers guard Donovan Mitchell sets a franchise record with 71 points, most by any player in 17 years, as the Cavaliers rallied from 21 down to beat the Chicago Bulls 145-134 in overtime. Mitchell’s total matched the eighth-highest in league history and marked the most points by an NBA player since Lakers great Kobe Bryant scored 81 against Toronto on Jan. 22, 2006. Wilt Chamberlain owns the NBA record with 100 for Philadelphia against New York on March 2, 1962, at Hershey, Pa.&quot;,<br>    &quot;source&quot;: &quot;https://www.nba.com/news/history-this-date-in-nba-jan&quot;<br>  }<br>]</pre><p>I want the source to be emphasized during the augmented response from LLM so the user can go through it.</p><h4>.env</h4><pre># weaviate<br>WEAVIATE_HTTP_PORT=8080<br>WEAVIATE_HOST=&quot;weaviate-service&quot;<br>WEAVIATE_GRPC_PORT=50051<br>WEAVIATE_COLLECTION=&quot;docs&quot;<br>EMBEDDING_MODEL=&quot;mxbai-embed-large&quot;<br><br><br># ollama<br>OLLAMA_API_ENDPOINT=&quot;ollama-generative-service&quot;<br>OLLAMA_PORT=11434<br>OLLAMA_MODEL=&quot;llama3.2&quot;</pre><h4>config.py</h4><pre>import os<br>from dotenv import load_dotenv<br><br>load_dotenv()<br><br>class Settings:<br>    WEAVIATE_HTTP_PORT: int = os.getenv(&quot;WEAVIATE_HTTP_PORT&quot;)<br>    WEAVIATE_HOST: int = os.getenv(&quot;WEAVIATE_HOST&quot;)<br>    WEAVIATE_GRPC_PORT: int = os.getenv(&quot;WEAVIATE_GRPC_PORT&quot;)<br>    WEAVIATE_COLLECTION: str = os.getenv(&quot;WEAVIATE_COLLECTION&quot;)<br>    OLLAMA_API_ENDPOINT: int = os.getenv(&quot;OLLAMA_API_ENDPOINT&quot;)<br>    OLLAMA_PORT: int = os.getenv(&quot;OLLAMA_PORT&quot;)<br>    OLLAMA_MODEL: str = os.getenv(&quot;OLLAMA_MODEL&quot;)<br>    EMBEDDING_MODEL: str = os.getenv(&quot;EMBEDDING_MODEL&quot;)<br><br>config = Settings()</pre><h4>weaviate_client.py</h4><pre>import weaviate<br>from config import config<br><br># https://weaviate.io/developers/weaviate/connections/connect-custom<br><br>client = weaviate.connect_to_custom(<br>    http_host=config.WEAVIATE_HOST,<br>    http_port=config.WEAVIATE_HTTP_PORT,<br>    http_secure=False,<br>    grpc_host=config.WEAVIATE_HOST,<br>    grpc_port=config.WEAVIATE_GRPC_PORT,<br>    grpc_secure=False<br>)<br><br>print(&quot;weaviate client is ready: &quot;, client.is_ready())  # Should print: `True`<br><br>#client.close()<br><br></pre><h4>ollama_client.py</h4><pre>from ollama import Client<br>from config import config<br><br>client = Client(host=f&quot;http://{config.OLLAMA_API_ENDPOINT}:{config.OLLAMA_PORT}&quot;)</pre><h4>create_weaviate_collection.py</h4><p>This code will create a <a href="https://weaviate.io/developers/weaviate/manage-data/collections"><em>collection</em></a> in <a href="https://weaviate.io/platform">Weaviate</a> where we store our vector embeddings and the data above.</p><pre>import weaviate<br>import weaviate.classes as wvc<br>from weaviate.classes.config import Configure<br>from weaviate_client import client as weaviateClient<br>from config import config<br><br>API_ENPOINT = f&quot;http://{config.OLLAMA_API_ENDPOINT}:{config.OLLAMA_PORT}&quot;<br><br># creating collection<br>try:<br>    collection = weaviateClient.collections.create(<br>        name=config.WEAVIATE_COLLECTION,<br>        vectorizer_config=Configure.Vectorizer.text2vec_ollama(<br>            api_endpoint=API_ENPOINT,<br>            model=config.EMBEDDING_MODEL,<br>        ),<br>        generative_config=Configure.Generative.ollama(<br>            api_endpoint=API_ENPOINT,<br>            model=config.OLLAMA_MODEL,<br>        ),<br>        properties=[<br>            wvc.config.Property(<br>                name=&quot;when&quot;,<br>                data_type=wvc.config.DataType.TEXT,<br>            ),<br>            wvc.config.Property(<br>                name=&quot;text&quot;,<br>                data_type=wvc.config.DataType.TEXT,<br>            ),<br>            wvc.config.Property(<br>                name=&quot;source&quot;,<br>                data_type=wvc.config.DataType.TEXT,<br>            )<br>        ]<br>    )<br>    print(collection.config.get(simple=False))<br>except Exception as e:<br>    print(e)<br>finally:<br>    weaviateClient.close()</pre><h4>import_data.py</h4><p>Once the data above is imported, everything is ready to go.</p><pre>import json<br>from weaviate_client import client as weaviateClient<br>from config import config<br>import weaviate.classes as wvc<br><br><br>docs = list()<br>file = open(&#39;history_this_date_in_nba_jan.json&#39;)<br>data = json.load(file)<br>collection = weaviateClient.collections.get(config.WEAVIATE_COLLECTION)<br><br>with collection.batch.dynamic() as batch:<br> for doc in data:<br>  batch.add_object(<br>   {<br>    &quot;when&quot;: doc[&quot;when&quot;],<br>    &quot;text&quot;: doc[&quot;text&quot;],<br>    &quot;source&quot;: doc[&quot;source&quot;]<br>   }<br>  )<br><br>failed_objects = collection.batch.failed_objects<br>if failed_objects:<br> print(f&quot;Number of failed imports: {len(failed_objects)}&quot;)<br> print(f&quot;First failed object: {failed_objects[0]}&quot;)<br><br>file.close()<br>weaviateClient.close()</pre><h4>query.py</h4><pre>import sys<br>import json<br>from weaviate_client import client as weaviateClient<br>from ollama_client import client as ollamaClient<br>from config import config<br><br>class RAG:<br>    def __init__(self, data, query):<br>        try:<br>            output = ollamaClient.generate(<br>                model=config.OLLAMA_MODEL,<br>                prompt=f&quot;Using this data: {data}. Respond to this prompt: {query} and include the source&quot;<br>            )<br>            self.response = output[&#39;response&#39;]<br>        except Exception as e:<br>            print(e)<br><br>    def printResponse(self):<br>        print(self.response)<br><br>class Query:<br><br>    def weaviate(self, query):<br>        print(&quot;[QUERY]:&quot;, query)<br>        docs = weaviateClient.collections.get(config.WEAVIATE_COLLECTION)<br>        data = list()<br>        response = docs.query.near_text(query=query, limit=2)<br>        # print(&quot;[Results]: &quot;)<br>        for obj in response.objects:<br>            # print(json.dumps(obj.properties, indent=2))<br>            data.append(obj.properties)<br>        return data<br><br><br>if __name__==&quot;__main__&quot;:<br>    query = &#39; &#39;.join(sys.argv[1:])<br>    data = Query().weaviate(query)<br>    rag = RAG(data, query)<br>    rag.printResponse()<br><br>weaviateClient.close()  # Free up resources</pre><p>Run the <em>query.py </em>above with the following parameters.</p><pre>python query.py What is the longest game in NBA history and how many overtimes did it last?<br><br>[QUERY]: What is the longest game in NBA history and how many overtimes did it last?<br><br>The longest game in NBA history was played between the Indianapolis Olympians and the Rochester Royals on January 6, 1951. The game lasted six overtimes, with the Olympians ultimately emerging victorious by a score of 75-73.<br>Source: https://www.nba.com/news/history-this-date-in-nba-jan</pre><p>Now we got our augmented response from <em>Ollama!</em></p><p>If we ask a question out of scope from our internal data, e.g.</p><pre>python query.py why the sky is blue?<br><br>I think there may be a bit of a mismatch here! The data you provided seems to be related to NBA history, but the question &quot;why the sky is blue?&quot; is a scientific question that has a well-established answer.<br><br>The sky appears blue because of a phenomenon called Rayleigh scattering, named after the British physicist Lord Rayleigh, who first described it in the late 19th century. When sunlight enters Earth&#39;s atmosphere, it encounters tiny molecules of gases such as nitrogen and oxygen. These molecules scatter the shorter (blue) wavelengths of light more than the longer (red) wavelengths, giving the sky its blue color.<br><br>Here&#39;s a summary from NASA:<br><br>&quot;The Earth&#39;s atmosphere scatters sunlight in all directions. Blue light has a shorter wavelength and is scattered more than other colors by the tiny molecules of gases in the atmosphere. This is why the sky typically appears blue during the daytime.&quot;<br><br>Source:<br>NASA: &quot;Why is the Sky Blue?&quot; (https://www.nasa.gov/planetary/apod/archive/html/2013_03_12.html)</pre><h3>Final Thoughts.</h3><p>Based on my practical use case where I use <a href="https://api.slack.com/docs/apps"><em>slack-app</em></a>, and <a href="https://api.slack.com/interactivity/slash-commands"><em>slash-commands</em></a><em>. </em>Automating the retrieval of information is a very promising integration with vector-embeddings and LLM as a reasoning engine.</p><p><em>More advanced tools like </em><a href="https://platform.openai.com/docs/guides/function-calling?api-mode=chat"><em>function-calling</em></a><em> </em>are also interesting for<em> </em><a href="https://www.ibm.com/think/topics/agentic-workflows"><em>agentic workflows</em></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac099dcf468e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blue/Green Deployment in Kubernetes using Jenkins Declarative Pipeline.]]></title>
            <link>https://medium.com/@marjune/blue-green-deployment-in-kubernetes-using-jenkins-declarative-pipeline-b5ad8e40f9c3?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5ad8e40f9c3</guid>
            <category><![CDATA[groovy]]></category>
            <category><![CDATA[blue-green-deployment]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Sat, 01 Feb 2025 15:34:06 GMT</pubDate>
            <atom:updated>2025-02-20T11:19:11.956Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://docs.aws.amazon.com/whitepapers/latest/overview-deployment-options/bluegreen-deployments.html">Blue/Green deployment</a> is now the standard deployment strategy for any application with zero downtime and quick rollback unless an alternative is chosen for a specific reason.</p><p>I’ll create a continuous deployment using <em>Jenkins</em> declarative pipeline with a <a href="https://docs.aws.amazon.com/whitepapers/latest/overview-deployment-options/bluegreen-deployments.html">Blue/Green</a> strategy in <em>Kubernetes</em>.</p><h3>Setting up Jenkins.</h3><p>Since I’m using Kubernetes to deploy my application with Blue/Green, I’ll also deploy <em>Jenkins</em> in the same cluster with a different namespace.</p><p>I’m following <a href="https://www.jenkins.io/doc/book/installing/kubernetes/#setup-jenkins-on-kubernetes"><em>setup-jenkins-on-kubernetes</em></a>, with a few changes. For my <em>Jenkins</em> to update/manage deployment, I added <a href="https://kubernetes.io/docs/reference/kubectl/"><em>kubectl</em></a> command line tool and rebuilt a new docker image with the <em>Dockerfile </em>below.</p><pre>FROM jenkins/jenkins:lts<br><br>USER root<br>RUN apt-get update -y<br>RUN apt-get install -y wget<br>RUN wget https://dl.k8s.io/v1.31.2/bin/linux/amd64/kubectl<br>RUN chmod +x kubectl<br>RUN mv kubectl /usr/local/bin/</pre><p>And proceed with <a href="https://www.jenkins.io/doc/book/installing/kubernetes/#setup-jenkins-on-kubernetes"><em>setup-jenkins-on-kubernetes</em></a><em> </em>with the new image. I added <em>k8s.local </em>in my /etc/hosts as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*o2Kw3boiZ_5ltn4PUoINPQ.png" /><figcaption>Jenkins in 32000 node port.</figcaption></figure><p><em>Jenkins</em> is up and running, we’re good to go.</p><h3>Application Architecture.</h3><p>In a <a href="https://docs.aws.amazon.com/whitepapers/latest/overview-deployment-options/bluegreen-deployments.html">Blue/Green</a> setup, we create two identical environments. One environment is <em>Blue </em>which will be the production and the other one is <em>Green </em>where the new version of the application will be deployed, switching back and forth during deployment/rollback.</p><p>In our sample application, we also have two services, production, and test. Switching the test service during deployment to the <em>Green</em> environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_5khOsE1lJvOXnno94Tsg.png" /></figure><h4>Application Dockerfile.</h4><pre>FROM nginx<br><br>COPY ./index.html /usr/share/nginx/html/index.html</pre><h4>Application version.</h4><p>To mimic the application versions, update the HTML e.g &lt;h1&gt;This is Version 1&lt;/h1&gt;. Then build a new docker image i.e. docker build . -t web-app:v1</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Welcome to nginx!&lt;/title&gt;<br>&lt;style&gt;<br>html { color-scheme: light dark; }<br>body { width: 35em; margin: 0 auto;<br>font-family: Tahoma, Verdana, Arial, sans-serif; }<br>&lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br><br>&lt;h1&gt;This is Version 1&lt;/h1&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h4>Namespace.</h4><pre>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: web</pre><h4>Services for production and testing.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7e87a5411d3760628e409dbc24d2445/href">https://medium.com/media/f7e87a5411d3760628e409dbc24d2445/href</a></iframe><h4>Deployments for Blue and Green.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3006136414e81691d01b3927c77a30bf/href">https://medium.com/media/3006136414e81691d01b3927c77a30bf/href</a></iframe><p>Once the objects above are created, we can proceed with deployment.</p><blockquote>Services. In initial setup the svc-web-app-test is pointing to the prod or</blockquote><blockquote>web-app-a the same with the production.</blockquote><pre>kubectl get svc -n web -o wide<br>NAME               TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE     SELECTOR<br>svc-web-app        NodePort   10.43.37.170   &lt;none&gt;        8081:30654/TCP   7h22m   app=web-app-a<br>svc-web-app-test   NodePort   10.43.66.230   &lt;none&gt;        8081:30655/TCP   7h22m   app=web-app-a</pre><blockquote>Deployment environments. web-app-b has no pods since we’re not deploying new version of our app yet.</blockquote><pre>kubectl get deployment -n web -o wide<br>NAME        READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES       SELECTOR<br>web-app-a   2/2     2            2           15s   web-app-a    web-app:v1   app=web-app-a,environment=blue<br>web-app-b   0/0     0            0           15s   web-app-b    web-app:v1   app=web-app-b,environment=green</pre><p>For now, our <em>web-app-b</em> deployment is scaled down to zero. <em>web-app-a(</em><strong><em>blue)</em></strong> serving as production.</p><blockquote>Pods. All pods belongs to web-app-a as our initial setup.</blockquote><pre>kubectl get pods -n web -o wide<br>NAME                         READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES<br>web-app-a-5c9465f88b-6mx4m   1/1     Running   0          10m   10.42.0.28   colima   &lt;none&gt;           &lt;none&gt;<br>web-app-a-5c9465f88b-7xkhb   1/1     Running   0          10m   10.42.0.27   colima   &lt;none&gt;           &lt;none&gt;</pre><p>Check if our production service is working, we can access it below. <br>web-app-a service <em>NodePort </em>is 30654.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6W-UA03OsVvX61cnhjaNw.png" /></figure><blockquote>To deploy new version, kindly update the html and build new image.<br>After deployment with a new version using the pipeline below.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dg4RQCYRZaCn1atpUxmvfA.png" /></figure><h3>Jenkins Deployment Pipeline.</h3><p>Now we’re ready to create a pipeline and let <em>Jenkins</em> manage the deployment.</p><h4>Jenkinsfile.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9fee169363c72b6bc489b9d26da17da/href">https://medium.com/media/b9fee169363c72b6bc489b9d26da17da/href</a></iframe><blockquote>Note: The parameters are hard coded, in reality it should be dynamic from your docker repository showing certain number of versions available to deploy.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9YO4bXdOXa2vW2RhhQGmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXMMjMctkA23a4AuiZNbnw.png" /></figure><h4>Pipeline Stages.</h4><p>In our deployment pipeline we have five stages which is arbitrary, we can add more if we want.</p><h4>Evaluate Environment.</h4><p>This stage determines which environment is <em>Blue</em> and <em>Green.</em></p><h4>Deploying to the Green environment.</h4><ol><li>First, get the current replicas in <em>Blue </em>and use that number to scale out the <em>Green </em>environment.</li><li>Update the <em>Green </em>environment to the new version.</li><li>Switch the test service to <em>Green </em>and scale out to match the number of <em>Blue</em> replicas.</li></ol><h4>Testing.</h4><p>In the testing stage, all sorts of testing can be done here automated or manual. In our example, it’s just a simple test to see if the new version is up. If the latest version has issues, the deployment will fail after five minutes. Tho, this is just an arbitrary figure it can be updated.</p><h4>Deployment Approval.</h4><p>This stage requires manual approval — go or abort. Approval should not be later than five minutes otherwise the deployment will be aborted.</p><h4>Switch Traffic to Green.</h4><p>Finally, this stage will be the time to switch the environment label from <em>Green</em> to <em>Blue</em> and vice versa as well as the production’s traffic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5ad8e40f9c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Kubernetes by setting up a cluster and its components manually.]]></title>
            <link>https://medium.com/@marjune/learning-kubernetes-by-setting-up-a-cluster-and-its-components-manually-ac86ee84c221?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac86ee84c221</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[etcd]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Sun, 26 Jan 2025 19:04:38 GMT</pubDate>
            <atom:updated>2025-01-27T14:02:24.650Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes has too many tools and jargon scattered around, and it’s overwhelming. The best way to learn is to understand the core components of K8s and put the pieces together. This way, we should gain a fundamental understanding of how it works.</p><blockquote><a href="https://kubernetes.io/docs/concepts/overview/">Overview</a></blockquote><blockquote>Kubernetes is a portable, extensible, open source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.</blockquote><p>I‘ll set up my k8s cluster from scratch and install each component manually for learning purposes. I’ll enter the <em>Chamber of Secrets </em>voluntarily to face the <em>Serpent, </em>and<em> </em>get my hands dirty while enjoying the journey.</p><blockquote>That which we need the most will be found where we least want to look.</blockquote><h3>Core components.</h3><p>In K8s <a href="https://kubernetes.io/docs/concepts/overview/components/">documentation</a>, these are the key components of Kubernetes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8edPB1eprXDuqx7GG3-Ciw.png" /><figcaption>Kubernetes key com</figcaption></figure><h4>Control plane.</h4><p><a href="https://kubernetes.io/docs/concepts/architecture/#etcd"><em>ectd</em></a><em>, </em><a href="https://kubernetes.io/docs/concepts/architecture/#kube-apiserver"><em>kube-api-server</em></a><em>, </em><a href="https://kubernetes.io/docs/concepts/architecture/#kube-scheduler"><em>scheduler</em></a><em>, </em><a href="https://kubernetes.io/docs/concepts/architecture/#kube-controller-manager"><em>controller manager</em>,</a> and <a href="https://kubernetes.io/docs/concepts/architecture/#cloud-controller-manager"><em>cloud controller manager</em></a><em>.</em></p><h4>Worker node.</h4><p><a href="https://kubernetes.io/docs/concepts/architecture/#kubelet"><em>kubelet</em></a><em>, </em><a href="https://kubernetes.io/docs/concepts/architecture/#kube-proxy"><em>kube-proxy</em></a><em>, and </em><a href="https://kubernetes.io/docs/concepts/architecture/#container-runtime"><em>container-runtime</em></a><em>.</em></p><blockquote>I’m following this <a href="https://github.com/kelseyhightower/kubernetes-the-hard-way">Guide</a>.</blockquote><h3>Setting up a k8s cluster.</h3><p>I’m using AWS to set up the k8s cluster by provisioning EC2 instances for control planes, and worker nodes. Install and configure each component where it should belong. As shown in the diagram below. Two instances for control planes, two for worker nodes for high availability in case one machine crashes, and a single instance that will serve as a load balancer for k8s API that resides in control planes. The best practice is that it should be auto-scaled but I’m not going to this time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ky2VjpWVgDSH37plaoT_9Q.png" /><figcaption>Kubernetes Cluster.</figcaption></figure><p>I’m using Terraform to provision these instances above and manually install each component in control planes and worker nodes. I published the entire script in my GitHub repo (<a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually"><em>kubernetes-cluster-setup-manually</em></a>).</p><h4>Compute resources.</h4><p>Terraform scripts are in<em> </em><a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/tree/main/compute-resources"><em>compute-resources</em></a><em>.</em></p><p>Once the instances are up and running, we are good to start. I’m using Ubuntu ami, <em>t2.micro </em>instance types for the load balancer, and worker nodes while <em>t2.medium </em>for control planes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IgFA_mHyhoaxW5LZeu0niQ.png" /><figcaption>K8s cluster with 5 instances.</figcaption></figure><h4>Utilities.</h4><p>I’m using the <em>k8-api-load-balancer</em> instance as my jump host where I have to generate certificates and other configurations before copying to the rest of the instances. Installing these <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/client/utilities.sh"><em>utilities.sh</em></a>, and <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/client/kubectl.sh"><em>kubectl.sh</em></a> for our <a href="https://kubernetes.io/docs/reference/kubectl/">command line tool</a> to interact with the k8s API as a user.</p><h4>Certificates.</h4><p>The first thing to prepare before configuring the k8s cluster is the <a href="https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/">certificates</a> where k8s components and <a href="https://kubernetes.io/docs/concepts/security/service-accounts/">service accounts</a> require <a href="https://kubernetes.io/docs/reference/access-authn-authz/authentication/">authentication</a> in interacting with k8s API.</p><p>These scripts;<em> </em><a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/certificates/ca.conf"><em>config.conf</em></a><em>, </em><a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/certificates/ca.sh"><em>ca.sh</em></a> (to generate <em>ca.crt, </em>and <em>ca.key</em>). Using <em>openssl</em>.</p><ol><li>Execute this <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/certificates/client-server-cert.sh"><em>client-server-cert.sh</em></a> for our <em>admin </em>user and k8s components certificates.</li><li>Once everything is generated, distribute these<em> .key, </em>and<em> .crt</em> <br> into the rest of the instances. <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/certificates/scp-to-control-planes.sh"><em>scp-to-control-planes.sh</em></a> and <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/certificates/scp-to-worker-nodes.sh"><em>scp-to-worker-nodes.sh</em></a></li></ol><h4>/etc/hosts.</h4><p>I updated the <em>/etc/hosts </em>in my five instances with <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/hosts/hosts.txt">hosts.txt</a>.</p><h4>Load balance the control plane servers.</h4><p>In preparation for our k8s API, and the rest of the control plane components, Creating an <em>nginx </em>proxy to load balance the two control plane instances.</p><ol><li>Installing <em>nginx</em> in <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/load-balance-control-planes/nginx.sh"><em>nginx.sh</em></a>, and creating a configuration file.</li><li>I updated as well the <em>/etc/nginx/nginx.conf </em>file to add <br>include /etc/nginx/tcpconf.d/*</li><li>Then reloading the <em>nginx </em><em>sudo nginx -s reload</em></li></ol><h4>Control Planes.</h4><p>Everything is good so far, I’m now ready to start configuring control plane components in both of my 2 instance intended for it.</p><ol><li>Starting with the <a href="https://kubernetes.io/docs/concepts/architecture/#etcd"><em>ectd</em></a>, the key-value store for k8s cluster data. <br> Downloading(<a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/etcd.sh"><em>etcd.sh</em></a>) <a href="https://kubernetes.io/docs/concepts/architecture/#etcd"><em>ectd</em></a> and creating <a href="https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files"><em>unit file</em></a><em> </em>that systemd will manage.</li><li><a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/kube-components.sh"><em>kube-components.sh</em></a><em> </em>will download the binary components necessary and move them into <em>/usr/local/bin/. </em>Including as well the <em>kubectl </em>command line tool.</li><li>Generate <em>encryption-config.yaml</em> which is the <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/encryption.sh"><em>encryption.sh</em></a><em> </em>script<em> </em>will do. K8s will use this to <a href="https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/">encrypt data at rest</a>.</li><li>Generating <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/kube-config.sh"><em>kube-config.sh</em></a> to <a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/">organize cluster access</a> for control plane components such as <a href="https://kubernetes.io/docs/concepts/architecture/#kube-scheduler"><em>scheduler</em></a><em>, </em>and<em> </em><a href="https://kubernetes.io/docs/concepts/architecture/#kube-controller-manager"><em>controller manager</em></a><em>. </em>The scripts will also copy the <em>.crt, .key, .kubeconfig, </em>and the <em>encryption-config.yaml </em>into <em>/var/lib/kubernetes/ </em>directory.</li><li>The control plane setup is almost done, just the <a href="https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files"><em>unit file</em></a><em> </em>for <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/kube-apiserver.sh"><em>apiserver.sh</em></a>, <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/kube-controller-manager.sh"><em>kube-controller-manager.sh</em></a>, and <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/kube-scheduler.sh"><em>kube-scheduler.sh</em></a><em>.</em></li><li>Everything is good. Now, to start the services above with <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/control-planes/start-kube-components.sh"><em>start-kube-components.sh</em></a><em>.</em></li></ol><blockquote>Note: <a href="https://kubernetes.io/docs/concepts/architecture/#cloud-controller-manager">cloud controller manager</a> is excluded since it’s optional.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lrbjk0fjo0P1A_XQ0u6Y3w.png" /><figcaption>etcd status</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQWraONbWc1qAn-jJzqxJg.png" /><figcaption>sudo etcdctl member list in one of the control nodes.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xwXC4NSvGqiI791OmCRQw.png" /><figcaption>kube-apiserver, kube-controller-manage, and kube-scheduler service status.</figcaption></figure><p>All necessary services for control plane components are up and running.</p><h4>Testing K8s API.</h4><p>In <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/testing/test-kubernetes-api.sh"><em>test-kubernetes-api.sh</em></a><em> </em>curl commands to test the k8s API. And test some <em>kubectl </em>commands as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*knyNztcycpWveHZB7HTVsQ.png" /></figure><p>This can be done either in control planes or in the load balancer, it requires the <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/client/admin-kube-config.sh"><em>admin-kube-config.sh</em></a><em> </em>there.</p><h4>Worker Nodes.</h4><p>Since worker nodes are not yet ready, it will show <strong><em>No resource found </em></strong>if I run kubectl get nodes --kubeconfig admin.kubeconfig</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hykWKuTwC2FVM5AaCyWN9g.png" /><figcaption>getting nodes if worker nodes are not yet ready.</figcaption></figure><p>Installing and configuring worker node components.</p><ol><li>Downloading the binary and installation, <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/components.sh"><em>components.sh</em></a><em>. </em>As well as the <em>kubectl </em><a href="https://kubernetes.io/docs/reference/kubectl/"><em>command line tool</em></a><em>.</em></li><li>Creating <em>containerd</em> <em>config.toml </em>and <a href="https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files"><em>unit file</em></a><em> </em><a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/containerd.sh"><em>containerd.sh</em></a><em>.</em></li><li>Create <em>bridge.conf </em>and <em>loopback.conf </em>for <a href="https://github.com/kelseyhightower/kubernetes-the-hard-way/blob/master/docs/09-bootstrapping-kubernetes-workers.md#configure-cni-networking">configure-cni-networking</a>, <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/worker-node-1-network.sh"><em>network.sh</em></a></li><li>Generate <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/worker-node-1-kubeconfig.sh"><em>kubeconfig.sh</em></a><em> </em>for kube-proxy and worker node to communicate the k8s API.</li><li>Create <a href="https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files"><em>unit files</em></a><em> </em>for <a href="https://kubernetes.io/docs/concepts/architecture/#kubelet"><em>kubelet</em></a>(<a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/worker-node-1-kubelet.sh"><em>kubelet.sh</em></a><em>) </em>and <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/kube-proxy.sh"><em>kube-proxy.sh</em></a></li><li>Applying <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/"><em>RBAC</em></a> for k8s api to access <a href="https://kubernetes.io/docs/concepts/architecture/#kubelet"><em>kubelet</em></a> in worker-nodes. <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/rbac-kubelet-auth.sh"><em>rbac-kubelet-auth.sh</em></a><em>.</em></li><li>Worker nodes are now done. Starting the services in <a href="https://github.com/mrjbtc/kubernetes-cluster-setup-manually/blob/main/worker-nodes/start-worker-components.sh"><em>start-worker-components.sh</em></a></li></ol><p>Getting the status of the three services should show them active and running below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EeBPTOtE_U3ecoreZ1eEgA.png" /><figcaption>sudo systemctl status containerd kube-proxy kubelet</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SnJJKy6jl2lMwVjg6P6SGQ.png" /><figcaption>kubectl get nodes — kubeconfig admin.kubeconfig</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*2JnCgqs9DxJ4-s_k6NRXyg.png" /></figure><p>And that’s it, k8s cluster from scratch is now up and running!!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3f4GBSnRIOPkbT_L" /><figcaption>Photo by <a href="https://unsplash.com/@zacdurant?utm_source=medium&amp;utm_medium=referral">Zac Durant</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The easy route.</h3><p>All the hassle above in setting up a cluster is very tedious, but it’s good for learning. Moving forward, most cloud providers like AWS have their <a href="https://aws.amazon.com/eks/">EKS</a>.</p><p>And also, there are a bunch of management tools out there for Kubernetes. To name a few like Helm, <a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/">Kubeadm</a>, <a href="https://minikube.sigs.k8s.io/docs/start/?arch=%2Fmacos%2Fx86-64%2Fstable%2Fbinary+download">Minikube</a>, and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac86ee84c221" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deconstructing Hamming code | Error correction | Simulation in Python.]]></title>
            <link>https://medium.com/@marjune/deconstructing-hamming-code-error-correction-6fd47b0e2311?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fd47b0e2311</guid>
            <category><![CDATA[paritybit]]></category>
            <category><![CDATA[hamming-code]]></category>
            <category><![CDATA[error-correction]]></category>
            <category><![CDATA[binary]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Thu, 21 Nov 2024 17:14:19 GMT</pubDate>
            <atom:updated>2024-11-24T19:57:00.268Z</atom:updated>
            <content:encoded><![CDATA[<p>Hamming code? Yes, it’s not a new thing. It was introduced in the 1950s, almost a century ago. So what is it?, it’s an error correction pioneered by <a href="https://en.wikipedia.org/wiki/Richard_Hamming">Richard_Hamming</a> back in the day. During the transmission of a <em>binary </em>message from machine A to machine B through a network, the receiving end has no clue what the original message was, if something went corrupted. The obvious alternative is to produce a copy of the entire message as a backup, but the issue is doubling or tripling the original message which is very inefficient.</p><p>Hence, by adding a few data called a <em>parity bit</em> in the original message; error correction is made possible without a huge increase of the total message. The total <em>parity bit</em> added in the message followed the formula <br><em>2ᴾ</em> ≥ <em>m</em> + <em>p</em> + <em>1</em>. Where <em>2ᴾ</em> is the total vector length of the binary message, <em>m is </em>the original message, and <em>p is </em>how many parity bits are added for error correction.</p><h3>Deconstructing Hamming Code.</h3><p>For example, if we send a simple message ”<strong><em>Hi</em></strong><em>”, </em>converting these two characters into binary will be “<strong><em>01001000 01101001</em></strong><em>”. </em>The binary conversion can be found at <a href="https://www.ascii-code.com/">https://www.ascii-code.com/</a>.</p><p>If one of the bits flips in our binary message<em>, </em>i.e. from <em>1 </em>to <em>0, </em>and vice versa; we can detect and correct them on the receiving end. Following the formula (<em>2ᴾ</em> ≥ <em>m</em> + <em>p</em> + <em>1</em>), determine how many parity bits <em>p </em>to add to our message.</p><p>Given:</p><p>Message: ”<strong><em>Hi</em></strong><em>”<br></em>Binary equivalent: “<strong><em>01001000 01101001</em></strong><em>” </em>and <em>m</em> vector length is <em>16.</em></p><p>let’s try <em>p = 5<br>2ᴾ</em> ≥ <em>m</em> + <em>p</em> + <em>1<br>2⁵ </em>≥ <em>16 </em>+ <em>5 </em>+ <em>1<br>32 </em>≥ 22 which is correct! So, we have to add <em>5</em> parity bits plus our <em>16-</em>bit message.</p><p>In the illustration below, our binary message plus the <em>5 </em>parity bits into an array with a length of <em>(m + p) = 21 </em>to understand how this works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K3jhNXl5-YM1bzNt2-ZIOQ.png" /></figure><h4>Parity bits positions.</h4><p>Before calculating the actual values of our parity bits [<strong><em>P1, P2, P3, P4, </em></strong>and<strong><em> P5</em></strong>], we must first understand their positions in the array in <em>1, 2, 4, 8, 16, ….. </em>and so on. As we can see the pattern, it’s in the power of <strong><em>2 </em></strong><em>i.e</em>. <strong><em>2⁰, 2¹, 2², 2³, 2⁴</em></strong>, ……. and so on.</p><h4>Even or Odd parity bits values.</h4><p>After establishing the positions of our parity bits, let’s now calculate their values relative to our binary message; we only have two types of parity bits, even or odd. Even is <em>0, </em>and odd is <em>1</em>.</p><blockquote>How to calculate the actual values of the parity bits?</blockquote><p><em>P1 position 1.</em> From position 1 add 1 bit, skip 1, add 1 bit, skip 1, …. and so on.<br><em>P2 position 2.</em> From position 2 add 2 bits, skip 2, add 2 bits, … and so on.<br><em>P3 position 4. </em>From position 4 add 4 bits, skip 4, add 4 bits, … and so on.<br><em>P4 position 8. </em>From position 8 add 8 bits, skip 8, add 8 bits, … and so on.<br><em>P5 position 16. </em>From position 16 add 16 bits, skip 16, add 16 bits, … and so on.</p><p><strong><em>Excluding the parity bits positions(1, 2, 4, 8, 16, and so on ….) into the calculation, the starting point is always at the position of the parity bit.</em></strong></p><p>Hopefully, the visual illustrations below for each parity bit calculation are clear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kToXdt0yAd8sjuZd00y2dw.png" /><figcaption>P1 parity bit calculation.</figcaption></figure><p><strong><em>P1 </em></strong><em>(3 + 5 + 7 + 9 + 11 + 13 +15 + 17 + 19 + 21) = </em><strong><em>4 which is even (0)</em></strong><em>. </em>It excludes position 1 since it’s a parity bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fGwjTlTi-sNPoSQhZxddMQ.png" /><figcaption>P2 parity bit calculation.</figcaption></figure><p><strong><em>P2 </em></strong><em>(3 + 6 + 7 + 10 + 11 + 14 + 15 + 18 + 19) = </em><strong><em>3 which is odd (1)</em></strong><em>. </em>It excludes position 2 since it’s a parity bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kMRCBKgJCL7VB17O0ZMBA.png" /><figcaption>P3 parity bit calculation.</figcaption></figure><p><strong><em>P3 </em></strong><em>(5 + 6 + 7 + 12 + 13 + 14 + 15 + 20 + 21) = </em><strong><em>4 which is even (0)</em></strong><em>. </em>It excludes position 4 since it’s parity bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zZg1Fdcwe0_Zyc-MN0-RXg.png" /><figcaption>P4 parity bit calculation.</figcaption></figure><p><strong><em>P4 </em></strong><em>(9 + 10 + 11 + 12 + 13 + 14 + 15) = </em><strong><em>3 which is odd (1)</em></strong><em>. </em>It excludes position 8 since it’s a parity bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66KFfzujdVM9B1S6x6TdMQ.png" /><figcaption>P5 parity bit calculation.</figcaption></figure><p><strong><em>P5 </em></strong><em>(17 + 18 + 19 + 20 + 21) =</em><strong><em> 2 which is even (0)</em></strong><em>. </em>It excludes position 16 since it’s a parity bit.</p><p>As mentioned earlier <strong><em>Even = 0, </em></strong>and<strong> <em>Odd = 1</em></strong><em>. </em>Now, the entire binary message plus the 5 parity bits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1CNl_5iyGTye_fSFiefoyQ.png" /><figcaption>Binary message plus the 5 parity bits.</figcaption></figure><h4>Error detection and correction.</h4><p>The final piece of the puzzle is, how error detection and correction work with the help of the parity bits. By simulating an error in our binary message i.e. bit flip in position 13 from 0 to 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHFe3GH_GNGt9C4xt0V-Ng.png" /><figcaption>Error in the binary message i.e the bit flip.</figcaption></figure><p>Original parity bits are, <em>P1 = 0, P2 = 1, P3 = 0, P4 = 1, P5 = 0. </em>To detect and correct the error, let’s calculate our parity bits again the same calculation earlier.</p><p>New parity bits after the error. <br><strong>P1 = 1</strong><br>P2 = 1<br><strong>P3 = 1 </strong><br><strong>P4 = 0</strong><br>P5 = 0</p><p>Comparing the original parity bits to the new ones will show a discrepancy for some parity bits, specifically <em>P1</em>, <em>P3, and P4</em>; the rest are okay. <strong>To detect the error and correct them, add the positions of affected parity bits <em>P1</em>, <em>P3, and P4 </em>which is (1 + 4 + 8) = 13. And there we go, in position 13 where the error is.</strong></p><p>You can follow the entire process above to test for yourself and simulate errors, it should be straightforward.</p><h3>Simulate in Python.</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d45e5194478094eb0d8a0ac198a0eed/href">https://medium.com/media/0d45e5194478094eb0d8a0ac198a0eed/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fd47b0e2311" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform | Infrastructure Management | AWS | Stack Structure reducing technical debt.]]></title>
            <link>https://medium.com/@marjune/terraform-infrastructure-management-aws-stack-structure-reducing-technical-debt-ddbfa488e5f3?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddbfa488e5f3</guid>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[technical-debt]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Thu, 10 Oct 2024 07:30:33 GMT</pubDate>
            <atom:updated>2024-10-10T07:30:33.029Z</atom:updated>
            <content:encoded><![CDATA[<p>Technical debt is always part of anything whatever it is that we’re doing. It will be compounded over time to the point where it’s hard to change something without affecting another resource in the stack.</p><p>When I started to use Terraform to provision and manage cloud resources in AWS, most examples I found looked like this stack;</p><pre>AWS<br>  - backend.tf<br>  - variables.tf<br>  - data.tf<br>  - ec2.tf<br>  - security_groups.tf<br>  - s3.tf<br>  - alb.tf<br>  - ...</pre><h3>Managing Infrastructure.</h3><p>Any organization, big or small; is composed of departments and has different responsibilities. Within those departments e.g. Engineering, surely owns different applications.</p><p>Suppose we follow the example structure above in our stack where we manage the infrastructure. It’s 100% guaranteed that we end up with one huge stack mixing resources from different logical applications to which a resource belongs. e.g we ended up managing for <em>xxx-backend-api, </em>and <em>yyy-another-api, </em>etc. into one stack.</p><h3>Technical Debt.</h3><p>Putting everything in a single stack is not a great idea for obvious reasons.</p><ol><li>Every change will potentially affect all of the resources in the stack.</li><li>Resources from individual logical applications e.g. <em>xxx-backend-api </em>are not isolated from the rest.</li><li>Simultaneous terraform plan and apply for various changes are not possible because the entire stack has only one state file and each operations require locking the state file.</li></ol><p>These are just a few caveats for having one huge stack of resources.</p><h3>Isolating logical application into a stack.</h3><p>Before creating resources, we should define first the scope of whatever resources that we’re provisioning, and group them into a logical single stack.</p><p>For example, we have to provision infrastructure for our backend API named <em>xxx-backend-api </em>which serves as our logical application. We have <em>EC2, ASG, Launch template, ALB, Security Groups, ACM Certificate, </em>and <em>Route53 record. </em>These resources must be grouped into one independent stack, and there should not be any resource that does not belong to <em>xxx-backend-api.</em></p><h3>Stacks Structure.</h3><p>Once we already defined and grouped the resources to be provisioned into our logical application e.g <em>xxx-backend-api, </em>our stacks structure looked like this,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*H2mnqsWD2qd7icEWlAw8Lw.png" /><figcaption>Stack structure.</figcaption></figure><p>Each application within these stacks is isolated, has few resources, and has its responsibility. The thing to note is the stack dependency where one stack depends on another i.e. <a href="https://developer.hashicorp.com/terraform/language/state/remote-state-data">remote-state-data</a>.</p><h3>DRY (Do Not Repeat Yourself).</h3><p>Considering multi-region and environment(prod, dev, staging) setup. We should avoid repeating any infrastructure configuration in each region and environment. But please take note that not every region has the same infrastructure setup; in this case, it should be in a different stack.</p><h4>Variables and Precedence.</h4><p>To avoid redundancy, every environment or region setting should be defined in variables *.tfvars e.g dev-us-east-1.tfvars, prod-us-east-1.tfvars</p><p>Terraform loads variables in a specific order of <a href="https://developer.hashicorp.com/terraform/language/values/variables#variable-definition-precedence">precedence</a>, all *.tfvars and *.auto.tfvars will automatically load and *.auto.tfvars has higher precedence over *.tfvars which means, *.auto.tfvars will override the variable in *.tfvars , so please take note.</p><h3>Final Thought.</h3><p>The perspective that is worth considering first before starting IaC is the scope of the application’s infrastructure that we’re about to create. In this way, we only limit our stack within the scope. In the future, when there are more applications to manage it’s easier to create a new stack. The idea that the environment(dev, qa), and region will be the placeholder of the entire stack in each cloud account should be avoided to reduce technical debt to a minimum.</p><p>Also, refactoring and manipulating state files for some reason e.g. <em>terraform import, terraform state mv, </em>etc., etc. can have a low impact on the entire infrastructure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddbfa488e5f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS IAM least privilege permissions for EC2 Auto scaling deployment use case.]]></title>
            <link>https://medium.com/@marjune/aws-iam-least-privilege-permissions-for-ec2-auto-scaling-deployment-use-case-1bd3217cbb50?source=rss-af481dc98e1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bd3217cbb50</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[iam-roles]]></category>
            <dc:creator><![CDATA[marjune]]></dc:creator>
            <pubDate>Sat, 13 Apr 2024 11:27:58 GMT</pubDate>
            <atom:updated>2024-04-19T13:54:15.655Z</atom:updated>
            <content:encoded><![CDATA[<p>EC2, ASG, IAM, and ALB are services all over the place at <a href="https://docs.aws.amazon.com/">https://docs.aws.amazon.com</a>. So the goal is to have the least privileged permissions for the role that will do the deployment.</p><p>Crafting an IAM permission for a role that only does the following:</p><ol><li>Update the EC2 Auto scaling group with a specific launch template.</li><li>Run instances to launch the template version.</li><li>And additionally, modifying ALB listeners/rules. (but not required).</li></ol><h4>Read Access.</h4><p>Just Describe and Get for EC2, ASG, and ALB.</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;GetAndDesc&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;elasticloadbalancing:Describe*&quot;,<br>        &quot;ec2:Describe*&quot;,<br>        &quot;autoscaling:Get*&quot;,<br>        &quot;autoscaling:Describe*&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><h4>Update Auto Scaling Group.</h4><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;UpdateAutoScalingGroup&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;autoscaling:UpdateAutoScalingGroup&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:autoscaling:{REGION}:{ACCOUNT_ID}:autoScalingGroup:*:autoScalingGroupName/{NAME_OF_ASG}&quot;<br>    }<br>  ]<br>}</pre><h4>Run instance in launch template.</h4><p>With this permission, we can only run instances and create tags with a specific launch template.</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;RunInstance&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [&quot;ec2:RunInstances&quot;, &quot;ec2:CreateTags&quot;]<br>      &quot;Resource&quot;: &quot;*&quot;,<br>      &quot;Condition&quot;: {<br>        &quot;StringLike&quot;: {<br>          &quot;ec2:LaunchTemplate&quot;: [<br>            &quot;arn:aws:ec2:{REGION}:{ACCOUNT_ID}:launch-template/{LT_ID}&quot;<br>          ]<br>        }<br>      }<br>    }<br>  ]<br>}</pre><h4>IAM Pass Role.</h4><p>We also need a iam:PassRole to the role that EC2 is using.</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;PASSROLE&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iam:PassRole&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:iam::{ACCOUNT_ID}:role/{INSTANCE_ROLE}&quot;<br>      ],<br>      &quot;Condition&quot;: {<br>        &quot;StringEquals&quot;: {<br>          &quot;iam:PassedToService&quot;: [<br>            &quot;ec2.amazonaws.com&quot;<br>          ]<br>        }<br>      }<br>    }<br>  ]<br>}</pre><h4>Modify listener rules in ALB.</h4><p>This permission is just additional in case we need to modify ALB listener rules.</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Version&quot;: &quot;2012-10-17&quot;,<br>      &quot;Statement&quot;: [<br>        {<br>          &quot;Sid&quot;: &quot;ModifyELB&quot;,<br>          &quot;Effect&quot;: &quot;Allow&quot;,<br>          &quot;Action&quot;: &quot;elasticloadbalancing:Modify*&quot;,<br>          &quot;Resource&quot;: [<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener/app/{ALB_NAME}/*/*/*&quot;,<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener/app/{ALB_NAME}/*/*&quot;,<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener-rule/app/{ALB_NAME}/*/*/*/*&quot;,<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener-rule/app/{ALB_NAME}/*/*/*&quot;<br>          ]<br>        }<br>      ]<br>    }<br>  ]<br>}</pre><h4>Putting it together.</h4><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;GetAndDesc&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;elasticloadbalancing:Describe*&quot;,<br>        &quot;ec2:Describe*&quot;,<br>        &quot;autoscaling:Get*&quot;,<br>        &quot;autoscaling:Describe*&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;*&quot;<br>    },<br>    {<br>      &quot;Sid&quot;: &quot;UpdateAutoScalingGroup&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;autoscaling:UpdateAutoScalingGroup&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:autoscaling:{REGION}:{ACCOUNT_ID}:autoScalingGroup:*:autoScalingGroupName/{NAME_OF_ASG}&quot;<br>    },<br>    {<br>      &quot;Sid&quot;: &quot;RunInstance&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;ec2:RunInstances&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;,<br>      &quot;Condition&quot;: {<br>        &quot;StringLike&quot;: {<br>          &quot;ec2:LaunchTemplate&quot;: [<br>            &quot;arn:aws:ec2:{REGION}:{ACCOUNT_ID}:launch-template/{LT_ID}&quot;<br>          ]<br>        }<br>      }<br>    },<br>    {<br>      &quot;Sid&quot;: &quot;PASSROLE&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iam:PassRole&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:iam::{ACCOUNT_ID}:role/{INSTANCE_ROLE}&quot;<br>      ],<br>      &quot;Condition&quot;: {<br>        &quot;StringEquals&quot;: {<br>          &quot;iam:PassedToService&quot;: [<br>            &quot;ec2.amazonaws.com&quot;<br>          ]<br>        }<br>      }<br>    },<br>    {<br>      &quot;Version&quot;: &quot;2012-10-17&quot;,<br>      &quot;Statement&quot;: [<br>        {<br>          &quot;Sid&quot;: &quot;ModifyELB&quot;,<br>          &quot;Effect&quot;: &quot;Allow&quot;,<br>          &quot;Action&quot;: &quot;elasticloadbalancing:Modify*&quot;,<br>          &quot;Resource&quot;: [<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener/app/{ALB_NAME}/*/*/*&quot;,<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener/app/{ALB_NAME}/*/*&quot;,<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener-rule/app/{ALB_NAME}/*/*/*/*&quot;,<br>            &quot;arn:aws:elasticloadbalancing:{REGION}:{ACCOUNT_ID}:listener-rule/app/{ALB_NAME}/*/*/*&quot;<br>          ]<br>        }<br>      ]<br>    }<br>  ]<br>}</pre><p>To add more constraints or conditions to these policies kindly refer to AWS docs.</p><p><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/permissions-for-launch-templates.html#permissions-for-launch-templates-create">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/permissions-for-launch-templates.html#permissions-for-launch-templates-create</a></p><p><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ExamplePolicies_EC2.html#iam-example-runinstances-launch-templates">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ExamplePolicies_EC2.html#iam-example-runinstances-launch-templates</a></p><p><a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/us-iam-role.html">https://docs.aws.amazon.com/autoscaling/ec2/userguide/us-iam-role.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bd3217cbb50" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>