<?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 Ehis Iribhogbe on Medium]]></title>
        <description><![CDATA[Stories by Ehis Iribhogbe on Medium]]></description>
        <link>https://medium.com/@ehisjude420?source=rss-de4b9b517c7e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HQMBn3kFi5ui1sWVIl2gew@2x.jpeg</url>
            <title>Stories by Ehis Iribhogbe on Medium</title>
            <link>https://medium.com/@ehisjude420?source=rss-de4b9b517c7e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:00:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ehisjude420/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[Project 2: Building a Decentralized Auction Smart Contract in Solidity]]></title>
            <link>https://medium.com/@ehisjude420/project-2-building-a-decentralized-auction-smart-contract-in-solidity-433b60d61d79?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/433b60d61d79</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Wed, 24 Sep 2025 09:47:27 GMT</pubDate>
            <atom:updated>2025-09-24T09:47:27.787Z</atom:updated>
            <content:encoded><![CDATA[<h3>Brief Introduction</h3><p>Auctions are one of the oldest methods of selling goods and services. In Web3, we can make them <strong>transparent, trustless, and decentralized</strong>. Instead of relying on an auction house or a centralized platform, Ethereum smart contracts allow anyone to participate in bidding while guaranteeing fair rules through code.</p><p>In this project, we’ll build an <strong>Auction Smart Contract</strong> from scratch using Solidity. You’ll learn about:</p><ul><li>Managing auction states with enums</li><li>Bidding logic and highest binding bid</li><li>Withdrawals and payouts</li><li>Protecting against vulnerabilities</li></ul><h3>How the Auction Works</h3><ol><li>The auction is created by an <strong>owner</strong> (seller).</li><li>It has a <strong>start block</strong> and an <strong>end block</strong> (time window).</li><li>Users call placeBid() and send atleast 0.1 ETH to participate.</li><li>The contract keeps track of bids in a <strong>mapping</strong>.</li><li>The <strong>highest binding bid</strong> (not necessarily the highest bid) becomes the selling price.</li><li>The auction owner can cancel or finalize.</li></ol><p>7. At the end:</p><ul><li>Owner gets the <strong>highest binding bid</strong>.</li><li>Highest bidder withdraws any excess they overbid.</li><li>Other bidders withdraw their full amount.</li></ul><h3>Solidity Code</h3><p>Let’s see the full contract.</p><pre>// SPDX-License-Identifier: GPL-3.0<br>pragma solidity &gt;=0.5.0 &lt;0.9.0;<br><br>contract AuctionCreator {<br>    Auction[] public auctions;<br><br>    function createAuction() public {<br>        Auction newAuction = new Auction(msg.sender);<br>        auctions.push(newAuction);<br>    }<br>}<br><br>contract Auction {<br>    address payable public owner;<br>    uint public startBlock;<br>    uint public endBlock;<br>    string public ipfsHash;<br><br>    enum State {Started, Running, Ended, Cancelled}<br>    State public auctionState;<br><br>    uint public highestBindingBid;<br>    address payable public highestBidder;<br><br>    mapping(address =&gt; uint) public bids;<br>    uint public bidIncrement;<br><br>    constructor(address eoa) {<br>        owner = payable(eoa);<br>        auctionState = State.Running;<br>        startBlock = block.number;<br>        endBlock = startBlock + 40320; // approx 1 week<br>        ipfsHash = &quot;&quot;;<br>        bidIncrement = 1 ether;<br>    }<br><br>    modifier notOwner() {<br>        require(msg.sender != owner, &quot;Owner cannot bid&quot;);<br>        _;<br>    }<br><br>    modifier afterStart() {<br>        require(block.number &gt;= startBlock, &quot;Auction not started yet&quot;);<br>        _;<br>    }<br><br>    modifier beforeEnd() {<br>        require(block.number &lt;= endBlock, &quot;Auction already ended&quot;);<br>        _;<br>    }<br><br>    modifier onlyOwner() {<br>        require(msg.sender == owner, &quot;Only owner can call this&quot;);<br>        _;<br>    }<br><br>    function min(uint a, uint b) pure internal returns (uint) {<br>        return a &lt;= b ? a : b;<br>    }<br><br>    function cancelAuction() public onlyOwner {<br>        auctionState = State.Cancelled;<br>    }<br><br>    function placeBid() public payable notOwner afterStart beforeEnd {<br>        require(auctionState == State.Running, &quot;Auction not running&quot;);<br>        require(msg.value &gt;= 0.01 ether, &quot;Minimum bid is 0.01 ETH&quot;);<br><br>        uint currentBid = bids[msg.sender] + msg.value;<br>        require(currentBid &gt; highestBindingBid, &quot;Bid not high enough&quot;);<br><br>        bids[msg.sender] = currentBid;<br><br>        if (currentBid &lt;= bids[highestBidder]) {<br>            highestBindingBid = min(currentBid + bidIncrement, bids[highestBidder]);<br>        } else {<br>            highestBindingBid = min(currentBid, bids[highestBidder] + bidIncrement);<br>            highestBidder = payable(msg.sender);<br>        }<br>    }<br><br>    function finalizeAuction() public {<br>        require(auctionState == State.Cancelled || block.number &gt; endBlock, &quot;Auction not yet ended&quot;);<br>        require(msg.sender == owner || bids[msg.sender] &gt; 0, &quot;Not authorized&quot;);<br><br>        address payable recipient;<br>        uint value;<br><br>        if (auctionState == State.Cancelled) {<br>            // everyone gets refund<br>            recipient = payable(msg.sender);<br>            value = bids[msg.sender];<br>        } else {<br>            // auction ended successfully<br>            if (msg.sender == owner) {<br>                recipient = owner;<br>                value = highestBindingBid;<br>            } else if (msg.sender == highestBidder) {<br>                recipient = highestBidder;<br>                value = bids[highestBidder] - highestBindingBid;<br>            } else {<br>                recipient = payable(msg.sender);<br>                value = bids[msg.sender];<br>            }<br>        }<br><br>        bids[recipient] = 0; // reset before transfer (security)<br>        recipient.transfer(value);<br>    }<br>}</pre><h3>Step-by-Step Code Breakdown</h3><h4>1) State Variables</h4><ul><li><strong>owner</strong>: The seller who created the auction.</li><li><strong>startBlock / endBlock</strong>: The time window for the auction.</li><li><strong>auctionState</strong>: Enum to track lifecycle.</li><li><strong>highestBindingBid</strong>: Actual selling price.</li><li><strong>highestBidder</strong>: Who wins.</li><li><strong>bids mapping</strong>: Stores each user’s bid.</li><li><strong>bidIncrement</strong>: Minimum increment between bids.</li></ul><pre>address payable public owner;<br>uint public startBlock;<br>uint public endBlock;<br>string public ipfsHash;<br>enum State {Started, Running, Ended, Cancelled}<br>State public auctionState;<br>uint public highestBindingBid;<br>address payable public highestBidder;<br>mapping(address =&gt; uint) public bids;<br>uint public bidIncrement;</pre><p><strong>2) Constructor :</strong></p><ul><li>Initializes the auction with the deployer’s address.</li><li>Runs for approx. one week (based on block numbers).</li><li>Sets the bid increment.</li></ul><pre>constructor(address eoa) {<br>    owner = payable(eoa);<br>    auctionState = State.Running;<br>    startBlock = block.number;<br>    endBlock = startBlock + 40320; // ~1 week<br>    ipfsHash = &quot;&quot;;<br>    bidIncrement = 1 ether;<br>}</pre><p><strong>3) Modifiers :</strong> These help enforce auction rules cleanly.</p><pre>modifier notOwner() { require(msg.sender != owner, &quot;Owner cannot bid&quot;); _; }<br>modifier afterStart() { require(block.number &gt;= startBlock, &quot;Not started&quot;); _; }<br>modifier beforeEnd() { require(block.number &lt;= endBlock, &quot;Already ended&quot;); _; }<br>modifier onlyOwner() { require(msg.sender == owner, &quot;Only owner&quot;); _; }</pre><p><strong>4) Place Bid :</strong></p><ul><li>Enforces minimum bid.</li><li>Updates bids mapping.</li><li>Adjusts <strong>highest binding bid</strong> and highest bidder dynamically.</li></ul><pre>function placeBid() public payable notOwner afterStart beforeEnd {<br>    require(auctionState == State.Running, &quot;Auction not running&quot;);<br>    require(msg.value &gt;= 0.01 ether, &quot;Minimum bid is 0.01 ETH&quot;);<br><br>    uint currentBid = bids[msg.sender] + msg.value;<br>    require(currentBid &gt; highestBindingBid, &quot;Bid not high enough&quot;);<br><br>    bids[msg.sender] = currentBid;<br><br>    if (currentBid &lt;= bids[highestBidder]) {<br>        highestBindingBid = min(currentBid + bidIncrement, bids[highestBidder]);<br>    } else {<br>        highestBindingBid = min(currentBid, bids[highestBidder] + bidIncrement);<br>        highestBidder = payable(msg.sender);<br>    }<br>}</pre><p><strong>5) Cancel Auction :</strong> Owner can cancel in emergencies.</p><pre>function cancelAuction() public onlyOwner {<br>    auctionState = State.Cancelled;<br>}</pre><p><strong>6) Finalize Auction :</strong></p><ul><li>Ensures only owner or bidders can finalize.</li><li>Handles three cases: <strong>cancelled</strong>, <strong>owner payout</strong>, <strong>refunds</strong>.</li><li>Uses <strong>checks-effects-interactions pattern</strong> for safety.</li></ul><pre>function finalizeAuction() public {<br>    require(auctionState == State.Cancelled || block.number &gt; endBlock, &quot;Auction not yet ended&quot;);<br>    require(msg.sender == owner || bids[msg.sender] &gt; 0, &quot;Not authorized&quot;);<br><br>    address payable recipient;<br>    uint value;<br><br>    if (auctionState == State.Cancelled) {<br>        recipient = payable(msg.sender);<br>        value = bids[msg.sender];<br>    } else {<br>        if (msg.sender == owner) {<br>            recipient = owner;<br>            value = highestBindingBid;<br>        } else if (msg.sender == highestBidder) {<br>            recipient = highestBidder;<br>            value = bids[highestBidder] - highestBindingBid;<br>        } else {<br>            recipient = payable(msg.sender);<br>            value = bids[msg.sender];<br>        }<br>    }<br><br>    bids[recipient] = 0;<br>    recipient.transfer(value);<br>}</pre><h3>Testing the Auction</h3><ol><li>Deploy via <strong>Remix IDE</strong>.</li><li>Call createAuction() from AuctionCreator.</li><li>Fund from different wallets via placeBid().</li><li>Try cancellation or wait until end block.</li><li>Call finalizeAuction() as different participants.</li></ol><h3>Security Considerations</h3><ul><li>Always <strong>reset balances before transfers</strong> (prevents re-entrancy).</li><li>Bidding uses require checks for fairness.</li><li>Auction rules enforced with modifiers.</li><li>For production: consider <strong>pull payments pattern</strong> and <strong>OpenZeppelin libraries</strong>.</li></ul><h3>Key Takeaways</h3><ul><li>Auctions in Solidity demonstrate <strong>mappings</strong>, <strong>enums</strong>, and <strong>modifiers</strong>.</li><li>Bids are tracked safely in state.</li><li>Withdrawals ensure fairness: losers get refunds, winner pays binding bid.</li><li>Security best practices are essential when handling ETH.</li></ul><p>Hey, I’m Ehis 👋. I’ve spent the last 6+ years building scalable backend systems in fintech and banking, and now I’m diving into the Web3 and blockchain space. Super excited to learn, build, and connect with people in this ecosystem. Thanks for reading, let’s connect!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=433b60d61d79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Decentralized Lottery Smart Contract in Solidity]]></title>
            <link>https://medium.com/@ehisjude420/building-a-decentralized-lottery-smart-contract-in-solidity-fc00209dee4c?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc00209dee4c</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 07:09:41 GMT</pubDate>
            <atom:updated>2025-09-16T07:09:41.923Z</atom:updated>
            <content:encoded><![CDATA[<h3>Project 1: Building a Decentralized Lottery Smart Contract in Solidity</h3><h3>Introduction</h3><p>Lotteries have existed for centuries, but traditional systems rely on centralized authorities that may not always be transparent or trustworthy. With <strong>Web3 and smart contracts</strong>, we can design a lottery that’s <strong>transparent, tamper-proof, and decentralized</strong>.</p><p>No middlemen. No trust issues. Just pure code running on the <strong>Ethereum Virtual Machine (EVM)</strong>.</p><p>In this article, I’ll walk you through building a simple <strong>Decentralized Lottery smart contract in Solidity</strong>. If you’re new to Web3, this is a great hands-on project to understand how smart contracts manage state, enforce rules, and handle ETH transfers.</p><p>By the end, you’ll learn about:</p><ul><li>Smart contract deployment</li><li>Payable functions &amp; ETH transfers</li><li>State management in Solidity</li><li>Random number generation (and why it’s tricky on-chain)</li></ul><h3>How the Lottery Works</h3><p>We’ll enforce the following rules through our smart contract:</p><ol><li>The lottery starts when the contract is deployed.</li><li>Anyone with an Ethereum wallet can join by sending <strong>exactly 0.1 ETH</strong>.</li><li>Each entry costs 0.1 ETH , multiple entries increase your winning chances.</li><li>The <strong>contract manager</strong> (deployer) controls when a winner can be picked.</li><li>At least <strong>3 players</strong> are required before a winner is drawn.</li><li>Once triggered, a random winner is selected, receives the prize, and the lottery resets.</li></ol><p>Full Solidity Contract Code</p><pre>// SPDX-License-Identifier: GPL-3.0<br>pragma solidity &gt;=0.5.0 &lt;0.9.0;<br><br>contract Lottery {<br>    // state variables<br>    address payable[] public players;<br>    address payable public manager; <br>    <br>    constructor() {<br>        manager = payable(msg.sender);<br>        players.push(manager); // manager listed but cannot play<br>    }<br>    <br>    // accept exactly 0.1 ETH per entry<br>    receive() external payable {<br>        require(msg.sender != manager, &quot;Manager cannot participate&quot;);<br>        require(msg.value == 0.1 ether, &quot;Must send exactly 0.1 ETH&quot;);<br>        players.push(payable(msg.sender));<br>    }<br>    <br>    // manager-only balance view<br>    function getBalance() public view returns (uint) {<br>        require(msg.sender == manager, &quot;Only manager can view balance&quot;);<br>        return address(this).balance;<br>    }<br>    <br>    // pseudo-random (not secure for production)<br>    function random() internal view returns (uint) {<br>        return uint(<br>            keccak256(<br>                abi.encodePacked(block.difficulty, block.timestamp, players.length)<br>            )<br>        );<br>    }<br>    <br>    // pick a winner &amp; reset<br>    function pickWinner() public {<br>        if (players.length &lt; 10) {<br>            require(msg.sender == manager, &quot;Only manager can pick winner with &lt;10 players&quot;);<br>        } else {<br>            require(players.length &gt;= 10, &quot;At least 10 players required&quot;);<br>            // anyone can call if &gt;= 10 players<br>        }<br><br>        require(players.length &gt;= 3, &quot;At least 3 players required&quot;);<br>        <br>        uint r = random();<br>        uint index = r % players.length;<br>        address payable winner = players[index];<br><br>        // IMPORTANT: read balance directly (so non-manager calls won&#39;t revert)<br>        uint totalBalance = address(this).balance; <br>        uint managerFee = totalBalance / 10;     // 10%<br>        uint winnerPrize = totalBalance - managerFee; // 90%<br><br>        manager.transfer(managerFee);<br>        winner.transfer(winnerPrize);<br><br>        // reset for next round<br>        players = new address payable;<br>        players.push(manager);<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJkgz-hl8qqByNtHO_QCkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LzBpn-CZWhzrAOEOMBrXmg.png" /></figure><h3>Step-by-Step Code Breakdown</h3><h3>1. State Variables</h3><ul><li>players: dynamic array storing participants(payable means it can receive ETH).</li><li>manager: the contract deployer with special permissions.</li></ul><pre>// SPDX-License-Identifier: GPL-3.0<br>pragma solidity &gt;=0.5.0 &lt;0.9.0;<br>contract Lottery {<br>    // state variables<br>    address payable[] public players; <br>    address payable public manager; <br>  }</pre><h3>2. Constructor</h3><ul><li>Runs once at deployment.</li><li>Sets the manager as the deployer.</li><li>Prevents manager from participating.</li></ul><pre>constructor() {<br>    manager = payable(msg.sender);<br>    players.push(manager); // listed but blocked from participate<br>}</pre><h3>3) receive() function : Joining the Lottery</h3><ul><li>Accepts <strong>exactly 0.1 ETH</strong>.</li><li>Rejects entries from the manager.</li><li>Adds player’s address to the array.</li></ul><pre>receive() external payable {<br>    require(msg.sender != manager, &quot;Manager cannot participate&quot;);<br>    require(msg.value == 0.1 ether, &quot;Must send exactly 0.1 ETH&quot;);<br>    players.push(payable(msg.sender));<br>}</pre><h3>4) getBalance() function</h3><ul><li>Only the manager can view the contract’s balance.</li></ul><pre>function getBalance() public view returns (uint) {<br>    require(msg.sender == manager, &quot;Only manager can view balance&quot;);<br>    return address(this).balance;<br>}</pre><h3>5) random() function</h3><ul><li>Generates a <strong>pseudo-random number</strong> using keccak256.</li><li>Not secure for production since miners can manipulate block values.</li><li>In real-world dApps, use <strong>Chainlink VRF</strong> for verifiable randomness.</li></ul><pre>function random() internal view returns (uint) {<br>    return uint(<br>        keccak256(<br>            abi.encodePacked(block.difficulty, block.timestamp, players.length)<br>        )<br>    );<br>}</pre><h3>6) pickWinner() function</h3><ul><li>If fewer than 10 players → only the manager can call.</li><li>If 10+ players → anyone can call.</li><li>Requires a minimum of 3 players.</li><li>Splits pot: <strong>90% to winner, 10% to manager</strong>.</li><li>Resets for the next round.</li></ul><pre>function pickWinner() public {<br>    if (players.length &lt; 10) {<br>        require(msg.sender == manager, &quot;Only manager can pick winner with &lt;10 players&quot;);<br>    } else {<br>        require(players.length &gt;= 10, &quot;At least 10 players required&quot;);<br>    }<br><br>    require(players.length &gt;= 3, &quot;At least 3 players required&quot;);<br>    <br>    uint r = random();<br>    uint index = r % players.length;<br>    address payable winner = players[index];<br><br>    // read balance directly so non-manager calls don&#39;t revert<br>    uint totalBalance = address(this).balance; <br>    uint managerFee = totalBalance / 10;<br>    uint winnerPrize = totalBalance - managerFee;<br><br>    manager.transfer(managerFee);<br>    winner.transfer(winnerPrize);<br><br>    players = new address payable;<br>    players.push(manager);<br>}</pre><h3>Deploying and Testing the Lottery contract</h3><ul><li>Open Remix IDE.</li><li>Compile and deploy the contract.</li><li>Connect MetaMask to a testnet (e.g., Sepolia or Goerli).</li><li>Send <strong>0.1 ETH</strong> from multiple wallets to the contract address.</li><li>After 3+ players, call pickWinner().</li><li>Verify payouts on a block explorer.</li></ul><h3>📌 Key Takeaways</h3><ul><li><strong>payable</strong> enables receiving and sending ETH in Solidity.</li><li><strong>require()</strong> enforces rules and prevents invalid actions.</li><li>On-chain randomness is insecure → use <strong>Chainlink VRF</strong> in real-world apps.</li><li>Every contract execution costs <strong>gas fees</strong>.</li></ul><h3>What I Learned</h3><ul><li>How <strong>payable addresses</strong> work for ETH transfers.</li><li>Writing a <strong>receive function</strong> to safely handle incoming ETH.</li><li>Why <strong>keccak256 pseudo-randomness</strong> isn’t secure.</li><li>Managing smart contract state with visibility specifiers &amp; conditions.</li></ul><h3>Conclusion</h3><p>This lottery dApp is a great <strong>beginner Solidity project</strong> to practice smart contract fundamentals like state variables, payable functions, ETH transfers, and randomness.</p><p>While this works as a demo, a <strong>real-world decentralized lottery</strong> would require:</p><ul><li><strong>Chainlink VRF</strong> for secure randomness</li><li><strong>Oracles</strong> for off-chain data</li><li>Better <strong>security measures</strong> for player fairness</li></ul><p>It’s an exciting start into <strong>decentralized applications</strong> and shows how Web3 can reinvent even the simplest ideas like a lottery.</p><p>Hey, I’m Ehis 👋. I’ve spent the last 6+ years building scalable backend systems in fintech and banking, and now I’m diving into the Web3 and blockchain space. Super excited to learn, build, and connect with people in this ecosystem. Thanks for reading, let’s connect!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc00209dee4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency, Processes, Threads, and Thread Pools]]></title>
            <link>https://medium.com/@ehisjude420/concurrency-processes-threads-and-thread-pools-31ea6be9a79b?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/31ea6be9a79b</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Fri, 10 May 2024 14:07:59 GMT</pubDate>
            <atom:updated>2024-05-10T14:07:59.749Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction : </strong>Concurrency, the art of managing multiple tasks simultaneously. In this discussion, I will delve into how various concepts, including Concurrency, Processes, Threads, Stack, and Thread Pools, collaboratively contribute to enhancing the overall performance, scalability, and responsiveness of your applications.</p><p><strong>Table of contents</strong></p><ol><li><strong>Introduction : </strong>definition and importance of concurrency in managing multiple tasks simultaneously.</li></ol><p><strong>2. Concepts :</strong></p><ul><li>Concurrency: Managing multiple tasks simultaneously, like a chef handling multiple orders.</li><li>Processes: Independent tasks, similar to customer orders in a restaurant.</li><li>Threads: Workers executing tasks, akin to waiters serving customers.</li><li>Stack: Memory storing tasks in progress, like a waiter’s task list.</li><li>Thread Pool: A team of workers (threads) managing tasks together, like a team of chefs in a kitchen.</li></ul><p><strong>3. Restaurant Scenario</strong></p><ul><li>Description of a restaurant with one waiter and one chef.</li><li>Illustration of order taking and task execution.</li></ul><p><strong>4. Challenges : </strong>limitations of a fixed number of chefs (threads) leading to potential starvation and delays in task processing.</p><p><strong>5. Solutions : </strong>considerations such as Message Queue systems and Lock mechanisms to address starvation and regulate resource access.</p><p><strong>Let’s Go !</strong></p><p>Let’s draw inspiration from the bustling setting of a restaurant to grasp the definitions of Thread, Thread Pool, Process, Stack, and Concurrency:</p><p>👉<strong> Concurrency: </strong>Imagine a chef effortlessly managing multiple orders simultaneously.</p><p>👉 <strong>Processes:</strong> Each customer’s order mirrors an independent process.</p><p>👉<strong> Stack:</strong> Analogous to a waiter’s memory, storing orders and tasks in progress.</p><p>👉 <strong>Thread: </strong>Visualize the waiter gracefully serving the customers — each waiter represents a thread.</p><p>👉<strong> Thread Pool:</strong> A collaborative team of chefs managing the culinary operations.</p><p>Now, envision a restaurant with one waiter and one chef : 👇</p><p>1. A customer arrives and takes a seat at a restaurant table.</p><p>2. The waiter takes the first customer’s order and adds it to their task list (stack).</p><p>3. The waiter then goes to the kitchen to give the chef the first order.</p><p>4. While the waiter is in the kitchen, another customer arrives at the restaurant and sits down at a table.</p><p>5. The waiter takes the second customer’s order and seamlessly incorporates it into its task list (stack). And takes this new order to the chef to prepare.</p><p>6. Returning from the kitchen with the first customer’s order, the waiter serves the first customer’s food.</p><p>7. After giving the first customer their food, the waiter then goes to the kitchen to get the second customer’s order.</p><p>👉 <strong>The Challenge :</strong> However, the scenario poses a challenge ; If the restaurant has only a fixed number of chefs (threads), there’s a limit to how many orders they can handle concurrently so a new order might be queued up and delayed (starvation) until a chef becomes available to take the order. If some orders take longer to complete than others, those orders might tie up a thread for a significant amount of time.</p><p>👉<strong>The solution :</strong> To tackle this, we can consider strategic solutions such as employing a Message Queue system to eliminate potential starvation or implementing a Lock mechanism to regulate resource access.</p><p><strong>In conclusion,</strong> mastering the concepts of Concurrency, Processes, Threads, and Thread Pools is essential for building robust and responsive applications. By understanding these concepts and their interactions, developers can create software that efficiently manages multiple tasks, leading to improved performance and scalability. Remember, like a well-run restaurant with its chefs and waiters, a well-designed application architecture can handle complex tasks smoothly and efficiently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31ea6be9a79b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Message Queues and Pub-Sub Messaging Systems]]></title>
            <link>https://medium.com/@ehisjude420/message-queues-and-pub-sub-messaging-systems-8a545d4871e6?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a545d4871e6</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Tue, 30 Apr 2024 08:21:16 GMT</pubDate>
            <atom:updated>2024-04-30T08:21:16.015Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction : </strong>In today’s interconnected digital world, efficient communication between software components is crucial for building scalable, responsive, and reliable applications. Message queues and pub-sub messaging systems are two powerful technologies that facilitate this communication, ensuring messages are delivered in an orderly and timely manner. In this article, we’ll explore the fundamentals of message queues and pub-sub messaging systems, their key features, and how they enhance the overall performance and reliability of modern software applications.</p><p>💌 Message Queues are like virtual mailboxes. They make sure your messages get delivered in order, like letters in a mailbox.</p><p>📢 Pub-Sub (Publish-Subscribe) Messaging Systems are like announcements. They disseminate information to multiple recipients simultaneously, similar to a megaphone addressing a crowd.</p><p><strong>Table of contents</strong></p><ol><li><strong>Introduction : </strong>explanation of message queues and pub-sub messaging systems.</li><li><strong>Message Queues :</strong></li></ol><ul><li>definition and its purpose.</li><li>Example scenario: a restaurant.</li><li>Key features and benefits:</li><li>Examples of message queue systems</li></ul><p><strong>3. Pub-Sub Messaging Systems</strong></p><ul><li>Definition and purpose.</li><li>Example scenario: hosting a virtual event.</li><li>Components: Publisher, Subscribers, Topic.</li><li>How it works.</li><li>Examples of pub-sub systems: Kafka, Redis Pub-Sub, Google Cloud Pub/Sub, Amazon SNS, Microsoft Azure Event Grid.</li></ul><p><strong>Exploring Message Queue Systems</strong></p><p>A Message Queue System is a technology that helps different systems send and receive messages in an organized and orderly way. It ensures that messages are processed in the right order.</p><p>let’s explain a Message Queue using a restaurant scenario:</p><p>📌<strong> The Dinner Area:</strong> This is where all the customers like you sit and enjoy their meals.</p><p>📌<strong>The Waiters: </strong>This is the person who takes your food orders.</p><p>📌<strong>The Chefs: </strong>They’re responsible for making your food. But here’s the thing: they can only cook one dish at a time because they need to pay attention and make sure everything is perfect.</p><p>Now, let’s introduce the Message Queue: The Message Queue is like a special notepad that the waiter carries. Instead of taking each order to the kitchen immediately, the waiter writes down all the orders on this notepad.</p><p>So, here’s how it works:</p><p>👉You and other customers give your orders to the waiter. Instead of the waiter running to the kitchen with each order, the waiter writes down all the orders on the notepad (Message Queue) in the order they were received.</p><p>👉The chef and cooks in the kitchen pay attention to the notepad. They start with the first order on the list and make that dish.</p><p>👉Once the first dish is done, the waiter takes it to the dinner area, and then the chef moves on to the next order on the notepad (Message Queue).</p><p>This process keeps going until all the orders have been cooked and served, one by one.</p><p>So, the Message Queue helps the restaurant keep things in order, just like a list of orders, ensuring that everyone’s food is cooked and served in the right sequence, even when it’s really busy.</p><p>Message queues, such as RabbitMQ, Apache ActiveMQ, and Amazon SQS (Simple Queue Service), serve as critical purpose in microservices architecture.</p><p>They are essential for several reasons: 👇</p><p>📍<strong>Orderly Processing:</strong> Message queues ensure that tasks or messages are processed in a specific order thereby preventing chaos in applications.</p><p>📍 <strong>Decoupling: </strong>They decouple different parts of a system, allowing components to work independently without being tightly connected. This enhances flexibility and makes it easier to scale and maintain systems.</p><p>📍<strong> Reliability:</strong> Even if a part of the system fails, messages in the queue remain intact until they are successfully processed, reducing the risk of data loss or system failures.</p><p>📍 <strong>Asynchronous Communication: </strong>They enable asynchronous communication between different services, allowing one part of a system to send a message and continue working while another part processes the message.</p><p>Note that message queues are essential for maintaining order, improving reliability, and enabling efficient, scalable, and fault-tolerant software architectures.</p><p><strong>Exploring Pub-Sub Messaging Systems</strong></p><p>A Pub-Sub (Publish-Subscribe) Messaging System is like a digital news broadcaster. It spreads messages to many people at once, just like a megaphone in a crowd. It’s the superhero behind broadcasting information efficiently.</p><p>📣<strong> Imagine a scenario: </strong>You’re hosting a virtual event, and you want to notify all attendees about a schedule change. A Pub-Sub system allows you to announce the change, and everyone instantly receives the update without you individually contacting each person.</p><p>Now, let’s break it down: 👇</p><p>📍 <strong>Publisher</strong>: This is like the event organizer with the megaphone. They have important information to share.</p><p>📍<strong>Subscribers</strong>: These are like the event attendees listening to the megaphone. They want to receive updates.</p><p>📍<strong>Topic</strong>: The topic is the subject of the announcement. It helps ensure that the right people hear the right messages. Think of it as the category of news being broadcasted.</p><p>Here’s how it works:</p><p>👉 <strong>The Publisher </strong>(event organizer) sends out an announcement (message) about the schedule change related to a specific Topic (e.g., “Event Updates”).</p><p>👉<strong>Subscribers </strong>(event attendees) who are interested in Event Updates receive the announcement instantly, ensuring that everyone stays informed without the organizer individually contacting each attendee.</p><p>So, Pub-Sub Messaging Systems are like magical megaphones in the digital world, helping distribute information efficiently to many interested parties at once.</p><p><strong>Examples of Pub-Sub</strong> (Publish-Subscribe) systems are Kafka, Redis Pub-Sub, Google Cloud Pub/Sub, Amazon S.N.S (Simple Notification Service), Microsoft Azure Event Grid, etc.</p><p>These Pub-Sub systems offer different features and capabilities, making them suitable for various use cases in software development and IoT applications.</p><p><strong>In conclusion, </strong>Message Queues and Pub-Sub Messaging Systems play pivotal roles in modern software architecture, enabling efficient and reliable communication between components. Message Queues ensure orderly processing and decoupling of tasks, while Pub-Sub systems efficiently disseminate information to multiple recipients. These systems are crucial for building scalable, responsive, and fault-tolerant applications, making them indispensable tools for developers working with microservices and distributed systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a545d4871e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the World of Caching]]></title>
            <link>https://medium.com/@ehisjude420/exploring-the-world-of-caching-6f4be2b58bfe?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f4be2b58bfe</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Mon, 15 Apr 2024 10:52:36 GMT</pubDate>
            <atom:updated>2024-04-15T10:52:36.945Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>In this article, we’ll explore the concept of caching, and delve into its various strategies, discussing their benefits and drawbacks, and examining the importance of cache eviction policies.</p><p><strong>What is Caching ?</strong></p><p>Caching is a technique that is used to improve the performance and efficiency of data retrieval by storing frequently accessed data in a temporary, high-speed storage location called a “cache”. Caching can significantly reduce the time and resources required to fetch data from its original, slower source, such as a database or a remote server.</p><p><strong>Scenario: E-commerce Website</strong><br>Here is a simple scenario to illustrate how caching works. Let’s say you are a web developer and you have a website that displays a list of products and customers frequently search for and view product details. These product details, including images, descriptions, and prices, are stored in a database.</p><p><strong>Without caching:</strong><br>Every time a customer searches for a product or views a product page, a request is made to the database to retrieve the required data. Database queries are relatively slow and resource-intensive, especially during high traffic periods, leading to slower page loading times and increased server load.</p><p><strong>With caching:</strong><br>The first time a customer searches for a product or views a product page, the data is fetched from the database and cached in a temporary storage. Subsequent requests for the same data are served directly from the cache, which is much faster than querying the database.This reduces the load on your database server, improves page loading times, and provides a better user experience. If you are looking to improve the performance of your applications, caching is a technique that you should consider.</p><p><strong>Different caching strategies: </strong><br>📌 Cache aside<br>📌 Read-Through<br>📌 Write-Through<br>📌 Write-Behind</p><p>Note that the choice of caching strategy can vary depending on your specific use case.</p><ol><li><strong>Cache aside Caching Strategy</strong></li></ol><p>The Cache-aside is a caching strategy in which the application first checks the cache for the data it needs. If the data is not in the cache, the application retrieves it from the database and then stores it in the cache. This ensures that the cache always has the most up-to-date data.</p><p>The cache-aside strategy is different from the read-through strategy in that the application is responsible for fetching the data from the database and populating the cache.</p><p><strong>Here’s how the Cache aside strategy works:</strong></p><ul><li><strong>Cache Population: </strong>When the application needs to access a piece of data, it first checks if that data is already present in the cache. If it’s not, this is referred to as a “cache miss.”</li><li><strong>Data Retrieval: </strong>In case of a cache miss, the application retrieves the required data directly from the slower data store, which could be a database.</li><li><strong>Cache Insertion: </strong>After retrieving the data, the application explicitly stores (or “caches”) this data in the cache store, associating it with an appropriate cache key. This step is crucial as it populates the cache for subsequent access.</li><li><strong>Subsequent Access:</strong> The next time the application needs the same data, it will find it in the cache, preventing the need to fetch it from the slower data store again. This is referred to as a “cache hit.”</li><li><strong>Cache Eviction:</strong> The cache-aside strategy doesn’t inherently handle cache eviction (removing old or less frequently used data from the cache). Instead, this responsibility typically falls on the application as well. The application might use strategies like LRU (Least Recently Used) or TTL (Time-to-Live) to decide which data should be removed from the cache when it becomes full.</li></ul><p><strong>Here are some of the benefits of using the cache-aside strategy:</strong></p><ul><li><strong>Improved performance: </strong>The cache can reduce the number of requests to the database, which can improve performance.</li><li><strong>Reduced load on the database:</strong> The cache can reduce the load on the database by caching frequently accessed data.</li><li><strong>Improved data consistency:</strong> The cache can help to ensure that the data is always consistent by storing the most up-to-date data.</li></ul><p><strong>Here are some of the drawbacks of using the cache-aside strategy:</strong></p><ul><li><strong>Increased latency:</strong> The cache-aside strategy can introduce latency because the application must first check the cache for the data before it can retrieve it from the database.</li><li><strong>Data inconsistency</strong>: If the cache is not updated properly, it can become inconsistent with the database.</li></ul><p>Overall, the cache-aside strategy is a good choice for applications that need to ensure that the cache always has the most up-to-date data. However, it is important to weigh the benefits and drawbacks of this strategy before deciding whether to use it.</p><p><strong>2. Read-Through Caching Strategy</strong></p><p>Read-through caching is a caching strategy in which the application always checks the cache for the data it needs. If the data is not in the cache, the cache provider fetches the data from the database and populates the cache. This ensures that the application always gets the data from the cache, even if it has not been accessed before.</p><p>In the read-through strategy, the cache provider is responsible for fetching the data from the database and populating the cache.The read-through strategy is a good choice for applications that need to improve performance by reducing the number of requests to the database. However, it can also increase latency because the application must first check the cache for the data before it can retrieve it from the database.</p><p><strong>Here’s how the Read-Through Cache strategy works:</strong></p><ul><li><strong>Data Request: </strong>When an application requests specific data, the cache checks whether the requested data is already present (cache hit) or not (cache miss).</li><li><strong>Cache Hit:</strong> If the requested data is found in the cache, it is immediately returned to the application, eliminating the need to access the slower data store.</li><li><strong>Cache Miss: </strong>If the requested data is not present in the cache, instead of the application fetching the data from the slower data store directly, the cache takes charge by initiating the process of retrieving the data from the data store.</li><li><strong>Data Retrieval:</strong> The cache actively goes to the slower data store (such as a database) to fetch the required data. Once fetched, the data is populated into the cache.</li><li><strong>Cache Update: </strong>After fetching the data, the cache stores it in its storage, associating it with the appropriate cache key. This populates the cache for subsequent access.</li><li><strong>Data Delivery: </strong>The cache then hands over the retrieved data to the application, which requested it in the first place. This data is also retained in the cache for potential future requests.</li></ul><p><strong>Benefits of Read-Through Cache Strategy:</strong></p><p>📌 Reduced Latency<br>📌Seamless Access<br>📌Data Consistency</p><p><strong>Drawbacks of Read-Through Cache Strategy:</strong></p><p>📌Performance Overhead<br>📌Complex Implementation<br>📌Resource Consumption</p><p>Overall, the read-through caching strategy is a good choice for applications that need to improve performance by reducing the number of requests to the database. However, it is important to weigh the benefits and drawbacks of this strategy before deciding whether to use it.</p><p><strong>3. Write-Through Caching Strategy</strong></p><p>Write-through caching is a caching strategy in which the cache provider is notified whenever the database is updated. The cache provider then updates the cache with the new data. This ensures that the cache is always consistent with the database.</p><p><strong>Here’s how the Write-Through Cache strategy works:</strong></p><ul><li><strong>Data Modification:</strong> When the application updates or writes new data, it first updates the cache with the modified data.</li><li><strong>Cache Update:</strong> The cache, in a write-through configuration, immediately stores the modified data. This ensures that the cache always holds the most up-to-date information.</li><li><strong>Data Propagation: </strong>After updating the cache, the data is also propagated to the slower data store. This step guarantees that the data store also reflects the latest changes.</li><li><strong>Synchronous Update:</strong> The write to the data store is usually synchronous, meaning that the application waits for the update to be confirmed before proceeding. This ensures data consistency between the cache and the data store.</li></ul><p><strong>Benefits of Write-Through Cache Strategy:</strong></p><ul><li><strong>Data Consistency: </strong>The Write-Through Cache strategy ensures that both the cache and the data store contain the same data at all times, minimizing the risk of data inconsistencies.</li><li><strong>Immediate Updates:</strong> Updates are reflected in both the cache and the data store in real-time, maintaining the accuracy of data across the system.</li><li><strong>Less Data Loss: </strong>Since data is immediately written to the data store, there’s minimal risk of data loss in case of system crashes or failures.</li></ul><p><strong>Drawbacks of Write-Through Cache Strategy:</strong></p><ul><li><strong>Performance Impact:</strong> Writing data to both the cache and the data store introduces additional write operations, potentially impacting write-intensive workloads.</li><li><strong>Higher Latency: </strong>The synchronous nature of write operations can introduce latency in the application, as it has to wait for the data store update to complete.</li><li><strong>Resource Usage:</strong> Frequent writes to both the cache and the data store can increase resource consumption.</li></ul><p>Overall the write-through strategy is a good choice for applications that need to ensure that the cache is always consistent with the database. However, it can also increase latency because the cache provider must first update the cache before it can return the data to the application.</p><p><strong>4. Write-Behind Caching Strategy</strong></p><p>The Write-Behind Cache strategy is a caching approach used in computer systems to optimize write operations and improve performance. In this strategy, when data is modified or written by the application, the cache is updated immediately, while the corresponding update to the slower data store is deferred or postponed.</p><p><strong>Here’s how the Write-Behind Cache strategy works:</strong></p><ul><li><strong>Data Modification:</strong> When the application updates or writes new data, it first updates the cache with the modified data.</li><li><strong>Cache Update: </strong>The cache, in a write-behind configuration, immediately stores the modified data. This ensures that the cache reflects the most recent changes.</li><li><strong>Deferred Data Store Update:</strong> Instead of immediately propagating the update to the data store, the Write-Behind Cache strategy allows the application to defer this update. The system typically accumulates a batch of changes before initiating the updates to the data store.</li><li><strong>Asynchronous Update: </strong>Periodically or when a certain threshold is reached, the cache manager initiates an asynchronous process to write the accumulated changes to the underlying data store. This process can involve sending multiple updates in a single batch, reducing the overhead of individual updates.</li></ul><p><strong>Benefits of Write-Behind Cache Strategy:</strong></p><ul><li><strong>Reduced Latency: </strong>The Write-Behind Cache strategy minimizes the immediate write latency introduced by data store updates, as the cache handles the update immediately and data store updates occur asynchronously.</li><li><strong>Optimized Write Operations:</strong> Aggregating updates into batches optimizes data store write operations, improving efficiency and potentially reducing data store load.</li><li><strong>Improved Performance:</strong> For write-intensive workloads, the strategy can significantly improve overall system performance by reducing the impact of data store write delays.</li></ul><p><strong>Drawbacks of Write-Behind Cache Strategy:</strong></p><ul><li><strong>Data Store Delay: </strong>While the cache updates are immediate, the updates to the data store are deferred, which might result in a temporary inconsistency between the cache and the data store.</li><li>Managing the asynchronous updates and ensuring data consistency is complex.</li><li><strong>Potential Data Loss:</strong> If the system crashes before the deferred updates are applied to the data store, there’s a risk of losing the updates.</li></ul><p>Overall the Write-Behind Cache strategy is particularly useful for scenarios where write performance is crucial, and temporary inconsistencies between the cache and the data store can be tolerated or mitigated. It’s commonly employed in systems that deal with high write volumes, such as logging applications, where optimizing the speed of write operations takes precedence over immediate data consistency.</p><p><strong>Cache Eviction Policies</strong></p><p>These policies play a crucial role in efficiently managing limited cache space. They help determine which data to remove when the cache reaches its capacity, all while optimizing performance.</p><p><strong>What Are Cache Eviction Policies ?</strong></p><p>Cache eviction policies are rules or algorithms used to determine which data should be removed or evicted from a cache when it reaches its storage limit or when certain conditions are met.Different eviction policies are suited for different use cases.</p><ul><li><strong>Least Recently Used (L.R.U) : </strong>L.R.U is a cache eviction policy that removes the least recently used item from the cache when it’s full. In other words, the item that hasn’t been accessed for the longest time takes the exit. been accessed for the longest time will be evicted first.</li><li><strong>The Least Frequently Used (L.F.U) :</strong> L.F.U, on the other hand, evicts the item that has been used the least number of times when the cache reaches its limit. This means that the item that hasn’t been used frequently lately will be the first to go.</li></ul><p>Various caching tools like Redis, Memcached, and AWS Elasticache offer distinct features and capabilities, allowing developers to choose the best fit for their specific use cases, whether it’s for data storage, session management, or reducing database load.</p><p><strong>In summary,</strong> caching is a technique that improves data retrieval performance by storing frequently accessed data in a temporary storage location. Different caching strategies, like cache-aside and read-through, offer benefits such as reduced database load but can introduce latency and data consistency issues. Eviction policies, such as LRU and LFU, help manage cache space efficiently. Choosing the right strategy and policy is key to optimizing application performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f4be2b58bfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Differences between Daemon sets and Static pods (Thread)]]></title>
            <link>https://medium.com/@ehisjude420/differences-between-daemon-sets-and-static-pods-thread-f0cd73627fc6?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0cd73627fc6</guid>
            <category><![CDATA[static-pod]]></category>
            <category><![CDATA[differences-between]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[daemonset]]></category>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 11:06:42 GMT</pubDate>
            <atom:updated>2023-03-15T11:28:07.777Z</atom:updated>
            <content:encoded><![CDATA[<h3>Differences between Daemon sets and Static pods</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OdHyu-0VvQG0R186kUCFAQ.png" /><figcaption>image from <a href="https://itstarter.tistory.com/920">https://itstarter.tistory.com/920</a></figcaption></figure><p><strong>Introduction : </strong>Kubernetes is an open-source container orchestration platform that provides powerful tools for managing and deploying containerized applications at scale. Two important concepts in Kubernetes are DaemonSets and Static Pods. DaemonSets ensure that a specific pod is running on every node in the cluster, while Static Pods are simple pods that are managed directly by the kubelet on a specific node. While both of these features offer similar functionality, there are key differences between them that can impact how you deploy and manage your applications. In this article, we’ll explore the differences between DaemonSets and Static Pods in Kubernetes, including their use cases, benefits, and drawbacks.</p><p><strong>Prerequisites: </strong>A fundamental understanding of kubernetes and its various components.</p><p>Let’s Go !</p><p>Daemon Sets and Static Pods are two types of pods in Kubernetes that run on nodes in a cluster. However, there are some key differences between these two :</p><ol><li>Daemon Sets: Daemon sets are used to ensure that a single instance of a pod runs on every node in a cluster. This is useful for running system-level services such as log collectors, network proxies, and monitoring agents. The pods created by a Daemon Set are managed by the Kubernetes control plane, and if a node goes down, the Daemon Set controller will automatically reschedule the pod to another node.</li><li>Static Pods: Static Pods are pods that are directly created on the host rather than being managed by the Kubernetes control plane. This means that the control plane does not have control over the lifecycle of the pod, and it will not reschedule it in case of a node failure. Static pods are useful in cases where there is a need for more control over the pod, or in scenarios where the control plane itself is not available.</li><li>Daemon set ensures that one instance of an application is available on all node in a kubernetes cluster and this is handled by the deamon set controller through the api server.</li><li>Static pods are created directly by the kubelet without any inteference from the kube api-server or the rest of the other control plane components.</li><li>Both static pods and the pods created by the daemon set are ignored by the kube-scheduler.</li></ol><p>In summary, Daemon Sets are easier to manage and provide more automatic recovery, while Static Pods offer more control and can be useful in certain scenarios where the control plane is not available.</p><p><strong>Here are two examples of how Daemon Sets and Static Pods can be used:</strong></p><ol><li><strong>Daemon Set Example:</strong> Imagine you have a logging system for your cluster, and you want to ensure that there is a logging agent running on every node to collect logs from the containers running on that node. In this case, you could use a Daemon Set to automatically deploy a logging agent pod to every node in the cluster. The Daemon Set controller would take care of creating, updating, and deleting pods as needed to ensure that there is always one instance of the logging agent running on each node.</li><li><strong>Static Pod Example:</strong> Imagine you have a critical application running in your cluster that requires a specific version of a database. You don’t want the Kubernetes control plane to interfere with the running of this database, as any downtime could cause problems for your application. In this case, you could use a Static Pod to run the database on each node. By creating the Static Pod directly on the host, you bypass the control plane and have more control over the lifecycle of the pod.</li></ol><p>These are just two examples of how Daemon Sets and Static Pods can be used in a Kubernetes cluster. Both types of pods have their use cases, and the choice between the two will depend on your specific needs and requirements.</p><p>Here’s an example of how you might use a Static Pod to deploy a critical database to a Kubernetes cluster:</p><ol><li>Create a YAML file for the Static Pod definition, for example let call this yaml file db.yaml</li></ol><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: database<br>spec:<br>  containers:<br>  - name: database<br>    image: myregistry/database:v1.0<br>    ports:<br>    - containerPort: 5432<br>    volumeMounts:<br>    - name: data<br>      mountPath: /var/lib/data<br>  volumes:<br>  - name: data<br>    hostPath:<br>      path: /var/lib/data</pre><p>2. move the YAML file to the /etc/kubernetes/manifests directory on each node where you want the database to run:</p><pre>$ mv db.yaml /etc/kubernetes/manifests</pre><p>3. Restart the kubelet service</p><pre>$ systemctl restart kubelet</pre><p>4. Verify that the Static Pod has been successfully created and is running on each node:</p><pre>$ kubectl get pods</pre><p>By copying the YAML file to the /etc/kubernetes/manifests directory on each node, the Static Pod is directly created on the host and is not managed by the Kubernetes control plane but instead it is managed by the kubelet on that Node. This provides more control over the lifecycle of the pod and ensures that the database is running even if the control plane is not available.</p><p>Here’s an example of how you might use a Daemon Set to deploy a logging agent to every node in a Kubernetes cluster:</p><ol><li>Create a YAML file for the Daemon Set definition, for example:</li></ol><pre>apiVersion: apps/v1<br>kind: DaemonSet<br>metadata:<br>  name: logging-agent<br>spec:<br>  selector:<br>    matchLabels:<br>      app: logging-agent<br>  template:<br>    metadata:<br>      labels:<br>        app: logging-agent<br>    spec:<br>      containers:<br>      - name: logging-agent<br>        image: myregistry/logging-agent:v1.0<br>        ports:<br>        - containerPort: 8080<br>        volumeMounts:<br>        - name: logs<br>          mountPath: /var/logs<br>      volumes:<br>      - name: logs<br>        hostPath:<br>          path: /var/logs</pre><p>2. Apply the Daemon Set definition using the kubectl apply command:</p><pre>$ kubectl apply -f logging-agent-daemonset.yaml</pre><p>3. Verify that the Daemon Set has been successfully created and that a pod has been created on each node in the cluster:</p><pre>$ kubectl get daemonset</pre><p>In this example, the Daemon Set definition specifies a template for the logging agent pod, including the Docker image to use and the volumes to mount. The Daemon Set controller takes care of creating one instance of the pod on each node in the cluster and managing its lifecycle, ensuring that there is always a logging agent running on every node.</p><p><strong>In conclusion</strong>, Daemon Sets and Static Pods are two distinct concepts in Kubernetes that can be used to deploy and manage your applications. While Daemon Sets are best suited for deploying and managing background processes that need to run on all nodes in a Kubernetes cluster, Static Pods are ideal for deploying and managing simple, single-instance pods that run on a specific node.</p><p>By understanding the differences between these two concepts and their use cases, you can make informed decisions when it comes to deploying and managing your applications in Kubernetes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0cd73627fc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to achieve  encapsulation in Java]]></title>
            <link>https://medium.com/@ehisjude420/how-to-achieve-encapsulation-in-java-add6ef27d033?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/add6ef27d033</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Mon, 13 Feb 2023 10:58:44 GMT</pubDate>
            <atom:updated>2023-02-13T10:58:44.353Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ALcdSbpATl1AiYYTpT7KVA.png" /></figure><h3>How to achieve encapsulation in Java</h3><p><strong>Introduction :</strong> Encapsulation is one of the fundamental concepts of object-oriented programming (OOP), and it plays a crucial role in designing robust and maintainable software systems. In Java, encapsulation is the process of wrapping data and behavior within an object, providing a level of abstraction and protection from direct access and modification. By using encapsulation, developers can hide the internal details of a class, reduce the coupling between objects, and increase the overall stability and security of a system.</p><p>In this article, we will briefly discuss about what OOP is, the four basic concept of OOP, the basics of encapsulation in Java and explore some best practices for achieving encapsulation in your code. I hope this article will help provide valuable insights and practical tips to help you improve your OOP skills and build better applications.</p><p><strong>Prerequisites :</strong> In order to understand the example of implementing encapsulation in java I will be using, it is necessary that you have prior knowledge of programming language (i used java in this article).</p><p>let’s GO !</p><p>Before we delve into the topic of encapsulation in Java, let us first have a brief overview of Object-Oriented Programming (OOP) and its fundamental principles.</p><p><strong>what is Object-Oriented Programming (OOP) ?</strong></p><p>Object-Oriented Programming (OOP) is a programming paradigm that is based on the concept of “<strong>objects</strong>”, An object is a combination of data and behavior, which can represent a real-world entity, such as a person, a car, or a bank account. OOP provides a way to organize code and create reusable, modular components that can interact with each other.</p><p>In OOP, the behavior of an object is defined by its methods, and the data is stored in fields or properties.</p><p><strong>The four basic principles of OOP are:</strong></p><ol><li><strong>Encapsulation:</strong> Encapsulation is the mechanism of wrapping data and functions within an object, hiding the implementation details from the outside world. This helps in protecting the data from unauthorized access and modification, and ensures that the object’s behavior remains consistent even if the implementation changes.</li><li><strong>Abstraction:</strong> Abstraction refers to the ability to focus on the essential features of an object, ignoring the non-essential details. In OOP, abstraction is achieved through classes, which provide a blueprint for objects</li><li><strong>Inheritance:</strong> Inheritance is the mechanism of creating new classes based on existing classes. The new classes inherit the properties and behaviors of the existing classes, and can also add new features and modify existing ones. This helps in creating a hierarchical class structure and promotes code reusability.</li><li><strong>Polymorphism: </strong>Polymorphism is the ability of an object to take on many forms. In OOP, polymorphism is achieved through method overriding and method overloading, which allow objects of different classes to respond to the same method call in different ways.</li></ol><p>These principles work together to provide a structured and organized approach to programming, and help to promote software modularity, maintainability, and extensibility.</p><p>To read more about OOP and its principles, check out</p><ul><li>check out this article from <a href="https://www.educative.io/blog/object-oriented-programming">Educative.</a></li><li>check out this article from <a href="https://www.spiceworks.com/tech/devops/articles/object-oriented-programming/">spiceworks</a></li></ul><p>Now let me talk about how we can achieve encapsulation in java, there are various ways to achieve encapsulation in java.</p><p><strong>There are several best practices for achieving encapsulation in Java:</strong></p><ol><li>Declare instance variables as private: This ensures that the variables can only be accessed within the class and not from outside.</li><li>Use getters and setters: Getters and setters provide controlled access to the instance variables. This allows you to validate data before setting the value and perform additional actions after getting the value.</li><li>Use constructor arguments to set required values: This allows you to set required values for an object and ensures that these values are set when the object is created.</li><li>Avoid using public static variables: Public static variables can be accessed from anywhere in the code and their values can be changed by any part of the code. Instead, use private static variables and provide getters and setters if necessary.</li></ol><h4><strong>Using access modifiers</strong></h4><p>One of the most important ways to achieve encapsulation in Java is through the<strong> use of access modifiers</strong>. Java provides several access modifiers such as public, private, protected, and default, that allow you to control the visibility of your class members. For example, you can make a class member private by using the private access modifier. This makes the member only accessible within the class, making it impossible for any other class to access it directly.</p><p>In java encapsulation can be achieved by using access modifiers such as private and public to control the visibility of class variables and methods.</p><pre>public class Employer {<br><br>  private String name;<br>  private String address;<br><br>}</pre><p>The java code above is an “Employer” class with two private variables of type String, named “name” and “address”.</p><p><strong>Using the getter and setter methods</strong></p><p>Another way to achieve encapsulation in Java is through the <strong>use of getter and setter methods</strong>. Getter methods allow you to retrieve the value of a class member, while setter methods allow you to set the value of a class member. You can make a class member private and only provide access to it through these methods. This way, you can ensure that the value of a class member can only be changed through the setter method and that it can only be retrieved through the getter method. This ensures that the data is protected and that it can only be accessed through well-defined interfaces.</p><pre>public class Employer {<br><br>  private String name;<br>  private String address;<br><br>  public String getName(){<br>    return name;<br>  }<br>  public void setName(String name){<br>    this.name = name;<br>  }<br>  public String getAddress(){<br>    return address;<br>  }<br>  public void setAddress(String address){<br>    this.address = address;<br>  }<br><br>}</pre><p>The code above defines a Java class called “Employer”. It has two private instance variables, “name” and “address”, which are both of type String. This means that these variables can only be accessed within the class.</p><p>The class also provides four methods:</p><ol><li>getName() - returns the value of the &quot;name&quot; instance variable.</li><li>setName(String name) - sets the value of the &quot;name&quot; instance variable to the value passed as an argument.</li><li>getAddress() - returns the value of the &quot;address&quot; instance variable.</li><li>setAddress(String address) - sets the value of the &quot;address&quot; instance variable to the value passed as an argument.</li></ol><p>These methods are used to access and update the private variables from outside the class. The use of getters and setters is considered a good practice as it provides a level of abstraction and encapsulation to the class. The this keyword is used to refer to the current instance of the class within its own methods.</p><p>The principle of encapsulation is achieved by keeping the variables private and exposing public get and set methods. This allows us to hide the internal state of the student object and protects it from unauthorized access and modification.</p><p>By doing so, we can change the implementation of the student object in the future without affecting the client code, making the code more maintainable and flexible. Encapsulation provides a level of abstraction that is crucial for software development.</p><p><strong>In summary,</strong> OOP provides a powerful and flexible way to model real-world entities and organize code, making it easier to create complex software systems that are easier to maintain and evolve over time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=add6ef27d033" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Different ways to configure environmental variables in kubernetes.]]></title>
            <link>https://medium.com/@ehisjude420/different-ways-to-configure-environmental-variables-in-kubernetes-d446709e7656?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d446709e7656</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Mon, 06 Feb 2023 08:40:15 GMT</pubDate>
            <atom:updated>2023-02-06T08:40:15.097Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*2c_p9erGnYITnWu2E7dtrg.jpeg" /></figure><p><strong>Different ways to configure environmental variables in kubernetes.</strong></p><p><strong>Introduction : </strong>Environmental variables play an important role in the configuration of applications running in a <strong>Kubernetes (k8s) </strong>cluster. These variables store information such as API keys, passwords, and other configuration data that are used by the containers in a Pod to connect to external resources and interact with each other.</p><p>In this article, we will explore the different ways to configure environmental variables in Kubernetes, including how to declare variables in the Pod definition file, using <strong>ConfigMaps</strong> and <strong>Secrets</strong>. Understanding these methods will help you choose the best approach for your specific requirements and enable you to better manage configuration settings for your applications running in a K8s cluster.</p><p><strong>Prerequisites :</strong> Before reading this article, you should be familiar with</p><ul><li>Containerization and Docker.</li><li>Kubernetes architecture and its components (check out this <a href="https://medium.com/@ehisjude420/kubernetes-as-a-container-orchestrating-tool-5ee477ce1ad9">article </a>i wrote on K8s).</li><li>Familiarity with command-line interface (CLI) and YAML syntax.</li><li>Also i will mostly refer to Kubernetes as k8s.</li></ul><p>Let’s Go !</p><p><strong>What are environmental variables ?</strong></p><p>In Kubernetes, environmental variables refer to key-value pairs that are supplied to containers during runtime. They serve as labels or tags for information, making it easy to locate and utilize when needed.</p><p>For example, imagine you are going on a road trip and need to plan your route. You write down the name of each city you want to visit and attach a label or tag called “destination” to each one. Now, you have a list of destinations that you can easily reference and update as needed.</p><p>Similarly, in software development, environmental variables can be utilized to store crucial information like database credentials, API keys, or configuration settings, and labeled or tagged for easy retrieval. By doing this, the application can reference and utilize this information without having to embed it directly into the code.</p><p>So, in simple terms, an environmental variable is a label or tag that you attach to a piece of information to make it easily accessible and reusable within your application.</p><p><strong>Why do we need environmental variables ?</strong></p><p>Environmental variables play a crucial role in modern software development, as they provide a way to store and access configuration information for your applications. In the context of K8s, environmental variables are used to configure the behavior of containers and applications running within the cluster. By using environment variables, you can decouple configuration information from the application code, making it easier to manage and maintain the application. Furthermore, environmental variables provide a convenient way to configure applications for different environments, such as development, staging and production.</p><p>For example, you can use environment variables to configure database credentials, API keys, and other sensitive information in a secure and controlled manner. Overall, environmental variables are a key tool for building robust and scalable applications on K8s.</p><p>There are several ways to configure environmental variables in K8s, such as :</p><ol><li><strong>Declaring variables in the Pod definition file using name and value pair</strong></li></ol><p>Declaring variables in a Pod definition file in K8s is a way to pass data to your containerized applications at runtime. This data can include environment variables, command-line arguments, or configuration files. Declaring variables in the Pod definition file is a flexible and straightforward method for configuring your applications.</p><p>In the Pod definition file, you can use the env field to define environment variables that will be set within the container. For example</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: my-pod<br>spec:<br>  containers:<br>  - name: my-container<br>    image: busybox<br>  - env:<br>    - name: DATABASE_HOST<br>      value: postgres<br>    - name: DATABASE_NAME<br>      value: product<br>    - name: DATABASE_PASSWORD<br>      value: pr0dr0b0t<br>    - name: DATABASE_USER<br>      value: product_robot<br>    - name: DATABASE_PORT<br>      value: &quot;5432&quot;</pre><p>Declaring variables in the Pod definition file is a simple and effective way to configure your applications in K8s and the environmental variables can be declared in the Pod definition file as a list of key-value pairs and passed to the containers running in the Pod.</p><p><strong>2. Using ConfigMap</strong></p><p>ConfigMap is a K8s object that is used to store configuration data for applications as key-value pairs. It allows you to decouple configuration data from the application image and store it in a centralized location. You can manage the configuration data in ConfigMap using kubectl, or you can create and update ConfigMap objects using manifests. ConfigMap can be used in multiple ways in K8s, such as setting environment variables, providing configuration files, or passing command-line arguments to containers.</p><p>With ConfigMap, you can configure and update your application without having to rebuild the image, making it a flexible and scalable way to manage configuration in K8s.</p><p>Here is an example of using ConfigMap in K8s with YAML manifest:</p><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata: <br>  name: app-config<br>data:<br>  APP_COLOR: blue<br>  APP_MODE: prod</pre><p>This ConfigMap creates two key-value pairs: APP_COLOR and APP_MODE</p><p>To use this ConfigMap in a Pod definition :</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: simple-webapp-color<br>  labels:<br>    name: simple-webapp-color<br>spec:<br>  containers:<br>    - name: simple-webapp-color<br>      image: simple-webapp-color<br>      ports:<br>        - containerPort: 8080<br>      envFrom:<br>        - configMapRef:<br>            name: app-config</pre><p>The environment variables APP_COLOR and APP_MODE are set using the envFrom field and referencing the ConfigMap using the configMapRef field.</p><p>With this setup, the container can access the configuration data from the mounted ConfigMap and use it to configure the application.</p><p>For more information on using ConfigMap as environmental variables in K8s, check out the official K8s <a href="https://kubernetes.io/docs/concepts/configuration/configmap/">Documentation</a>.</p><p><strong>3. Using Secrets</strong></p><p>Secrets in K8s can be used to configure environmental variables for Pods. Secrets are stored as key-value pairs and can be passed to a Pod as environment variables or used to mount a volume in the Pod. When using Secrets, sensitive information is stored in an encrypted form and is only decrypted and made available to the Pod at runtime.</p><p>To configure environmental variables with Secrets in K8s, you need to first create the Secret and then reference it in the Pod definition file using the envFrom field in the spec.containers section. This allows you to map the keys in the Secret to the environment variables in the Pod.</p><p>Here’s an example of how to configure environmental variables using secrets in K8s:</p><ol><li>First encode your secrets with base64 : Base64 encoding can be used to encode secrets in k8s. To encode a secret with base64 in the terminal, you can use the following command :</li></ol><pre>echo -n &quot;user1&quot; | base64<br>r34TYp89AtrQ= </pre><pre>echo -n &quot;myhost&quot; | base64<br>cGf56tyGjH</pre><pre>echo -n &quot;password1$&quot; | base64<br>ghTu780POl</pre><p>Note that “user1”, “myhost” and “password1$” are the sensitive values i want to encode. This will return the encoded secret as a string of characters in base64 format.</p><p>2. Create a secret in your Kubernetes cluster by storing sensitive information in a key-value format. In a k8s YAML file, you can add the encoded secret as the value of an environmental variable, like this:</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: app-secret<br>data:<br>  DB_Host: cGf56tyGjH  #encoded base64 format<br>  DB_User: r34TYp89AtrQ=   #encoded base64 format<br>  DB_Password: ghTu780POl  #encoded base64 format</pre><p>Note that the values are base64-encoded, as secrets are stored as binary data in the K8s cluster.</p><p>3. Use the envFrom field in your pod definition to set environment variables from the secret.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: simple-pod<br>  labels:<br>    name: simple-webapp-color<br>spec:<br>  containers:<br>    - name: simple-webapp-color<br>      image: simple-webapp-color<br>      ports:<br>        - containerPort: 8080<br>      envFrom:<br>        - secretRef:<br>            name: app-secret</pre><p>This will set three environment variables which are DB_Host, DB_User and DB_Password based on the data stored in the secret.</p><p>OR via the CommandLine Interface (CLI), run the following command :</p><p>kubectl create secret generic db-secret --from-literal=DB_Host=sql01 --from-literal=DB_User=root --from-literal=DB_Password=password123</p><p>4. Verify that the environment variables are set by accessing the pod and checking the environment:</p><pre>kubectl exec simple-pod env | grep DB_User</pre><p>The above command will give you the below result:</p><pre><br>DB_Host=user1</pre><p>With these above steps, you can securely configure environmental variables in your Kubernetes cluster using secrets.</p><p><strong>Note :</strong> Secrets are not encrypted but are encoded data in base64 format and anyone with the base64 encoded secret can easily decode it. As such the secrets can be considered not very safe. However, some best practices around using secrets make it safer. As in best practices like:</p><ul><li>Not adding secret object definition files to source code repositories.</li><li><a href="https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/"><strong>Enabling Encryption at Rest</strong></a><strong> </strong>for Secrets so they are stored encrypted in ETCD. (check out the official K8s <a href="https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/">Documentation </a>for more info about enabling encryption at Rest in ETCD )</li></ul><p>Also the way K8s handles secrets, such as:</p><ul><li>A secret is only sent to a node if a pod on that node requires it.</li><li>Kubelet stores the secret into a tmpfs so that the secret is not written to disk storage.</li><li>Once the Pod that depends on the secret is deleted, kubelet will delete its local copy of the secret data as well.</li></ul><p>For more information on using Secret as environmental variables in K8s, check out the official K8s <a href="https://kubernetes.io/docs/concepts/configuration/secret/">Documentation</a>.</p><p><strong>In conclusion</strong>, configuring environmental variables in K8s is an important aspect of deploying and running applications in a cluster. Whether you prefer to use ConfigMaps, Secrets, or the command-line interface, it is important to choose the right method for your specific needs and to make sure your configurations are secure and managed correctly.</p><p>By understanding the different ways to configure environmental variables in K8s, you can ensure that your applications are deployed and running smoothly, and that the data they need to function is readily available. With the ability to configure environmental variables, you can create flexible and scalable applications that can be adapted to meet changing requirements, while maintaining control over the configuration data they need to function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d446709e7656" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes as a Container Orchestrating tool (Part Two)]]></title>
            <link>https://medium.com/@ehisjude420/kubernetes-as-a-container-orchestrating-tool-part-two-1bfb367fd31?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bfb367fd31</guid>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Mon, 21 Nov 2022 10:10:19 GMT</pubDate>
            <atom:updated>2022-11-21T10:10:19.239Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQzbo5t_A76h6aDBY3YlBQ.png" /></figure><p><strong>Introduction</strong></p><p>In this article, I will be discussing about kubernetes, what happens when applications get deployed into a Kubernetes cluster and the different components involved in this process. In a Kubernetes cluster, there are lots of components that will enable the deployments of applications into a cluster. You can check out <strong>the first part of this </strong><a href="https://medium.com/@ehisjude420/automating-software-releases-with-aws-code-pipeline-b90b87a7546e"><strong>article</strong> </a>I wrote about Kubernetes to get more info. Note that in this article I will mostly refer to Kubernetes as k8s.</p><p>Let’s go …</p><p><strong>Kubernetes </strong>is a container orchestration tool i.e it’s the job of K8s to start and stop container-based applications. We can define our workload in code (desired state) and k8s will help make sure that our application remains in that <strong>desired state</strong>. The desired state is a concept in k8s that when we define what our application should look like hence it is the job of k8s to make sure that our system meets that defined desired state.</p><p>Remember that a pod is wrapped around deployment and a deployment contains the containerized application we want to deploy into a k8s cluster. K8s only work with pods and deployments that is why we want to wrap our application around a pod.</p><p>what is a pod ?</p><p><strong>Pod:</strong> It’s the basic unit of work in k8s. It can contain one or more container-based applications. it is just your container-based application that needs to be deployed into your k8s cluster. But it’s advisable to have just one application per pod.</p><p>what are the components of k8s ?</p><p>K8s cluster is made up of two different type of nodes, which are :</p><ul><li>control-plane Node</li><li>worker node.</li></ul><p><strong>Control plane node:</strong> It handles the cluster management, operations, pod scheduling, monitoring of pods, and restarting of failed pods and it is the primary access point for any cluster-related activity.</p><p>There are four components running on every master node. These components are:</p><ol><li><strong>API-server:</strong> It’s the front-end interface of the K8s Cluster. It is a restful API that exposes restful CRUD operations and listens over Http or Https using JSON. When a request is sent to the cluster, the api-server acts as the cluster gateway, i.e it is the first entry point or the only way we can interact with the cluster. Also, the api-server validates the request and acts as a gatekeeper for authentication, and also persists the info into the etcd. By default, the api-server runs on port <strong>6443</strong> but can be configured to use another port. This port is used by all that need to communicate with the api-server. Anytime you interact with k8s, you interact with the api-server also called the k8s API.</li></ol><p><strong>2. etcd:</strong> It is the persistent key-value store of the cluster. Every change in the cluster gets saved or updated in this key-value store. When we send a request to the api-server, the api-server first persists that info into the etcd store. The etcd runs between the port range of <strong>2379–2380</strong>. Only the api-server can communicate with the etcd within that port range.</p><p><strong>3. The Scheduler:</strong> The scheduler is in charge of pod scheduling and It watches the api-server for unscheduled pods and tries to schedule them on the worker node based on the available resources on the worker node and the pod requested resources. It runs on port 102551 and it is only used by itself.</p><p><strong>4. Controller-manager:</strong> It is responsible for keeping the k8s cluster in the desired state. It also detects state changes of the k8s cluster. For example, if we specify that we want 4 pod(desired state) running of a particular application , and one of that pod crashes for some reason, the replica-set controller which is an example of a controller manager will be aware and it will try to keep the cluster in the specified desired state by sending a request to the scheduler to reschedule a new pod. It runs on port 10252 and it is only used by itself. Examples of controller-managers are replica-set controllers and deployment controllers.</p><p>Note that the control plane will only run pods that are system pods, examples are the api-server pod, etcd pod, scheduler pod, and controller-manager pod. The control plane does not run your application pod because this is the job of the worker nodes.</p><p>So what is a worker node ?</p><p><strong>Worker Node:</strong> This is where our application pods get deployed into and run our workloads. The worker node can start a pod and the container inside the pod. Also, the worker node ensures there is networking reachability to the pods and services running in the worker node. Worker nodes can be both physical or Virtual machines. The worker nodes will have the kubelet, kube-proxy and any container runtime such as Docker running inside. The worker nodes are managed by the master Node.</p><p>Note that the worker nodes need more resources like CPU, ram, and storage than the master nodes because the worker node runs more load.</p><p><strong>Kube-proxy:</strong> It is responsible for forwarding requests between the services and pods. It is responsible for pod networking and also responsible for routing traffic to pods. It also does load balancing, if there are multiple replicas of a particular pod.</p><p><strong>Container Runtime Interface (CRI):</strong> It is where the actual runtime environment where our container-based applications will run. An example of a container runtime is docker or container-d. It has the responsibility of pulling the container image from our container registry and starting and stopping the container.</p><p><strong>kubelet:</strong> It is an agent on the node that receives the request from the scheduler. It is responsible for starting a container inside a pod. it interacts with the container runtime and node during this process. It is responsible for starting and stopping a pod. The kubelet report the operational status of both pod and node state changes to the api-server. It runs on port 10250 and it is used only by all the control plane components.</p><p>Note that kube-proxy, kubelet and container runtime are components that are required on both master and worker nodes.</p><p>Now how do you interact with your k8s cluster ? One of the tools you can use is a command line tool called Kubectl.</p><p>The diagram below shows the different components in k8s and the image was gotten from this <a href="https://www.researchgate.net/figure/The-control-components-of-K8S-45_fig3_353250083">www.researchgate.net.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*V5H3vsn6Q0n9-zaKqq9jfQ.png" /><figcaption>k8s components</figcaption></figure><p>what is kubectl ?</p><p><strong>Kubectl:</strong> This is the command-line tool used to communicate with the K8s cluster. When we interact with k8s, we are most likely to use kubectl which is a k8s CLI tool. We can use kubectl to perform operations on our k8s cluster. When we use kubectl commands to create a resource in k8s, we are most likely sending a POST request to the K8s api-server.</p><p>Example of using a kubectl command : Assuming we want to view all the worker nodes on our current k8s cluster, we will type the kubectl command “<strong>kubectl get nodes</strong>”, what we are actually doing is sending a GET request to the K8s api server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMQfRrYeX830fNfZABKOHw.jpeg" /><figcaption>kubectl get nodes</figcaption></figure><p>The above image shows the worker nodes i currently have on my Amazon EKS Cluster i created. Note that when using a managed k8s service like Amazon EKS, you are only responsible for your worker nodes while the cloud provider in this case Amazon web service takes care of your master nodes for you. Click on this <a href="https://aws.amazon.com/eks/">Link </a>to learn more about Amazon EKS.</p><p><strong>What are the processes involved when applications are been deployed into a k8s cluster and how the different k8s components interact with each other ?</strong></p><p>Let’s say we have a k8s cluster with <strong>one control plane node</strong> and <strong>two worker nodes</strong> and we have a request to deploy an application into the K8s cluster. When we want to do is deploy a pod that contains our application into the K8s cluster. Assuming you already have your deployment file called deployment.yaml, which is a manifest file that contains information about the application deployment.</p><p>To deploy this application into k8s, on the command line using the kubectl command we type “<strong>Kubectl apply deployment.yaml</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*yhPz9rfOjx1EHMjp8lEWlQ.png" /><figcaption>nginx-deployment.ymal</figcaption></figure><p>The above screenshot was gotten from <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">https://kubernetes.io/docs/concepts/workloads/controllers/deployment/</a></p><p>What happens next is Kubectl will send the request to <strong>the api-server </strong>which will validates your request and if all is okay it sends it to the <strong>etcd store</strong> to store the information.Next the <strong>controller manager</strong> now requests <strong>the scheduler</strong> to schedule a pod on a node. Note that the scheduler is always watching etcd and to see if etcd has any pods that need to be assigned to a node. The scheduler decides on the worker node to schedule that pod based on the available resources in the worker node and the requested resources that the pod needs. After deciding on the worker node to schedule the pod, the scheduler now sends the request to the corresponding <strong>kubelet</strong> on the specified worker node.</p><p>It’s the kubelet that does the actual scheduling on the worker node. The kubelet will then send a message to the <strong>container runtime</strong> on that worker node to pull down the appropriate docker image specified in the pod spec of the manifest file (deployment.yaml) and start the pod on that worker node. If the pod is a member of a <strong>service </strong>then that service info is updated in the <strong>Kube-proxy</strong> on that node.</p><p>what is a service ?</p><p>A <strong>service </strong>provides a persistent access point to our pods (deployed applications) in k8s. Since pods are ephemeral i.e there are not designed to run forever, and when a Pod is dies or is terminated it cannot be brought back but instead a new pod is rescheduled into the k8s cluster. So when a new pod is rescheduled into the k8s, the only way the other k8s object can reach this new pod is via a service. For more info about k8s service click on this <a href="https://kubernetes.io/docs/concepts/services-networking/service/">link</a> from the official k8s documentation.</p><p><strong>Summary </strong>: Note that when you run k8s in the cloud using either EKS, GKS, or AKS, i.e Platform as a Service (PaaS), the control plane is completely abstracted from you. You have no control over the control plane i.e the scaling, underlying infrastructure and management will be handled by the cloud provider but you will be in-charge of the worker node. If you are running k8s on-prem(Physical data-center), both the control plane and the worker node will be left to you to manage.</p><p>Also the kubectl is the only k8s component that doesn’t run as a container, it runs through Systemd service and the kubelet, Kube-proxy along with container runtime must be installed on every node either the master node or worker node. Also, both the kubelet and Kube-proxy come together with the api-server.</p><p>The sole purpose of this blog is to document and share the concepts and tools i am currently learning during my cloud journey, so feel free to give feedbacks and i am open to criticism. Thank You for taking your time to read.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bfb367fd31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating software releases with AWS Code Pipeline.]]></title>
            <link>https://medium.com/@ehisjude420/automating-software-releases-with-aws-code-pipeline-b90b87a7546e?source=rss-de4b9b517c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b90b87a7546e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-codepipeline]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Ehis Iribhogbe]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 10:41:45 GMT</pubDate>
            <atom:updated>2021-12-09T10:41:45.046Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automating software releases with AWS Code Pipeline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*64UuVMVzLVgJLYj2XPul7A.png" /></figure><p><strong>Brief introduction:</strong> Here, I will give a brief introduction of a DevOps CI/CD pipeline, the process flow of a good CI/CD pipeline. I will also give examples of some of the commonly used CI/CD tools, I will be using AWS Code pipeline as my CI/CD tool so I will give a brief definition of AWS Code pipeline with some of its benefits. I will conclude with the different stages, and components of AWS Code pipeline and its different actions types with providers. So stay with me.</p><p>Let’s Go…</p><p><strong>What is a DevOps Pipeline?</strong></p><p>A DevOps pipeline is a set of practices and tools that development and operations teams use to produce, test, and deploy software more quickly and efficiently. You must first write code before releasing an app or a new feature to users. Then double-check that it doesn’t result in any fatal errors, which could cause the app to crash. Avoiding such scenarios involves running different types of tests. Finally, after everything is operating well, you may make the code available to your users. From this simple explanation, you can conclude that a DevOps pipeline consists of build, test, and deploy stages.</p><p>To ensure that code moves from one stage to another seamlessly requires that we implement several strategies like <strong>continuous Integration and continuous delivery </strong>(CI/CD).</p><p><strong>The process flow of a CI/CD</strong>: When developers push code to a remote source repository, it triggers a continuous integration system that kicks off builds, tests, and other processes. The <strong>continuous integration</strong> system can run code analysis, syntax checks and other processes that ensure the code adheres to standards. If all tests passed successfully, then packaging, publishing artifacts, or containerization is also performed in the pipeline. <strong>Continuous delivery </strong>is an extension<strong> </strong>of continuous integration. It entails encouraging developers to deploy code to production in small pieces to speed up the release process. After all, tests must have passed, developers push their code to a staging environment where Quality Assurance Engineers perform numerous tests before the code can be pushed to a production environment so it can be accessible to users.</p><p><strong>Examples</strong> of some commonly used continuous integration and deployment tools are <a href="https://www.jenkins.io/"><strong>Jenkins</strong></a>, <a href="https://travis-ci.org/"><strong>Travis-ci</strong></a>,<a href="https://circleci.com/"><strong> circle-ci</strong></a><strong>, </strong><a href="https://about.gitlab.com/"><strong>GitLab</strong></a><strong>, </strong><a href="https://www.jetbrains.com/teamcity/?source=google&amp;medium=cpc&amp;campaign=12704032245&amp;gclid=CjwKCAiA78aNBhAlEiwA7B76p9c8FbSubyav2yG8ep4uTsicouYXuINJQduecoVJSZk9jFwMjnSSsxoCYjYQAvD_BwE"><strong>Teamcity</strong></a><strong>,</strong><a href="https://bitbucket.org/product/features/pipelines"><strong> bitbucket pipelines</strong></a><strong>, </strong><a href="https://aws.amazon.com/codepipeline/"><strong>AWS Code pipeline</strong></a><strong>, </strong>etc.</p><p>Stay with me…</p><p><strong>What is AWS Code Pipeline?</strong></p><ul><li>AWS provides some set of services to enable companies to rapidly and reliably build and deliver products using DevOps practices. These services simplify provisioning and managing infrastructure, deploying application code, automating software releases processes, and monitoring your application and infrastructure performance.</li><li>AWS code pipeline is a continuous integration and pipeline service in aws. It allows you to define the different stages and actions of your software release process in one place and help visualize how your code flows from a source repository all the way to the deployment environment. Based on the release processes defined, AWS code pipeline can help you orchestrate the building, testing, approval, and deployment of your application every time an update has been made to your source repository system.</li></ul><p><strong>Benefits of using AWS Code Pipeline</strong></p><ol><li>It is a fully managed pipeline service.</li><li>You pay for the only active pipelines.</li><li>Tight integration with many other aws services.</li><li>extensible via lambda and custom actions.</li></ol><p><strong>Different Components within the AWS Code Pipeline</strong></p><ol><li><strong>Pipeline:</strong> The definition of software release processes. The pipeline ties all of the steps and systems involved in your release process. A pipeline can also be considered as a code with instructions and actions to be taken by a continuous and deployment tool like aws code pipeline during the CI/CD process.</li><li><strong>Executions: </strong>The invocations of a defined pipeline process. Each pipeline has an execution history and each execution has an execution id, status, source revision, and completed date.</li></ol><p>Don’t leave me yet…</p><p><strong>Different stages in AWS Code Pipeline.</strong></p><ol><li><strong>Source Stage:</strong> This is where your source code is being stored. This is where the CI/CD process kicks off, here developers constantly push code here. It supports four different providers currently which are AWS CodeComit, Amazon ECR, Amazon s3, and Github.</li><li><strong>Build or Test Stage</strong>: Here, your code is constantly tested and if all tests pass, your code is built with a build tool based on the programming language of your code. If the build is successful, it can be packaging and containerization can also be done. The code pipeline build action type, the supported providers are aws code build and Jenkins.</li><li><strong>Deployment</strong> <strong>stage</strong>: If the test and build stage is successful, the deployment process kicks off, this is where the outputs from the test and build stage are deployed to several environments like staging and production environment. For the deploy action types, supported provided include aws cloud formation, aws code deploy, Elastic beanstalk, Jenkins, and fargate.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*Sj2_hyRhEwJJtSkwRUAgfw.png" /><figcaption><strong>Different stages on a Code Pipeline</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*1IfEfNMYjNWUHjXG0wyalg.png" /></figure><p><strong>Note:</strong></p><ul><li>A Code pipeline requires at least two stages i.e a source stage and any other between the build or deploy stage and at any point in your pipeline, you can trigger a lambda function.</li><li>You can always add a new stage to a pipeline.</li><li>When using aws code pipeline as your CI/CD tool, on the test and build stage if you choose aws code build as your action provider, a <strong>buildSpec.yml file </strong>will be required to perform the test and build process. This buildSpec.yml file contains instructions that will be performed on the test and build stage while for the deployment stage if aws code deploy is the chosen action provider, an <strong>appSpec.yml file </strong>will be needed here to perform the deployment process, this file contains the instructions for the deployment stage.</li><li>If you are using <strong>jenkins</strong> as your CI/CD tool, a YAML formatted pipeline script will be required to automate the test, build, and deployment processes. You can refer to my<a href="https://medium.com/@ehisjude420/jenkins-as-an-automation-tool-4f2c52afda5"> article</a> on Jenkins for more info or check the official <a href="https://www.jenkins.io/">documentation</a> website.</li></ul><p><strong>Components within the aws code Pipelin</strong>e</p><ol><li><strong>Stages: </strong>It is a particular phase or a functional portion of your pipeline. In AWS code Pipeline a stage is a collection of action groups that contain actions.</li><li><strong>Transitions:</strong> This is the connection between stages. It can be disabled which will prevent execution from traveling through the reminder pipeline.</li><li><strong>Artifacts: </strong>Different stages can have input and output artifacts, depending on the type of stage. For example, the source stage outputs an unmodified artifact, the build stage can take this artifact as its input artifact and perform some modification and output a new artifact which will be passed along to the deploy stage of the pipeline as an input artifact.</li></ol><p>Almost done…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6mXf-jXBiq5y6WNGUw5H8A.png" /><figcaption><strong>pipeline components</strong></figcaption></figure><p><strong>Different action types and providers available to use inside aws code Pipeline</strong></p><ol><li><strong>Source action type: </strong>The source action providers are used to kick off the AWS code pipeline ci/cd process. The supported action providers are CodeComit, Amazon ECR, Amazon s3, Github.</li></ol><p>2<strong>. Build action type: </strong>The providers here are was codeBuild, Jenkins.</p><p>3.<strong> Test action type:</strong> It offers integration with AWS CodeBuild, AWS device farm, Jenkins.</p><p>4. <strong>Deploy action type</strong>: Its providers include AWS cloud formation, code deploy, elastic beanstalk, was ECS, S3 bucket.</p><p>5.<strong> Approval action type: </strong>It includes one option which is manual approval or Denial action. This is used to give approval for code to be deployed to a more stable environment like production. When all kinds of tests have been performed by the Quality Assurance Engineers in the staging environment before the code can be pushed to the production environment, manual approval will be required by the Team lead and also a denial action can be taken too.</p><p>6. <strong>Invoke action type:</strong> The single provider is the AWS lambda, which can be used to perform custom logic that needs to run as part of your continuous deployment process.</p><p><strong>In Summary:</strong> Note that a pipeline is a continuous tool that defines your entire release process. You can have a stage where your source repository kicks off this pipeline when an update is pushed. You can also have a stage where your code is built, tested, your code is deployed to a staging environment when the build process is completed. In the staging environment, Quality Assurance Engineers perform their different tests and manual approval might be required for validation before the code is being deployed to the production environment. AWS ci/cd pipeline can be created by using the aws console or executing a YML formatted template file.</p><p>I hope with this brief article, you now have a little understanding of what a DevOps pipeline is and how it can help speed up your software development life cycle. However, the DevOps pipeline is a broad subject, and every organization will have its own way of integrating one into its workflows. The main goal is to deliver high-quality products faster and easier in an automated way.</p><p>The end…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b90b87a7546e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>