<?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 Rakshith Jakkani on Medium]]></title>
        <description><![CDATA[Stories by Rakshith Jakkani on Medium]]></description>
        <link>https://medium.com/@jakkanirakshith15?source=rss-186707bd0294------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ROYCiwTCo8rvagFS47Z7eQ.jpeg</url>
            <title>Stories by Rakshith Jakkani on Medium</title>
            <link>https://medium.com/@jakkanirakshith15?source=rss-186707bd0294------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 19 May 2026 06:55:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jakkanirakshith15/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[Cross-Account Switch Role Identity in AWS]]></title>
            <link>https://medium.com/@jakkanirakshith15/cross-account-switch-role-identity-in-aws-72cc149ae652?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/72cc149ae652</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-devops]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Fri, 15 May 2026 12:18:59 GMT</pubDate>
            <atom:updated>2026-05-15T12:18:59.077Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75qGHYpZBPy3EBAu5yYM2A.png" /></figure><p>In real-world AWS environments, organizations rarely operate from a single account. A common pattern is to have a dedicated <strong>Identity Account or Management Account </strong>where all users live, and separate accounts for different environments sandbox, staging, production with limited direct access.</p><p>This guide walks through setting up <strong>cross-account role switching</strong> so a user in the Identity Account can switch into a Sandbox account using the AWS console or CLI, without needing separate credentials for each account.</p><p><strong>How it works:</strong> AWS Security Token Service (STS) lets a principal in Account A call sts:AssumeRole for a role defined in Account B. The role’s <em>trust policy</em> explicitly allows this. No passwords are shared only short-lived temporary credentials are issued, valid for the session duration.</p><p>Prerequisites</p><p>Account Details AWS Console accessIdentityAdmin or IAM permissions to create usersAWS Console accessSandboxAdmin permissions to create IAM rolesAccount IDsBoth12-digit account numbers for both accounts Browser</p><p>For console-based role switching</p><h3>Step 1</h3><p>Create an IAM User in the Identity Account</p><p>This user will authenticate here, then switch into other accounts</p><p>Log into the <strong>Identity Account</strong> (account 183295435445) and navigate to <strong>IAM → Users → Create user</strong>.</p><ul><li>Go to <strong>IAM → Users</strong> in the AWS Console and click <strong>Create user</strong>.</li><li>Enter a username such as dev-user. Enable <strong>AWS Management Console access</strong> and set a password. Optionally require a password reset on first login.</li><li>On the <strong>Set permissions</strong> page, you can attach a minimal policy now. We’ll scope it further using sts:AssumeRole below.</li><li>Review and click <strong>Create user</strong>. Note the console sign-in URL and credentials.</li></ul><p>Attach the following inline policy to this IAM user (or to a group the user belongs to) so they can assume the role in the Sandbox account:</p><p>JSON — Allow sts:AssumeRoleCopy</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;AllowSandboxRoleSwitch&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:iam::987654321987:role/cross-account-role&quot;<br>    }<br>  ]<br>}</pre><p>Replace 185863138492 with your Sandbox account’s 12-digit ID, and cross-account-role with the exact role name you’ll create in Step 2. These must match exactly.</p><p><strong>Best practice:</strong> Create an IAM <em>group</em> (e.g. sandbox-switchers) with this policy and add users to it. This scales easily as your team grows.</p><h3>Step 2</h3><p>Create the Cross-Account Role in the Sandbox Account</p><p>This role trusts the Identity Account and grants permissions when assumed</p><p>Go to <strong>IAM → Roles → Create role</strong>.</p><ul><li>Under <strong>Trusted entity type</strong>, select <strong>AWS account</strong> (not AWS service or Web identity).</li><li>Select <strong>Another AWS account</strong> and enter the Identity Account’s 12-digit ID: 183295435445.</li><li>Leave <em>Require external ID</em> unchecked for internal accounts. Only enable it when a third-party vendor will assume this role.</li><li>Click <strong>Next</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sG0pcLHR8Z3jVLh04iL4lA.png" /></figure><ul><li>On the <strong>Add permissions</strong> page, search for and attach the policies this role should carry. For a sandbox, AdministratorAccess is common. For production, scope it tightly.</li><li>On the final page, set the <strong>Role name</strong> to cross-account-role and optionally add a description like <em>“Assumed by Identity Account users for sandbox access.”</em></li><li>Click <strong>Create role</strong>.</li></ul><p>Use descriptive names like identity-sandbox-admin-role in production environments. This makes it easy to identify roles across multiple accounts in AWS Organizations, especially in CloudTrail logs.</p><h3>Step 3</h3><p>Verify the Trust Policy &amp; Copy the Switch Role Link</p><p>AWS generates a pre-filled URL that makes switching frictionless</p><p>After creating the role, open it at <strong>IAM → Roles → cross-account-role</strong>. Click the <strong>Trust relationships</strong> tab and confirm the trust policy was set up correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGpLEh9x9NzS_lztaYUH5Q.png" /></figure><p>The auto-generated trust policy should look like this:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: {<br>        &quot;AWS&quot;: &quot;arn:aws:iam::123456789123:root&quot;<br>      },<br>      &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>      &quot;Condition&quot;: {}<br>    }<br>  ]<br>}</pre><p>Using :root as the Principal trusts the entire Identity Account. Any IAM entity in that account with the sts:AssumeRole permission pointing to this role ARN can assume it. For tighter control, replace :root with a specific user ARN: arn:aws:iam::123456789123:user/dev-user.</p><p>Now, from the role <strong>Summary</strong> section (top of the page), locate <strong>Link to switch roles in console</strong> and copy it:</p><p>URL — Switch Role Console LinkCopy</p><pre>https://signin.aws.amazon.com/switchrole?roleName=cross-account-role&amp;account=123456789123</pre><p>Share this link with the IAM user you created in Step 1, or bookmark it for yourself. When clicked while logged into the Identity Account, it pre-fills the switch role dialog.</p><h3>Step 4</h3><p>Log In as the IAM User and Switch to the Sandbox Account</p><p>Complete the loop — test end-to-end in the console and CLI</p><p>Log out of any current AWS session and log in as the IAM user from the Identity Account.</p><ul><li>Navigate to the Identity Account sign-in URL: <a href="https://183295435445.signin.aws.amazon.com/console">https://987654321987.signin.aws.amazon.com/console</a></li><li>Log in with the IAM user credentials you created in Step 1 (username + password).</li><li>Paste the switch role URL from Step 3 into your browser, <strong>or</strong> click your account name in the top-right corner of the console and select <strong>Switch role</strong>.</li><li>In the dialog, enter: <strong>Account</strong> = 987654321987, <strong>Role</strong> = cross-account-role. Optionally set a display name (e.g. <em>Sandbox</em>) and a color for the badge.</li><li>Click <strong>Switch Role</strong>. You’re now operating in the Sandbox account under the assumed role with temporary credentials.</li></ul><p>The top-right account badge changes to show the role name and account alias. Recent role switches are remembered, so future switches take just two clicks. Click <strong>Back to [username]</strong> to return to the Identity Account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_7ON822K3Ar3r_k9Nrdzhg.png" /></figure><p>If you see <em>“Not authorized to assume role”</em>: verify (1) the IAM user has an sts:AssumeRole policy pointing to the correct role ARN, and (2) the trust policy in the Sandbox role has the correct Identity Account ID.</p><p>You can also switch roles via the <strong>AWS CLI</strong> by adding a profile to your config:</p><p>~/.aws/configCopy</p><pre># Base profile for the Identity Account IAM user<br>[profile identity]<br>aws_access_key_id     = AKIA...YOUR...KEY<br>aws_secret_access_key = your-secret-key<br>region                = us-east-1</pre><pre># Profile that assumes the Sandbox role<br>[profile sandbox]<br>role_arn              = arn:aws:iam::123456789123:role/cross-account-role<br>source_profile        = identity<br>region                = us-east-1</pre><p>Shell — Verify the role switch via CLICopy</p><pre># Use the sandbox profile for any AWS CLI command<br>aws sts get-caller-identity --profile sandbox</pre><pre># Expected output confirms you are in the Sandbox account<br>{<br>    &quot;UserId&quot;:  &quot;AROAEXAMPLEID:session-name&quot;,<br>    &quot;Account&quot;: &quot;123456789123&quot;,<br>    &quot;Arn&quot;:     &quot;arn:aws:sts::123456789123:assumed-role/cross-account-role/session-name&quot;<br>}</pre><h3>Cross-Account Access Configured</h3><p>You’ve set up a secure, credential-free way for IAM users to switch between AWS accounts using temporary STS credentials. This pattern scales across many accounts in AWS Organizations, repeat Steps 2–3 for each target account and share switch role links with your team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72cc149ae652" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best Free Way to Use Multiple AI Models with Python]]></title>
            <link>https://medium.com/@jakkanirakshith15/best-free-way-to-use-multiple-ai-models-with-python-8ac05ad62c20?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ac05ad62c20</guid>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Tue, 28 Apr 2026 06:05:32 GMT</pubDate>
            <atom:updated>2026-04-28T06:05:32.640Z</atom:updated>
            <content:encoded><![CDATA[<p>If you want access to multiple AI models in one place without managing separate accounts for every provider, <strong>OpenRouter</strong> is one of the easiest ways to start.</p><p>Instead of signing up individually for different AI companies, OpenRouter gives you a single API that can route your request to many popular models.</p><p>That means you can test models, compare responses, switch providers, and build apps faster.</p><p>In this guide, I’ll walk through:</p><ul><li>How to sign up and log in</li><li>How to create an API key</li><li>Where to find free models</li><li>How to use OpenRouter in Python code</li><li>Tips for beginners</li></ul><h3>What is OpenRouter?</h3><p>OpenRouter is an API gateway that gives developers access to many AI models through one endpoint.</p><p>Instead of using different APIs for:</p><ul><li>OpenAI</li><li>Google</li><li>Anthropic</li><li>Meta</li></ul><p>You can use one OpenRouter API key.</p><p>This is especially useful for developers who want to experiment with multiple models.</p><h3>Step 1: Create an OpenRouter Account</h3><p>Go to the official website:</p><p><strong>openrouter.ai</strong></p><p>Then click <strong>Sign In</strong>.</p><p>You’ll usually see login options like:</p><ul><li>Google login</li><li>GitHub login</li><li>Email login (if available)</li></ul><p>Use whichever is easiest for you.</p><p>After login, you’ll enter the dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6eE6aOqBlX9vTgGRRN0xA.png" /></figure><h3>Step 2: Create an API Key</h3><p>Once logged in:</p><ol><li>Open Dashboard</li><li>Go to <strong>Keys</strong> or <strong>API Keys</strong> section</li><li>Click <strong>Create Key</strong></li><li>Give it a name</li><li>Copy and save it safely</li></ol><p>Example:</p><pre>sk-or-v1-xxxxxxxxxxxxxxxx</pre><p>Important:</p><p>Never expose your API key in public GitHub repositories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6DRzFsP81LD09dvJZLAeA.png" /></figure><h3>Step 3: Find Free Models</h3><p>One of the best things in OpenRouter is free community models.</p><p>Examples often available:</p><ul><li>Google Gemma free models</li><li>Meta Llama free variants</li><li>Mistral AI free models</li><li>Small open-source instruct models</li></ul><p>Look for models with:</p><pre>:free</pre><p>Examples:</p><pre>google/gemma-3-4b-it:free<br>meta-llama/llama-3.2-3b-instruct:free<br>mistralai/mistral-small:free</pre><p>These are great for learning and testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N9sjr7BoFuLWmbW-bgf_Iw.png" /></figure><h3>Step 4: Install Python Library</h3><p>Use OpenAI-compatible SDK.</p><pre>pip install openai</pre><h3>Step 5: Python Example Using OpenRouter</h3><pre>from openai import OpenAI</pre><pre>client = OpenAI(<br>    api_key=&quot;YOUR_OPENROUTER_KEY&quot;,<br>    base_url=&quot;https://openrouter.ai/api/v1&quot;<br>)</pre><pre>response = client.chat.completions.create(<br>    model=&quot;google/gemma-3-4b-it:free&quot;,<br>    messages=[<br>        {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Explain Docker in simple words&quot;}<br>    ]<br>)</pre><pre>print(response.choices[0].message.content)</pre><h3>Why Developers Like OpenRouter</h3><h4>1. One API for Many Models</h4><p>No need to manage multiple providers.</p><h4>2. Easy Model Testing</h4><p>Switch models by changing one line:</p><pre>model=&quot;google/gemma-3-4b-it:free&quot;</pre><p>to</p><pre>model=&quot;meta-llama/llama-3.2-3b-instruct:free&quot;</pre><h4>3. Budget Friendly</h4><p>Free models available for experiments.</p><h4>4. Great for Side Projects</h4><p>Useful for:</p><ul><li>Chatbots</li><li>Resume analyzers</li><li>Code assistants</li><li>Summarizers</li><li>AI tools</li></ul><h3><strong>Tips</strong></h3><h4><strong>Use Environment Variables</strong></h4><p>Instead of hardcoding keys:</p><pre>import os<br>api_key = os.getenv(&quot;OPENROUTER_API_KEY&quot;)<br></pre><p><strong>Handle Rate Limits</strong></p><p>Some free models are busy during peak time.</p><p>If one model fails, switch to another free model.</p><p><strong>Compare Output</strong></p><p>Different models give different quality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ac05ad62c20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End-to-End Guide: Encrypting an Existing Azure VM Disk Using Customer-Managed Keys]]></title>
            <link>https://medium.com/@jakkanirakshith15/end-to-end-guide-encrypting-an-existing-azure-vm-disk-using-customer-managed-keys-3fcca1d26949?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fcca1d26949</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[disk]]></category>
            <category><![CDATA[encryption]]></category>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 15:29:31 GMT</pubDate>
            <atom:updated>2026-02-26T15:29:31.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lBCnugCUZsaJRfBZNsQ0BA.png" /></figure><p>When building secure cloud architectures, encryption at rest is not optional, it’s foundational.</p><p>While Azure automatically encrypts managed disks using platform-managed keys, many organizations require <strong>Customer-Managed Keys (CMK)</strong> for compliance, regulatory, or security control reasons.</p><p>In this article, we’ll walk through an end-to-end process to encrypt an <strong>existing Azure VM disk</strong> using:</p><ul><li>Azure Key Vault</li><li>Customer-managed encryption key</li><li>Disk Encryption Set</li><li>Existing Virtual Machine</li></ul><p><strong>Understanding the Architecture:</strong></p><p>Before jumping into configuration, let’s understand how Azure disk encryption with CMK works.</p><p>Azure does not encrypt the disk directly using your Key Vault key.</p><p>Instead, it uses a layered model:</p><ol><li>Azure generates a Disk Encryption Key (DEK).</li><li>Your Key Vault key encrypts (wraps) that DEK.</li><li>The wrapped DEK is stored securely.</li><li>When the VM starts, Azure retrieves and unwraps the key.</li></ol><p>Architecture flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pK2zIcDDDxrwbYkuCFuL2A.png" /></figure><p><strong>Step 1:</strong> Create a Key Vault</p><p>Go to the Azure Portal and create a Key Vault.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HKCexFE1fIOZyn8JuYGc0w.png" /></figure><p>Important configuration settings:</p><ul><li>Enable <strong>Soft Delete</strong></li><li>Enable <strong>Purge Protection</strong></li><li>Ensure region matches your VM region</li><li>Assign a role based access control</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lf67pKuike8ur81Cz578g.png" /></figure><ul><li>Configure networking (Public or Private based on your architecture)</li></ul><p><em>Note: If using Private Endpoint, ensure network connectivity is properly configured. Even you cannot access through azure portal since your browser sending request with public IP</em></p><ul><li>If your creating private key vault below steps, if not please ignore below steps, make it public and continue with review and create</li><li>select vnet, location and subnet where your vm is deployed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wf_l5GvEjCKMRUb07j5bsQ.png" /></figure><p>After creation, confirm the vault is successfully deployed.</p><p>Important: Assign yourself <strong>key vault administrator role</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bdDjstoNjXaB-xcAjg_ksw.png" /></figure><p><strong>Step 2:</strong> Create an Encryption Key</p><p>Inside your Key Vault:</p><ol><li>Go to <strong>Keys</strong></li><li>Click <strong>Generate/Import</strong></li><li>Select: RSA, 2048 or 3072 bits</li><li>Provide a name (e.g., vm-disk-key)</li><li>Create the key</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwcONRAm4Pt3PATLJAok0g.png" /></figure><p>Ensure the key status shows <strong>Enabled</strong>.</p><p><strong>Step 3:</strong> Create a Disk Encryption Set (DES)</p><p>Next, create a Disk Encryption Set.</p><p>Search for <strong>Disk Encryption Sets</strong> in the Azure Portal and click <strong>Create</strong>.</p><p>Configuration:</p><ul><li>Same region as VM and Key Vault</li><li>Encryption type: Customer-managed key</li><li>Select your Key Vault</li><li>Select your key</li><li>Select a specific key version (recommended)</li></ul><p>Why Disk Encryption Set?</p><p>It acts as a bridge between your disk and your Key Vault key, using a managed identity to access the key securely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cct707kL8o9Byo50y1Ad-g.png" /></figure><h3>🔐 Step 4: Grant Key Permissions to the Disk Encryption Set</h3><p>This is the most critical step.</p><p>The Disk Encryption Set has a system-assigned managed identity. That identity must have permission to use the key.</p><p>Go to:</p><p>Key Vault → Access Control (IAM) → Add Role Assignment</p><p>Assign:</p><p><strong>Key Vault Crypto Service Encryption User</strong></p><p>Assign this role to:</p><ul><li>The managed identity of the Disk Encryption Set</li></ul><p>Simple way: Go to disk encryptionset and just click on top up. Role will be assinged automatically</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hKuagJIqzW4hAr_BF-FTpQ.png" /></figure><p>Without this permission, encryption will fail.</p><p><strong>Step 5:</strong> Stop the Virtual Machine</p><p>Before changing disk encryption settings:</p><ol><li>Go to your Virtual Machine</li><li>Click <strong>Stop</strong></li><li>Wait until it shows <strong>Stopped (deallocated)</strong></li></ol><p>This ensures safe modification of the disk configuration.</p><p><strong>Step 6: </strong>Attach Disk Encryption Set to Existing Disk</p><p>Now we modify the disk.</p><p>For OS Disk:</p><ol><li>Go to VM → Disks</li><li>Click the OS disk</li><li>Open <strong>Configuration</strong></li><li>Under Encryption:</li></ol><ul><li>Select <strong>Customer-managed key</strong></li><li>Choose your Disk Encryption Set</li><li>Save changes</li></ul><p>For Data Disk:</p><p>Repeat the same process for each data disk.</p><p><strong>Step 7:</strong> Start the VM</p><p>Go back to your VM and click <strong>Start</strong>.</p><p>If everything is configured correctly:</p><ul><li>VM starts successfully</li><li>No permission errors</li><li>No key access errors</li></ul><p>Behind the scenes, Azure:</p><ul><li>Retrieves your key</li><li>Unwraps the disk encryption key</li><li>Mounts the disk securely</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fcca1d26949" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How nodeSelector works behind the scenes: nodeSelector, Filtering, and Scoring Explained]]></title>
            <link>https://medium.com/@jakkanirakshith15/how-nodeselector-works-behind-the-scenes-nodeselector-filtering-and-scoring-explained-ed6a02ac456e?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed6a02ac456e</guid>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Tue, 20 May 2025 12:38:37 GMT</pubDate>
            <atom:updated>2025-05-20T12:38:37.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*3O5YQ_iT-B7Yx96S.png" /></figure><p>When you deploy a Pod in Kubernetes, have you ever wondered <strong>how it decides which node to run on</strong>? At first point, it might seem like magic. You apply a YAML file, and a few moments later, your Pod is running somewhere in your cluster.</p><p>But under the hood, Kubernetes follows a well-defined decision-making process to find the <strong>most suitable node</strong>. This decision isn’t random. It involves intelligent filtering, scoring, and binding. Especially when you use constraints like a nodeSelector.</p><p>In this blog, we’ll walk through what really happens <strong>step-by-step</strong> when you apply a Deployment with a nodeSelector. We&#39;ll uncover how the <strong>Kubernetes scheduler</strong> evaluates nodes, shortlists the ones that match, scores them based on multiple factors, and finally assigns your Pod to the best possible location.</p><p>Whether you’re debugging a pending Pod or trying to control Pod placement more precisely, understanding this flow will help you use Kubernetes more effectively.</p><h3><strong>Node Labeling:</strong></h3><p>Lets assume you labeled a node with key=disktype value=ssd</p><p>Label a node using simple command <strong>kubectl label node &lt;nodeName&gt; disktype=ssd</strong></p><p>once you labeled, describe your node (kubectl describe no &lt;nodeName&gt;). You should label like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ES9L4GQPgsNrgcgibv4-A.png" /></figure><h3><strong>Pod Scheduling:</strong></h3><p>Lets assume, you defined nodeSelector as shown in below deployment file</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  labels:<br>    app: node-selector<br>  name: node-selector<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: node-selector<br>  strategy: {}<br>  template:<br>    metadata:<br>      labels:<br>        app: node-selector<br>    spec:<br>      nodeSelector:<br>        disktype: ssd<br>      containers:<br>      - image: nginx<br>        name: nginx<br>        resources: {}</pre><p>Apply the manifest file using <strong>kubectl apply -f &lt;fileName&gt;</strong></p><p>Now… the actual kubernetes intelligence comes in..</p><p>1. API Server Interaction</p><ul><li>kubectl sends the YAML manifest to the <strong>Kubernetes API Server</strong> (the entry point of the control plane).</li></ul><p>1.1 The API Server:</p><ul><li>Authenticates and authorizes your request.</li><li>Validates the schema of the Deployment object.</li><li>Stores the Deployment definition in <strong>etcd</strong>, the Kubernetes backing store (key-value database).</li><li>Triggers relevant informers and controllers (specifically the Deployment controller).</li></ul><h4>Deployment Controller (part of kube-controller-manager)</h4><p>2. Deployment → ReplicaSet</p><ul><li>The <strong>Deployment controller</strong> sees a new Deployment and:</li><li>Creates a <strong>ReplicaSet</strong> that matches the Deployment’s spec.</li><li>The ReplicaSet defines the desired number of Pod replicas with the given Pod template (including the nodeSelector).</li></ul><p>3. ReplicaSet → Pods</p><ul><li>The <strong>ReplicaSet controller</strong> creates the required number of Pods.</li><li>These Pods include the nodeSelector in their .spec.</li></ul><h3>Kubernetes Scheduler</h3><p>What is the Scheduling Cycle?</p><p>When a Pod is created, it doesn’t immediately run on a node. It needs to be scheduled<strong>. </strong>That is,<strong> </strong>assigned to a node in the cluster.</p><p>The Kubernetes Scheduler<strong> </strong>decides which node the Pod should run on, and it does that in two steps:</p><p><strong>Step 4.1: Filtering Phase</strong> — Who Can Host the Pod?</p><p>In this step, Kubernetes checks which nodes are eligible<strong> </strong>to run the Pod.</p><p>What is Filtering?</p><p>Filtering is like <strong>shortlisting nodes</strong> that:</p><ul><li>Have enough <strong>CPU and memory</strong>.</li><li>Have <strong>matching labels</strong> (nodeSelector, affinity, etc.).</li><li>Are <strong>Ready</strong> (not down or under maintenance).</li><li>Are not <strong>tainted</strong> in a way that would block this Pod.</li></ul><h4>Example:</h4><p>You create a Pod with:</p><pre>nodeSelector:<br>  disktype: ssd</pre><p>Imagine your cluster has 3 nodes:</p><pre>+-----------+----------------+-------------+-------+<br>| Node Name | disktype Label | Free Memory | Ready |<br>+-----------+----------------+-------------+-------+<br>| node-a    | ssd            | 4Gi         | ✅    |<br>| node-b    | hdd            | 8Gi         | ✅    |<br>| node-c    | ssd            | 0.5Gi       | ✅    |<br>+-----------+----------------+-------------+-------+</pre><p>Filtering checks:</p><ul><li><strong>node-a</strong>: OK (label matches, enough memory, Ready)</li><li><strong>node-b</strong>: NO (label does not match)</li><li><strong>node-c</strong>: NO (not enough memory)</li><li>Only <strong>node-a</strong> passes the filter.</li></ul><p><strong>Step 4.2: Scoring Phase</strong> — Who Is the Best Host?</p><p>Now Kubernetes scores the filtered nodes to find the<strong> </strong>best one.</p><p>Even if multiple nodes pass filtering, Kubernetes wants to pick the <strong>most optimal node</strong> based on:</p><ul><li>How much free resources they have (e.g., avoid overloading a node).</li><li>Pod affinity/anti-affinity rules.</li><li>Topology (spread Pods across zones/hosts).</li><li>Custom policies.</li></ul><p><strong>Why Score?</strong></p><p>To balance the load and use resources smartly.</p><p>Example Scoring :</p><p>Say 2 nodes passed filtering: node-a and node-d.</p><pre>+--------+----------+-------------+-------+<br>| Node   | CPU Free | Free Memory | Score |<br>+--------+----------+-------------+-------+<br>| node-a | 4 core   | 4Gi         | 70    |<br>| node-d | 8 cores  | 10Gi        | 90    |<br>+--------+----------+-------------+-------+</pre><p>Scheduler picks <strong>node-d</strong> (highest score) and assigns the Pod to it.</p><p><strong>Final Step 4.3: Binding</strong></p><p>Once the best node is selected:</p><ul><li>The scheduler tells the <strong>API Server</strong>: “Bind this Pod to node-d”.</li></ul><h4>Kubelet on the Target Node</h4><p>5. Kubelet Pulls and Starts Pod</p><ul><li>The kubelet on node-d:</li><li>Watches the API server for Pods assigned to it.</li><li>Sees the new Pod with matching nodeName.</li><li>Pulls the container images via CRI (Container Runtime Interface) — e.g., containerd, dockershim, or CRI-O.</li><li>Mounts volumes, sets up networking (via CNI), and starts containers.</li></ul><h4>Runtime Status</h4><p>6. Pod Transitions Through States</p><ul><li>API server reflects changes to Pod status:</li><li>Pending → image pulled → ContainerCreating → container started → Running.</li></ul><p><strong>Overall flow of scheduling a pod on specific node</strong></p><pre>kubectl apply<br>     ↓<br>API Server → store in etcd → notify Deployment controller<br>     ↓<br>Deployment → ReplicaSet → Pod<br>     ↓<br>Pod has `nodeSelector`<br>     ↓<br>Scheduler filters nodes → scores nodes → binds Pod to Node<br>     ↓<br>Pod assigned → Kubelet on node → container runtime pulls and starts containers<br>     ↓<br>Pod status updates → Running</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed6a02ac456e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup kubernetes cluster using kubeadm a step by step guid]]></title>
            <link>https://medium.com/@jakkanirakshith15/how-to-setup-kubernetes-cluster-using-kubeadm-a-step-by-step-guid-3f18f75c171b?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f18f75c171b</guid>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Tue, 12 Nov 2024 21:18:40 GMT</pubDate>
            <atom:updated>2024-11-18T09:13:07.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRJDzQwfFaqUo--xz0bIkA.png" /></figure><p>In this blog we will just going to discuss about how to set up kubernetes cluster using kubeadm. All you have to do is, just follow the steps</p><p>In my case, I used AWS ubuntu instances. you can also use this blog for on-prim servers or any other cloud vms. You just have to make sure that all your nodes communicate each other on ports 6443 and 10250 port.</p><p>Before you begin:</p><ul><li>2 GB or more of RAM per machine (any less will leave little room for your apps)</li><li>2 CPUs or more.</li><li>Full network connectivity between all machines in the cluster (public or private network is fine).</li><li>Unique hostname, MAC address, and product_uuid for every node using command <strong>cat /sys/class/dmi/id/product_uuid</strong></li><li>You <strong>MUST</strong> disable swap if the kubelet is not properly configured to use swap. use <strong>sudo swapoff -a </strong>command to disable the swap memory</li></ul><h4>Installing a container runtime</h4><ul><li>This part should perform on every node(master and worker nodes)</li><li>By default, the Linux kernel does not allow IPv4 packets to be routed between interfaces. so lets enable IPv4 packet forwarding</li></ul><pre>echo net.ipv4.ip_forward = 1 | sudo tee /etc/sysctl.d/k8s.conf<br><br># Apply sysctl params without reboot<br>sudo sysctl --system</pre><ul><li>Verify that net.ipv4.ip_forward is set to 1 with:</li></ul><pre>sysctl net.ipv4.ip_forward</pre><p>Step 1: Installing containerd</p><ul><li>Download and setup the containerd on each node using below command</li></ul><pre># refere this link for different version of containerd https://github.com/containerd/containerd/releases<br>wget https://github.com/containerd/containerd/releases/download/v2.0.0/containerd-2.0.0-linux-amd64.tar.gz<br><br># extract the files in /usr/local folder<br>tar Cxzvf /usr/local containerd-2.0.0-linux-amd64.tar.gz<br><br>#create a systemd directory for the containerd<br>mkdir -p /usr/local/lib/systemd/system/<br><br>#create a file and past the below content in this file<br>vi /usr/local/lib/systemd/system/containerd.service</pre><pre># Copyright The containerd Authors.<br>#<br># Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);<br># you may not use this file except in compliance with the License.<br># You may obtain a copy of the License at<br>#<br>#     http://www.apache.org/licenses/LICENSE-2.0<br>#<br># Unless required by applicable law or agreed to in writing, software<br># distributed under the License is distributed on an &quot;AS IS&quot; BASIS,<br># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br># See the License for the specific language governing permissions and<br># limitations under the License.<br><br>[Unit]<br>Description=containerd container runtime<br>Documentation=https://containerd.io<br>After=network.target local-fs.target dbus.service<br><br>[Service]<br>ExecStartPre=-/sbin/modprobe overlay<br>ExecStart=/usr/local/bin/containerd<br><br>Type=notify<br>Delegate=yes<br>KillMode=process<br>Restart=always<br>RestartSec=5<br><br># Having non-zero Limit*s causes performance problems due to accounting overhead<br># in the kernel. We recommend using cgroups to do container-local accounting.<br>LimitNPROC=infinity<br>LimitCORE=infinity<br><br># Comment TasksMax if your systemd version does not supports it.<br># Only systemd 226 and above support this version.<br>TasksMax=infinity<br>OOMScoreAdjust=-999<br><br>[Install]<br>WantedBy=multi-user.target</pre><pre>#run the below commands <br>systemctl daemon-reload<br><br>systemctl enable --now containerd</pre><p>Step 2: Installing runc</p><ul><li>Download the runc.&lt;ARCH&gt; binary from <a href="https://github.com/opencontainers/runc/releases"><strong>https://github.com/opencontainers/runc/releases</strong></a> according your system configuration it may be amd64 or arm64. In my case I am using amd64</li></ul><pre>#run the below commands to install runc<br>wget https://github.com/opencontainers/runc/releases/download/v1.2.1/runc.amd64<br><br>install -m 755 runc.amd64 /usr/local/sbin/runc</pre><p>Step 3: Installing CNI plugins</p><ul><li>Download the cni-plugins-&lt;OS&gt;-&lt;ARCH&gt;-&lt;VERSION&gt;.tgz archive from <a href="https://github.com/containernetworking/plugins/releases">https://github.com/containernetworking/plugins/releases</a> , verify its sha256sum, and extract it under /opt/cni/bin</li></ul><pre>wget https://github.com/containernetworking/plugins/releases/download/v1.6.0/cni-plugins-linux-amd64-v1.6.0.tgz<br><br>mkdir -p /opt/cni/bin<br><br>tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.6.0.tgz</pre><p>Configuring the systemd cgroup driver</p><ul><li>Run the following command to create a default configuration file:</li></ul><pre>sudo containerd config default &gt; /etc/containerd/config.toml</pre><ul><li>To use the systemd cgroup driver in /etc/containerd/config.toml with runc, set as shown below images</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6snYULoU0au4zl5MmrMMYg.png" /></figure><ul><li>as shown in the above image add <strong>SystemdCgroup = true</strong> in config.toml file</li><li>Once add enabled the <strong>SystemdCgroup </strong>run <strong>sudo systemctl restart containerd</strong></li></ul><p>Overriding the sandbox (pause) image</p><ul><li>In your <a href="https://github.com/containerd/containerd/blob/main/docs/cri/config.md">containerd config</a> you can overwrite the sandbox image by setting the following config:</li><li>There is aleardy everything set. You just need to add <strong>sandbox_image = “registry.k8s.io/pause:3.2” </strong>line in it</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9KdtKiHwLGluKOdK5QU4g.png" /></figure><ul><li>You might need to restart containerd as well once you&#39;ve updated the config file: systemctl restart containerdInstalling kubeadm, kubelet and kubectl</li></ul><h3>Installing kubeadm, kubelet and kubectl</h3><ul><li>You will install these packages on all of your machines:</li><li>kubeadm: the command to bootstrap the cluster.</li><li>kubelet: the component that runs on all of the machines in your cluster and does things like starting pods and containers.</li><li>kubectl: the command line util to talk to your cluster.</li><li>These instructions are for Kubernetes v1.30.</li></ul><pre>#Update the apt package index and install packages needed to use the Kubernetes apt repository:<br>sudo apt-get update<br><br>sudo apt-get install -y apt-transport-https ca-certificates curl gpg<br><br>#Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:<br># If the directory `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.<br># sudo mkdir -p -m 755 /etc/apt/keyrings<br>curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg<br><br># This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list<br>echo &#39;deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /&#39; | sudo tee /etc/apt/sources.list.d/kubernetes.list<br><br>#Update the apt package index, install kubelet, kubeadm and kubectl, and pin their version:<br>sudo apt-get update<br>sudo apt-get install -y kubelet kubeadm kubectl<br>sudo apt-mark hold kubelet kubeadm kubectl<br><br>#Enable the kubelet service before running kubeadm:<br>sudo systemctl enable --now kubelet</pre><h4>Initializing your control-plane node</h4><ul><li>These steps needs to be perform only on master node</li><li>To initialize the control-plane node run <strong>kubeadm init</strong></li><li>Once you run the kubeadm init the below information will be shown. Follow the instruction which have been showed after executing the kubeadm init</li></ul><pre>Your Kubernetes control-plane has initialized successfully!<br><br>To start using your cluster, you need to run the following as a regular user:<br><br>  mkdir -p $HOME/.kube<br>  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config<br>  sudo chown $(id -u):$(id -g) $HOME/.kube/config<br><br>You should now deploy a Pod network to the cluster.<br>Run &quot;kubectl apply -f [podnetwork].yaml&quot; with one of the options listed at:<br>  /docs/concepts/cluster-administration/addons/<br><br>You can now join any number of machines by running the following on each node<br>as root:<br><br>  kubeadm join &lt;control-plane-host&gt;:&lt;control-plane-port&gt; --token &lt;token&gt; --discovery-token-ca-cert-hash sha256:&lt;hash&gt;</pre><ul><li>note down the kubeadm join whole command and paste it somewhere. use that command to add a worker node to your cluster.</li><li>whenever you want to add a worker node, simply have network connectivity between master and node install the required packages as shown in previous steps and run this command(which you have noted)in worker node</li><li>make sure you stopped kubelete in worker node before running the kubeadm join command. once the command executed, start again the kubelete</li><li>Alternatively, if you are the root user, you can run:</li></ul><pre>export KUBECONFIG=/etc/kubernetes/admin.conf</pre><ul><li>Installing a Pod network add-on</li></ul><pre>kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml</pre><ul><li>restart the kubelete in all servers using <strong>systemctl restart kubelete</strong></li><li>list the nodes and try to launch a pod.</li></ul><blockquote><em>Here we goooo cluster set up is done</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f18f75c171b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes — Centralized Secret Management using Hashicorp-Vault, PostgreSQL, and External Secret…]]></title>
            <link>https://medium.com/@jakkanirakshith15/kubernetes-centralized-secret-management-using-hashicorp-vault-postgresql-and-external-secret-84f01a2f4ae1?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/84f01a2f4ae1</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[hashicorp]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[hashicorp-vault]]></category>
            <category><![CDATA[vault]]></category>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Thu, 22 Aug 2024 06:49:05 GMT</pubDate>
            <atom:updated>2024-08-22T06:49:05.950Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes — Centralized Secret Management using Hashicorp-Vault, PostgreSQL, and External Secret Operator</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3V0_KHZaATnXYdjgfqI88A.png" /></figure><p>In this story we will be going to install Hashicorp-Vault in kubernetes with PostgreSQL as a backend and also we will be looking at how to mount or pass secrets which are in vault, to the kubernetes pod.</p><p>Lets have a basic idea on Hashicorp-Vault, vault backend and External secret Operator.</p><p><strong>Hashicorp-Vault: </strong>A vault server which stores and manages the secrets like db credentials, tokens, certificates and more. Vautl server is also does data encryption and data management by using secret engines like AWS Secret Manager, MYSQL, KV Secret Engine and many more. We will be using KV Secret Engine in this blog.</p><p><strong>Vault backend: </strong>A<strong> </strong>backend is nothing but, a storage which stores the state of vault server. For example you already installed and configured your vault server, suddenly your vault server goes down due to some reason, your data may be lost which is there in vault. To overcome this situation, there is a consept called backend. When your vautl server goes down, you want to launch again with the data that was present in previous vault, simply you just have to configure your previous backend, so that your vault server will launched with previous data that is present in backend. In this blog, we will be using PostgreSQL as a backend.</p><p><strong>External secret Operator(ESO): </strong>ESO is a kubernetes operator which is used to get the secrets from vault server and pass that secret to kubernetes pod. As of now, simply we can assume that, it is a mediator for Vault server and kubernetes pod.</p><p>Pre-requisites:</p><ul><li>Kubernetes Cluster</li><li>PostgreSQL Database</li><li>Kubectl and Helm configured with cluster</li><li>jq package: You can use the given command based on your OS to install the JQ tool</li></ul><pre>For Debian/Ubuntu-based systems:-<br>sudo apt-get update<br>sudo apt-get install jq<br><br>For Mac Systems:-<br>brew install jq<br><br>For Fedora/RHEL-based systems:-<br>sudo dnf install jq</pre><p><strong>PostgreSQL Database setup</strong></p><ul><li>Once your database is ready, connect to the database and run below schema in your database.</li></ul><pre>CREATE TABLE vault_kv_store (<br>  parent_path TEXT COLLATE &quot;C&quot; NOT NULL,<br>  path        TEXT COLLATE &quot;C&quot;,<br>  key         TEXT COLLATE &quot;C&quot;,<br>  value       BYTEA,<br>  CONSTRAINT pkey PRIMARY KEY (path, key)<br>);<br><br>CREATE INDEX parent_path_idx ON vault_kv_store (parent_path);<br><br>CREATE TABLE vault_ha_locks (<br>  ha_key                                      TEXT COLLATE &quot;C&quot; NOT NULL,<br>  ha_identity                                 TEXT COLLATE &quot;C&quot; NOT NULL,<br>  ha_value                                    TEXT COLLATE &quot;C&quot;,<br>  valid_until                                 TIMESTAMP WITH TIME ZONE NOT NULL,<br>  CONSTRAINT ha_key PRIMARY KEY (ha_key)<br>);<br></pre><ul><li><strong>vault_kv_store: </strong>Table name, you can use name of your choice</li><li><strong>vault_ha_locks: </strong>Table name, you can use name of your choice.</li><li>Once you run above schema, then your database ready to use with the vault server. Before that, vault server required your database connectionURL to access your database.</li><li>ConnectionURL is look something like this below</li></ul><pre>postgresql://&lt;USERNAME&gt;:&lt;PASSWORD&gt;@&lt;HOST&gt;:5432/&lt;DB_NAME&gt;?sslmode=disable</pre><ul><li>Once you get your connection URL, note it somewhere we will going to use that connection url in vault installation.</li></ul><p><strong>Hashicorp-Vault Installation in Kubernetes</strong></p><p>NOTE: Vault pods has to access database, configure your cluster to have access to database. if your using AWS Cloud, Attach neccessary permissions to node group or vault pod by service account</p><ul><li>Create file called <strong>values.yaml</strong> and paste the below content in the file</li></ul><pre>injector:<br>  # True if you want to enable vault agent injection.<br>  enabled: false<br><br>server:<br><br>  # Affinity Settings<br>  # Commenting out or setting as empty the affinity variable, will allow<br>  # deployment to single node services such as Minikube<br>  affinity: null<br>  <br>  # Run Vault in &quot;standalone&quot; mode. This is the default mode that will deploy if<br>  # no arguments are given to helm. This requires a PVC for data storage to use<br>  # the &quot;file&quot; backend.  This mode is not highly available and should not be scaled<br>  # past a single replica.<br>  standalone:<br>    enabled: false<br><br>  # Run Vault in &quot;HA&quot; mode. There are no storage requirements unless audit log<br>  # persistence is required.  In HA mode Vault will configure itself to use Consul<br>  # for its storage backend.  The default configuration provided will work the Consul<br>  # Helm project by default.  It is possible to manually configure Vault to use a<br>  # different HA backend.<br>  ha:<br>    enabled: true<br>    # config is a raw string of default configuration when using a Stateful<br>    # deployment. Default is to use a Consul for its HA storage backend.<br>    # This should be HCL.<br><br>    # Note: Configuration files are stored in ConfigMaps so sensitive data<br>    # such as passwords should be either mounted through extraSecretEnvironmentVars<br>    # or through a Kube secret.  For more information see:<br>    # https://www.vaultproject.io/docs/platform/k8s/helm/run#protecting-sensitive-vault-configurations<br>    config: |<br>      ui = true<br>      listener &quot;tcp&quot; {<br>        tls_disable = 1<br>        address = &quot;[::]:8200&quot;<br>        cluster_address = &quot;[::]:8201&quot;<br>      }<br>      storage &quot;postgresql&quot; {<br>        connection_url=&quot;&lt;ConnectionURL that we already got it in STEP 1&gt;&quot;<br>        table=&quot;vault_kv_store&quot;,<br>        ha_enabled=true,<br>        ha_table=&quot;vault_ha_locks&quot; <br>      }<br>      service_registration &quot;kubernetes&quot; {}</pre><ul><li>Execute the below commands to install the vault</li></ul><pre>helm repo add hashicorp https://helm.releases.hashicorp.com<br><br>helm repo update<br><br>helm search repo vault --versions<br><br>helm install vault hashicorp/vault -f values.yaml -n vault</pre><ul><li>Verify the vault pods using command kubectl get pods -n vault, it should look something like below image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j_Z2Rn9w9Y9lHdRpCfpzXg.png" /></figure><ul><li>To Initialise and unseal your vault server pods follow the below steps.</li></ul><p>a) execute the following command kubectl exec vault-0 -n vault -- vault operator init -key-shares=1 -key-threshold=1 -format=json &gt; cluster-keys.json</p><p>b) you’ll notice that cluster-keys.json file has been created in your system <strong>(NOTE: keep it safe)</strong></p><p>c) Display the unseal key found in cluster-keys.json using following command cat cluster-keys.json | jq -r &quot;.unseal_keys_b64[]&quot; copy the output of command and keep it safe somewhere.</p><p>d) Create a variable named VAULT_UNSEAL_KEY to capture the Vault unseal key using following command VAULT_UNSEAL_KEY=$(cat cluster-keys.json | jq -r &quot;.unseal_keys_b64[]&quot;)</p><p>e) Unseal Vault running on the vault-0 pod using following command kubectl exec vault-0 -n vault -- vault operator unseal $VAULT_UNSEAL_KEY</p><p>f) Retrieve the status of Vault on the vault-0 pod using following command kubectl exec vault-0 -n vault -- vault status</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ExZd_5-D7-WZawleC3jXHA.png" /></figure><ul><li>To Join the other Vault pods to the Vault cluster execute the below commands one by one.</li></ul><p>a) CLUSTER_ROOT_TOKEN=$(cat cluster-keys.json | jq -r &quot;.root_token&quot;)</p><p>b) kubectl exec vault-0 -n vault -- vault login $CLUSTER_ROOT_TOKEN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V3DHOVGs37lyxvDWuf8Ohg.png" /></figure><p>c) Unseal the other two vault pods using below commands so that they will automatically join with the vault master pod</p><pre>kubectl exec vault-1 -n vault -- vault operator unseal $VAULT_UNSEAL_KEY<br><br>kubectl exec vault-2 -n vault -- vault operator unseal $VAULT_UNSEAL</pre><p>d) Once you done, verify all the vault pods using following command kubectl get pods -n vault output should look like below image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*gLZJk3pu79klSVFSnBRpjQ.png" /></figure><ul><li>Access Vault server</li></ul><p>a) To access our vautl server first we need have a root key to login, extract the root key from cluster-keys.json file using following command cat cluster-keys.json | jq -r &quot;.root_token&quot; once you run the command, you’ll get root key. keep it safe and do not share with anyone.</p><p>b) Expose the vault server using following command kubectl port-forward —namespace vault svc/vault 8200:8200 output shoud look like this Or you can expose vault via proxy/LB so that you can access it directly from your browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M7z6I0N7M3eEYZ6j0VWk8g.png" /></figure><p>c) keep this window exposing vault, if you want to execute any command launch an other command window and use. Or you can also expose vault by attaching service type NodePort, LoadBalancer or any other way.</p><p>d) open your browser and access vault by search as follow localhost:8200 output will be like below image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M9WBfT8IoKFjr0RjWW5cKA.png" /></figure><p>e) Enter the root key and login. To get root key, excute this command cat cluster-keys.json | jq -r &quot;.root_token&quot;</p><ul><li>Once you login as root with token enable the kv secret engine as shown in below images</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQwWfskuOXK7C57d9o9ywQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lnQIK0FRkeoaE65QeA9kdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gxDszXO3Ip46dLERJOxQg.png" /></figure><ul><li>Leave all fields as default and click on <strong>Enable engine.</strong></li></ul><p><strong>Install External Secret Operator</strong></p><ul><li>Install the External Secret Operator using helm. To install ESO use the following helm commands</li></ul><pre>  helm repo add external-secrets https://charts.external-secrets.io<br><br>  helm install external-secrets \<br>     external-secrets/external-secrets \<br>     -n external-secrets \<br>     --create-namespace<br><br></pre><ul><li>Verify the external secrets installation by running the following command kubectl get pods,crd -n external-secrets</li><li>Create the secret using following command kubectl create secret -n vault generic vault-token --from-literal<strong>=</strong>token<strong>=</strong>&#39;your-copied-root-token&#39; (NOTE: you can also create a specific user, attach necessary policies and you can use that user token to access these secrets)</li><li>Once you create secret, verify using command kubectl get secrets -n vautl you should be able to see your secret.</li><li>Create a SecretStore. To do this, we create a file called secret-store.yml with the following content:</li></ul><pre>apiVersion: external-secrets.io/v1beta1<br>kind: ClusterSecretStore # You could also choose ClusterSecretStore <br>metadata:<br>  name: secret-store-vault<br>spec:<br>  provider:<br>    vault:<br>      server: &quot;http://vault.vault:8200&quot; #https://your-vault-server:8200<br>      # Version is the Vault KV secret engine version.<br>      version: &quot;v2&quot;<br>      auth:<br>        # points to a secret that contains a vault token<br>        # https://www.vaultproject.io/docs/auth/token<br>        tokenSecretRef:<br>          namespace: &quot;vault&quot; # secrets namespace that we create with root token<br>          name: &quot;vault-token&quot; # secrets that we create with root token<br>          key: &quot;token<br></pre><ul><li>Once you create the above file apply the file using command kubectl apply -f secret-store.yaml</li><li>Once you apply the file, verify secret store is created or not kubectl get secretstore -n eso you should be see your secretstore.</li><li>Describe the secretstore to verify if it successfully working or not using command kubectl describe secretstore secret-store-vault -n eso and should see as shown in below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*2JkBn2-3PvzpDPdY287Ztw.png" /></figure><ul><li>Till now, our set up is done. Now, lets create secret in vault, get the secret and mount to the pod</li></ul><p><strong>Create Secret In Vault, Get the Secret and Mount to the Pod</strong></p><ul><li>Login using the root token and create a secret. go to kv/ path click on <strong>Create secret→ </strong>enter path key value pairs</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*imibu49devp_hTmbF_iAwA.png" /></figure><ul><li>Then create the externalsecret with kubectl apply -f external-secret.yml.</li></ul><pre>apiVersion: external-secrets.io/v1beta1<br>kind: ExternalSecret<br>metadata:<br>  name: external-secret-github<br>  namespace: vault<br>spec:<br>  refreshInterval: &quot;15s&quot; # The secrets will be refreshed every 15 seconds<br>  secretStoreRef:<br>    name: secret-store-vault # Reference to the secret store we have created above<br>    kind: SecretStore <br>  target:<br>    name: my-secret # K8S secret name<br>  data:<br>    - secretKey: MY_TOKEN # K8S secret key in the secret<br>      remoteRef:<br>        key: kv/db-pass # Path to the vault secret<br>        property: password # Property name of the secret </pre><ul><li>Let’s check again if everything is working properly: kubectl get externalsecret -n eso you should see as shown in the below image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nRUjqZEy3Ci0OL-1tXSPPg.png" /></figure><ul><li>Once externalsecret working fine, there should be one new secret created in the namespace with the name of <strong>my-secret. </strong>verify using command kubectl get secrets -n vault</li><li>Here you go…… verify if your vault secret is present in this secret or not using the command kubectl get secret my-secret -n vault -o jsonpath<strong>=</strong>&#39;{.data}&#39; you should get response as shown in the below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ePrL98sHHkn9i_UxYrfLiw.png" /></figure><ul><li>Now copy the MY_TOKEN value and decode it via online base 64 decoder or base64 CLI. You should be able to see the original value that is there in vault secret.</li><li>Try to change the value in vault server, you can see the change here in the secret. (This is the beauty of ESO)</li></ul><p><strong>Create a pod and pass your secrets as environment variables</strong></p><ul><li>create a my-pod.yaml and paste the below content</li></ul><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: mypod<br>  namespace: vault<br>spec:<br>  containers:<br>    - image: jweissig/app:0.0.1<br>      name: test-app<br>      env:<br>      - name: DB_PASSWORD<br>        valueFrom:<br>          secretKeyRef:<br>            name: my-secret<br>            key: MY_TOKEN</pre><ul><li>create the pod using command kubectl apply -f my-pod.yaml</li><li>exec into the pod kubectl exec -it mypod -n vault -- bash</li><li>check your secret value echo $DB_PASSWORD</li></ul><blockquote>END</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84f01a2f4ae1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install Hashicorp Vault with KubeVault in Kubernetes and attach secrets to pods]]></title>
            <link>https://medium.com/@jakkanirakshith15/how-to-install-with-hashicorp-vault-with-kubevault-in-kubernetes-and-attach-secrets-to-pods-d69734a24228?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/d69734a24228</guid>
            <category><![CDATA[hashicorp-vault]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[vault]]></category>
            <category><![CDATA[secrets]]></category>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Mon, 19 Aug 2024 08:34:38 GMT</pubDate>
            <atom:updated>2024-08-20T09:50:01.264Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udncNC2QH2m2mROvhjLJtg.png" /></figure><p>We had a requirment is that, Hashicorp Vault server should be there in kubernetes cluster, should be managed various components like Authentication,authorization, Secret Engine and many more. Vautl secrets should be consumed by kubernetes pods. So, to fulfill this requirment, we choose to have the <strong>KubeVault Operator with Hashicorp Vault, CSI Driver with Vault provider.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tzo6QNQYVTfWm0KUnZxBFA.png" /></figure><p><strong>PART: A (Basic Theory about KubeVault Operator)</strong></p><p>If you don’t want to read theory part, you can skip and start with the PART: B which is handson practicle</p><p>Lets understand some basics and will go with the practicle thing.</p><ol><li>What is KubeVault Operator ?</li></ol><p>KubeVault Operator is an kubernetes controller for the Hashicorp Vault. Kubevault operator manages the vault server. Managing in the sence, like authentication, authorization, vault client and server communication, Vault’s Secret Engine and many more. Ideally, We can also deploy Hashicorp Vault in kubernetes without using of KubeVault Operator but, it is very defficult to manage the vault server.</p><p>2. Why to use KubeVault ?</p><p>KubeVault operator makes it easy to deploy, maintain and manage Vault servers in Kubernetes. It covers automatic initialization and unsealing, and securely stores unseal keys and root tokens in a cloud KMS (Key Management Service) service. It provides the following features:</p><ul><li>Deploy TLS Secured <a href="https://kubevault.com/docs/v2024.3.12/concepts/vault-server-crds/vaultserver">Vault Server</a></li><li>Manage Vault Server <a href="https://kubevault.com/docs/v2024.3.12/concepts/tls-encryption/overview">TLS using Cert-manager</a></li><li>Automate <a href="https://kubevault.com/docs/v2024.3.12/concepts/vault-server-crds/unsealer/overview">Initialization &amp; Unseal process of Vault Servers</a></li><li>Add Durability to Vault’s Data using <a href="https://kubevault.com/docs/v2024.3.12/concepts/vault-server-crds/storage">Storage Backend</a></li><li>Enable &amp; Configure <a href="https://kubevault.com/docs/v2024.3.12/concepts/secret-engine-crds/secretengine">Secret Engines</a></li><li>Create &amp; Configure <a href="https://kubevault.com/docs/v2024.3.12/concepts/secret-engine-crds/gcp-secret-engine/gcprole">Vault Roles</a></li><li>Manage <a href="https://kubevault.com/docs/v2024.3.12/concepts/policy-crds/vaultpolicy">Vault Policy</a> &amp; <a href="https://kubevault.com/docs/v2024.3.12/concepts/policy-crds/vaultpolicybinding">Vault Policy Binding</a></li><li>Manage user privileges using <a href="https://kubevault.com/docs/v2024.3.12/concepts/secret-engine-crds/secret-access-request">SecretAccessRequest</a></li><li>Manage user privileges using <a href="https://kubevault.com/docs/v2024.3.12/concepts/secret-engine-crds/secret-role-binding">SecretRoleBinding</a></li><li>Inject Vault secrets into K8s resources</li><li>Automate tedious operations using <a href="https://kubevault.com/docs/v2024.3.12/reference/cli">KubeVault CLI</a></li><li>Monitor Vault using Prometheus &amp; Grafana Dashboard</li></ul><p><strong>PART: B (Practicle with KubeVult Operator)</strong></p><p><strong>Step: 1 Generating the license</strong></p><ul><li>Before installation, Make sure that you have kubectl and helm packages and should be configured to your kubernetes cluster</li><li>To install KubeVault, first we need to have the license. So first we need to generate the license.</li><li>To get the license go to KubeVault official website and generate the license <a href="https://kubevault.com/docs/v2024.3.12/setup/install/kubevault/"><strong>https://kubevault.com/docs/v2024.3.12/setup/install/kubevault/</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TK4dAoIDBtVkcLxNxvWDnA.png" /></figure><ul><li>As shown in the above image, enter the details. For cluster ID run the give command <strong>kubectl get ns kube-system -o=jsonpath=’{.metadata.uid}’ </strong>once your license recieved to your mail keep it safe.</li><li>Note: The license is valid only for month, if you want to implement it in production, you have to buy the license from <strong>AppsCode.com</strong></li></ul><p><strong>Step: 2 KubeVault Operator Installation in kubernetes</strong></p><ul><li>Install the KubeVault operator using helm</li></ul><pre>helm install kubevault oci://ghcr.io/appscode-charts/kubevault \ <br> --version v2024.3.12 \ <br> --namespace kubevault --create-namespace \ <br> --set-file global.license=/path/to/the/license.txt</pre><ul><li>To check if KubeVault operator pods have started, run the following command kubectl get pods --all-namespaces -l &quot;app.kubernetes.io/instance=kubevault</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4lONobM4ZUJkSTE6H_rfUQ.png" /></figure><ul><li>Now, to confirm CRD groups have been registered by the operator, run the following command kubectl get crd -l app.kubernetes.io/name=kubevault</li></ul><p><strong>Step: 3 CSI Driver and Vault Provider Setup</strong></p><ul><li>Install the CSI Driver using the helm commands</li></ul><pre>helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts<br><br>helm install csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver \<br>  --set &quot;syncSecret.enabled=true&quot; \<br>  --set &quot;enableSecretRotation=true&quot; \<br>  --set &quot;rotation-poll-interval=15s&quot; \<br>  --namespace kube-system</pre><ul><li>Once you run the helm commands, verify with the following command kubectl get pods -n kube-system -l &quot;app=secrets-store-csi-driver</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWMPXoSHMt7o4cOwfMbxCA.png" /></figure><ul><li>Install the Vault Provider using helm</li></ul><pre>helm repo add hashicorp https://helm.releases.hashicorp.com<br><br>helm install vault hashicorp/vault \<br>  --set &quot;server.enabled=false&quot; \<br>  --set &quot;injector.enabled=false&quot; \<br>  --set &quot;csi.enabled=true&quot;</pre><ul><li>Once you executed successfully, verify the provider pods using command kubectl get pods -l &quot;app.kubernetes.io/name=vault-csi-provider&quot;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wm6-Wzsr6vy82BDCZ7BRCg.png" /></figure><p><strong>Step: 4 Vault Server Installation</strong></p><ul><li>Create a namespace for isolation using command kubectl create ns demo</li><li>Verify vault server version crds using command kubectl get vaultserverversions you should see like the below image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*kYKJT9VdQaenzO3nxK8JnA.png" /></figure><ul><li>Configure or install vaultServerVersion, Create a vault-server-version.yaml and paste the below yaml configuration in it</li></ul><pre>apiVersion: catalog.kubevault.com/v1alpha1<br>kind: VaultServerVersion<br>metadata:<br>  name: 1.10.3<br>spec:<br>  exporter:<br>    image: kubevault/vault-exporter:v0.1.1<br>  unsealer:<br>    image: kubevault/vault-unsealer:v0.8.0<br>  vault:<br>    image: vault:1.10.3<br>  version: 1.10.3</pre><ul><li>Then apply the yaml file using kubectl apply -f vault-server-version.yaml</li><li>Install Vault Server, Create a vault-server.yaml file and paste the below configuration in it.</li></ul><pre>apiVersion: kubevault.com/v1alpha2<br>kind: VaultServer<br>metadata:<br>  name: vault<br>  namespace: demo<br>spec:<br>  replicas: 1<br>  version: 1.10.3<br>  serviceTemplates:<br>  - alias: vault<br>    metadata:<br>      annotations:<br>        name: vault<br>    spec:<br>      type: NodePort<br>  backend:<br>    inmem: {}<br>  unsealer:<br>    secretShares: 4<br>    secretThreshold: 2<br>    mode:<br>      kubernetesSecret:<br>        secretName: vault-keys</pre><ul><li>In the above configuration file, spec.backend, I used <strong>inmemory </strong>as per testing. You can use other backend to persist the vault server data as following the link <a href="https://kubevault.com/docs/v2024.3.12/concepts/vault-server-crds/vaultserver/">https://kubevault.com/docs/v2024.3.12/concepts/vault-server-crds/vaultserver/</a> Once you open the link scroll down to the <a href="https://kubevault.com/docs/v2024.3.12/concepts/vault-server-crds/vaultserver/">spec.backend</a> and click on any backend that you want to configure.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwtmxGlm-jn9UBPA6PS6SQ.png" /></figure><ul><li>Change the <strong>spec.backend </strong>configuration as per your requirement and apply the vault-server.yaml using command kubectl apply -f vault-server.yaml</li><li>Verify vault server’s state using command kubectl get vaultserver -n demo It should in ready state as shown in below image (NOTE: it will take 2 or 3 minutes)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvUN1RxIA9F7uJn0Ybd58g.png" /></figure><ul><li>Once, the vaultserver is ready, you should a pod launched in the same namespace. Verify using command kubectl get pods -n demo you should see like below image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*TBv0XrayGM7QFIhFGw0Cig.png" /></figure><ul><li>Once server pod is running, there should be<strong> “vault-keys“</strong> secret created in the same namespace. verify using command kubectl get secrets -n demo</li><li>Get the secret as a yaml configuration using command kubectl get secrets vault-keys -n demo -o yaml once you get yaml configuration, in data field you will find <strong>vault-root-token: </strong>copy the root token and decode using online base64 decoder or in command line and store it somewhere.</li><li>Expose the vault server using the command kubectl port-forward -n demo pod/vault-0 8200</li><li>Go to browser search for localhost:8200 then you will be able to see vault UI</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CuDhB3OQT8fGa9yX90uL5g.png" /></figure><ul><li>Sign in method should be <strong>Token</strong> and Enter the token that you have stored somewhere and click on sign in</li><li>once you sign in Enable the KV secret Engine, Create the secret by following the below images (Please follow the arrow directions)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q_D1J4fU5Gh_wF92W9u7hA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*08SJ1E_A-Ejuw8_wQVwVeA.png" /></figure><ul><li>NOTE: You can also use version 2, if you want to use version 2, then the path should be <strong>kv</strong></li><li>Go to secret/ folder and click on <strong>Create secret, </strong>Enter the path, key and value and then click on save</li></ul><p><strong>Step: 5 Access secrets from the vault</strong></p><ul><li>Create a serviceAccount.yaml and paste the below configuration in file</li></ul><pre>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  name: pod-sa<br>  namespace: demo</pre><ul><li>Create a VaultPolicy-VaultPolicyBinding.yaml and paste the below yaml configuration in it</li></ul><pre>apiVersion: policy.kubevault.com/v1alpha1<br>kind: VaultPolicy<br>metadata:<br>  name: kv-se-policy<br>  namespace: demo<br>spec:<br>  vaultRef:<br>    name: vault<br>  policyDocument: |<br>    path &quot;secret/db-password&quot; {<br>      capabilities = [&quot;read&quot;]<br>    }    <br>---<br>apiVersion: policy.kubevault.com/v1alpha1<br>kind: VaultPolicyBinding<br>metadata:<br>  name: kv-se-role<br>  namespace: demo<br>spec:<br>  vaultRef:<br>    name: vault<br>  policies:<br>  - ref: kv-se-policy<br>  subjectRef:<br>    kubernetes:<br>      serviceAccountNames:<br>      - &quot;pod-sa&quot;<br>      serviceAccountNamespaces:<br>      - &quot;demo&quot;</pre><ul><li>Create a secretProviderClass.yaml and paste the below yaml configuration in it.</li></ul><pre>apiVersion: secrets-store.csi.x-k8s.io/v1alpha1<br>kind: SecretProviderClass<br>metadata:<br>  name: vault-database<br>  namespace: demo<br>spec:<br>  provider: vault<br>  parameters:<br>    vaultAddress: &quot;http://vault.demo:8200&quot;<br>    roleName: &quot;k8s.&lt;Your_ClusterID&gt;.demo.kv-se-role&quot;   <br>    objects: |<br>      - objectName: &quot;db-password&quot;<br>        secretPath: &quot;/secret/db-pass&quot;<br>        secretKey: &quot;password&quot;<br>  secretObjects:            <br>    - secretName: db-secret  # k8s secret name that you want SecretProviderClass to provision<br>      type: Opaque<br>      data:<br>        - objectName: &quot;db-password&quot;<br>          key: db-password</pre><ul><li>In the above configuration file, <strong>roleName </strong>field:</li></ul><pre>ClusterID = Your cluster id, which you provided to get the licence<br>demo = your vault namespace<br>kv-se-role = The VaultPolicyBinding name that you have created above</pre><ul><li>Verify secretproviderclass using kubectl get secretproviderclass -n demo you should be able see your secretproviderclass named with vault-database.</li><li>Once your created secretProviderClass, one new secret should be created with the name <strong>db-secret</strong> as you mention in the secretProviderClass yaml configuration.</li><li>Create a demo-pod.yaml and paste the below configuration init.</li></ul><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: mypod<br>  namespace: demo<br>spec:<br>  containers:<br>    - image: jweissig/app:0.0.1<br>      name: test-app<br>      env:<br>      - name: DB_PASSWORD<br>        valueFrom:<br>          secretKeyRef:<br>            name: db-secret<br>            key: db-password</pre><ul><li>Verify your pod is up or not using command kubectl get pods -n demo you should see pod Running.</li><li>Exec into the pod using command kubectl exec -it mypod -n demo -- sh</li><li>Once your inside the pod, go to <strong>/secrets-store/test</strong> using command cd /secrets-store/test you should a file name called <strong>db-password </strong>open the file using command cat db-password then you should be able to see the value that is present in the vault.</li><li>Keep changing the values in vault server and check if values are updated in the secret that is created by secretProviderClass.</li><li>NOTE: Pod gets updated values once it restarts, you can use any custom script to do this task.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d69734a24228" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Centralized VPC Endpoints]]></title>
            <link>https://medium.com/@jakkanirakshith15/centralized-vpc-endpoints-f6ce1cf394f6?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6ce1cf394f6</guid>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Thu, 09 May 2024 10:14:47 GMT</pubDate>
            <atom:updated>2024-05-09T10:14:47.446Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*LFlW8ov96T5dzDu-C9dujw.png" /></figure><p><strong>Use case:</strong> When you have multiple account under the organization, and you want to access AWS resources across all accounts privately and this solution should be cost effective.</p><p>What is VPC Endpoints ?</p><p>VPC endpoints are virtual devices. They are horizontally scaled, redundant, and highly available Amazon VPC components that allow communication between instances in an Amazon VPC and services without imposing availability risks or bandwidth constraints on network traffic. There are two types of VPC endpoints</p><p>When you make use of VPC Endpoints, When an EC2 instance or other resources wants to communicate with the other AWS Service, the traffic will flow within the AWS Network. It will not flow via internet</p><p>Resources that we gonna use in this task:</p><ol><li>AWS Route 53</li><li>Transit Gateway</li><li>VPC Endpoint</li><li>EC2 instance</li></ol><p><strong>Step 1:</strong> Transit Gateway setup with VPC Attachments<br>create the Transit gateway with default settings as shown in the below picture. You just have to enter the name of Transit Gateway and click on create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FbBxRn2gFNyKOdjQxfYhyQ.png" /></figure><p>Wait for the TGW to be available</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F7plaLAgXAnf-UswkZGghg.png" /></figure><p>Go to Transit Gateway Attachment tab and create the attachment as show in the below instructions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8ySfrLVXPOGGC0uJRG06g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t91eh6XEIevrgsNxmQTYag.png" /></figure><p>Enter the name of Attachment, Select the transit gateway ID which your created in the last step and select attachment type VPC and select the centralized VPC and subnets as well.</p><p>Create another attachment which points to other VPC(which consumes centralized VPC endpoint). and follow the same steps if you want to attach number of VPCs.</p><p>once both VPC attachments are available as shown in below image, We can proceed with next steps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*i7r_nvW-pOeLL96EDPzYHw.png" /></figure><p><strong>Step 2:</strong> Create VPC Endpoint in central Account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cKrgQq5A01SAirOYYCqyzA.png" /></figure><p>Name → Give any name that you want, Service category → AWS services</p><p>In services search, I entered Lambda for testing purpose. You can enter any service that you want to connect privately and select service name.</p><p>Select the Central VPC and subnets. Select default security group or create a security group which allows the inbound traffic from your child account.</p><p>Click on create to create the VPC endpoint. Wait till it get activated</p><p>Select VPC Endpoint go to actions → Modify Private DNS Name → uncheck Enable for this endpoint → click on save changes.</p><p><strong>Step 3</strong>: Create Private Hosted Zone in Route 53</p><p>create the hosted zone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*OfFSxaIKqKTNOBAwy213jQ.png" /></figure><p>Domain name → Give the name of your choice, select Private Hosted Zone.</p><p>Select the Central VPC and child VPC to which VPCs you want to share the Endpoint access. Create PHZ</p><p>Select the PHZ that you create in the last step and click on create record</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6vFZTiSdzik7FqRX1xYsQ.png" /></figure><p>Enable Alias select Alias to VPC endpoint, Select the region where your VPC endpoint has created. select the VPC endpoint and click in create records.</p><p>Launch an instance in child VPC and log in to it. Try to resolve your DNS in my case it is rakshith.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*EBh6dgnJ0u6888xIYk4N1A.png" /></figure><p>Hence we can see that our instance is connecting to lambda using private IP. So we can conclude that traffic is flowing privately.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6ce1cf394f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS LAMBDA, API Gateway, RDS IN LOCAL SYSTEM USING SERVERLESS FRAMEWORK]]></title>
            <link>https://medium.com/@jakkanirakshith15/aws-lambda-api-gateway-rds-in-local-system-using-serverless-framework-b9f5d6ea89cc?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9f5d6ea89cc</guid>
            <category><![CDATA[serverless-offline]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[rds-mysql]]></category>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Tue, 23 Jan 2024 06:58:56 GMT</pubDate>
            <atom:updated>2024-01-23T06:58:56.423Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS LAMBDA IN LOCAL SYSTEM USING SERVERLESS FRAMEWORK</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*KXQq1ktRUUwWXyVV8TN8_A.png" /></figure><p>The story behind the this blog is…………….</p><p>In a recent project one of our client faced a challenge in their app development environment. When developer updates the code, he needs to push the updated code to GitHub. Once commit happens, pipeline will trigger deploy it in AWS Lambda function. Some times the code changes worked great but some other times code changes were crashed developers heads. So we decided to take this up and make this development process smoother. while this remains in my mind, I came up with a solution where they can develop their code and test in their local system. If changes were worked fine in developing environment, then they pushed code to GitHub and deployed in AWS Lambda through pipeline. And the solution is Serverless Framework with serverless-offline plugin.</p><ul><li>The main agenda of this blog is to know the greatness of serverless framework and its plugins like serverless-offline</li><li>You can simply follow this blog when your lambda function have to fetch data from database and give response back to the user. Every application functionality. Your code might simply process the request and give the response back to the user (you can follow this blog in that case as well but, you don’t need launch a docker container.)</li><li>In my case when a user or external sources triggers the Lambda, the lambda runs, fetch the data from database and return the response.</li></ul><p><strong>My Project Introduction</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*sDO6V28kLZUjVmOeDnUdUA.png" /></figure><ul><li>When user triggers the lambda function by manual or by some external sources, Lambda function will fetch database credentials from AWS Secretes Manager and create a Database connection pool. So that my lambda can communicate with the database. Then the lambda fetch some data from database and give back to the user</li></ul><p><strong>SERVERLESS FRAMEWORK</strong></p><ul><li>Before going to do practical, lets explore serverless framework and its plugins and serverless-offline plugin at a high level.</li><li>Serverless Framework helps you to develop and deploy lambda functions, along with the infrastructure they require.</li><li>The main advantage of serverless framework, It manages your application code and as well as the Infrastructure the you defined.</li><li>When you define infrastructure in serverless framework, In the backend the Cloud Formation stack will be generated and applied in AWS cloud.</li><li>It supports multiple languages like Node.js, Python, Java and more…</li></ul><p>Note:- I am not defining any resources in this block as I worked around the API Gateway, Lambda and Database.</p><p><strong>Serverless-offline Plugin</strong></p><p>This Serverless plugin emulates AWS Lambda and API Gateway on your local machine to speed up your development cycles. To do so, it starts an HTTP server that handles the request’s lifecycle like API Gateway does and invokes your handlers.</p><p><strong>Lets get started……</strong></p><p><strong>Step 1:</strong></p><ul><li>Log into AWS account. Open Secretes Manager console. Create secret with your database credentials.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iy9m4UxgD9w8GRxmkJNxAQ.png" /></figure><ul><li>In my project code, The secrets are fetching from the AWS secrets manager so that I created secretes In AWS cloud.</li></ul><p><strong>Step 2:</strong></p><ul><li>Create a folder and place all your lambda function code in that particular folder</li><li>Install the serverless Framework using npm command <strong>npm install -g serverless. </strong><em>If you don’t already have Node.js on your machine, install it first If you don’t want to install Node or NPM, you can install serverless as a standalone binary. for more information about installation, please follow official serverless documentation.</em></li><li>create a serverless.yaml file</li></ul><pre>service: lambda-invoke-aws-sdk-v3<br><br>plugins:<br>  - serverless-offline<br><br>provider:<br>  iamRoleStatements:<br>    - Action:<br>        - lambda:InvokeAsync<br>        - lambda:InvokeFunction<br>      Effect: Allow<br>      Resource: &quot;*&quot;<br>  memorySize: 128<br>  name: aws<br>  region: ap-south-1<br>  runtime: nodejs18.x<br>  versionFunctions: false<br><br>functions:<br>  hello:<br>    handler: index.handler<br>    events:<br>      - httpApi:<br>          method: get<br>          path: /filterData<br><br></pre><ul><li>service: Specifies the name of the service or application.</li><li>plugins: Lists the Serverless Framework plugins you want to use. In this case, the serverless-offline plugin is included, which allows you to simulate AWS Lambda and API Gateway locally for testing purposes.</li><li>provider: Describes the configuration for the cloud provider (in this case, AWS). It includes IAM role statements, memory size, AWS region, runtime, and other provider-specific settings.</li><li>functions: Defines the AWS Lambda functions in your service. In this case, there&#39;s one function named &quot;hello&quot; with a handler function index.handler and an HTTP API event that responds to HTTP GET requests at the path &quot;/filterData.&quot;</li></ul><p><strong>Step 3:</strong></p><ul><li>Create a Dockerfile for the MySQL database (In my case, my database launched in docker container. You can also install MySQL server in local machine).</li></ul><pre># Use the official MySQL image from Docker Hub<br>FROM mysql:latest<br><br># Set environment variables for MySQL<br>ENV MYSQL_ROOT_PASSWORD=&lt;Enter the password that you want to set&gt;<br>ENV MYSQL_DATABASE=&lt;Enter the name of database&gt;<br><br># Copy SQL files into the container<br>COPY --chown=mysql:mysql ./Dump20231213.sql/ /docker-entrypoint-initdb.d/ <br>COPY --chown=mysql:mysql ./Dump20240108.sql/ /docker-entrypoint-initdb.d/<br><br><br># Expose the MySQL port<br>EXPOSE 3306</pre><ul><li>Build the docker image using command <strong>docker build -t &lt;ImageName&gt; .</strong></li></ul><p>Note: In the above command the dot(.) should also there, it represents current folder.</p><ul><li>once the docker image built verify</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*aiKG33T6zYPAnOtBhw7CFg.png" /></figure><ul><li>Run the docker image in order to launch a MySQL container with the command <strong>docker run -p 3306:3306 — name=&lt;ContainerName&gt; -d &lt;ImageName&gt;</strong></li><li>Once the container is created, verify if it is running up and running.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rr8YEisyyIUDzoq21hlWxw.png" /></figure><ul><li>exec into the MySQL container</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6xPoy96kMMfzd3iSE78bnA.png" /></figure><ul><li>Once you enter into the docker container log into mysql server</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*CuxIEHBYDpToUqBQ2zkTWA.png" /></figure><ul><li>Enter the password that you have gave in your dockerfile.</li><li>Execute your database schema file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*kBHiMDDDBDzzyTmCz6kLhA.png" /></figure><ul><li>Verify your databases using command <strong>SHOW DATABASES;</strong></li><li>Verify your Tables using command <strong>SHOW TABLES;</strong></li><li>Make your database default with command <strong>USE &lt;DatabaseName&gt;;</strong></li><li>By default Node.js uses mysql_native_password protocol to communicate with the MySQL database. Latest MySQL server uses caching_sha2_passwod.</li><li>Use the following command to change the authentication protocol <strong>ALTER USER ‘root’ IDENTIFIED WITH mysql_native_password BY ‘&lt;Enter your db Password&gt;’;</strong></li><li>Now your MySQL database is ready. You can go ahead and launch a serverless framework application now.</li></ul><p><strong>Step 4:</strong></p><ul><li>Run the following command to install the packages that you have used in you node.js code <strong>npm install</strong></li><li>Now run your serverless framework using serverless-offline plugin with the command <strong>serverless-offline</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*zf8tkfmGhzdrYSq5_3iAqA.png" /></figure><ul><li>You can test this url in postman <strong>http://localhost:3000/&lt;YourAppPath&gt;</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3r3gg8VjhHR9a1Q9xuFNQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9f5d6ea89cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PROTECT MISSION-CRITICAL PODS FROM EVICTION]]></title>
            <link>https://medium.com/@jakkanirakshith15/protect-mission-critical-pods-from-eviction-f4c2996ee2fc?source=rss-186707bd0294------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4c2996ee2fc</guid>
            <dc:creator><![CDATA[Rakshith Jakkani]]></dc:creator>
            <pubDate>Tue, 18 Apr 2023 17:36:40 GMT</pubDate>
            <atom:updated>2023-04-18T17:36:40.384Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone,</p><p><strong>The problem which we faced</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*Pz2CQpcRdneCydp5u7cCOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*HSskMt4cYkSCpiBaaIObtg.png" /></figure><p>The pods were keep on evicted in our cluster. when we were trying to figurout the reason why this pods are evicting, then we got know that, one of the pod is consuming very high resources (lets say the pod <strong>a </strong>consuming 2gb memory and 1.5vcpu , other pods <strong>b </strong>and <strong>c </strong>were consuming only 0.5gb memory and 0.5vcpu, the node has only 20gb disk space and 2vCPU ). just because of pod <strong>a</strong>, the other pods(<strong>a</strong> and <strong>b</strong>) also evicted. but, at any cost pod <strong>b</strong> should be at running state.</p><p>Then we found a kubernetes feature called <strong>priority class</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*HSskMt4cYkSCpiBaaIObtg.png" /></figure><p><strong>General flow of pod scheduling in kubernetes</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*CXiKb-3aKAL6i_tcd-eQvg.png" /></figure><p>The control plane consists of multiple components, out of which the scheduler (usually the built-in <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/">kube-scheduler</a>) is one of the components which is responsible for assigning a node to a pod.</p><p>Whenever a pod is created, it enters a “pending” state, after which the scheduler determines which node is best suited for the placement of the new pod.</p><p>In the background, the scheduler runs as an infinite loop looking for pods without a nodename set that are <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/pod-scheduling-readiness/">ready for scheduling</a>. For each Pod that needs scheduling, the scheduler tries to decide which node should run that Pod. If the scheduler cannot find any node, the pod remains in the pending state, which is not ideal.</p><p><strong>Let’s start with PriorityClass</strong></p><p>we will be discussing on three basic terms <strong>WHAT</strong>, <strong>WHY</strong> and <strong>HOW</strong></p><p><strong>====&gt;</strong> <strong>what is priorityclass ?</strong></p><p>PriorityClass is a cluster-wide API object in Kubernetes and part of the “scheduling.k8s.io/v1” API group. It contains an integer value (-1000000000&lt;lower priority&gt; to 1000000000&lt;higher priority&gt;) represents the value that the scheduler uses to determine Pod’s relative priority.</p><p><strong>====&gt; why priorityclass ?</strong></p><p>let’s say we have three pods (A) dev-pod (B) qa-pod and (C) prod-pod running on the same cluser. Our least priority would be <strong>dev-pod</strong> intermediate priority is <strong>qa-pod</strong> and high priority is <strong>prod-pod. </strong>when i want to run 3 pods according to their priorityclass the, when node has enough resources for scheduling three pods then the scheduler will schedule the three pods. In a case where we don’t have enough resources to schedule the pods (if you also have cluster autoscaler to scale up the nodes, there will be a certain time required to node to be at ready state).</p><p><a href="https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#preemption">Pod preemption</a> is a Kubernetes feature that allows the cluster to preempt pods (removing an existing Pod to schedule a new Pod) on the basis of priority. <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#pod-priority">Pod priority</a> indicates the importance of a pod relative to other pods while scheduling. If there aren’t enough resources to run all the current pods, the scheduler tries to evict lower-priority pods over high-priority ones.</p><p>Also, when a healthy cluster experiences a node failure, typically, lower-priority pods get preempted to create room for higher-priority pods on the available node. This happens even if the cluster can bring up a new node automatically since pod creation is usually much faster than bringing up a new node.</p><p><strong>====&gt; How to use priorityclass</strong></p><p>Let’s have manifest configurations for three pods <strong>dev-pod, qa-pod </strong>and <strong>prod-pod.</strong></p><p><strong>dev-pod manifest</strong></p><p>create a manifest file with below code</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: dev-pod<br>  labels:<br>    env: dev<br>spec:<br>  containers:<br>  - name: dev-nginx<br>    image: nginx<br>    resources:<br>      requests:<br>        memory: &quot;2Gi&quot;<br>        cpu: &quot;0.5&quot;<br>      limits:<br>        memory: &quot;2Gi&quot;<br>        cpu: &quot;0.5&quot;</pre><p>use command <strong>kubectl apply -f &lt;yourFileName&gt;</strong></p><p><strong>qa-pod manifest</strong></p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: qa-pod<br>  labels:<br>    env: preprod<br>spec:<br>  containers:<br>  - name: preprod-nginx<br>    image: nginx<br>    resources:<br>      requests:<br>        memory: &quot;2Gi&quot;<br>        cpu: &quot;0.5&quot;<br>      limits:<br>        memory: &quot;2Gi&quot;<br>        cpu: &quot;1&quot;</pre><p>use command <strong>kubectl apply -f &lt;yourFileName&gt;</strong></p><p><strong>prod-pod manifest</strong></p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: prod-pod<br>  labels:<br>    env: prod<br>spec:<br>  containers:<br>  - name: prod-nginx<br>    image: nginx<br>    resources:<br>      requests:<br>        memory: &quot;1Gi&quot;<br>        cpu: &quot;1.5&quot;<br>      limits:<br>        memory: &quot;2Gi&quot;<br>        cpu: &quot;1.8&quot;</pre><p>use command <strong>kubectl apply -f &lt;yourFileName&gt;</strong></p><p>NOTE:- In my case, for testing I have only one node with 20gb disk and 2vcpu</p><p>when I deploy thos three pods one of the pod went to <strong>pending</strong> state as you can absorve in the below image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*gVDgLXolGFXSP5kgzF4bLw.png" /></figure><p>when i describe the prod-pod to see why it was gone to pending state, it was stating that due to insuffiecent cpu, the particular prod-pod was not scheduled as you can observer in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*X4fUDj0O_xgJt4hobzzIbA.png" /></figure><p>So, now prod-pod has to be in running state, for that we will be using <strong>priorityclass</strong></p><p><strong>priorityclass manifest</strong></p><pre>apiVersion: scheduling.k8s.io/v1<br>kind: PriorityClass<br>metadata:<br>  name: sample<br>value: 10000000 # any integer value between -1000000000 to 1000000000 <br>globalDefault: false </pre><p>as you can observe the integer value, “the higher the value, the higher the priority” it doesn’t mean that this pod will not evict. But it will be the last pod to evict whenever resources are degreded in the node.</p><p><strong>Refer priorityclass in pod manifest:-</strong></p><p>Before you make changes to the pod manifest you will have to delete the existing pod (prod-pod) which is in pending state use command <strong>kubectl delete pod &lt;yourPodName&gt; </strong>to delete the pod<strong> </strong>. while using priorityclass we cannot configure changes which is already in running or pending state.</p><p>The allowed fields that can be updated are:</p><ul><li>spec.containers[*].image</li><li>spec.initContainers[*].image</li><li>spec.activeDeadlineSeconds</li><li>spec.tolerations (only additions to existing tolerations)</li><li>spec.terminationGracePeriodSeconds (allow it to be set to 1 if it was previously negative)</li></ul><p>All other fields are immutable after the Pod is created, including spec.hostAliases and spec.priorityClassName.</p><p>The below code is the code which is updated with the priorityclass</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: prod-pod<br>  labels:<br>    env: prod<br>spec:<br>  containers:<br>  - name: prod-nginx<br>    image: nginx<br>    resources:<br>      requests:<br>        memory: &quot;1Gi&quot;<br>        cpu: &quot;1.5&quot;<br>      limits:<br>        memory: &quot;2Gi&quot;<br>        cpu: &quot;1.8&quot;<br>  priorityClassName: sample</pre><p>use command kubectl apply -f &lt;yourFileName&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*-BzwWBw3KInKA5tiEfqqOw.png" /></figure><p>you can obsorve in the image that <strong>qa-pod </strong>was terminated and <strong>prod-pod</strong> is up and running and <strong>dev-pod</strong> is in pendig state due to insufficient cpu</p><p>you can also create indivisual priorityclasses for each pod like for dev-pod, priorityclass value 1000000 and for qa-pod, priorityclass value 2000000 as per your requirement</p><p>NOTE:- If you set <strong>globalDefault: true </strong>then the particular priorityclass resource priority value( example:-1000000 ) will be applied to everypod in the cluster</p><p>To know more about priorityclasse and pod preemption please visit official kubernetes documentation <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/">https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4c2996ee2fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>