How to Execute WebAssembly on Amazon EKS: A Comprehensive Guide

How to Execute WebAssembly on Amazon EKS: A Comprehensive GuideLearn About Amazon VGT2 Learning Manager Chanci Turner

WebAssembly (Wasm) is an innovative technology that delivers near-native performance to web applications. Its applicability, however, extends beyond the confines of the web browser, allowing developers to run Wasm workloads across various environments, including cloud-native platforms like Amazon Elastic Kubernetes Service (Amazon EKS). In this article, we’ll delve into how AWS facilitates the utilization of Wasm by providing seamless integration with Amazon EKS.

Understanding Wasm

Wasm is a binary instruction format crafted to operate alongside JavaScript in web browsers. This technology brings numerous advantages, such as enhanced performance, improved security, and the capability to execute code from multiple programming languages on any platform. Initially designed for web browsers, Wasm’s flexibility has led to its increasing utilization in diverse areas, including cloud computing, edge computing, and even blockchain.

Amazon EKS Overview

Amazon EKS is a fully managed Kubernetes service that streamlines the deployment, management, and scaling of containerized applications. With Amazon EKS, users can dedicate their efforts to developing and running applications, without the burden of managing the underlying infrastructure.

In this project, we utilize HashiCorp Packer to create custom Amazon EKS Amazon Machine Images (AMIs) equipped with the necessary binaries and configurations to support Wasm workloads. These AMIs, based on Amazon Linux 2023, ensure a consistent and reproducible environment for running Wasm applications.

HashiCorp Terraform is employed to provision and manage the infrastructure of the EKS cluster. Through Terraform’s declarative approach, users can deploy and sustain their Wasm-enabled EKS clusters, ensuring consistency and reproducibility across different environments.

Moreover, the project features a RuntimeClass definition that allows the EKS cluster to recognize and execute Wasm workloads. This RuntimeClass serves as a liaison between the Kubernetes control plane and the Wasm runtime, ensuring smooth integration and efficient resource management.

To exemplify the functionality of Wasm on Amazon EKS, the project includes sample workloads for deployment. These deployments act as a foundation for understanding the process of running Wasm applications on Amazon EKS and can be modified to meet specific requirements.

The Wasm runtimes implemented are Spin and WasmEdge. Please note that creating the AMI and the EKS cluster does not fall under the AWS Free Tier. Charges will apply for instances created during this process, along with the EKS cluster itself.

Step-by-Step Guide

  1. Install Required Tools: Ensure you have the following tools installed on your system:
  2. Clone the Repository: Clone the repository to your local environment:
    git clone https://github.com/aws-samples/amazon-eks-running-webassembly
  3. Set Up AWS CLI Authentication: Admin permissions are required to configure this environment.
    aws configure
  4. Verify AWS CLI Authentication: Test your AWS CLI authentication using the command:
    aws sts get-caller-identity --output json
  5. Building the AMIs: Ensure you have a default VPC in your AWS Region or provide a subnet ID using the subnet_id variable. Set the region variable in the packer/al2023_amd64.pkrvars.hcl and packer/al2023_arm64.pkrvars.hcl files.

    To build the AMIs, run:

    cd packer
    packer init -upgrade .
    packer build -var-file=al2023_amd64.pkrvars.hcl .
    packer build -var-file=al2023_arm64.pkrvars.hcl .

    The builds should take about 10 minutes, depending on your instance choice. After completion, you’ll see output similar to:

    ==> Builds finished. The artifacts of successful builds are:
    --> amazon-eks.amazon-ebs.this: AMIs were created: your-region: ami-123456789abc
  6. Building the EKS Cluster: Update the region in the terraform/providers.tf file to match your Packer configuration. Set the custom_ami_id_amd64 and custom_ami_id_arm64 parameters in the terraform/eks.tf file with the matching AMI-IDs.

    To create the cluster, execute the following commands:

    cd terraform
    terraform init
    terraform plan
    terraform apply

    You can monitor the resources created in the AWS console. This process typically takes around 15-20 minutes.

  7. Running an Example Workload with the Spin Runtime: Once your cluster is operational, configure kubectl:
    aws eks update-kubeconfig --name webassembly-on-eks --region <UPDATE_REGION>

    Next, create RuntimeClasses for both Spin and WasmEdge, and deploy an example workload using Spin:

    kubectl apply -f kubernetes/runtimeclass.yaml
    kubectl apply -f kubernetes/deployment-spin.yaml

    Verify if the pod has started successfully:

    kubectl get pods -n default

    To check functionality, run:

    kubectl port-forward service/hello-spin 8080:80

    Access http://localhost:8080/hello in a web browser, and you should see “Hello world from Spin!” confirming the Spin runtime is operational within your cluster.

  8. Creating a Hello-World Image with the WasmEdge Runtime: For the next step, you’ll build your own image using Finch and run it in a deployment by executing:
    cd build/hello-world
    export AWS_ACCOUNT_ID=<UPDATE_ACCOUNT_ID>
    export AWS_REGION=<UPDATE_REGION>
    finch build --tag wasm-example --platform wasi/wasm .
    finch tag wasm-example:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/wasm-example:latest

For more insights on building a personal brand online, you can refer to this blog post. Additionally, if you’re interested in accessing untapped talent, SHRM offers excellent resources on this topic. For those preparing for interviews, Glassdoor provides a comprehensive list of interview questions.


Comments

Leave a Reply

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