Gunaseela Perumal M’s Post

View profile for Gunaseela Perumal M, graphic
Gunaseela Perumal M Gunaseela Perumal M is an Influencer

Vice President - Cloud Engineering | Kubernetes | SRE | AI Enthusiast | Goldman Sachs | IIM Bangalore | LinkedIn Top Voice

𝗥𝘂𝗻 𝗟𝗲𝗮𝗱𝗲𝗿 𝗘𝗹𝗲𝗰𝘁𝗶𝗼𝗻 𝗔𝗺𝗼𝗻𝗴 𝗣𝗼𝗱𝘀 𝗶𝗻 𝗞𝘂𝗯𝗲𝗿𝗻𝗲𝘁𝗲𝘀 𝗟𝗲𝗮𝗱𝗲𝗿 𝗘𝗹𝗲𝗰𝘁𝗶𝗼𝗻: Some applications require specific processes to run only on a single Pod instance to avoid duplicate tasks. Kubernetes Deployments with multiple Pod replicas require a leader election process outside the Pods to ensure only one Pod performs these tasks. 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 𝗨𝘀𝗲 𝗰𝗮𝘀𝗲𝘀: 🔶  𝙎𝙘𝙝𝙚𝙙𝙪𝙡𝙚𝙙 𝙏𝙖𝙨𝙠𝙨: Only one Pod should run batch processing, cache updates, etc. 🔶  𝙇𝙚𝙖𝙙𝙚𝙧-𝙊𝙣𝙡𝙮 𝙎𝙚𝙧𝙫𝙞𝙘𝙚𝙨: Sending notifications or triggering specific APIs that shouldn't be called multiple times. 𝘒𝘶𝘣𝘦𝘳𝘯𝘦𝘵𝘦𝘴 𝗟𝗲𝗮𝘀𝗲 𝘖𝘣𝘫𝘦𝘤𝘵 𝘤𝘰𝘮𝘦𝘴 𝘵𝘰 𝘵𝘩𝘦 𝘳𝘦𝘴𝘤𝘶𝘦!! Here's how leader election works using Leases: 🔶  𝙇𝙚𝙖𝙨𝙚 𝘾𝙧𝙚𝙖𝙩𝙞𝙤𝙣: The first Pod creates a Lease object using configurations such as Lease name, Pod name & namespace and updates the current timestamp along with the Lease duration. 🔶  𝙇𝙚𝙖𝙨𝙚 𝙏𝙧𝙖𝙘𝙠𝙞𝙣𝙜: The Lease object keeps track of the current leader Pod's name. 🔶  𝙇𝙚𝙖𝙙𝙚𝙧 𝙍𝙚𝙣𝙚𝙬𝙖𝙡: If the Leader Pod is still active, it renews the lease by updating the timestamp before it expires. 🔶  𝙇𝙚𝙖𝙙𝙚𝙧 𝙀𝙡𝙚𝙘𝙩𝙞𝙤𝙣: If the timestamp isn't updated, inactive replicas race to acquire the lock with its identity and assume the leader role. This process leverages the 𝙖𝙩𝙤𝙢𝙞𝙘 𝙣𝙖𝙩𝙪𝙧𝙚 𝙤𝙛 𝙆𝙪𝙗𝙚𝙧𝙣𝙚𝙩𝙚𝙨 operations to ensure that no two replicas can acquire the Lease simultaneously by keeping track of the 𝘳𝘦𝘴𝘰𝘶𝘳𝘤𝘦𝘝𝘦𝘳𝘴𝘪𝘰𝘯 field. Read more and Code snippet: https://lnkd.in/gatVJGzP & https://lnkd.in/gWNGht3J #Kubernetes #LeaderElection #Containerization

  • diagram

To view or add a comment, sign in

Explore topics