Emissary Ingress: Connecting Lambda to a Kubernetes ClusterIP Service in an EKS Cluster in the Same VPC
Image by Kacy - hkhazo.biz.id

Emissary Ingress: Connecting Lambda to a Kubernetes ClusterIP Service in an EKS Cluster in the Same VPC

Posted on

In the world of serverless computing and containerized applications, connecting the dots between different technologies can be a daunting task. But fear not, dear reader, for we’re about to embark on a journey to bridge the gap between AWS Lambda and a Kubernetes ClusterIP Service in an EKS cluster, all within the same VPC. Buckle up, and let’s dive into the wonderful world of Emissary Ingress!

The Problem Statement

Imagine you have a Kubernetes deployment running in an EKS cluster, with a ClusterIP Service exposing your application to the world. Now, you want to integrate this service with an AWS Lambda function, allowing it to receive and process events. Sounds simple, right? Well, not so fast. The challenge lies in connecting these two disparate technologies, ensuring seamless communication between them.

Enter Emissary Ingress

Emissary Ingress is an open-source ingress controller that enables secure, scalable, and observable ingress into Kubernetes clusters. By leveraging Emissary Ingress, we can create an entry point for our Lambda function to communicate with the ClusterIP Service, effectively bridging the gap between these two technologies.

Step 1: Prepare Your EKS Cluster and Kubernetes Deployment

Before we begin, make sure you have an EKS cluster up and running, with a Kubernetes deployment and a ClusterIP Service exposing your application. If you’re new to EKS, follow the AWS EKS Getting Started Guide to get started.


apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: my-app:latest
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
  - name: http
    port: 80
    targetPort: 8080
  type: ClusterIP

Step 2: Install Emissary Ingress

To install Emissary Ingress, you’ll need to create a new namespace and deploy the Emissary Ingress controller.


kubectl create namespace emissary
kubectl apply -f https://getambassador.io/yaml/ambassador/ambassador-crds.yaml
kubectl apply -f https://getambassador.io/yaml/ambassador/ambassador-ingress.yaml

Step 3: Create an Emissary Ingress Resource

Next, create an Emissary Ingress resource to expose your ClusterIP Service to the outside world.


apiVersion: getambassador.io/v2
kind: Ingress
metadata:
  name: my-app-ingress
spec:
  host: my-app.example.com
  tls:
    secret: tls-certificate
  rules:
  - host: my-app.example.com
    http:
      /:
        backend:
          serviceName: my-app-service
          servicePort: 80

Step 4: Configure Emissary Ingress to Route Traffic to Your ClusterIP Service

Update the Emissary Ingress resource to route traffic to your ClusterIP Service.


apiVersion: getambassador.io/v2
kind: Ingress
metadata:
  name: my-app-ingress
spec:
  host: my-app.example.com
  tls:
    secret: tls-certificate
  rules:
  - host: my-app.example.com
    http:
      /:
        backend:
          serviceName: my-app-service
          servicePort: 80
        resolver: inet
        route:
          - destination:
              host: my-app-service
              port:
                number: 80
            timeout:
              idle: 1h

Step 5: Create an AWS Lambda Function

Create a new AWS Lambda function using your preferred programming language. For this example, we’ll use a Node.js function.


exports.handler = async (event) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};

Step 6: Configure the AWS Lambda Function to Invoke the Emissary Ingress Resource

Update the AWS Lambda function to invoke the Emissary Ingress resource using the `aws-sdk` library.


const AWS = require('aws-sdk');
const http = require('http');

exports.handler = async (event) => {
  const ingressUrl = 'https://my-app.example.com';
  const params = {
    method: 'GET',
    hostname: ingressUrl,
    path: '/',
    headers: {
      'Content-Type': 'application/json',
    },
  };

  const req = http.request(params, (res) => {
    let data = '';
    res.on('data', (chunk) => {
      data += chunk;
    });
    res.on('end', () => {
      console.log('Response: ', data);
    });
  });

  req.on('error', (error) => {
    console.error('Error: ', error);
  });

  req.end();

  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};

