<?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 César Sepúlveda on Medium]]></title>
        <description><![CDATA[Stories by César Sepúlveda on Medium]]></description>
        <link>https://medium.com/@csepulvedab?source=rss-ea1607118f04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f_RD8B2D75QpqolujRyU7A.jpeg</url>
            <title>Stories by César Sepúlveda on Medium</title>
            <link>https://medium.com/@csepulvedab?source=rss-ea1607118f04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:01:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@csepulvedab/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[I Built a Kubernetes Operator That Programs My Cisco Router]]></title>
            <link>https://medium.com/@csepulvedab/i-built-a-kubernetes-operator-that-programs-my-cisco-router-c7f3a984115f?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7f3a984115f</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[cisco]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubebuilder]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Wed, 25 Feb 2026 16:53:22 GMT</pubDate>
            <atom:updated>2026-02-25T16:53:22.369Z</atom:updated>
            <content:encoded><![CDATA[<p>I wrote a Kubernetes operator in Go that talks to a Cisco 4331 router via RESTCONF. It creates VLANs, DHCP pools, and ACLs on the router, all triggered by `kubectl apply`. Pods get their IPs directly from the router’s DHCP server, and inter-VLAN traffic is controlled by real ACLs running on real hardware. This is the full walkthrough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h0j30Q2HXm-2axld1TcZYw.png" /><figcaption>Infra — mini pc cluster and cisco gear</figcaption></figure><h3>1. Why?</h3><p>Kubernetes networking is, by default, flat. Every pod can reach every other pod. That’s fine for many workloads, but in plenty of scenarios you actually want segmentation. You want the database on a different network than the web servers. You want firewall rules between them.</p><h4>There are better tools for this</h4><p>I want to be honest from the start: if you need network segmentation in Kubernetes today, <strong>use Cilium or Calico</strong>. They provide NetworkPolicy enforcement, eBPF based segmentation, encryption, observability. They work in software, they scale, and thousands of companies run them in production. That’s the right answer for most people.</p><p>If you’re deep in the Cisco world, <strong>ACI with Nexus switches</strong> is the official enterprise play. It integrates natively with Kubernetes, gives you policy-driven microsegmentation, multi-tenant networking, full visibility. But it requires Nexus 9000 hardware and APIC controllers, and that’s a serious investment.</p><h4>So why did I do this?</h4><p>I had a Cisco 4331 router and a Catalyst switch on my desk. Not data center gear. Just mid-range networking equipment, the kind of thing you can pick up on eBay for a couple hundred bucks. The 4331 runs IOS-XE 16.12 and has <strong>RESTCONF</strong> enabled: a REST API for managing the router configuration over HTTPS.</p><p>I wanted to see if I could wire that into Kubernetes. Not through some vendor plugin, but through a custom operator that I wrote from scratch. The idea was simple: define VLANs and policies as Kubernetes CRDs, and let the operator program the router to make them real.</p><p>A pod says “I belong to VLAN 10.” The operator creates the subinterface on the router, sets up DHCP, writes the ACLs, and the pod gets an IP from the router. No CLI sessions. No separate workflow. Just YAML.</p><p>This was never about competing with Cilium or replacing ACI. It was about proving that the operator pattern can extend Kubernetes to control physical network infrastructure, even with equipment that wasn’t designed for this.</p><h3>2. Physical Architecture</h3><p>This runs on real hardware. No simulations, no GNS3, no virtual routers.</p><h4>The Lab</h4><pre>| Component  | Model                     | IP             | Role                              |<br>| - - - - - -| - - - - - - - - - - - - - | - - - - - - - -| - - - - - - - - - - - - - - - - - |<br>| **Router** | Cisco 4331 (IOS-XE 16.12) | 192.168.200.1  | Gateway, DHCP, ACLs, RESTCONF API |<br>| **Switch** | Cisco Catalyst            | 192.168.200.2  | L2 switching, VLAN trunks         |<br>| **Node 1** | Mini PC (8 vCPU, 32 GB)   | 192.168.200.11 | K3s server + worker               |<br>| **Node 2** | Mini PC (8 vCPU, 24 GB)   | 192.168.200.12 | K3s server + worker               |<br>| **Node 3** | Mini PC (4 vCPU, 16 GB)   | 192.168.200.13 | K3s server + worker               |</pre><h4>Network Topology</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*R69_yWvWXkf1fmHPOWbYMw.png" /></figure><h4>Two NICs per Node</h4><p>Each node has two network interfaces. This is key to the whole design.</p><p>- <strong>NIC1 (`enp1s0`)</strong>: Management. Goes to an access port on the switch, VLAN 1, network `192.168.200.0/24`. Carries all the K3s traffic: API server, etcd, Flannel overlay.<br>- <strong>NIC2 (`enp2s0`)</strong>: Trunk. Goes to a trunk port on the switch that allows VLANs 10, 20, 30. This is the VLAN data plane. Pods attach to this interface via macvlan.</p><h4>Switch Ports</h4><p>- Ports connected to NIC2 on each node: <strong>trunk mode</strong>, allowing tagged traffic for VLANs 10, 20, 30<br>- Ports connected to NIC1 on each node: <strong>access mode</strong>, VLAN 1 (management)<br>- Uplink to router Gi0/0/0: <strong>trunk mode</strong> (802.1Q), carrying all VLANs</p><h4>Router on a Stick</h4><p>The router’s `GigabitEthernet0/0/0` is a trunk. It has subinterfaces for each VLAN (`.10`, `.20`, `.30`), each one with its own IP, DHCP pool, and ACL. All inter-VLAN traffic goes through the router, where ACLs decide what passes and what gets dropped.</p><h4>Two Networks per Pod</h4><p>Every pod ends up with two interfaces:</p><pre>Pod<br>├── eth0: 10.42.x.x (Flannel overlay: K8s API, DNS, Services)<br>└── net1: 172.16.x.x (VLAN via macvlan: app data traffic)</pre><p>Kubernetes internal stuff (API, DNS, service discovery) goes over Flannel. Application traffic between VLANs goes through the physical network, through the router, through real ACLs.</p><h3>3. Step by Step</h3><p>Starting from a completely clean cluster. No operator installed, no VLANs, no demo apps. Everything from scratch.</p><h4>3.1 Install the Operator</h4><pre>helm install cisco-restconf-operator ./charts/cisco-restconf-operator \<br> - set image.tag=v0.8.1 \<br> - set router.username=admin \<br> - set router.password=&#39;1234&#39;</pre><pre>NAME: cisco-restconf-operator<br>LAST DEPLOYED: Tue Feb 24 15:08:32 2026<br>NAMESPACE: default<br>STATUS: deployed</pre><p>One command. That’s it. Here’s what it created:</p><p><strong>Three CRDs</strong> registered in the Kubernetes API:</p><pre>$ kubectl get crd | grep cisco<br>ciscorouterconfigs.cisco.io 2026–02–24T18:08:32Z<br>ciscovlans.cisco.io 2026–02–24T18:08:32Z<br>vlanpolicies.cisco.io 2026–02–24T18:08:32Z</pre><p><strong>The operator pod plus</strong> a <strong>DaemonSet</strong> running on all three nodes (handles VLAN sub-interfaces and the DHCP CNI daemon):</p><pre>$ kubectl get pods -n cisco-operator-system<br>NAME READY STATUS<br>cisco-restconf-operator-controller-manager-74bdd6c5c-x48f2 1/1 Running<br>cisco-restconf-operator-vlan-setup-6qgdw 2/2 Running<br>cisco-restconf-operator-vlan-setup-7dj8f 2/2 Running<br>cisco-restconf-operator-vlan-setup-gldg4 2/2 Running</pre><p><strong>Two secrets</strong>: one with the router credentials, one with TLS certs for the mutating webhook:</p><pre>$ kubectl get secret -n cisco-operator-system | grep -E &quot;router|webhook&quot;<br>cisco-restconf-operator-webhook-tls kubernetes.io/tls 2<br>cisco-router-credentials Opaque 2</pre><p>And here’s the interesting part. The Helm chart also creates a <strong>CiscoRouterConfig </strong>object, and the operator immediately connects to the router via RESTCONF:</p><pre>$ kubectl get ciscorouterconfigs -o wide<br>NAME HOST CONNECTED MESSAGE AGE<br>default 192.168.200.1 true Connected to LAB-ROUTER (IOS-XE 16.12) 26s</pre><p>Look at the status:</p><pre>status:<br> connected: true<br> hostname: LAB-ROUTER<br> lastConnected: &quot;2026–02–24T18:08:35Z&quot;<br> message: Connected to LAB-ROUTER (IOS-XE 16.12)<br> version: &quot;16.12&quot;</pre><p>The operator is alive, talking to the router, and reporting back its hostname and firmware version. It will re-validate the connection every 5 minutes.</p><h4>3.2 Create VLANs</h4><p>Three VLANs for the demo:</p><pre># 00-vlans.yaml<br>apiVersion: cisco.io/v1alpha1<br>kind: CiscoVLAN<br>metadata:<br> name: vlan-10<br>spec:<br> vlanId: 10<br> cidr: &quot;172.16.10.0/24&quot;<br> gateway: &quot;172.16.10.1&quot;<br> dhcpRange:<br> start: &quot;172.16.10.100&quot;<br> end: &quot;172.16.10.200&quot;<br> - -<br>apiVersion: cisco.io/v1alpha1<br>kind: CiscoVLAN<br>metadata:<br> name: vlan-20<br>spec:<br> vlanId: 20<br> cidr: &quot;172.16.20.0/24&quot;<br> gateway: &quot;172.16.20.1&quot;<br> dhcpRange:<br> start: &quot;172.16.20.100&quot;<br> end: &quot;172.16.20.200&quot;<br> - -<br>apiVersion: cisco.io/v1alpha1<br>kind: CiscoVLAN<br>metadata:<br> name: vlan-30<br>spec:<br> vlanId: 30<br> cidr: &quot;172.16.30.0/24&quot;<br> gateway: &quot;172.16.30.1&quot;<br> dhcpRange:<br> start: &quot;172.16.30.100&quot;<br> end: &quot;172.16.30.200&quot;</pre><pre>$ kubectl apply -f 00-vlans.yaml<br>ciscovlan.cisco.io/vlan-10 created<br>ciscovlan.cisco.io/vlan-20 created<br>ciscovlan.cisco.io/vlan-30 created</pre><p>A few seconds later, all three are Active:</p><pre>$ kubectl get ciscovlans -o wide<br>NAME VLAN-ID CIDR GATEWAY STATE PODS AGE<br>vlan-10 10 172.16.10.0/24 172.16.10.1 Active 18s<br>vlan-20 20 172.16.20.0/24 172.16.20.1 Active 18s<br>vlan-30 30 172.16.30.0/24 172.16.30.1 Active 18s</pre><p>The status on each VLAN tells you exactly what got created on the router:</p><pre>status:<br> state: Active<br> routerSubinterface: GigabitEthernet0/0/0.10<br> message: VLAN 10 configured on GigabitEthernet0/0/0.10<br> lastReconciled: &quot;2026–02–24T18:09:13Z&quot;</pre><p>So what actually happened on the router? I queried it via RESTCONF to confirm.</p><p><strong>Subinterfaces created</strong>, each one with its own IP and `ip nat inside`:</p><pre>GigabitEthernet0/0/0 (trunk, no IP)<br>GigabitEthernet0/0/0.10 172.16.10.1/24<br>GigabitEthernet0/0/0.20 172.16.20.1/24<br>GigabitEthernet0/0/0.30 172.16.30.1/24</pre><p><strong>DHCP pools</strong>, one per VLAN:</p><pre>{ &quot;id&quot;: &quot;VLAN10_POOL&quot;, &quot;network&quot;: &quot;172.16.10.0/24&quot;, &quot;default-router&quot;: &quot;172.16.10.1&quot; }<br>{ &quot;id&quot;: &quot;VLAN20_POOL&quot;, &quot;network&quot;: &quot;172.16.20.0/24&quot;, &quot;default-router&quot;: &quot;172.16.20.1&quot; }<br>{ &quot;id&quot;: &quot;VLAN30_POOL&quot;, &quot;network&quot;: &quot;172.16.30.0/24&quot;, &quot;default-router&quot;: &quot;172.16.30.1&quot; }</pre><p><strong>Base ACLs.</strong> This is important. By default, each VLAN can talk to itself and to the internet, but is <strong>blocked</strong> from reaching any other VLAN:</p><pre>VLAN10_ACL:<br> 10 permit ip 172.16.10.0 0.0.0.255 -&gt; 172.16.10.0 0.0.0.255 (intra-VLAN ok)<br> 20 deny ip 172.16.10.0 0.0.0.255 -&gt; 172.16.20.0 0.0.0.255 (block VLAN 20)<br> 30 deny ip 172.16.10.0 0.0.0.255 -&gt; 172.16.30.0 0.0.0.255 (block VLAN 30)<br>1000 permit ip any -&gt; any (internet ok)<br>VLAN20_ACL:<br> 10 permit ip 172.16.20.0 0.0.0.255 -&gt; 172.16.20.0 0.0.0.255<br> 20 deny ip 172.16.20.0 0.0.0.255 -&gt; 172.16.10.0 0.0.0.255<br> 30 deny ip 172.16.20.0 0.0.0.255 -&gt; 172.16.30.0 0.0.0.255<br>1000 permit ip any -&gt; any<br>VLAN30_ACL:<br> 10 permit ip 172.16.30.0 0.0.0.255 -&gt; 172.16.30.0 0.0.0.255<br> 20 deny ip 172.16.30.0 0.0.0.255 -&gt; 172.16.10.0 0.0.0.255<br> 30 deny ip 172.16.30.0 0.0.0.255 -&gt; 172.16.20.0 0.0.0.255<br>1000 permit ip any -&gt; any</pre><p>One `kubectl apply`. The router now has subinterfaces, DHCP pools, and ACLs for three VLANs. I didn’t type a single command on the router CLI.</p><h4>### 3.3 Deploy Applications (Before Policy)</h4><p>The demo uses three pods:</p><p>- <strong>postgres </strong>on VLAN 20: a PostgreSQL database<br>- <strong>hello-world</strong> on VLAN 10: a Flask app that tries to connect to PostgreSQL<br>- <strong>no-hello-world</strong> on VLAN 30: the exact same Flask app, but on a different VLAN</p><pre># 04-apps.yaml (simplified)<br>apiVersion: v1<br>kind: Pod<br>metadata:<br> name: hello-world<br> namespace: demo<br> annotations:<br> cisco.io/vlan: vlan-10 # ← This is all you need<br>spec:<br> containers:<br> - name: hello-world<br> image: 192.168.100.254:5000/hello-world:v1<br> env:<br> - name: DB_HOST<br> value: &quot;postgres-vlan.demo.svc.cluster.local&quot;</pre><p>The pod only has `cisco.io/vlan: vlan-10`. A <strong>mutating webhook</strong> intercepts pod creation and injects the Multus network annotation automatically. The app uses DNS (`postgres-vlan.demo.svc.cluster.local`) to find the database. The operator creates a headless Service that resolves to the database’s DHCP-assigned VLAN IP.</p><pre>$ kubectl apply -f 04-apps.yaml<br>namespace/demo created<br>pod/postgres created<br>pod/hello-world created<br>pod/no-hello-world created</pre><pre>$ kubectl get pods -n demo -o wide<br>NAME READY STATUS IP NODE<br>hello-world 1/1 Running 10.42.1.97 node-2<br>no-hello-world 1/1 Running 10.42.1.98 node-2<br>postgres 1/1 Running 10.42.0.93 node-1</pre><p>The VLAN CRDs now show one active pod each:</p><pre>$ kubectl get ciscovlans -o wide<br>NAME VLAN-ID CIDR GATEWAY STATE PODS<br>vlan-10 10 172.16.10.0/24 172.16.10.1 Active 1<br>vlan-20 20 172.16.20.0/24 172.16.20.1 Active 1<br>vlan-30 30 172.16.30.0/24 172.16.30.1 Active 1</pre><p>I port-forwarded both Flask apps to my laptop:</p><pre>kubectl port-forward pod/hello-world -n demo 8080:8080 &amp;<br>kubectl port-forward pod/no-hello-world -n demo 8081:8080 &amp;</pre><p>Open `<a href="http://localhost:8080`">http://localhost:8080`</a> and `<a href="http://localhost:8081`">http://localhost:8081`</a>. Both apps have a dashboard that auto-refreshes every second, showing whether the database is reachable.</p><p><strong>Both show DB UNREACHABLE</strong>. Red badge on both.</p><pre>// hello-world (VLAN 10) at http://localhost:8080/api/status<br>{<br> &quot;db_reachable&quot;: false,<br> &quot;db_error&quot;: &quot;connection failed: No route to host&quot;,<br> &quot;net1_ip&quot;: &quot;172.16.10.2&quot;,<br> &quot;pod&quot;: &quot;hello-world&quot;<br>}<br>// no-hello-world (VLAN 30) at http://localhost:8081/api/status<br>{<br> &quot;db_reachable&quot;: false,<br> &quot;db_error&quot;: &quot;connection failed: No route to host&quot;,<br> &quot;net1_ip&quot;: &quot;172.16.30.2&quot;,<br> &quot;pod&quot;: &quot;no-hello-world&quot;<br>}</pre><p>That’s the base ACL doing its job. VLANs 10 and 30 both have `deny` rules blocking traffic to VLAN 20 where PostgreSQL lives. The segmentation is real, enforced on the router hardware, not in software.</p><h4>3.4 Apply a VLANPolicy</h4><p>Now let’s selectively open access. We want hello-world (VLAN 10) to reach PostgreSQL (VLAN 20) on TCP 5432, but keep no-hello-world (VLAN 30) blocked.</p><pre># 01-policy.yaml<br>apiVersion: cisco.io/v1alpha1<br>kind: VLANPolicy<br>metadata:<br> name: app-to-db<br>spec:<br> source: vlan-10<br> destination: vlan-20<br> rules:<br> - protocol: tcp<br> ports: [5432]</pre><pre>$ kubectl apply -f 01-policy.yaml<br>vlanpolicy.cisco.io/app-to-db created</pre><pre>$ kubectl get vlanpolicies -o wide<br>NAME SOURCE DESTINATION STATE ACL-ENTRIES AGE<br>app-to-db vlan-10 vlan-20 Applied 10 9s</pre><p>The operator updated both ACLs on the router:</p><pre>status:<br> state: Applied<br> aclEntries: 10<br> message: &quot;ACL rules applied: VLAN10_ACL (5 entries), VLAN20_ACL (5 entries)&quot;</pre><p>Here’s what the ACLs look like now on the router. The operator inserted `permit` rules <strong>before</strong> the existing `deny` rules:</p><pre>VLAN10_ACL (after policy):<br> 10 permit tcp 172.16.10.0 -&gt; 172.16.20.0 eq 5432 &lt;&lt; NEW: allow TCP 5432<br> 20 permit ip 172.16.10.0 -&gt; 172.16.10.0 (intra-VLAN)<br> 30 deny ip 172.16.10.0 -&gt; 172.16.20.0 (block everything else to VLAN 20)<br> 40 deny ip 172.16.10.0 -&gt; 172.16.30.0 (block VLAN 30)<br>1000 permit ip any -&gt; any (internet)<br>VLAN20_ACL (after policy):<br> 10 permit tcp 172.16.20.0 -&gt; 172.16.10.0 established &lt;&lt; NEW: return traffic only<br> 20 permit ip 172.16.20.0 -&gt; 172.16.20.0<br> 30 deny ip 172.16.20.0 -&gt; 172.16.10.0<br> 40 deny ip 172.16.20.0 -&gt; 172.16.30.0<br>1000 permit ip any -&gt; any</pre><p>Two things to notice:</p><p>1. <strong>VLAN10_ACL </strong>now has a `permit tcp … eq 5432` at sequence 10, before the deny. VLAN 10 can initiate TCP connections to VLAN 20 on the PostgreSQL port.<br>2. <strong>VLAN20_ACL</strong> has an `established` rule. This allows return traffic from connections that VLAN 10 started, but VLAN 20 cannot initiate new connections to VLAN 10.</p><p><strong>VLAN30_ACL didn’t change at all.</strong> No policy mentions VLAN 30, so it stays fully blocked.</p><h4>3.5 The Result</h4><p>Back to the browsers. The dashboards refresh every second.</p><p><strong>hello-world (VLAN 10) at `</strong><a href="http://localhost:8080`**"><strong>http://localhost:8080`</strong></a></p><pre>{<br> &quot;db_reachable&quot;: true,<br> &quot;db_host&quot;: &quot;postgres-vlan.demo.svc.cluster.local&quot;,<br> &quot;latency_ms&quot;: 7.2,<br> &quot;net1_ip&quot;: &quot;172.16.10.2&quot;,<br> &quot;pod&quot;: &quot;hello-world&quot;<br>}</pre><p>Green badge. <strong>**DB REACHABLE**</strong>, 7.2ms. It can also write and read data:</p><pre>// GET http://localhost:8080/db<br>{<br> &quot;status&quot;: &quot;SUCCESS&quot;,<br> &quot;inserted&quot;: {<br> &quot;id&quot;: 1,<br> &quot;created_at&quot;: &quot;2026–02–24T18:14:04.158103&quot;<br> },<br> &quot;recent_messages&quot;: [<br> {<br> &quot;content&quot;: &quot;Hello from 172.16.10.2 at 18:14:04&quot;,<br> &quot;id&quot;: 1<br> }<br> ]<br>}</pre><p><strong>no-hello-world (VLAN 30) at `</strong><a href="http://localhost:8081`**"><strong>http://localhost:8081`</strong></a></p><pre>{<br> &quot;db_reachable&quot;: false,<br> &quot;db_error&quot;: &quot;connection failed: timeout expired&quot;,<br> &quot;net1_ip&quot;: &quot;172.16.30.2&quot;,<br> &quot;pod&quot;: &quot;no-hello-world&quot;<br>}</pre><p>Red badge. <strong>DB UNREACHABLE.</strong> Same Docker image. Same code. Same DB_HOST env var. The only difference is one line in the YAML: `cisco.io/vlan: vlan-30` instead of `vlan-10`. The router drops the traffic.</p><pre>// GET http://localhost:8081/db<br>{<br> &quot;status&quot;: &quot;ERROR&quot;,<br> &quot;error&quot;: &quot;connection failed: No route to host&quot;<br>}</pre><h3>4. What’s Next</h3><p>The full source code is on <strong>GitHub</strong>: <a href="https://github.com/csepulveda/cisco-kubernetes">https://github.com/csepulveda/cisco-kubernetes</a></p><p>Let me repeat what I said at the beginning: this is not production software. The code is tied to a specific router model (Cisco 4331), a specific IOS-XE version (16.12), and a specific physical setup. If you actually need network segmentation in Kubernetes, go with <strong>Cilium</strong> or <strong>Calico</strong>. If you’re in the Cisco ecosystem and have the budget, <strong>ACI with Nexus</strong> is what it’s designed for. Those are real, tested, supported solutions.</p><p>This project is something else. It’s a lab experiment. A proof of concept. And the thing it proves is this: <strong>Kubernetes operators can manage anything that has an API</strong>.</p><p>The operator pattern is a control loop. It watches for desired state (your CRDs) and makes actual state match. Most operators manage stuff inside the cluster: databases, message queues, certificates. But nothing says it has to stay inside. The reconciliation loop doesn’t care whether it’s creating a Pod or configuring a physical router 3 meters away.</p><p>In this case it’s a Cisco router. But it could be a firewall, a load balancer, a DNS provider, a cloud networking service, some legacy system with SOAP endpoints. If it has an API and it has state, you can write an operator for it.</p><p>That’s what I find exciting about this. I wired a mid-range Cisco 4331 (not a Nexus 9000, not an ACI fabric, just a regular router) into a Kubernetes control plane using nothing but RESTCONF and Go. No vendor SDK, no proprietary integration, no expensive hardware. Just the operator pattern doing what it does best: turning YAML into reality.</p><p><em>Built with Go, Kubebuilder, K3s, and a lot of patience debugging YANG models at 2am.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7f3a984115f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Literally “Anywhere”: Adding a Smartphone as a Node to My Cluster]]></title>
            <link>https://medium.com/@csepulvedab/kubernetes-literally-anywhere-adding-a-smartphone-as-a-node-to-my-cluster-006be8a8ed7b?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/006be8a8ed7b</guid>
            <category><![CDATA[cilium]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[homelab]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Wed, 27 Aug 2025 14:16:23 GMT</pubDate>
            <atom:updated>2025-08-27T14:25:22.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZ-jAabSCY-5XO1JmunOkw.png" /><figcaption>3 nodes cluster and a Smartphone</figcaption></figure><p>Many people have at home an old phone in a box or on a shelf. Maybe the screen is broken, the battery is weak, or it was just left behind after an update.</p><p>That was my case. I had a OnePlus 6 with a broken screen. One day I saw a promotion for screen replacement and I remembered this phone, so I bought a screen for about 15 dollars. A few weeks later it arrived. Since it was an old phone, I tried to replace the screen myself. It was a fun process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QYFEcs1Z2dNoRHnWCxNAUQ.png" /></figure><p>When the phone was working again, I wanted to give it a purpose. I checked if it was possible to use Linux on it. I found that this phone has good Linux support, so I installed <strong>postmarketOS</strong>. The steps were simple: unlock OEM and flash the phone from the <a href="https://flash.postmarketos.org/">installer page</a>. It worked.</p><p>At home I have my own Kubernetes cluster. It has 3 nodes using miniPCs and a NAS with TrueNAS. I like to test things, so I wanted to see if I could add the phone as a new node.</p><p>This part was harder. I had to rebuild the kernel with some features that are not normal for a phone: iSCSI support, VLAN support, eBPF, and some Netfilter modules. I used <strong>pmbootstrap</strong> on a Linux computer to build the kernel and image, then I flashed them with pmbootstrap and fastboot.</p><p>It could be done in an easier way, but my cluster uses <strong>Cilium</strong> instead of kube-proxy, so I wanted to keep it the same. After many tests and errors, it finally worked. The phone was running as a new node and I could run services and apps on it.</p><pre>#install:<br>git clone https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git<br>cd pmbootstrap<br>python3 -m venv venv<br>source venv/bin/activate<br>./pmbootstrap.py init<br><br>#dep check:<br>./pmbootstrap.py status<br>./pmbootstrap.py pull<br><br>#kernel config:<br>cd $(./pmbootstrap.py config work)/cache_git/pmaports<br>cd device/community/linux-postmarketos-qcom-sdm845/<br><br>cat &lt;&lt;EOF &gt; config-postmarketos-qcom-sdm845.aarch64<br># Core networking / IPSec / XFRM (para Cilium túneles, IPSec)<br>CONFIG_INET6_ESP=y<br>CONFIG_INET6_ESPINTCP=y<br>CONFIG_INET6_ESP_OFFLOAD=m<br>CONFIG_INET_ESP=y<br>CONFIG_INET_ESPINTCP=y<br>CONFIG_INET_ESP_OFFLOAD=m<br>CONFIG_NFT_XFRM=m<br>CONFIG_XFRM_ALGO=y<br>CONFIG_XFRM_INTERFACE=m<br>CONFIG_XFRM_MIGRATE=y<br>CONFIG_XFRM_STATISTICS=y<br>CONFIG_XFRM_SUB_POLICY=y<br>CONFIG_XFRM_USER=y<br><br># Netfilter / TProxy / Conntrack (para kube-proxy replacement con Cilium)<br>CONFIG_NF_CONNTRACK=m<br>CONFIG_NF_CONNTRACK_IPV4=y<br>CONFIG_NF_CONNTRACK_IPV6=y<br>CONFIG_NF_CT_NETLINK=m<br>CONFIG_NF_DEFRAG_IPV4=y<br>CONFIG_NF_DEFRAG_IPV6=y<br>CONFIG_NF_TPROXY_IPV4=m<br>CONFIG_NF_TPROXY_IPV6=m<br>CONFIG_NETFILTER_XTABLES=y<br>CONFIG_NETFILTER_XT_MATCH_BPF=m<br>CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m<br>CONFIG_NETFILTER_XT_MATCH_POLICY=m<br>CONFIG_NETFILTER_XT_MATCH_SOCKET=m<br>CONFIG_NETFILTER_XT_TARGET_CT=m<br>CONFIG_NETFILTER_XT_TARGET_NOTRACK=m<br>CONFIG_NETFILTER_XT_TARGET_TPROXY=m<br><br># Traffic control / BPF<br>CONFIG_NET_CLS_BPF=m<br><br># Device Mapper + Multipath<br>CONFIG_BLK_DEV_DM=y<br>CONFIG_DM_MULTIPATH=y<br>CONFIG_DM_MULTIPATH_IOA=y<br>CONFIG_DM_MULTIPATH_QL=y<br>CONFIG_DM_MULTIPATH_ST=y<br><br># SCSI Device Handlers<br>CONFIG_SCSI_DH=y<br>CONFIG_SCSI_DH_ALUA=y<br>CONFIG_SCSI_DH_EMC=y<br>CONFIG_SCSI_DH_RDAC=y<br><br># SCSI core + iSCSI client<br>CONFIG_BLK_DEV_SD=y<br>CONFIG_CHR_DEV_SG=y<br>CONFIG_ISCSI_BOOT_SYSFS=y<br>CONFIG_ISCSI_TCP=y<br>CONFIG_LIBISCSI=y<br>CONFIG_SCSI=y<br>CONFIG_SCSI_ISCSI_ATTRS=y<br>CONFIG_SCSI_NETLINK=y<br>CONFIG_SCSI_TRANSPORT_ISCSI=y<br>EOF<br><br>## Compile and image generation<br>cd ~/pmbootstrap<br>./pmbootstrap.py checksum linux-postmarketos-qcom-sdm845<br>./pmbootstrap.py build linux-postmarketos-qcom-sdm845 --force<br>./pmbootstrap.py install<br><br>## Install fastboot and unlock device<br>sudo apt install fastboot<br>fastboot devices<br>fastboot oem unlock<br><br>## flash the phone:<br>./pmbootstrap.py flasher flash_rootfs<br>./pmbootstrap.py flasher flash_kernel<br>./pmbootstrap.py chroot fastboot reboot<br><br></pre><p>I still need to understand better how the battery works. Sometimes it changes very fast between charging and discharging. Other times it stays full without moving.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9328vmMlSJBqdLoN84DtA.png" /><figcaption>Battery and Charger Stats.</figcaption></figure><p>This is how the stats look in Grafana, and here are some examples of workloads running on the phone node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hsE261Fu-jiavRgh" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/0*EHEuaWCoApTdiugh" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/0*MwpiPAzCvy_mUUot" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSkbb_IMj-fNU9I7t69bUw.png" /></figure><p>Is this the strangest Kubernetes node you have seen? For me it is a fun project and now I can say that Kubernetes can run anywhere.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=006be8a8ed7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing Ephemeral EKS Clusters from a Local k3s Setup Using KRO, ACK, and ArgoCD]]></title>
            <link>https://medium.com/@csepulvedab/managing-ephemeral-eks-clusters-from-a-local-k3s-setup-using-kro-ack-and-argocd-93f4807009ba?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/93f4807009ba</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[rok]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Fri, 11 Jul 2025 14:39:10 GMT</pubDate>
            <atom:updated>2025-07-11T14:39:10.714Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1FppG5NZetpHUXifo0SBsw.png" /></figure><h3>Intro</h3><p>Running workloads on AWS EKS is powerful, but for developers who need short-lived clusters for testing, validation, or experimentation, it often feels like overkill. Not only does EKS require upfront planning, but leaving it running comes with an ongoing cost, not ideal when you’re just trying to test a controller, validate a Helm chart, or debug an integration.</p><p>I run a bare-metal k3s cluster at home. It’s fast, lightweight, and gives me everything I need for day-to-day development. But occasionally, I need to run something in a real AWS environment; like testing IAM roles, VPC behavior, or features that only exist in EKS. That’s when I realized: <em>what if I could declaratively spin up an EKS cluster from my local k3s, connect it to ArgoCD, and have it automatically deployed and managed as part of my GitOps workflows?</em></p><p>That’s exactly what this project achieves.</p><h3>From Local to Cloud, Seamlessly</h3><p>The core idea is simple: manage AWS EKS clusters as if they were just another resource in your local Kubernetes environment. The magic comes from combining a few powerful tools:</p><ul><li><strong>KRO</strong>, which lets you define a dependency graph of AWS resources like EKS clusters, node groups, and add-ons, all through CRDs.</li><li><strong>ACK</strong>, the AWS Controllers for Kubernetes, which make it possible to manage cloud infrastructure directly from Kubernetes.</li><li><strong>ArgoCD</strong>, which keeps everything in sync and allows new clusters to be instantly available for application deployment.</li></ul><p>All of this runs inside my local k3s cluster. From here, I can create an EKS cluster on AWS, provision all the necessary infrastructure, and register it with ArgoCD automatically; without leaving my terminal.</p><h3>Why I Built This</h3><p>Most of the time, I don’t want an EKS cluster running permanently. I want to spin one up, test something, and then tear it down to avoid costs. AWS gives us the APIs to do this, but wiring everything together manually is time-consuming. With this setup, I get full lifecycle automation: the EKS cluster, VPC, subnets, roles, addons, ArgoCD integration, and even sample applications like NGINX are all handled automatically.</p><p>It’s perfect for use cases like:</p><ul><li>Testing Kubernetes operators in a real cloud environment</li><li>Validating IAM permissions across EKS and other services</li><li>Simulating multi-cluster workflows with ArgoCD</li><li>Testing several Operators in a controlled and isolated environment.</li></ul><p>The fact that it all starts from a local definition and ends with a fully managed cluster; connected and ready to deploy, is what makes it so powerful.</p><h3>What the Flow Looks Like</h3><p>You write a YAML manifest describing your desired EKS cluster: its name, CIDR blocks, version, and admin role. Once applied, KRO builds out the full dependency graph. ACK handles the actual provisioning of each AWS resource. And when the EKS cluster is ready, ArgoCD automatically detects it and starts deploying any configured apps.</p><p>For example, when testing ESO, I just create a new resource graph called eso-eks.yaml. Within minutes, I have a fully working EKS cluster with everything ready for my test cases. Once I’m done, I delete the resource graph and the entire infrastructure is destroyed.</p><p>No manual cleanup. No surprise billing. Just cloud infrastructure on demand.</p><h3>Final Thoughts</h3><p>If you’re someone who frequently jumps between local and cloud-native development, or if you just want more control over when and how you use AWS resources, this approach can save you time and money. You don’t need to keep EKS running 24/7. With KRO and ACK in your local k3s, the cloud becomes just another target in your Kubernetes universe; one that you can bring up and down as easily as any other deployment.</p><p>Let me know if you try it; I’m curious how others might extend or adapt it to their own use cases.</p><p>You can find all the code and step-by-step instructions in my GitHub repository: <a href="https://github.com/csepulveda/kro-eks-manager">github.com/csepulveda/kro-eks-manager</a></p><p><strong>P.S.</strong> You might be wondering:why not use Terraform or CDK? The reason is simple: I’ve used both extensively, and while they’re powerful, I see a lot of potential in KRO. It feels like the right time to explore it and contribute early, especially as it matures into a first-class option for all kind of resources on Kubernetes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93f4807009ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Zero to EKS and Hybrid-Nodes —Part 3: Setting up the NLB, Ingress, and Services on a Hybrid…]]></title>
            <link>https://medium.com/@csepulvedab/from-zero-to-eks-and-hybrid-nodes-part-3-setting-up-the-nlb-ingress-and-services-on-a-hybrid-d43e534ae8cd?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/d43e534ae8cd</guid>
            <category><![CDATA[hybrid-cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 03:18:19 GMT</pubDate>
            <atom:updated>2025-04-21T03:52:54.161Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Zero to EKS and Hybrid-Nodes —Part 3: Setting up the NLB, Ingress, and Services on a Hybrid EKS Infrastructure</h3><h3>Introduction:</h3><p>In the <a href="https://medium.com/@csepulvedab/from-zero-to-eks-and-hybrid-nodes-part-1-the-vpc-and-vpn-configuration-af31c69b0d1f">previous part</a>, we set up the EKS cluster and deployed the first hybrid nodes. At that point, the network topology looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Bs7D2Qgx0Hr16vQl.png" /></figure><p>Now, in this third part, we’re going to set up the <strong>Network Load Balancer (NLB)</strong>, configure <strong>Ingress</strong>, and deploy services to expose our application running on this hybrid infrastructure. We’ll also observe and analyze the behavior of a Kubernetes Deployment in this mixed node environment.</p><h3>Network Topology Changes:</h3><p>To enable communication between pods running on AWS-managed nodes and those on hybrid nodes, we need to configure <strong>specific routing rules on our VPN gateway/router</strong>.</p><p>In a production environment, you could enable <strong>BGP in Cilium</strong> (if your network supports it), but since this is a lab setup, we’ll handle routing manually via static routes on the gateway.</p><h3>Disabling kube-proxy on Hybrid Nodes:</h3><p>Since we’re replacing kube-proxy functionality with Cilium, we’ll prevent kube-proxy from running on hybrid nodes using the following patch:</p><pre>kubectl patch daemonset kube-proxy \<br>  -n kube-system \<br>  --type=&#39;json&#39; \<br>  -p=&#39;[<br>    {<br>      &quot;op&quot;: &quot;add&quot;,<br>      &quot;path&quot;: &quot;/spec/template/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/0/matchExpressions/2/values/-&quot;,<br>      &quot;value&quot;: &quot;hybrid&quot;<br>    }<br>  ]&#39;</pre><h3>Get EKS API Server Endpoint:</h3><p>This will be needed in the next step:</p><pre>aws eks describe-cluster --name my-eks-cluster --query &quot;cluster.endpoint&quot;</pre><h3>Updating the Cilium Configuration:</h3><p>Next, we’ll update our cilium-values.yaml file to:</p><ol><li>Enable kubeProxyReplacement.</li><li>Enable Layer 2 (L2) announcements.</li><li>Define the /25 subnets to be used for pod IPs.</li><li>Set the Kubernetes API server endpoint and port.</li></ol><pre>affinity:<br>  nodeAffinity:<br>    requiredDuringSchedulingIgnoredDuringExecution:<br>      nodeSelectorTerms:<br>      - matchExpressions:<br>        - key: eks.amazonaws.com/compute-type<br>          operator: In<br>          values:<br>          - hybrid<br>ipam:<br>  mode: cluster-pool<br>  operator:<br>    clusterPoolIPv4MaskSize: 25<br>    clusterPoolIPv4PodCIDRList:<br>    - 192.168.101.0/25<br>    - 192.168.101.128/25<br>operator:<br>  replicas: 1<br>  affinity:<br>    nodeAffinity:<br>      requiredDuringSchedulingIgnoredDuringExecution:<br>        nodeSelectorTerms:<br>        - matchExpressions:<br>          - key: eks.amazonaws.com/compute-type<br>            operator: In<br>            values:<br>              - hybrid<br>  unmanagedPodWatcher:<br>    restart: false<br>envoy:<br>  enabled: false<br>kubeProxyReplacement: true<br>l2announcements:<br>  leaseDuration: 2s<br>  leaseRenewDeadline: 1s<br>  leaseRetryPeriod: 200ms<br>  enabled: true<br>externalIPs:<br>  enabled: true<br><br>k8sClientRateLimit:<br>  qps: 100<br>  burst: 150<br><br>k8sServiceHost: &lt;CLUSTER_HOST&gt;<br>k8sServicePort: 443</pre><p>Apply the changes:</p><pre>cd commands/02-cilium-updates<br>helm upgrade -i cilium cilium/cilium -n kube-system -f cilium-values.yaml</pre><h3>Verifying Cilium Agents:</h3><p>You should now see cilium-agent pods running on the hybrid nodes, and no kube-proxy pods there:</p><pre>kubectl -n kube-system get pods -o wide<br>NAME                               READY   STATUS    RESTARTS   AGE   IP                NODE                         NOMINATED NODE   READINESS GATES<br>aws-node-k8qw5                     2/2     Running   0          31m   10.0.21.61        ip-10-0-21-61.ec2.internal   &lt;none&gt;           &lt;none&gt;<br>cilium-lxphl                       1/1     Running   0          48s   192.168.100.102   mi-00a55e151790a4c81         &lt;none&gt;           &lt;none&gt;<br>cilium-operator-7658767979-f57v5   1/1     Running   0          52s   192.168.100.101   mi-014887c08038cb6c2         &lt;none&gt;           &lt;none&gt;<br>cilium-znwdm                       1/1     Running   0          49s   192.168.100.101   mi-014887c08038cb6c2         &lt;none&gt;           &lt;none&gt;<br>coredns-6b9575c64c-fxzv9           1/1     Running   0          35m   10.0.25.252       ip-10-0-21-61.ec2.internal   &lt;none&gt;           &lt;none&gt;<br>eks-pod-identity-agent-k559t       1/1     Running   0          31m   10.0.21.61        ip-10-0-21-61.ec2.internal   &lt;none&gt;           &lt;none&gt;<br>kube-proxy-6j74v                   1/1     Running   0          15m   10.0.21.61        ip-10-0-21-61.ec2.internal   &lt;none&gt;           &lt;none&gt;</pre><h3>Static Routing:</h3><p>Now it’s time to configure static routes on the VPN router. First, check which hybrid node is responsible for each /25 subnet:</p><pre>kubectl get ciliumnodes<br>NAME                   CILIUMINTERNALIP   INTERNALIP        AGE<br>mi-00a55e151790a4c81   192.168.101.51     192.168.100.102   8m14s<br>mi-014887c08038cb6c2   192.168.101.192    192.168.100.101   8m14s</pre><p>Set the routes:</p><pre>ip route add 192.168.101.0/25 via 192.168.100.102<br>ip route add 192.168.101.128/25 via 192.168.100.101</pre><p>Now out network will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WmEeefZZBk8dd57Mj-vTw.png" /></figure><h3>Installing the Load Balancer Controller:</h3><p>Add the following Terraform file to your project to install the AWS Load Balancer Controller via Helm, and create the required IAM role:</p><pre>resource &quot;helm_release&quot; &quot;aws-load-balancer-controller&quot; {<br>  name       = &quot;aws-load-balancer-controller&quot;<br>  chart      = &quot;aws-load-balancer-controller&quot;<br>  repository = &quot;https://aws.github.io/eks-charts&quot;<br>  namespace  = &quot;kube-system&quot;<br>  version    = &quot;1.12.0&quot;<br><br>  set {<br>    name  = &quot;serviceAccount.create&quot;<br>    value = &quot;true&quot;<br>  }<br>  set {<br>    name  = &quot;serviceAccount.name&quot;<br>    value = module.eks_loadbalancer_iam.iam_role_name<br>  }<br>  set {<br>    name  = &quot;serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn&quot;<br>    value = module.eks_loadbalancer_iam.iam_role_arn<br>  }<br>  set {<br>    name  = &quot;clusterName&quot;<br>    value = module.eks.cluster_name<br>  }<br>  set {<br>    name  = &quot;replicaCount&quot;<br>    value = &quot;1&quot;<br>  }<br>  set {<br>    name  = &quot;vpcId&quot;<br>    value = data.terraform_remote_state.vpc.outputs.vpc_id<br>  }<br><br>  # Optional affinity rule<br>  set {<br>    name  = &quot;affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key&quot;<br>    value = &quot;eks.amazonaws.com/capacityType&quot;<br>  }<br>  set {<br>    name  = &quot;affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator&quot;<br>    value = &quot;Exists&quot;<br>  }<br>}<br><br>module &quot;eks_loadbalancer_iam&quot; {<br>  source  = &quot;terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks&quot;<br>  version = &quot;5.54.0&quot;<br><br>  role_name                              = &quot;load-balancer-controller&quot;<br>  attach_load_balancer_controller_policy = true<br><br>  oidc_providers = {<br>    ex = {<br>      provider_arn               = module.eks.oidc_provider_arn<br>      namespace_service_accounts = [&quot;kube-system:load-balancer-controller&quot;]<br>    }<br>  }<br>}</pre><p>Deploy it:</p><pre>cd ../../EKS-HYBRID<br>cp ../load-balancer/load-balancer.tf .<br>tofu init<br>tofu apply</pre><p>Verify the changes:</p><pre>kubectl get deployment/aws-load-balancer-controller -n kube-system<br>NAME                           READY   UP-TO-DATE   AVAILABLE   AGE<br>aws-load-balancer-controller   1/1     1            1           5m</pre><h3>Deploying the Demo App:</h3><p>Now let’s deploy a simple app with 6 replicas to observe pod distribution across AWS and hybrid nodes.</p><pre>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: whoami<br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: whoami<br>  namespace: whoami<br>spec:<br>  replicas: 6<br>  selector:<br>    matchLabels:<br>      app: whoami<br>  template:<br>    metadata:<br>      labels:<br>        app: whoami<br>    spec:<br>      topologySpreadConstraints:<br>        - maxSkew: 1<br>          topologyKey: kubernetes.io/hostname<br>          whenUnsatisfiable: ScheduleAnyway<br>          labelSelector:<br>            matchLabels:<br>              app: whoami<br>      containers:<br>        - image: containous/whoami<br>          imagePullPolicy: Always<br>          name: whoami<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: whoami<br>  namespace: whoami<br>  annotations:<br>    service.beta.kubernetes.io/aws-load-balancer-type: &quot;external&quot;<br>spec:<br>  type: ClusterIP<br>  ports:<br>    - name: http<br>      port: 80<br>      targetPort: 80<br>  selector:<br>    app: whoami<br>---<br>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: whoami<br>  namespace: whoami<br>  annotations:<br>    alb.ingress.kubernetes.io/scheme: internet-facing<br>    alb.ingress.kubernetes.io/listen-ports: &#39;[{&quot;HTTP&quot;: 80}]&#39;<br>    alb.ingress.kubernetes.io/target-type: ip<br>    alb.ingress.kubernetes.io/load-balancer-type: nlb<br>spec:<br>  ingressClassName: alb<br>  rules:<br>    - http:<br>        paths:<br>          - path: /<br>            pathType: Prefix<br>            backend:<br>              service:<br>                name: whoami<br>                port:<br>                  number: 80</pre><p>Apply it:</p><pre>cd ../commands/03-create-service<br>kubectl apply -f service.yaml</pre><p>Check pod distribution:</p><pre>kubectl get pods -n whoami -o wide<br>NAME                     READY   STATUS    RESTARTS   AGE    IP                NODE                         NOMINATED NODE   READINESS GATES<br>whoami-7cb8f48c8-bhrvw   1/1     Running   0          2m6s   192.168.101.187   mi-014887c08038cb6c2         &lt;none&gt;           &lt;none&gt;<br>whoami-7cb8f48c8-gd48g   1/1     Running   0          6s     10.0.21.186       ip-10-0-21-61.ec2.internal   &lt;none&gt;           &lt;none&gt;<br>whoami-7cb8f48c8-hhs49   1/1     Running   0          2m9s   192.168.101.212   mi-014887c08038cb6c2         &lt;none&gt;           &lt;none&gt;<br>whoami-7cb8f48c8-n64gh   1/1     Running   0          2m9s   192.168.101.108   mi-00a55e151790a4c81         &lt;none&gt;           &lt;none&gt;<br>whoami-7cb8f48c8-q8bhj   1/1     Running   0          2m9s   192.168.101.56    mi-00a55e151790a4c81         &lt;none&gt;           &lt;none&gt;<br>whoami-7cb8f48c8-rr7kp   1/1     Running   0          9s     10.0.27.231       ip-10-0-21-61.ec2.internal   &lt;none&gt;           &lt;none&gt;</pre><h3>Test Round-Robin Behavior:</h3><p>Get the Ingress address:</p><pre> kubectl get ingress  -n whoami <br>NAME     CLASS   HOSTS   ADDRESS                                                               PORTS   AGE<br>whoami   alb     *       k8s-whoami-whoami-xxxx-yyyy.us-east-1.elb.amazonaws.com   80      36s</pre><p>Then run:</p><pre>for i in $(seq 1 10); <br>  do curl -s http://&lt;your-lb-dns&gt;/api | jq .ip <br>; done<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;192.168.101.212&quot;,<br>  &quot;fe80::b405:92ff:fe92:72f4&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;192.168.101.212&quot;,<br>  &quot;fe80::b405:92ff:fe92:72f4&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;10.0.21.186&quot;,<br>  &quot;fe80::6c8f:6aff:fe38:5e55&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;10.0.27.231&quot;,<br>  &quot;fe80::a8a6:26ff:feed:d649&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;192.168.101.108&quot;,<br>  &quot;fe80::28bc:50ff:fe48:d3d9&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;192.168.101.56&quot;,<br>  &quot;fe80::7869:ccff:fee5:b61b&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;192.168.101.187&quot;,<br>  &quot;fe80::14f6:88ff:fe17:f9ae&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;192.168.101.212&quot;,<br>  &quot;fe80::b405:92ff:fe92:72f4&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;10.0.21.186&quot;,<br>  &quot;fe80::6c8f:6aff:fe38:5e55&quot;<br>]<br>[<br>  &quot;127.0.0.1&quot;,<br>  &quot;::1&quot;,<br>  &quot;10.0.27.231&quot;,<br>  &quot;fe80::a8a6:26ff:feed:d649&quot;<br>]</pre><p>You should see requests being served by both AWS and hybrid nodes.</p><h3>Pricing Overview:</h3><p>Hybrid nodes <strong>do not incur EC2 costs</strong>, but you’ll still pay:</p><ul><li>EKS control plane fees</li><li>Data transfer</li><li><strong>Hybrid node usage based on vCPU-hours</strong></li></ul><p>Example:</p><blockquote><em>A 32 vCPU hybrid node = 32 × 24 × 30 = 23,040 vCPU-hours/month<br>At $0.02 per vCPU-hour, that’s </em><strong><em>~$460.80/month<br></em></strong><em>The cheapest AWS instance with 32 vCPU and GPU (e.g. g5g.xlarge) costs ~$987/month — nearly </em><strong><em>2x more expensive</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5wBKfknogDQAP-CRqZONpg.png" /></figure><h3>Conclusion:</h3><p>As you can see, it’s entirely possible to run a hybrid EKS environment combining AWS-managed and on-prem nodes. While this is not a common setup, it’s a powerful tool for organizations with existing infrastructure or specific compliance requirements.</p><p>This lab setup uses static routing, eks_managed_node_groups, and minimal redundancy. In a production scenario, you’d likely adopt:</p><ul><li><strong>VPC CNI custom networking</strong></li><li><strong>Karpenter </strong>for dynamic scaling</li><li><strong>BGP routing</strong> for flexibility</li><li><strong>A real VPN appliance</strong></li></ul><p>But as a proof of concept, it offers a strong foundation and a practical look into what’s required to implement EKS hybrid clusters successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwZf1mTw2PPRY_Ge2IF7dA.png" /></figure><p>All the files used by this lab could be found here: <a href="https://github.com/csepulveda/modular-aws-resources">https://github.com/csepulveda/modular-aws-resources</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d43e534ae8cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tools I Use Daily as a DevOps Engineer]]></title>
            <link>https://medium.com/@csepulvedab/tools-i-use-daily-as-a-devops-engineer-0e18e3f36b32?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e18e3f36b32</guid>
            <category><![CDATA[ek]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Fri, 11 Apr 2025 17:14:26 GMT</pubDate>
            <atom:updated>2025-04-11T17:14:26.749Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a post I plan to update frequently. Here’s the initial list of top tools I use in my day-to-day work — whether I’m managing Kubernetes clusters, working with AWS, or just trying to stay efficient.</p><h3>🔧 1. K9s</h3><p><a href="https://k9scli.io/">K9s</a> is a must-have for Kubernetes administrators. It’s lightweight, fast, and lets you:</p><ul><li>Check and explore Kubernetes resources</li><li>Create port-forwardings</li><li>Modify, delete, or view logs from pods</li><li>And much more</li></ul><p><strong>Install</strong>: brew install k9s</p><p><strong>Demo</strong>: <a href="https://www.youtube.com/watch?v=AMUQzyPvO04">YouTube – K9s in Action</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Q7TEsaRhsGYEurQF.png" /></figure><h3>🧭 2. kubectx &amp; kubens</h3><p><a href="https://github.com/ahmetb/kubectx">kubectx</a> and kubens are simple tools to manage multiple Kubernetes contexts and namespaces efficiently.</p><p><strong>Install</strong>: brew install kubectx</p><p><strong>Docs</strong>: <a href="https://github.com/ahmetb/kubectx">GitHub – kubectx</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*2A56UMKaEkw1BOA8.png" /></figure><h3>💣 3. aws-nuke</h3><p><a href="https://github.com/ekristen/aws-nuke">aws-nuke</a> helps you clean up AWS environments easily after testing or PoCs. Just define which IAM resources to keep — and nuke everything else.</p><p><strong>Install</strong>: brew install aws-nuke</p><p><strong>Docs</strong>: <a href="https://github.com/ekristen/aws-nuke">GitHub – aws-nuke</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*KmJV64UgJHJYq3KP.png" /></figure><h3>💸 4. eks-node-viewer</h3><p>A tool I use almost daily to check how many EKS nodes I’m running and estimate my spending.</p><p><strong>Install</strong>: brew tap aws/tap &amp;&amp; brew install eks-node-viewer<br><strong>Docs</strong>: <a href="https://github.com/awslabs/eks-node-viewer">GitHub – eks-node-viewer</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*l6ldXs4DaUI5f2lV.png" /></figure><p>If you found this list helpful, let me know! I’ll keep this post updated with new tools as I incorporate them into my workflow.</p><p>Stay tuned — more tools coming soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e18e3f36b32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Zero to EKS and Hybrid-Nodes — Part 2: The EKS and Hybrid Nodes configuration.]]></title>
            <link>https://medium.com/@csepulvedab/from-zero-to-eks-and-hybrid-nodes-part-2-the-eks-and-hybrid-nodes-configuration-c4490bc4092a?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4490bc4092a</guid>
            <category><![CDATA[hybrid-cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Fri, 11 Apr 2025 13:23:26 GMT</pubDate>
            <atom:updated>2025-04-21T02:45:15.432Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Zero to EKS and Hybrid-Nodes — Part 2: The EKS and Hybrid Nodes configuration.</h3><h3>Introduction:</h3><p>In the <a href="https://medium.com/@csepulvedab/from-zero-to-eks-and-hybrid-nodes-part-1-the-vpc-and-vpn-configuration-af31c69b0d1f">previous part</a>, we set up the VPC and the VPN Site-to-Site connection to prepare for our EKS cluster and hybrid nodes. The network diagram at that stage looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cofm_O-TAtWxdAhfjqjIew.png" /></figure><p>In this second part, we’ll configure the EKS cluster using <strong>OpenTofu</strong>, including <strong>SSM Activation</strong>, and manually set up two <strong>Hybrid nodes</strong> using nodeadm.</p><h3>Setup the EKS cluster</h3><p>Cluster creation is straightforward. We’ll use the state file from the VPC creation to retrieve outputs, and we’ll create the cluster using the <a href="https://github.com/terraform-aws-modules/terraform-aws-eks">terraform-aws-modules/eks/aws</a> module.</p><p>Full code is available here: <a href="https://github.com/csepulveda/modular-aws-resources/tree/main/EKS-HYBRID">https://github.com/csepulveda/modular-aws-resources/tree/main/EKS-HYBRID</a></p><pre>################################################################################<br># EKS Module<br>################################################################################<br>module &quot;eks&quot; {<br>  source  = &quot;terraform-aws-modules/eks/aws&quot;<br>  version = &quot;20.35.0&quot;<br><br>  cluster_name    = local.name<br>  cluster_version = var.eks_version<br><br>  enable_cluster_creator_admin_permissions = true<br>  cluster_endpoint_public_access           = true<br><br>  cluster_addons = {<br>    coredns = {<br>      configuration_values = jsonencode({<br>        replicaCount = 1<br>      })<br>    }<br>    eks-pod-identity-agent = {}<br>    kube-proxy             = {}<br>    vpc-cni                = {}<br>  }<br><br>  vpc_id                   = data.terraform_remote_state.vpc.outputs.vpc_id<br>  subnet_ids               = data.terraform_remote_state.vpc.outputs.private_subnets<br>  control_plane_subnet_ids = data.terraform_remote_state.vpc.outputs.control_plane_subnet_ids<br><br>  eks_managed_node_groups = {<br>    eks-base = {<br>      ami_type       = &quot;AL2023_x86_64_STANDARD&quot;<br>      instance_types = [&quot;t3.small&quot;, &quot;t3a.small&quot;]<br><br>      min_size      = 1<br>      max_size      = 1<br>      desired_size  = 1<br>      capacity_type = &quot;SPOT&quot;<br>      network_interfaces = [{<br>        delete_on_termination = true<br>      }]<br>    }<br>  }<br>  <br>  node_security_group_additional_rules = {<br>    allow-all-80-traffic-from-loadbalancers = {<br>      cidr_blocks = [for s in data.aws_subnet.elb_subnets : s.cidr_block]<br>      description = &quot;Allow all traffic from load balancers&quot;<br>      from_port   = 80<br>      to_port     = 80<br>      protocol    = &quot;TCP&quot;<br>      type        = &quot;ingress&quot;<br>    }<br>    hybrid-all = {<br>      cidr_blocks = [&quot;192.168.100.0/23&quot;]<br>      description = &quot;Allow all traffic from remote node/pod network&quot;<br>      from_port   = 0<br>      to_port     = 0<br>      protocol    = &quot;all&quot;<br>      type        = &quot;ingress&quot;<br>    }<br>  }<br><br>  cluster_security_group_additional_rules = {<br>    hybrid-all = {<br>      cidr_blocks = [&quot;192.168.100.0/23&quot;]<br>      description = &quot;Allow all traffic from remote node/pod network&quot;<br>      from_port   = 0<br>      to_port     = 0<br>      protocol    = &quot;all&quot;<br>      type        = &quot;ingress&quot;<br>    }<br>  }<br><br>  cluster_remote_network_config = {<br>    remote_node_networks = {<br>      cidrs = [&quot;192.168.100.0/24&quot;]<br>    }<br>    remote_pod_networks = {<br>      cidrs = [&quot;192.168.101.0/24&quot;]<br>    }<br>  }<br>  <br>  access_entries = {<br>    hybrid-node-role = {<br>      principal_arn = module.eks_hybrid_node_role.arn<br>      type          = &quot;HYBRID_LINUX&quot;<br>    }<br>  }<br><br><br>  node_security_group_tags = merge(local.tags, {<br>    &quot;karpenter.sh/discovery&quot; = local.name<br>  })<br><br>  tags = local.tags<br>}<br><br>################################################################################<br># Hybrid nodes Support<br>################################################################################<br>module &quot;eks_hybrid_node_role&quot; {<br>  source = &quot;terraform-aws-modules/eks/aws//modules/hybrid-node-role&quot;<br>  version = &quot;20.35.0&quot;<br><br>  name = &quot;hybrid&quot;<br><br>  tags = local.tags<br>}<br><br><br>resource &quot;aws_ssm_activation&quot; &quot;this&quot; {<br>  name               = &quot;hybrid-node&quot;<br>  iam_role           = module.eks_hybrid_node_role.name<br>  registration_limit = 10<br><br>  tags = local.tags<br>}<br><br>resource &quot;local_file&quot; &quot;nodeConfig&quot; {<br>  content  = &lt;&lt;-EOT<br>    apiVersion: node.eks.aws/v1alpha1<br>    kind: NodeConfig<br>    spec:<br>      cluster:<br>        name: ${module.eks.cluster_name}<br>        region: ${local.region}<br>      hybrid:<br>        ssm:<br>          activationId: ${aws_ssm_activation.this.id}<br>          activationCode: ${aws_ssm_activation.this.activation_code} <br>  EOT<br>  filename = &quot;nodeConfig.yaml&quot;<br>}</pre><h4><strong>Highlights of the configuration:</strong></h4><ul><li>One EKS-managed node group for core services and ACK controllers (to be installed in Part 3).</li><li>VPC CNI enabled via cluster_addons.</li><li>Ingress rules to allow traffic from on-premise networks.</li><li>Defined remote node and pod networks.</li><li>Created a role for hybrid nodes and granted access via access_entries.</li></ul><h4><strong>Hybrid Nodes and SSM Activation</strong></h4><p>We define:</p><ul><li>An IAM role using the hybrid node module.</li><li>An SSM Activation to allow hybrid nodes to join the cluster.</li><li>A nodeConfig.yaml file containing the activation credentials, automatically generated during tofu apply.</li></ul><pre>tofu apply<br>....<br>Apply complete! Resources: 50 added, 0 changed, 0 destroyed.</pre><p>This generates a nodeConfig.yaml file, which is critical for authenticating on-prem nodes via <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html">AWS Systems Manager</a>.</p><p>Update your kubeconfig after creation:</p><pre>aws eks update-kubeconfig --region us-east-1 --name my-eks-cluster</pre><p>Now your infrastructure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSbkK4IT-LJbOD__uwf1vg.png" /></figure><h3>S<strong>etting Up the Hybrid Nodes</strong></h3><p>SSH into the nodes (e.g., 192.168.100.101 and 192.168.100.102). These are configured with two networks:</p><ul><li>192.168.100.0/24 for nodes.</li><li>192.168.101.0/24 for pods.</li></ul><p>Transfer the node config:</p><pre>scp nodeConfig.yaml cesar@192.168.100.101:/tmp/<br>scp nodeConfig.yaml cesar@192.168.100.102:/tmp/</pre><p>Install and configure nodeadm:</p><pre>curl -OL &#39;https://hybrid-assets.eks.amazonaws.com/releases/latest/bin/linux/arm64/nodeadm&#39;<br>chmod a+x nodeadm<br>mv nodeadm /usr/local/bin/.<br><br>nodeadm install 1.32 --credential-provider ssm<br>nodeadm init --config-source file:///tmp/nodeConfig.yaml</pre><p>Repeat for both nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ilw-BnQTKTrU7HTNeexkw.png" /></figure><p>Once done, check node registration:</p><pre>kubectl get nodes -o wide<br>NAME                          STATUS     ROLES    AGE     VERSION               INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                       KERNEL-VERSION                    CONTAINER-RUNTIME<br>ip-10-0-19-137.ec2.internal   Ready      &lt;none&gt;   16m     v1.32.1-eks-5d632ec   10.0.19.137       &lt;none&gt;        Amazon Linux 2023.7.20250331   6.1.131-143.221.amzn2023.x86_64   containerd://1.7.27<br>mi-03c1eb4c6173151d6          NotReady   &lt;none&gt;   3m4s    v1.32.1-eks-5d632ec   192.168.100.102   &lt;none&gt;        Ubuntu 22.04.5 LTS             5.15.0-136-generic                containerd://1.7.24<br>mi-091f1dddb980a80ff          NotReady   &lt;none&gt;   3m51s   v1.32.1-eks-5d632ec   192.168.100.101   &lt;none&gt;        Ubuntu 22.04.5 LTS             5.15.0-136-generic                containerd://1.7.24</pre><p>The hybrid nodes appear but are NotReady — this is expected until we install a network controller.</p><p><strong><em>Disclaimer time</em>:</strong> Although the documentation claims compatibility with Ubuntu 22.04 and 24.04, I couldn’t get 24.04 working due to missing nf_conntrack when kube-proxy attempts to apply iptables rules. If you manage to fix this, please share!</p><h3><strong>Setting Up the Network with Cilium</strong></h3><p>We’ll use <strong>Cilium</strong> as CNI.</p><p><strong>cilium-values.yaml:</strong></p><pre>affinity:<br>  nodeAffinity:<br>    requiredDuringSchedulingIgnoredDuringExecution:<br>      nodeSelectorTerms:<br>      - matchExpressions:<br>        - key: eks.amazonaws.com/compute-type<br>          operator: In<br>          values:<br>          - hybrid<br>ipam:<br>  mode: cluster-pool<br>  operator:<br>    clusterPoolIPv4MaskSize: 24<br>    clusterPoolIPv4PodCIDRList:<br>    - 192.168.101.0/24<br>operator:<br>  affinity:<br>    nodeAffinity:<br>      requiredDuringSchedulingIgnoredDuringExecution:<br>        nodeSelectorTerms:<br>        - matchExpressions:<br>          - key: eks.amazonaws.com/compute-type<br>            operator: In<br>            values:<br>              - hybrid<br>  unmanagedPodWatcher:<br>    restart: false<br>envoy:<br>  enabled: false</pre><p>This yaml file indicate the affinity on cilium pods and also the cilium operator to run only en hybrid nodes, also we set the clusterPoolIPv4PodCIDRList pool, using the subnet 192.168.101.0/24</p><p><strong>Install Cilium:</strong></p><pre>helm repo add cilium https://helm.cilium.io/<br><br>helm upgrade -i cilium cilium/cilium \<br>--version 1.17.2 \<br>--namespace kube-system \<br>--values cilium-values.yaml<br><br>...<br>Release &quot;cilium&quot; does not exist. Installing it now.<br>NAME: cilium<br>LAST DEPLOYED: Fri Apr 11 08:35:31 2025<br>NAMESPACE: kube-system<br>STATUS: deployed<br>REVISION: 1<br>TEST SUITE: None<br>NOTES:<br>You have successfully installed Cilium with Hubble.<br><br>Your release version is 1.17.2.<br><br>For any further help, visit https://docs.cilium.io/en/v1.17/gettinghelp</pre><p>After a few minutes the nodes will be ready</p><pre>kubectl get nodes -o wide</pre><p>You shoud see:</p><pre>NAME                          STATUS   ROLES    AGE   VERSION               INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                       KERNEL-VERSION                    CONTAINER-RUNTIME<br>ip-10-0-19-137.ec2.internal   Ready    &lt;none&gt;   56m   v1.32.1-eks-5d632ec   10.0.19.137       &lt;none&gt;        Amazon Linux 2023.7.20250331   6.1.131-143.221.amzn2023.x86_64   containerd://1.7.27<br>mi-03c1eb4c6173151d6          Ready    &lt;none&gt;   42m   v1.32.1-eks-5d632ec   192.168.100.102   &lt;none&gt;        Ubuntu 22.04.5 LTS             5.15.0-136-generic                containerd://1.7.24<br>mi-091f1dddb980a80ff          Ready    &lt;none&gt;   43m   v1.32.1-eks-5d632ec   192.168.100.101   &lt;none&gt;        Ubuntu 22.04.5 LTS             5.15.0-136-generic                containerd://1.7.24</pre><p>Your hybrid nodes are now fully integrated with EKS. 🎊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hWZxHuIY04gQjcGwp_T9Xw.png" /></figure><p>Now your infrastructure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRh0oDcNTrr0XZiY_iAxaw.png" /></figure><h3><strong>What’s Next?</strong></h3><p>In the final part of this series, we’ll:</p><ul><li>Deploy the <strong>Network Load Balancer (NLB) Controller</strong>.</li><li>Set up an <strong>Ingress</strong>.</li><li>Deploy a sample <strong>service</strong> running entirely on hybrid/on-prem nodes.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4490bc4092a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Zero to EKS and Hybrid-Nodes — Part 1: The VPC and VPN configuration.]]></title>
            <link>https://medium.com/@csepulvedab/from-zero-to-eks-and-hybrid-nodes-part-1-the-vpc-and-vpn-configuration-af31c69b0d1f?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/af31c69b0d1f</guid>
            <category><![CDATA[vpn]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[hybrid-cloud]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Wed, 09 Apr 2025 12:47:06 GMT</pubDate>
            <atom:updated>2025-04-18T21:39:22.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Zero to EKS and Hybrid-Nodes — Part 1: The VPC and VPN configuration.</h3><p>In this post, I’ll walk you through how to create an Amazon EKS node running Kubernetes 1.32 and set up a Site-to-Site VPN to connect an on-prem virtual machine to your EKS cluster using Linux hybrid nodes. To complete the setup, we’ll deploy a Network Load Balancer (NLB) and an NGINX Ingress controller to manage traffic across both cloud-based and on-prem applications.</p><p>The goal is to demonstrate how we can extend our on-prem infrastructure into EKS, enabling a seamless hybrid environment. This approach is especially useful in scenarios where you want to leverage local GPU machines for LLM workloads, or manage CDN nodes running on data center hardware while orchestrating everything through Kubernetes.</p><figure><img alt="EKS infra" src="https://cdn-images-1.medium.com/max/1024/1*F-9m3iziuPDfgvQDNQuGXw.png" /><figcaption>As you could see the infra its simple, a EKS, a VPN, a Router and 2 hybrid nodes.</figcaption></figure><h3>Create VPC</h3><p>We’ll start by creating the VPC, which is quite straightforward using <strong>OpenTofu</strong> (formerly Terraform). Below is the configuration using the <a href="https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/5.19.0">terraform-aws-modules/vpc/aws</a> module:</p><p>The code is here: <a href="https://github.com/csepulveda/modular-aws-resources/tree/main/VPC">https://github.com/csepulveda/modular-aws-resources/tree/main/VPC</a></p><pre>module &quot;vpc&quot; {<br>  source  = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;5.19.0&quot;<br><br>  name = local.name #my-eks-cluster<br>  cidr = local.vpc_cidr #10.0.0.0/16<br><br>  azs             = local.azs #[&quot;us-east-1a&quot;, &quot;us-east-1b&quot;, &quot;us-east-1c&quot;]<br>  private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]<br>  public_subnets  = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]<br>  intra_subnets   = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 52)]<br><br>  enable_nat_gateway = true<br>  single_nat_gateway = true<br><br>  public_subnet_tags = {<br>    &quot;kubernetes.io/role/elb&quot; = 1<br>  }<br><br>  private_subnet_tags = {<br>    &quot;kubernetes.io/role/internal-elb&quot; = 1<br>    &quot;karpenter.sh/discovery&quot; = local.name<br>  }<br><br>  tags = local.tags<br>}</pre><p>To apply the changes, run:</p><pre>tofu apply</pre><p>Once applied, you should see an output similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eHNl1jkeKFY-vHSFIDb1cQ.png" /></figure><p>This setup creates a basic but functional VPC with three subnet types, each serving a specific purpose:</p><ol><li><strong>Private Subnets</strong>: Used for deploying nodes and pods.</li><li><strong>Public Subnets</strong>: Used for exposing services via Network Load Balancers.</li><li><strong>Intra Subnets</strong>: Dedicated to the EKS control plane.</li></ol><p>In the next steps, we’ll manually configure routing and VPN components. I’m choosing not to automate those with Terraform to better explain each concept and step in detail.</p><h3>VPN Site to Site:</h3><p>As you could see in the infra diagram, the local network CIDR is 192.168.100.0/23 and the VPC CIDR is 10.0.0.0/16 so we need to go to each subnet in our new VPC</p><h4>Create the Customer gateway.</h4><p>First we need to create the Customer gateway, this is a very simple step, we only need to define a name (<strong>Name tag<em> — optional</em></strong>) and also what is the public IP (<strong>IP address</strong>) address of our local network router (in my case the routes is in a DMZ behind a NAT)</p><p><strong>Name tag: </strong>eks-kybrid-customer-gateway<br><strong>IP Address</strong>: [Your public IPv4]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*xTwNb0n2A8hR-JpVbfJ-wg.gif" /></figure><h4>Create the Virtual private gateway</h4><p>To create the Virtual Private Gateway, you only need to assign a name tag. This component will act as the gateway between your AWS VPC and the on-premises network.</p><p><strong>Name tag: </strong>eks-kybrid-private-gateway</p><h4>Create the Site-To-Site VPN connection</h4><p>Once the Customer Gateway and Virtual Private Gateway are created, we can proceed to establish the Site-to-Site VPN connection.</p><p>In this step, we will configure the following settings:<br><strong>Name tag: </strong>eks-kybrid-vpn<br><strong>Target gateway type</strong>: Virtual Private Gateway (select the one created earlier)<br><strong>Customer gateway: </strong>Existing (select the previously created Customer Gateway)<br><strong>Routing options: </strong>Static<br><strong>Static IP prefixes:</strong> 192.168.100.0/23 (your on-prem network)<br><strong>Local IPv4 network CIDR:</strong> 192.168.100.0/23 (your on-prem network)<br><strong>Remote IPv4 network CIDR:</strong> 10.0.0.0/16 (the VPC CIDR)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ciGzUKzmPerdrirlpY4SWA.gif" /></figure><p>This configuration defines the routing paths for traffic between your on-premises network and the EKS cluster running in the cloud.</p><h4>Attach the Virtual private gateway to VPC</h4><p>In this step, we will attach the previously created private gateway to our EKS VPC. This connection allows the VPC to establish communication with the on-premises network through the Site-to-Site VPN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*E92FXWztxe9JOLnC0utqRA.gif" /></figure><h4>Setup Routes in VPC.</h4><p>To enable communication between resources in our VPC and the on-premises network, we need to update the routing tables. This configuration ensures that traffic destined for the local network is directed through the private gateway.</p><p>We will update each of the relevant route tables: <strong>private</strong>, <strong>public</strong>, and <strong>intra</strong>, by adding a route to the local CIDR block 192.168.100.0/23 with the <strong>Private Gateway</strong> as the target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*tdjv-InQZsmmgpF5Xt2xGg.gif" /></figure><h4>Configure the client.</h4><p>Now that everything is set up on the AWS side, it’s time to configure the VPN client on your local environment.</p><p>In my case, the client is a <strong>Ubuntu 24.04 virtual machine</strong> located in a <strong>DMZ</strong>, meaning any request sent to my public IP is forwarded to this machine. We’ll be using <strong>Strongswan</strong> as the VPN client to connect to AWS’s Site-to-Site VPN.</p><p><strong>Step 1: Download the VPN Configuration</strong></p><p>Go to the <strong>VPC Dashboard → Site-to-Site VPN Connections</strong>, select your VPN connection, and click <strong>Download Configuration</strong>. Choose <strong>Strongswan</strong> as the vendor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*oWnSOTkHM_1sGHWkH2IAMQ.gif" /></figure><p><strong>Step 2: Install Strongswan</strong></p><p>On your VPN client machine, install Strongswan using:</p><pre>apt update<br>apt install strongswan</pre><p><strong>Step 3: Configure the VPN Tunnels</strong></p><p>Use the provided AWS configuration as a base. Edit the file /etc/ipsec.conf with your VPN tunnel definitions, updating values where needed (e.g., IP addresses, leftupdown hook). Here’s an example configuration:</p><pre>config setup<br>        uniqueids = no<br><br>conn Tunnel1<br> auto=start<br> left=%defaultroute<br> leftid=186.10.xx.xx<br> right=34.194.25.197<br> type=tunnel<br> leftauth=psk<br> rightauth=psk<br> keyexchange=ikev1<br> ike=aes128-sha1-modp1024<br> ikelifetime=8h<br> esp=aes128-sha1-modp1024<br> lifetime=1h<br> keyingtries=%forever<br> leftsubnet=0.0.0.0/0<br> rightsubnet=0.0.0.0/0<br> dpddelay=10s<br> dpdtimeout=30s<br> dpdaction=restart<br> mark=100<br> leftupdown=&quot;/etc/ipsec.d/aws-updown.sh -ln Tunnel1 -ll 169.254.41.174/30 -lr 169.254.41.173/30 -m 100 -r 10.0.0.0/16&quot;<br><br>conn Tunnel2<br> auto=start<br> left=%defaultroute<br> leftid=186.10.xx.xx<br> right=100.27.149.167<br> type=tunnel<br> leftauth=psk<br> rightauth=psk<br> keyexchange=ikev1<br> ike=aes128-sha1-modp1024<br> ikelifetime=8h<br> esp=aes128-sha1-modp1024<br> lifetime=1h<br> keyingtries=%forever<br> leftsubnet=0.0.0.0/0<br> rightsubnet=0.0.0.0/0<br> dpddelay=10s<br> dpdtimeout=30s<br> dpdaction=restart<br> mark=200<br> leftupdown=&quot;/etc/ipsec.d/aws-updown.sh -ln Tunnel2 -ll 169.254.125.226/30 -lr 169.254.125.225/30 -m 200 -r 10.0.0.0/16&quot;</pre><p><strong>Step 4: Update the updown Script</strong></p><p>The file /etc/ipsec.d/aws-updown.sh manages the VTI interface setup for each tunnel. If your VPN client is behind a NAT (like mine), you need to manually set the src IP in the routing section.</p><p>Locate the add_route() function and modify the ip route add line to include your local machine’s internal IP (192.168.100.100 in this case):</p><pre>ip route add ${i} dev ${TUNNEL_NAME} metric ${TUNNEL_MARK}</pre><p>Here’s the complete updown script:</p><pre>#!/bin/bash<br><br>while [[ $# &gt; 1 ]]; do<br> case ${1} in<br>  -ln|--link-name)<br>   TUNNEL_NAME=&quot;${2}&quot;<br>   TUNNEL_PHY_INTERFACE=&quot;${PLUTO_INTERFACE}&quot;<br>   shift<br>   ;;<br>  -ll|--link-local)<br>   TUNNEL_LOCAL_ADDRESS=&quot;${2}&quot;<br>   TUNNEL_LOCAL_ENDPOINT=&quot;${PLUTO_ME}&quot;<br>   shift<br>   ;;<br>  -lr|--link-remote)<br>   TUNNEL_REMOTE_ADDRESS=&quot;${2}&quot;<br>   TUNNEL_REMOTE_ENDPOINT=&quot;${PLUTO_PEER}&quot;<br>   shift<br>   ;;<br>  -m|--mark)<br>   TUNNEL_MARK=&quot;${2}&quot;<br>   shift<br>   ;;<br>  -r|--static-route)<br>   TUNNEL_STATIC_ROUTE=&quot;${2}&quot;<br>   shift<br>   ;;<br>  *)<br>   echo &quot;${0}: Unknown argument \&quot;${1}\&quot;&quot; &gt;&amp;2<br>   ;;<br> esac<br> shift<br>done<br><br>command_exists() {<br> type &quot;$1&quot; &gt;&amp;2 2&gt;&amp;2<br>}<br><br>create_interface() {<br> ip link add ${TUNNEL_NAME} type vti local ${TUNNEL_LOCAL_ENDPOINT} remote ${TUNNEL_REMOTE_ENDPOINT} key ${TUNNEL_MARK}<br> ip addr add ${TUNNEL_LOCAL_ADDRESS} remote ${TUNNEL_REMOTE_ADDRESS} dev ${TUNNEL_NAME}<br> ip link set ${TUNNEL_NAME} up mtu 1419<br>}<br><br>configure_sysctl() {<br> sysctl -w net.ipv4.ip_forward=1<br> sysctl -w net.ipv4.conf.${TUNNEL_NAME}.rp_filter=2<br> sysctl -w net.ipv4.conf.${TUNNEL_NAME}.disable_policy=1<br> sysctl -w net.ipv4.conf.${TUNNEL_PHY_INTERFACE}.disable_xfrm=1<br> sysctl -w net.ipv4.conf.${TUNNEL_PHY_INTERFACE}.disable_policy=1<br>}<br><br>add_route() {<br> IFS=&#39;,&#39; read -ra route &lt;&lt;&lt; &quot;${TUNNEL_STATIC_ROUTE}&quot;<br>     for i in &quot;${route[@]}&quot;; do<br>     ip route add ${i} dev ${TUNNEL_NAME} metric ${TUNNEL_MARK} src 192.168.100.100<br> done<br> iptables -t mangle -A FORWARD -o ${TUNNEL_NAME} -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu<br> iptables -t mangle -A INPUT -p esp -s ${TUNNEL_REMOTE_ENDPOINT} -d ${TUNNEL_LOCAL_ENDPOINT} -j MARK --set-xmark ${TUNNEL_MARK}<br> ip route flush table 220<br>}<br><br>cleanup() {<br>        IFS=&#39;,&#39; read -ra route &lt;&lt;&lt; &quot;${TUNNEL_STATIC_ROUTE}&quot;<br>        for i in &quot;${route[@]}&quot;; do<br>            ip route del ${i} dev ${TUNNEL_NAME} metric ${TUNNEL_MARK}<br>        done<br> iptables -t mangle -D FORWARD -o ${TUNNEL_NAME} -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu<br> iptables -t mangle -D INPUT -p esp -s ${TUNNEL_REMOTE_ENDPOINT} -d ${TUNNEL_LOCAL_ENDPOINT} -j MARK --set-xmark ${TUNNEL_MARK}<br> ip route flush cache<br>}<br><br>delete_interface() {<br> ip link set ${TUNNEL_NAME} down<br> ip link del ${TUNNEL_NAME}<br>}<br><br># main execution starts here<br><br>command_exists ip || echo &quot;ERROR: ip command is required to execute the script, check if you are running as root, mostly to do with path, /sbin/&quot; &gt;&amp;2 2&gt;&amp;2<br>command_exists iptables || echo &quot;ERROR: iptables command is required to execute the script, check if you are running as root, mostly to do with path, /sbin/&quot; &gt;&amp;2 2&gt;&amp;2<br>command_exists sysctl || echo &quot;ERROR: sysctl command is required to execute the script, check if you are running as root, mostly to do with path, /sbin/&quot; &gt;&amp;2 2&gt;&amp;2<br><br>case &quot;${PLUTO_VERB}&quot; in<br> up-client)<br>  create_interface<br>  configure_sysctl<br>  add_route<br>  ;;<br> down-client)<br>  cleanup<br>  delete_interface<br>  ;;<br>esac</pre><p><strong>Step 5: Add Shared Secrets</strong></p><p>Open /etc/ipsec.secrets and add the shared secrets provided in the configuration file:</p><pre># This file holds shared secrets or RSA private keys for authentication.<br><br># RSA private key for this host, authenticating it to any other host<br># which knows the public part.<br><br>186.10.xx.xx 34.194.25.197 : PSK &quot;kPcU.tJ_sA33J7Z.I4f4gxxxxx&quot;<br>186.10.xx.xx 100.27.149.167 : PSK &quot;YtaQSGhvMKV4aLQx.4wxxxxxxx&quot;</pre><p><strong>Step 6: Start the VPN Service</strong></p><p>Restart the service and check the tunnel status:</p><pre>systemctl restart ipsec<br>ipsec status</pre><p>The following <em>video</em> demonstrates the complete setup step by step:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*tHCZvRlcevAZkHk-IObt-w.gif" /></figure><p>If everything is correctly configured, both tunnels should show as <strong>“up”</strong> in the <strong>AWS Console → Site-to-Site VPN Connections</strong> page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ZJLKEu4L8bVE-o39HveWQ.png" /></figure><p>At this stage, the network connectivity between the EKS cluster and the on-premises environment is fully configured:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bx3Qf_nA9rOu_mns6qSgnQ.png" /></figure><p>In <strong>Part 2</strong>, we will provision the EKS cluster using <strong>OpenTofu</strong>, set up the <strong>SSM activator</strong>, and register the on-premises nodes using <strong>nodeadm</strong> with the <strong>Cilium CNI</strong> driver.</p><p>In <strong>Part 3</strong>, we will install the <strong>AWS Load Balancer Controller</strong>, configure <strong>NGINX Ingress</strong>, and deploy our application across both <strong>EC2</strong> and <strong>hybrid (on-prem)</strong> nodes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af31c69b0d1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Trivy Vulnerability Reports with AWS Security Hub]]></title>
            <link>https://medium.com/@csepulvedab/integrating-trivy-vulnerability-reports-with-aws-security-hub-01ba5dd8bfb1?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/01ba5dd8bfb1</guid>
            <category><![CDATA[aws-security-hub]]></category>
            <category><![CDATA[kubernet]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[trivy]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Thu, 13 Mar 2025 20:53:48 GMT</pubDate>
            <atom:updated>2025-03-13T22:24:51.504Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*GGBPN8Y5A28Jn5soOMkjnw.png" /><figcaption>Integrating Trivy Vulnerability Reports with AWS Security Hub</figcaption></figure><p>At <a href="https://r2.co/">R2</a>, we rely on Trivy (<a href="https://trivy.dev/latest/">https://trivy.dev/</a>) in our EKS clusters to continuously scan container images for vulnerabilities. Although ECR provides very good built-in image scanning, we can’t depend solely on it, since many of our images originate from third-party repositories. Therefore, it’s crucial to constantly monitor these external images for potential vulnerabilities.</p><p>To achieve this, we implemented the Trivy Operator — a powerful Kubernetes tool that automatically scans new images whenever a pod is created, generating comprehensive vulnerability reports as Custom Resource Definitions (CRDs).</p><p>While these CRDs are highly useful, we needed a centralized system to track and manage security findings effectively. Integrating these reports with AWS Security Hub allows us to centralize vulnerability management, monitor our compliance with SLAs, and prioritize issues based on severity.</p><h3>Introducing the Trivy Webhook for AWS Security Hub</h3><p>To streamline this integration, we developed the <strong>Trivy-webhook-aws-security-hub</strong> (<a href="https://artifacthub.io/packages/helm/trivy-webhook-aws-security-hub/trivy-webhook-aws-security-hub">Helm Chart</a>, <a href="https://github.com/csepulveda/trivy-webhook-aws-security-hub">Source Code</a>). This webhook leverages the Trivy Operator’s notification endpoint, automatically receiving vulnerability reports and forwarding them directly into AWS Security Hub.</p><h3>Example Use Case:</h3><p>Let’s demonstrate how this works by deploying a pod with a known vulnerable image (python:3.8.19). We&#39;ll observe the webhook workflow and examine the resulting findings in AWS Security Hub.</p><p><strong>1. Pod Creation:</strong></p><p>Deploy the pod using the vulnerable image:</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: python-vulnerable-image<br>spec:<br>  containers:<br>  - name: python<br>    image: python:3.8.19</pre><p><strong>2. Trivy Operator Report (CRD):</strong></p><p>Upon pod creation, the Trivy Operator automatically scans the image and generates a vulnerability report as a CRD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eJRk9AXt7vWMAEMm0hLJ-w.png" /><figcaption>Vulnerability Report on Kubernetes</figcaption></figure><p><strong>3. Webhook Log:</strong></p><p>The Trivy webhook receives the CRD and sends it directly to AWS Security Hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q4WD2Q7fW4qRRqozVXarRA.png" /><figcaption>Trivy webhook log</figcaption></figure><p><strong>4. AWS Security Hub Findings:</strong></p><p>The vulnerability details now appear in AWS Security Hub, categorized by severity and clearly presented for efficient management and remediation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JjPqK7BIw17EFjE8mzt4xA.png" /><figcaption>AWS Security Hub</figcaption></figure><h3>Benefits:</h3><ul><li>Centralized tracking and management of vulnerabilities.</li><li>Immediate visibility into new vulnerabilities (CVEs).</li><li>Streamlined compliance management.</li></ul><p>We encourage everyone to utilize this webhook, provide feedback, report issues, and submit pull requests to enhance its capabilities. All installation and configuration details are available on our <a href="https://artifacthub.io/packages/helm/trivy-webhook-aws-security-hub/trivy-webhook-aws-security-hub">Artifact Hub page</a>.</p><p>Happy scanning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01ba5dd8bfb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Troubleshoot OOM Issues in Go Applications Running on Kubernetes]]></title>
            <link>https://medium.com/@csepulvedab/how-to-troubleshoot-oom-issues-in-go-applications-running-on-kubernetes-149e8bb104ac?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/149e8bb104ac</guid>
            <category><![CDATA[sidecar]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[oom]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Mon, 11 Nov 2024 04:26:22 GMT</pubDate>
            <atom:updated>2024-11-11T04:38:48.815Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes provides valuable mechanisms to prevent nodes from being affected when certain pods consume excessive CPU or memory resources, thanks to cgroups. However, memory limits can pose unique challenges. Unlike CPU limits, which can throttle usage over time, memory cannot be gradually restricted. When a container reaches its memory limit, it receives a SIGKILL signal, causing the container to restart.</p><p>In my current role, we addressed this by implementing a solution for all our Go applications using the pprof library. By enabling a listening port with pprof, we can retrieve memory heap data from any running process via the /debug/pprof/heap endpoint, which returns a memory heap dump.</p><p>We also developed a separate application that continuously monitors memory usage. This application queries the Kubernetes metrics server to check if any container is using more than 80% of its configured memory limit. If this threshold is exceeded, it connects to the pod’s IP on a pre-configured port, retrieves the heap memory data, and stores it in S3 for further analysis using the go tool pprof.</p><p>This approach works well for applications with gradual memory leaks, where memory accumulation occurs slowly over time. In such cases, the monitoring service can detect high memory usage and generate a heap dump before the application receives a SIGKILL due to an OOM event.</p><p>However, we often encounter cases where memory leaks are more aggressive, with containers jumping from 50 MB to over 1 GB in just a few seconds.</p><p>To handle these cases, we implemented a different approach using a library developed by <a href="https://github.com/ricardomaraschini/oomhero">Ricardo Maraschini</a>. This library allows a sidecar container to monitor process metrics in real-time, querying statistics every second instead of the 30-second intervals we had with the metrics server.</p><p>We built on this with our custom solution at <a href="https://github.com/csepulveda/oom-heap-dumper,">https://github.com/csepulveda/oom-heap-dumper,</a> which enhances <a href="https://github.com/ricardomaraschini/oomhero">Maraschini’s oomhero</a> library by adding functionality to check the app’s listening ports, download the heap from each port, and store it in S3.</p><p>Compared to the previous approach, this method introduces some security considerations and may not be suitable for every pod in the system. For this solution to work, we need to enable shareProcessNamespace and set the oom-heap-dumper container privileges with securityContext.privileged: true.</p><p>This updated approach allows us to capture a heap memory dump and send it to S3 for later analysis, even when memory spikes occur rapidly.</p><h3><strong>Practical Example</strong></h3><p>Consider the following code, which forces a memory leak by doubling memory usage with each iteration:</p><p><a href="https://github.com/csepulveda/go-memory-leak/tree/v0.0.3">GitHub - csepulveda/go-memory-leak at v0.0.3</a></p><p>When running this application in a container on our Kubernetes cluster, we observe the following results:</p><p><strong>Deployment Configuration:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f7c7266ea83bcbd4a81e4d98f4df2bc/href">https://medium.com/media/3f7c7266ea83bcbd4a81e4d98f4df2bc/href</a></iframe><p><strong>Memory Stats:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q1evP37F4v3TgoBe" /></figure><p><strong>App Logs and OOM events:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*96w7hC9yxSQC7bIp" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ATVxTZL4_ZC-3wBt" /></figure><p>As shown, monitoring the metric server directly and attempting to take a memory dump when usage exceeds 80% is challenging. With each cycle doubling memory usage, we go from 50% to nearly 100% in one jump. These rapid changes make it difficult for the metric server to capture and respond to fluctuations in real-time.</p><p>To address this, our first step is to add pprof middleware to our application.</p><h3>Using the Sidecar to auto generate the Heap File.</h3><p><strong>Code Comparison:</strong></p><p>https://github.com/csepulveda/go-memory-leak/compare/v0.0.3…v0.0.4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pHYkkRWTHHAVT1u2QKijEA.png" /></figure><p>This enables us to retrieve the application’s memory heap, allowing us to analyze it locally. For example, if the app is running on port 8080, we can launch the pprof web interface on port 8081 to analyze the heap file:</p><pre>go tool pprof -http=:8081 localhost:8080/debug/pprof/heap</pre><p>Through this analysis, we can see the memory leak originates within the main function, specifically when calling serializeJSON.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SmGsrbGk-hDVoDkn" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZT9r_rcd-LCvinck" /></figure><p>For this example, replicating the memory leak behavior is straightforward. However, in cases where memory leaks occur sporadically, capturing a memory dump at the exact moment of high memory usage is essential. This is where our sidecar solution becomes invaluable.</p><p><strong>Deployment Configuration to Add the Sidecar:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3a51fb145f99be0ef26c9d53421acce/href">https://medium.com/media/f3a51fb145f99be0ef26c9d53421acce/href</a></iframe><p>In this YAML, the keys and bucket name are masked for security, but it’s possible to pass credentials directly as environment variables or use a service account that grants write permissions to the bucket where memory heaps will be stored. For more on setting permissions, check out my post on configuring IAM roles with service accounts: <a href="https://medium.com/@csepulvedab/three-approaches-to-defining-iam-roles-in-kubernetes-on-eks-a3094201333f">https://medium.com/@csepulvedab/three-approaches-to-defining-iam-roles-in-kubernetes-on-eks-a3094201333f</a></p><p>When the app is running, you’ll see logs from our oom-dumper once it reaches the 70% memory threshold set as the maximum memory usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vTgShqos_G0jvaqj" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WqSynzQ9gR8hVUFu" /></figure><p><strong>Retrieving and Visualizing the Heap</strong></p><p>Download the heap from S3 and view it locally:</p><pre>aws s3 cp s3://xxxx/go-memory-leak-54d6d47d7-6hl64-7-8080-2024-11-11-03-49.heap .<br>download: s3://xxxx/go-memory-leak-54d6d47d7-6hl64-7-8080-2024-11-11-03-49.heap to ./go-memory-leak-54d6d47d7-6hl64-7-8080-2024-11-11-03-49.heap<br><br>go tool pprof -http=:8081 go-memory-leak-54d6d47d7-6hl64-7-8080-2024-11-11-03-49.heap</pre><p>Review the memory heap from the web interface provided by go tool pprof.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aXXSBGaoMqnVgkw-" /></figure><h3><strong>Conclusion</strong></h3><p>Using go tool pprof, we can manually capture memory heaps during OOM events. Setting up the pprof wrapper for on-demand heaps is relatively straightforward. However, capturing a heap at a specific high-memory usage moment can be challenging. For these cases, monitoring tools that automatically generate/store heaps can be invaluable, making the csepulveda/oom-heap-dumper sidecar an effective tool for managing memory dumps in high-demand situations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=149e8bb104ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three approaches to defining IAM roles in Kubernetes on EKS]]></title>
            <link>https://medium.com/@csepulvedab/three-approaches-to-defining-iam-roles-in-kubernetes-on-eks-a3094201333f?source=rss-ea1607118f04------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3094201333f</guid>
            <category><![CDATA[iam-roles]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[César Sepúlveda]]></dc:creator>
            <pubDate>Thu, 26 Sep 2024 11:11:53 GMT</pubDate>
            <atom:updated>2024-09-26T11:11:53.508Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*n_QfkDm-LEd3xP0A" /></figure><p>While using Kubernetes on AWS (Elastic Kubernetes Service), it’s essential to ensure that your applications have the correct permissions in AWS through IAM roles. Properly configuring these roles not only improves security but also helps streamline the development workflow, especially when you have applications that are frequently deployed.</p><p>I’m going to share with you three common ways to define IAM roles for Kubernetes applications within an EKS cluster.</p><p>Mention that the cluster was configured<a href="https://medium.com/@nicosingh/build-an-eks-cluster-with-terraform-d35db8005963"> Nico’s following post</a> about his EKS configuration module with Terraform.</p><p>For the three examples, we’ll use a sample application that uploads and lists files from an S3 bucket: <a href="https://www.linkedin.com/redir/redirect?url=https%3A%2F%2Fgithub%2Ecom%2Fcsepulveda%2Fsample-s3-uploader&amp;urlhash=KpVG&amp;trk=article-ssr-frontend-pulse_little-text-block">https://github.com/csepulveda/sample-s3-uploader</a> .</p><p>The terraform files added could be found in this fork: <a href="https://gitlab.com/csepulvedab/medium-deploy-eks-cluster-using-terraform">https://gitlab.com/csepulvedab/medium-deploy-eks-cluster-using-terraform</a></p><p><em>Spoiler</em> : There’s no one-size-fits-all solution! It will depend on how you manage your infrastructure and applications. 😉</p><h4>Create the IAM role from the Terraform repo that manages the entire cluster</h4><p>This is a fairly common option: having a single infrastructure repository that manages the EKS cluster, the IAM roles needed by the applications and the applications resources. The advantage here is centralization: you control everything from one place.</p><p><strong>Advantages:</strong></p><ul><li>Everything is centralized, making it easier to track changes and ensure that everything is well-coordinated.</li><li>You control the application’s permissions from a single repository, avoiding scattered roles.</li></ul><p><strong>Disadvantages</strong>:</p><ul><li>In fast-paced development environments, any change to an IAM role might mean updating the infrastructure repo. This can create dependencies on the DevOps team, slowing down developers.</li></ul><p>This approach is ideal if you’re looking for complete control over the infrastructure, but it might not be the best option if your development environment is constantly changing.</p><p><strong>Configuration example:</strong></p><figure><img alt="Example Terraform file added to the main repo" src="https://cdn-images-1.medium.com/max/955/0*scJhr1YzMWinPTRk" /><figcaption>Example Terraform file added to the main repo</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eGz6XREZnR8FU3Ij" /><figcaption>Values yaml configuration to deploy the app</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/0*fEBYhNNtO-xRudVp" /><figcaption>Example of the application working with the iam role.</figcaption></figure><h4>Create the IAM Role from a separate repo</h4><p>Another option is to maintain a separate Terraform repository for each application (or set of applications). In this repository, you define all the infrastructure related to the application, including the IAM role it needs to run on EKS. The pipeline for this repository would typically only require approval from the DevSecOps team, without the need for them to control the repository or apply changes directly.</p><p><strong>Advantages:</strong></p><ul><li>Greater flexibility and agility for development teams. Developers can manage their own permissions without relying so much on DevOps.</li></ul><p><strong>Disadvantages</strong>:</p><ul><li>The infrastructure is spread across multiple repositories, making it harder to have a global view of everything.</li><li>Maintaining and managing multiple Terraform repositories can become more complicated if there are many applications.</li></ul><p>This approach provides teams with significant independence, but it’s crucial to ensure proper coordination with the infrastructure team.</p><p>In this case, the Terraform file is very similar to the original. The main difference is that, being separate from the main infrastructure, it includes the creation of the IAM role and the retrieval of the EKS cluster data through data.</p><p><strong>Configuration example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yXRh8HZZfy8yOEFY" /><figcaption>app-repo/main.tf</figcaption></figure><p>As you can see, there are some small ‘complications’ when moving the application’s configuration completely outside of the main infrastructure repository. This is because there are certain pieces of data we need to recreate in a ‘creative’ way, such as the <em>provider_arn</em>, since we no longer have direct reference to <em>module.base.oidc_provider_arn</em>, as in the previous example.</p><p>In this case, the configuration of the application’s YAML file would remain the same, since the IAM role name doesn’t change.</p><h4>Create the IAM Role Using a Kubernetes Operator</h4><p>Finally, you can use a Kubernetes operator to manage IAM roles directly from the deployment files. This allows developers to define the permissions they need within their application’s configuration files.</p><p><strong>Advantages:</strong></p><ul><li>Developers have maximum flexibility to define permissions directly in the manifests, allowing for quick deployment in dynamic environments.</li><li>Less dependency on the infrastructure team, as permissions are managed in the same repo as the application.</li></ul><p><strong>Disadvantages:</strong></p><ul><li>Care must be taken with security, as developers might assign too many permissions without proper control.</li><li>Installing additional operators introduces some operational complexity.</li></ul><p>This approach is excellent if your applications are constantly changing and you need flexibility to quickly deploy and test. But, of course, watch out for security!</p><p><strong>Configuration example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/0*qIy0cZDkxJ7GeGiD" /><figcaption>We added the following content to the eks.tf file.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/0*GXItvnZVRV_e89eZ" /><figcaption>IAM Controller installation</figcaption></figure><p>With these changes applied, we can now add a new resource in our app using the API <em>iam.services.k8s.aws/v1alpha1</em> with the kind Role and the following content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/0*XjUJMtWKyAzDhRO5" /></figure><p>This type of resource will be utilized by the IAM role controller, which will handle the creation of the IAM role for us.</p><h3>Conclusion</h3><p>Each of these approaches has its pros and cons. In fast-paced development environments where applications are continuously deployed, defining IAM roles through a Kubernetes operator can offer the most flexibility. However, if security is your priority, centralizing role management in an infrastructure repository may give you more control.</p><p>In the end, it’s all about finding the perfect balance between security and agility, ensuring that development teams have the necessary control without compromising the security of the environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3094201333f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>