Architecting for Resilience: Crafting Opinionated EKS Clusters with Karpenter & Cilium Cluster Mesh — Part 1
Published: 2023-10-31 23:45:05

Welcome to the future of digital ecosystems, where robustness meets unparalleled innovation! We’re about to dive into a world where Amazon’s Elastic Kubernetes Service (EKS) isn’t just a service; it’s an unbreakable, scalable fortress! 🚀

Wondering how? We’re mixing it up with Karpenter to provide a faster and better scaling that enables a new set of possibilities, also using Cilium Cluster Mesh to connect our clusters and build for resiliency.

Cilium is our networking superhero, ensuring our clusters talk to each other smoothly, while Karpenter keeps an eye on the scale and provides us with the perfect cost efficiency.

In this thrill ride, we’re not just exploring tech but crafting resilient warriors ready to combat digital challenges! 🛡️ So buckle up as we whisk you away to a land where each EKS cluster is an unassailable castle in the cloud, and every service is a valiant knight guarding the gates!

Let’s make our EKS clusters fun, resilient, and ready to roll! 🎢

Here are a few reference links about the previous services and tools:
[**What is Amazon EKS?**](https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html)
[**Cluster Mesh**](https://cilium.io/use-cases/cluster-mesh/)
[**Karpenter**](https://karpenter.sh/)

## Setting the Stage: Crafting the VPC Setup 🏗️

Before we jump into the exciting realms of Cilium Cluster Mesh and EKS Karpenter, let’s roll up our sleeves and start with the foundation — creating a Virtual Private Cloud (VPC). Imagine this VPC as the land where we will build our unassailable EKS castles. And remember, every robust castle starts with a solid foundation!
{% gist https://gist.github.com/abebars/3c4c2439a5ecdc67f3108d6c86ddd3af.js %}
## Navigating the Sea of IPs: Creating a Secondary CIDR 🌐

Our shiny new VPC is like a blank canvas, ready to host our future EKS clusters. But here’s the rub — IPs are like gold in the cloud world, and running out of them is a real bummer! IP exhaustion can stall our journey and leave our services stranded. But worry not! We’ve got a savvy solution — introducing a secondary CIDR block. This is like having a backup stash of gold, ensuring our pods never run out of valuable IPs!
{% gist https://gist.github.com/abebars/f8481720043fdc10caa84e5c5ef01632.js %}
When we’re sculpting our subnets, we’ll tag them with usage: Pods. Why, you ask? Because this little beacon of labeling will be our guiding light when we venture into installing Cilium! 🌟

## The Landing Ground is Ready: VPC Setup Complete! 🌐

By wielding the powers of Terraform, we’ve crafted a formidable VPC, ripe and ready to host our unassailable EKS clusters. It’s not just any VPC; it’s a fortified domain strategically tagged and enriched with a secondary CIDR to ensure our pods have ample room to thrive. If you check your AWS console, you should see the created VPC like the following:

![](https://cdn-images-1.medium.com/max/6616/1*PSHeylsEFn-WumTKKAqyhA.png)

## Embarking on EKS: Initiating the Cluster Setup 🚀

Having laid the solid groundwork with our fortified VPC, we are now ready to step into the world of EKS and bring our clusters to life! The journey of setting up our EKS Cluster will be a confluence of meticulous configurations, innovative integrations, and strategic optimizations. Let’s kickstart this expedition!
{% gist https://gist.github.com/abebars/7121b3c5e92fc4c97c30d54828b1710a.js %}
In the previous file, there are two things to keep in mind. First, we are applying specific taints to our nodes, so these nodes will only become ready for deployment once we have Cilium Installed; these taints will be removed automatically once Cilium Pod is working on the node.

            key    = "node.cilium.io/agent-not-ready"
            value  = "true"
            effect = "NO_SCHEDULE"

Second, We will only rely on one managed node group, but we will leverage Karpenter; however, karpenter needs to be deployed on a node. (This may change soon once the Karpenter is available on the EKS Control Plane.)
[**[EKS] Karpenter inside control plane · Issue #1792 · aws/containers-roadmap**](https://github.com/aws/containers-roadmap/issues/1792)

Navigating back to the console, We should see the cluster being ready and deployments like (coredns, aws-node,kube-proxy) are deployed.

![](https://cdn-images-1.medium.com/max/5552/1*9jfzc8WjCdmf0UZNT3_4tw.png)

## Networking Nirvana: Installing Cilium on the EKS Cluster 🕸️

With the EKS Cluster firmly established and the initial Node Group ready to roll, it’s time to invite Cilium to the party! Cilium is our networking and security superhero, ensuring seamless communication between pods and enhancing our cluster’s security posture.

We will leverage the EKS Blueprint addon modules to install the Cilium helm chart with the required values. We will not deploy Cilium in a Changing mode but install it in Overlay Mode and Kube Proxy Free. Hence, we need to complete two steps ahead because EKS clusters are shipped by default with AWS VPC CNI and Kube Proxy installed, so we need to remove these. daemon sets first.
{% gist https://gist.github.com/abebars/fda3a59d5d3c879afa12904ab39e96b5.js %}
We can apply the helm chart with the necessary cilium configuration in the same step.

In this step, We will create a custom CNI Config and instrument cilium to use the Pods Subnets we made earlier; then, we pass this ConfigMap to cilium helm chart values.
{% gist https://gist.github.com/abebars/e10770a6d058be74669f5bac736096d7.js %}
### Balancing Terraform and Helm: A Synchronized Approach 🧩

I know there’s an undercurrent of preference for installing Helm through Terraform. Indeed, managing the state with Terraform offers elegance and control. However, installing and customizing charts and maintaining them centrally resonate more harmoniously when performed directly. This approach not only provides a consolidated management platform but also retains the flexibility of customization and scaling.

### Elevating with GitOps: A Gateway to Continuous Operations 🔄

And there’s more! For those inclined towards a GitOps approach, this module serves as a conduit, supporting GitOps methodologies and ensuring continuous and consistent operational flows. It’s a paradigm where declarative configurations meet version control, opening avenues for automatic and reliable application deployment and management.
{% gist https://gist.github.com/abebars/cd7186da219a82aca8cd3d3d916e2e10.js %}
After the chart is installed, we should have all pods up and running and the cluster is configured with Cilium as expected; you can see the following.

![](https://cdn-images-1.medium.com/max/3936/1*2ELjfEGQAMKkJAH_v6WxHA.png)

([K9s](https://k9scli.io/) is one of my favorite tools for navigating Kubernetes clusters through the CLI).

Since we installed [Hubble](https://github.com/cilium/hubble) on the cluster, Let’s check its cool UI and see how the traffic flows between the pods. To do so, let’s run:

    kubectl port-forward -n kube-system deployment/hubble-ui 8081:8081

Then, we can access the UI and check what’s happening in kube-system names

    http://localhost:8081/?namespace=kube-system

You should be able to see the traffic flowing between pods and to the internet as well, and since we haven’t defined any policies on the cluster yet, all of the traffic should be FORWARDED

![](https://cdn-images-1.medium.com/max/6828/1*lcFSgYAoHRV0n7tAAwE_Ag.png)

## Karpenter: The EKS Autoscaling Maestro 🚀

As we journey into the heart of our EKS setup, we arrive at Karpenter. This nimble auto scaler intelligently manages node provisioning, ensuring our workloads are optimally balanced and resources are used efficiently. Let’s delve into the installation!

Using a similar module from EKS Addons, we will install and configure Karpenter on the cluster.
{% gist https://gist.github.com/abebars/94bbde44f371a8ca837f110037ac976c.js %}
Then, we must update the Cluster Auth Roles to allow the Karpenter IAM role to create nodes and attach them to the cluster as needed. And you can do that by adding the created IAM Role ARN to `aws_auth_roles.`
{% gist https://gist.github.com/abebars/009faed5ec7afd0eab6ff833fb01a821.js %}
Now Karpenter Deployment should be ready.

![](https://cdn-images-1.medium.com/max/3968/1*bwMuYcFujYoEHSzrTQbxCA.png)

However, Kaprneter doesn’t know yet how or what type of nodes that we need; that’s where we need to use Provisioner & NodeTemplates These two CRDs are the core elements of Karpenter and define how nodes are being created and many other options.

Think about like NodeGroup but without creating an actual Node Group, it’s flexible because it’s made in Kubernetes, which always allows us to define them within the same scope. This is a constructive approach, for example, If you want to create these on the fly.

It’s time to manifest our desires in the form of CRDs. The first to materialize is our Provisioner, the maestro dictating the variations and specifications of the nodes we summon.
{% gist https://gist.github.com/abebars/2cc73e182e54c025c5b1e876d3cd94c9.js %}
And now, with the last resource we need to complete our symphony, Karpenter will start taking over our scaling.
{% gist https://gist.github.com/abebars/60f1e87e16947236e32eeacd6832f4aa.js %}
## Wrapping Up: Setting Up EKS 🌟

We’ve taken some significant steps in this guide! We’ve set up our own EKS Amazon Clusters and avoided running out of IP addresses by using secondary CIDRs. We’ve also tagged our subnets, so everything is easy to find.

We added Cilium to our project with the help of, and we’ve used Terraform and Helm to make everything easy to manage and adjust. For those who like using GitOps, our setup supports it too!

Then, we brought Karpenter to help our clusters use resources wisely and save on costs. We’ve made some custom adjustments and used AWSNodeTemplate to ensure our nodes are just how we want them.

## What’s Coming Up Next? 🤔

This is just the start! We’ve got our EKS set up with Cilium and Karpenter, but there’s much more to learn. In the following parts, we’ll explore Cluster Mesh configurations and more remarkable EKS and Cilium CLuster Mesh features. So, keep reading as we uncover more about Kubernetes and Cilium and learn how to make the most of them!