Step 7: Test the Connection

Trigger the AWS Lambda function by sending an event to it. The function should now invoke the Emissary Ingress resource, which will route traffic to your ClusterIP Service.

Conclusion

And there you have it! You’ve successfully connected an AWS Lambda function to a Kubernetes ClusterIP Service in an EKS cluster using Emissary Ingress. This setup enables secure, scalable, and observable communication between your serverless function and containerized application, all within the same VPC.

EKS Cluster Kubernetes Deployment ClusterIP Service Emissary Ingress AWS Lambda Function
VPC Deployment exposes app ClusterIP Service exposes app Emissary Ingress routes traffic to ClusterIP Service Lambda function invokes Emissary Ingress

This article has demonstrated the power of Emissary Ingress in connecting disparate technologies, enabling seamless communication between AWS Lambda and a Kubernetes ClusterIP Service in an EKS cluster. With this setup, you can now leverage the benefits of serverless computing and containerized applications, all within the same VPC.

  • Try experimenting with different Emissary Ingress configurations to optimize performance and security.
  • Explore integrating additional technologies, such as API Gateways or load balancers, to enhance the setup.
  • Read more about Emissary Ingress and its capabilities on the Ambassador Labs website.

Stay tuned for more exciting articles on serverless computing, containerization, and Emissary Ingress! If you have any questions or need further assistance, feel free to reach out in the comments below.

Frequently Asked Question

Get the scoop on connecting Lambda to a Kubernetes ClusterIP Service in an EKS cluster in the same VPC with Emissary Ingress!

What is Emissary Ingress, and how does it help me connect Lambda to a Kubernetes ClusterIP Service?

Emissary Ingress is an open-source, Kubernetes-native API gateway that enables you to securely connect your Lambda functions to a Kubernetes ClusterIP Service in an EKS cluster. It acts as an entry point for incoming traffic, routing requests to the correct destination within your cluster. With Emissary Ingress, you can focus on building and deploying your Lambda functions without worrying about the complexities of service discovery and traffic routing.

What are the benefits of using Emissary Ingress to connect Lambda to a Kubernetes ClusterIP Service?

Using Emissary Ingress provides several benefits, including simplified traffic routing, improved security, and enhanced observability. It enables you to use Kubernetes-native constructs, such as services and ingresses, to manage traffic to your Lambda functions. Additionally, Emissary Ingress provides built-in support for SSL/TLS termination, path-based routing, and traffic metrics, making it an ideal choice for connecting Lambda to a Kubernetes ClusterIP Service.

How does Emissary Ingress handle traffic routing from Lambda to a Kubernetes ClusterIP Service?

Emissary Ingress uses a combination of Kubernetes ingresses and service mesh technology to route traffic from Lambda functions to a Kubernetes ClusterIP Service. It creates an ingress resource that acts as an entry point for incoming traffic, which is then routed to the corresponding service within the cluster. This enables Emissary Ingress to provide path-based routing, traffic splitting, and traffic metrics, making it easy to manage complex traffic flows.

Can I use Emissary Ingress to connect multiple Lambda functions to a single Kubernetes ClusterIP Service?

Yes, Emissary Ingress supports connecting multiple Lambda functions to a single Kubernetes ClusterIP Service. You can define multiple ingresses that route traffic to the same ClusterIP Service, enabling you to handle multiple functions with a single service. This makes it easy to manage complex workflows and integrate multiple Lambda functions with your Kubernetes cluster.

Is Emissary Ingress compatible with AWS EKS?

Yes, Emissary Ingress is fully compatible with AWS EKS. It provides native support for EKS clusters, enabling you to deploy and manage Emissary Ingress alongside your EKS cluster. This makes it easy to integrate your Lambda functions with your EKS cluster, providing a seamless experience for building and deploying serverless applications.

Leave a Reply

Your email address will not be published. Required fields are marked *