<?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 Reza Sadriniaa on Medium]]></title>
        <description><![CDATA[Stories by Reza Sadriniaa on Medium]]></description>
        <link>https://medium.com/@reza.sadriniaa?source=rss-b244d9757cae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YcRVMuoRoI4p6ZWQSwPdGg.jpeg</url>
            <title>Stories by Reza Sadriniaa on Medium</title>
            <link>https://medium.com/@reza.sadriniaa?source=rss-b244d9757cae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:36:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reza.sadriniaa/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[Fixing Real Client IP Behind Kubernetes Ingress: My Journey with externalTrafficPolicy: Local…]]></title>
            <link>https://medium.com/@reza.sadriniaa/fixing-real-client-ip-behind-kubernetes-ingress-my-journey-with-externaltrafficpolicy-local-cb9d6a43c1d2?source=rss-b244d9757cae------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb9d6a43c1d2</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[ingresscontroller]]></category>
            <category><![CDATA[metallb]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Reza Sadriniaa]]></dc:creator>
            <pubDate>Wed, 10 Dec 2025 07:43:09 GMT</pubDate>
            <atom:updated>2025-12-10T07:43:09.820Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fixing Real Client IP Behind Kubernetes Ingress: My Journey with externalTrafficPolicy: Local, Dropped Requests, and MetalLB</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eeKzcIUxUzCYHeUTcHKO3w.png" /></figure><p>When you’re running applications in Kubernetes, getting the <strong>real client IP address</strong> seems like something that <em>should</em> just work—especially when you’re using an Ingress Controller. But I recently ran into a subtle but tricky issue: every incoming request was showing the <em>node IP</em> or <em>load balancer IP</em>, instead of the actual user’s IP.</p><p>This turned into a deep dive into Kubernetes networking, NAT behavior, MetalLB, and how externalTrafficPolicy: Local really works.<br> In this post, I’ll break down exactly what happened, how I debugged it, and the final architecture that gave me correct client IPs—without dropping traffic.</p><h3>📌 The Problem: Real Client IP Missing in Ingress</h3><p>My setup looked something like this:</p><pre>Client → LoadBalancer (MetalLB) → Ingress Controller → App</pre><p>But inside my application (and inside the ingress logs), the IPs I saw were:</p><ul><li>Node internal IP</li><li>Load balancer IP</li><li>Sometimes a NATed cluster IP</li></ul><p>I needed the <em>actual</em> user IP to appear in:</p><ul><li>X-Forwarded-For</li><li>X-Real-IP</li></ul><p>Common solutions (like enabling proxy headers) didn’t help, because this wasn’t an Ingress config issue — it was a Kubernetes networking behavior.</p><h3>🔍 Root Cause: Kubernetes NAT Hides Client IP</h3><p>By default, Kubernetes Services perform <strong>NAT (masquerading)</strong> when forwarding traffic to pods. This rewrites the source IP so the client’s real IP is lost.</p><p>To keep the original client IP, Kubernetes provides:</p><pre>externalTrafficPolicy: Local</pre><p>Setting this on the Service tells Kubernetes:</p><p><em>| “Do NOT NAT traffic. Route it only to nodes that directly received it.”</em></p><p>So I enabled it…</p><h3>⚡ What Happened After Enabling externalTrafficPolicy: Local</h3><p>Here’s the part they don’t tell you:</p><p>If a request lands on a node that <strong>does not</strong> have an Ingress pod running, Kubernetes will <strong>NOT</strong> forward the request to another node.</p><p>It simply <strong>drops the traffic.</strong></p><p>Exactly what I observed next:</p><ul><li>Random requests were failing</li><li>Some connections never reached my ingress</li><li>Logs were inconsistent</li></ul><p>Why?<br> Because MetalLB was sending traffic to nodes randomly, regardless of whether an ingress pod existed there.</p><p>So the sequence was:</p><ol><li>MetalLB advertises an IP</li><li>Traffic lands on <strong>Node A</strong></li><li>But ingress is running only on <strong>Node B</strong></li><li>Kubernetes refuses to forward the request (because of externalTrafficPolicy: Local)</li><li>✔ Real client IP preserved</li><li>❌ Request dropped</li></ol><p>At this point, I understood the behavior — but I needed a fix.</p><h3>🧠 Solution Direction: Ensure Traffic Only Reaches Nodes Running Ingress</h3><p>After some trial and error, it became clear:</p><blockquote><em>If </em><em>externalTrafficPolicy: Local is enabled, </em><strong><em>only send traffic to nodes that actually run ingress pods</em></strong><em>.</em></blockquote><p>There were two options:</p><h3>Option 1: Run Ingress as a DaemonSet</h3><p>This guarantees that <em>every</em> node has at least one Ingress pod.</p><p>But in my case, I didn’t want the ingress controller running everywhere.<br> Some nodes were GPU nodes, some were reserved for background jobs — not a good fit.</p><p>So I went with Option 2.</p><h3>Option 2 (Final Solution): Label Nodes + Schedule Ingress on Them + Use MetalLB Advertising</h3><p>This ended up being the cleanest and most flexible solution.</p><h3>✔️ Step 1 — Label the nodes I want to run ingress on</h3><pre>kubectl label node node1 ingress-ready=true<br>kubectl label node node2 ingress-ready=true</pre><h3>✔️ Step 2 — Update the Ingress Controller Deployment to schedule only on these nodes</h3><p>Example (for nginx ingress):</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: ingress-nginx-controller<br>spec:<br>  template:<br>    spec:<br>      nodeSelector:<br>        ingress-ready: &quot;true&quot;</pre><p>Now ingress pods run <strong>only</strong> on the nodes I selected.</p><h3>✔️ Step 3 — Configure MetalLB to advertise the LoadBalancer IP only on those same nodes</h3><p>MetalLB IPAddressPool + L2Advertisement:</p><pre>apiVersion: metallb.io/v1beta1<br>kind: IPAddressPool<br>metadata:<br>  name: ingress-public-ip<br>  namespace: metallb-system<br>spec:<br>  addresses:<br>    - 192.168.1.240-192.168.1.250<br>---<br>apiVersion: metallb.io/v1beta1<br>kind: L2Advertisement<br>metadata:<br>  name: ingress-l2<br>  namespace: metallb-system<br>spec:<br>  ipAddressPools:<br>    - ingress-public-ip<br>  nodeSelectors:<br>    - matchLabels:<br>        ingress-ready: &quot;true&quot;</pre><p>Now MetalLB only advertises the IP on the nodes where:</p><pre>ingress-ready=true</pre><p>Meaning:</p><ul><li>Traffic → only those nodes</li><li>Those nodes have ingress pods</li><li>No dropped traffic</li><li>Real client IP preserved</li></ul><p>Perfect.</p><h3>Step 4 — Enable externalTrafficPolicy: Local on Ingress Service</h3><p>Example Ingress-NGINX Service:</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: ingress-nginx-controller<br>  namespace: ingress-nginx<br>spec:<br>  type: LoadBalancer<br>  externalTrafficPolicy: Local<br>  ports:<br>    - name: http<br>      port: 80<br>      targetPort: 80<br>    - name: https<br>      port: 443<br>      targetPort: 443</pre><p>This ensures <strong>no NAT</strong>, so now the real client IP passes through correctly.</p><h3>🟢 Final Result</h3><p>After all changes:</p><ul><li>No traffic was dropped</li><li>Real client IP appeared correctly in:</li><li>Ingress logs</li><li>Application logs</li><li>X-Forwarded-For</li><li>MetalLB intelligently guided traffic only to ingress-ready nodes</li><li>Ingress controller was deployed <em>only</em> where I wanted it</li></ul><h3>📦 Final Architecture</h3><pre>                MetalLB (Advertise only on ingress-ready nodes)<br>                       ↙                        ↘<br>                  Node A (ingress)         Node B (ingress)<br>                       ↘                        ↙<br>                      Ingress Controller Pods<br>                             ↓<br>                          Applications</pre><p>No NAT → No dropped packets → Real client IP preserved.</p><h3>Conclusion</h3><p>What started as a simple “Why am I not seeing the real client IP?” became a deep dive into how Kubernetes routes external traffic.</p><p>Key lessons:</p><ul><li>externalTrafficPolicy: Local is mandatory for real client IPs</li><li>But it <em>requires</em> that traffic lands only on nodes running your ingress pods</li><li>MetalLB + node labels make this fully controllable</li><li>Avoid running ingress as a DaemonSet unless you truly want that</li></ul><p>If you’re using Kubernetes bare-metal + MetalLB + Ingress, this pattern is one of the cleanest and most production-friendly setups.</p><p>#Kubernetes #DevOps #CloudNative #Networking #Ingress #K8s #KubernetesIngress #LoadBalancer #MetalLB #Ingress</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb9d6a43c1d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[️Monitor Your Galera Cluster From the Browser]]></title>
            <link>https://medium.com/@reza.sadriniaa/%EF%B8%8Fmonitor-your-galera-cluster-from-the-browser-0ad501a698e5?source=rss-b244d9757cae------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ad501a698e5</guid>
            <dc:creator><![CDATA[Reza Sadriniaa]]></dc:creator>
            <pubDate>Sat, 30 Aug 2025 11:07:14 GMT</pubDate>
            <atom:updated>2025-08-30T11:07:14.734Z</atom:updated>
            <content:encoded><![CDATA[<p>Keeping an eye on a Galera cluster can sometimes feel like juggling multiple balls at once. I built <strong>galera_monitor</strong>, a lightweight Python web server that makes this process simple and visual.</p><h3>⚙️ What It Does</h3><p><strong>galera_monitor</strong> connects to all nodes in your Galera Cluster, collects key metrics, and displays them in a clean, intuitive dashboard — all from your browser. No agents. No complex setup. Just configure your nodes and start the server.</p><h3>📊 Metrics You Can Track</h3><p>Some of the key metrics it gathers include:</p><ul><li>wsrep_local_send_queue</li><li>wsrep_local_recv_queue</li><li>wsrep_cert_deps_distance</li><li>wsrep_last_committed</li><li>wsrep_thread_count</li><li>wsrep_flow_control_*</li><li>Queries/sec</li><li>Writes/sec</li><li>Running Threads</li><li>Memory Used</li><li>gcache.size, gcache.page_size, gcs.fc_limit</li><li>…and more!</li></ul><p>You can also monitor cluster health and performance through HAProxy, including active connection count per node.</p><h3>🔍 Why I Built It</h3><p>I needed a quick way to check the state of my Galera clusters without logging into each server manually. <strong>galera_monitor</strong> was my solution — simple, visual, and efficient.</p><h3>📂 Check Out the Source Code</h3><p>You can find the full source on GitHub:</p><p>👉 <a href="https://github.com/reza-sadrinia/galera_monitor">Source_code</a></p><h3>💬 Your Feedback Matters</h3><p>If you’re running Galera in production, I’d love to hear your thoughts and suggestions. My goal is to make <strong>galera_monitor</strong> a helpful tool for managing and monitoring Galera clusters more efficiently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mbh0jyyA_G0rsBZpE_hnIg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ad501a698e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automatic Kubernetes Certificate Renewal: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@reza.sadriniaa/automatic-kubernetes-certificate-renewal-a-step-by-step-guide-c4320192a74d?source=rss-b244d9757cae------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4320192a74d</guid>
            <category><![CDATA[kubernetes-security]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[certificate]]></category>
            <dc:creator><![CDATA[Reza Sadriniaa]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 09:52:57 GMT</pubDate>
            <atom:updated>2025-03-02T09:52:57.026Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*4JmvY1CX_wBRO2jYMwaoMQ.png" /></figure><p>🔐 <strong>The Importance of Certificates in Kubernetes and How to Manage Them</strong> 🛠️</p><p>In any Kubernetes cluster, certificates play a critical role in securing communication between control plane components and ensuring the integrity of the system. However, managing these certificates manually can be cumbersome and often forgotten, which may lead to disruptions in the cluster’s functionality when certificates expire.</p><h3>The Problem:</h3><p>When we deploy a cluster using tools like Kubespray, there’s an option to automatically renew certificates. This can be done by enabling the auto_renew_certificates variable, which will automatically renew certificates every month without any hassle.</p><p>However, problems arise when the cluster is not deployed in an automated fashion and no process is set up for renewing certificates. This is especially problematic because, by default, certificates in Kubernetes have a validity period of 365 days. After this period, if they are not renewed, the cluster may face connectivity issues due to expired certificates.</p><h3>The Solution:</h3><p>In such cases, you can set up an automatic renewal process using <strong>systemd.service</strong> and <strong>systemd.timer</strong>, along with a simple bash script. This process will ensure that the certificates are renewed automatically every month, avoiding any issues with expiration.</p><p>Here’s how you can do it:</p><h3>Steps:</h3><ol><li><strong>Create a Bash script</strong> for renewing the certificates:</li></ol><p>- Save the script as /usr/local/bin/k8s-certs-renew.sh.</p><pre>#!/bin/bash<br><br>echo &quot;## Expiration before renewal ##&quot;<br>/usr/local/bin/kubeadm certs check-expiration<br><br>echo &quot;## Renewing certificates managed by kubeadm ##&quot;<br>/usr/local/bin/kubeadm certs renew all<br><br>echo &quot;## Restarting control plane pods managed by kubeadm ##&quot;<br>/usr/local/bin/crictl pods --namespace kube-system --name &#39;kube-scheduler-*|kube-controller-manager-*|kube-apiserver-*|etcd-*&#39; -q | /usr/bin/xargs /usr/local/bin/crictl rmp -f<br><br>echo &quot;## Updating /root/.kube/config ##&quot;<br>cp /etc/kubernetes/admin.conf /root/.kube/config<br><br>echo &quot;## Waiting for apiserver to be up again ##&quot;<br>until printf &quot;&quot; 2&gt;&gt;/dev/null &gt;&gt;/dev/tcp/127.0.0.1/6443; do sleep 1; done<br><br>echo &quot;## Expiration after renewal ##&quot;<br>/usr/local/bin/kubeadm certs check-expiration</pre><p>2. <strong>Create a systemd service</strong> to call the script:</p><p>- Save the service as /etc/systemd/system/k8s-certs-renew.service.</p><pre>[Unit]<br>Description=Renew K8S control plane certificates<br><br>[Service]<br>Type=oneshot<br>ExecStart=/usr/local/bin/k8s-certs-renew.sh</pre><p>3. <strong>Create a systemd timer</strong> to trigger the service at regular intervals:</p><p>- Save the timer as cat /etc/systemd/system/k8s-certs-renew.timer.</p><pre>[Unit]<br>Description=Timer to renew K8S control plane certificates<br><br>[Timer]<br>OnCalendar=Fri *-*-1,2,3,4,5,6,7 03:10:00<br>RandomizedDelaySec=30min<br>Persistent=yes<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>4. <strong>Execute the following commands</strong> to complete the process:</p><pre>systemctl daemon-reload<br><br>systemctl restart k8s-certs-renew.timer</pre><h3>Important Note:</h3><ul><li>This process should be set up on <strong>all master nodes</strong> in the cluster to ensure certificates are renewed across the entire system.</li></ul><p>By automating the certificate renewal process, you can ensure your Kubernetes cluster remains secure without manual intervention.</p><p>#Kubernetes #Certificates #Automation #DevOps #K8s #SSL #ClusterManagement #Renewal</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4320192a74d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>