Serverless Kubernetes with AWS EKS and Fargate

Illustration of a person flying an orange and gray kite, with an orange shipping container being lifted by a crane in the background. The scene includes stacked containers and a cloudy sky, with the person wearing an orange scarf. Illustration of a person flying an orange and gray kite, with an orange shipping container being lifted by a crane in the background. The scene includes stacked containers and a cloudy sky, with the person wearing an orange scarf.

Today, we're diving deeper into the serverless world of AWS, specifically exploring EKS Fargate. Our journey started with ECS serverless, and now we're tackling Kubernetes with Firecracker, or as it's known, EKS Fargate.

AWS has invested significantly in integrating Firecracker into EKS, a somewhat unusual but potent combination. For those familiar, ECS also utilized Firecracker, but within EKS, it's fully integrated. Every time we initiate a pod, EKS automatically spins up a new server—a VM dedicated to our Firecracker container. This VM then acts as a node within Kubernetes.

Firecracker itself utilizes KVM to launch micro-virtual machines in non-virtualized environments almost instantaneously. The beauty of this setup is that each pod execution results in the creation of a micro VM, starting our container's image inside. This approach not only minimizes overprovisioning but also cuts costs by ensuring resources are precisely aligned with consumption needs.

Setting Up From Scratch

Let's begin by setting up our environment from scratch:

  1. Creating an EC2 Instance: First, navigate to EC2 instances and launch an instance using the Amazon Linux AMI. Review, launch, and select your preferred key for image connection. Once created, copy the external IP, open your terminal (Terminus in my case), and establish a connection by providing the IP, username (ec2-user), and linking to your SSH key.

  2. Installing Necessary Tools: Once connected (be sure to switch to root using sudo -i), install eksctl and kubectl. Commands for installation can be found in the video description below.

  3. Setting Up AWS CLI and Kubectl: Move the eksctl binary to /usr/bin and set permissions for kubectl before adding it to your bin folder. Setup your .aws folder in the home directory, creating a credentials file and configuring it with your region, which for this session will be eu-west-1 (Ireland).

  4. Creating the EKS Cluster: Test that eksctl is functioning with eksctl version. Then, create your serverless EKS cluster using the command:

   eksctl create cluster --name mkdev --version 1.14 --fargate

This step will take some time as AWS constructs your serverless EKS infrastructure.

  1. Deploying and Managing Workloads: Once your cluster is up, you'll notice default nodes for core components like coredns and kube-proxy. If you launch a pod in the default namespace, it will automatically connect to Fargate. However, deploying in other namespaces without a linked Fargate profile will leave your pod in a "Pending" state, awaiting EC2 worker instances.

  2. Creating a Deployment and Service:

Here's a simple deployment for a Node.js application:

   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: eks-demo
     labels:
       app: eks-demo
   spec:
     replicas: 1
     selector:
       matchLabels:
         app: eks-demo
     template:
       metadata:
         labels:
           app: eks-demo
       spec:
         containers:
           - name: eks-demo-container
             image: http://gcr.io/google-samples/node-hello:1.0
             ports:
               - containerPort: 8080
             resources:
               requests:
                 memory: "64Mi"
                 cpu: "250m"
               limits:
                 memory: "128Mi"
                 cpu: "1"
   ---
   apiVersion: v1
   kind: Service
   metadata:
     labels:
       app: eks-demo
     name: eks-demo
   spec:
     clusterIP: None
     ports:
       - port: 8080
     selector:
       app: eks-demo

Apply this configuration using:

   kubectl apply -f app.yml -n default

What's Next?

Our journey through serverless EKS with Fargate is just beginning. Check out this article, where we explore using the ALB Ingress Controller with Amazon EKS on Fargate, a setup that automatically configures your AWS Load Balancer, listeners, and target groups through Kubernetes Ingress.


Here's the same article in video form for your convenience: