AWS Database Blog
IPFS on AWS, Part 2: Deploy a production IPFS cluster on Amazon EKS
This series of posts provides a comprehensive introduction to running IPFS (InterPlanetary File System) on AWS:
- In Part 1, we introduce the IPFS concepts and test IPFS features on an Amazon Elastic Compute Cloud (Amazon EC2) instance
- In Part 2, we propose a reference architecture and build an IPFS cluster on Amazon Elastic Kubernetes Service (Amazon EKS)
- In Part 3, we deploy an NFT smart contract using Amazon Managed Blockchain and illustrate the use of IPFS as a way to decentrally store NFT-related data
In this second part of our series, we will deploy a production IPFS cluster on Amazon EKS. The IPFS cluster is deployed step-by-step so you can get an understanding of all the required components. These steps can be further automated at part of an infrastructure as code (IaC) strategy. We tried to limit the dependencies between the different sections, so you can can pause and resume implementing the solution after any section. To keep the commands as light as possible, the snippets are not all idempotent. All the steps are to be performed by a single user with sufficient permissions, but a more granular separation of duties can be applied leveraging AWS IAM.
Solution overview
The following diagram illustrates the architecture we will deploy.
The following are some key elements to consider:
- IPFS and the IPFS cluster (as designated in the diagram) are two different components running on different pods.
- The IPFS server contains different services with different requirements. Firstly, port 4001 needs to be reachable by other nodes from the IPFS network. The IPFS gateway can be accessed from the internet, but we chose to protect it behind an Application Load Balancer with Amazon Cognito authentication. Finally, the API should only be accessed by the IPFS cluster.
- Two Elastic IPs are assigned to the Network Load Balancer in front of the IPFS pods. This allows the IPFS servers to advertise these IP addresses to the other IPFS peers on the IPFS network (therefore contributing to the overall health of the IPFS network).
- The IPFS cluster component is load balanced and only accessible from the jumpbox.
- The architecture spans two Availability Zones, but it can easily be extended to three.
- Amazon EKS storage is configured on EFS One Zone using the Amazon EFS CSI driver.
- This architecture does not include a cloud delivery network component, but instead promotes the development of IPFS-compliant applications to globally distribute files through the IPFS network. If you have dependencies on classic web application clients connecting from multiple geographies, you may want to use Amazon CloudFront, and authenticate users with a Cognito@Edge solution such as the one documented in the following GitHub repo.
We walk you through the following high-level steps:
- Create a VPC using Amazon Virtual Private Cloud (Amazon VPC).
- Create a jumpbox.
- Set up Amazon EKS.
- Generate a certificate.
- Prepare an Amazon Cognito user group.
- Create two Elastic IPs.
- Prepare manifests.
- Create an Amazon EFS storage class.
- Deploy IPFS servers.
- Deploy the IPFS cluster.
- Test the cluster.
Create a VPC
We start by creating a VPC with two public subnets and two private subnets.
- On the Amazon VPC console, choose Create VPC.
- For Resources to create, select VPC and more
- For Name tag auto-generation, select Auto-generate and enter
ipfs
. - Enter
10.0.0.0/22
for IPv4 CIDR block. - For IPv6 CIDR block, select No Ipv6 CIDR block.
- For Tenancy, choose Default.
- Specify the number of Availability Zones (for this post, two) and subnets (two public and two private).
- Under Customize subnets CIDR blocks, enter
10.0.0.0/24
,10.0.1.0/24
,10.0.2.0/24
, and10.0.3.0/24
for the CIDR blocks for your subnets.
- For NAT gateways, select 1 per AZ.
- For VPC endpoints, select None.
- For DNS options, select Enable DNS hostnames and Enable DNS resolution.
- Choose Create VPC.
- After the VPC is created, go to the Subnets page on the Amazon VPC console.
- Select each public subnet individually and on the Actions menu, choose Edit subnet settings.
- Select Enable auto-assign public IPv4 address to allow automatic IP allocation, and choose Save.
Create a jumpbox
We will use the EC2 Instance Connect method to connect to the jumpbox, so we first need to lookup the IP address range assigned to this service in your region. Choose the CloudShell icon in the navigation pane and enter the following command:
Take note of the returned IP address range (18.202.216.48/29 in the case of the Ireland region, for example).
- On the Amazon EC2 console, choose Instances in the navigation pane.
- Choose Launch an instance and create an instance with the following parameters:
- For Name, enter
jumpbox
. - For Amazon Machine Image (AMI), choose Ubuntu Server 22.04 LTS (HVM), SSD Volume Type.
- For Architecture, choose 64-bit (x86).
- For Instance type, choose t2.micro.
- For Key pair (login), choose Proceed without key pair.
- For Network settings, choose Edit:
- set the VPC to the VPC you previously created
- set Subnet to the first public subnet
- enable Auto-assign public IP
- for Source type (Security group rule 1), choose Custom and enter the IP address range previously looked up.
- Keep all other default parameters, and choose Launch instance.
- For Name, enter
- After you create the instance, on the Instances page, select the instance and choose Connect.
- Connect with the EC2 Instance Connect method.
You will see a prompt similar to the following in a new tab: - If you do not already have access keys for your user, create access keys (refer to Get your access keys).
- Run the following commands to install
jq
,unzip
,kubectl
andawscliv2
. Refer to Setting up the AWS CLI if you’re not familiar with the AWS CLI configuration process.
All command-line instructions in the rest of this post should be run from an EC2 Instance Connect session.
Set up Amazon EKS
To set up Amazon EKS, complete the following steps.
- Configure AWS Identity and Access Management (IAM) roles:
- Create an IAM role for the EKS cluster called
eksClusterRole
. - Create an IAM role for the EKS cluster nodes called
AmazonEKSNodeRole
. When assigning policies, make sure to select theAmazonEKSWorkerNodePolicy
,AmazonEC2ContainerRegistryReadOnly
, andAmazonEKS_CNI_Policy
policies.
- Create an IAM role for the EKS cluster called
- On the Amazon EC2 console, choose Security groups in the navigation pane and create a security group with the following parameters:
- For Name, enter
ipfs-eks-control-plane-sg
. - For Description, enter
IPFS EKS control plane security group
. - For VPC, choose the
ipfs-vpc
previously created. - For Inbound rules, add a rule allowing all traffic from the jumpbox’s security group.
- Keep all other default parameters.
- For Name, enter
- On the Amazon EKS console, create a new cluster with the following parameters:
- For Name, enter
ipfs-cluster
. - For Kubernetes version, choose 1.27.
- For Cluster service role, choose
eksClusterRole
. - For VPC, choose
ipfs-vpc
created previously. - For Subnets, choose the two private subnets.
- For Security group, choose
ipfs-eks-control-plane-sg
. - For Cluster endpoint access, choose Private.
- Keep all other default parameters.
- For Name, enter
- When the cluster is ready, choose Add node group, under Compute in the navigation pane and create a managed node group with the following parameters:
- For Name, enter
ipfs-nodes
. - For Node IAM role, choose
AmazonEKSNodeRole
. - For AMI type, choose Amazon Linux 2 (AL2_x86_64).
- For Instance type, choose t3.medium.
- For Desired size, choose 2.
- For Minimum size, choose 2.
- For Maximum size, choose 4.
- For Subnets, choose the two private subnets.
- For Name, enter
- After the managed node group is created, configure
kubectl
to access the cluster: - Install
helm
(for more information, refer to Using Helm with Amazon EKS): - Install
eksctl
(refer to Installing or updating eksctl): - Install the AWS Load Balancer Controller (refer to Installing the AWS LoadBalancer Controller add-on):
Check aws-load-balancer-controller deployment is ready:
- Tag the two public subnets so they can be automatically discovered by the AWS Load Balancer Controller (see Subnet Auto Discovery for more details):
- For Key, enter
kubernetes.io/role/elb
. - For Value, enter
1
.
- For Key, enter
- Similarly, tag the two private subnets:
- For Key, enter
kubernetes.io/role/internal-elb
- For Value, enter
1
.
- For Key, enter
- Install the Amazon EFS driver (refer to Amazon EFS CSI driver):
Check the Amazon EFS driver has started:
- Create EFS filesystems and mount targets:
If you receive an error indicating that the EFS One Zone storage class isn’t available in a specific Availability Zone, you can use EFS Standard, use another Region, or update the procedure to use specific Availability Zones.
Generate a certificate
For instructions on creating a certificate for your domain, refer to Requesting a public certificate. If you don’t have a domain or want to create a new domain managed by AWS, you can also register a domain name using Amazon Route 53. For more details, refer to Registering and managing domains using Amazon Route 53.
When done, record the domain name that you used and the ARN of the certificate:
Prepare an Amazon Cognito user group
To protect access to the IPFS gateway, we will implement an Application Load Balancer that will authenticate users against an Amazon Cognito user group. To create an Amazon Cognito user group, use the following code:
Create two Elastic IPs
Create your Elastic IPs with the following code:
Prepare manifests
Kubernetes template manifests corresponding to the presented architecture have been prepared. Update them using all the objects that you have created:
- If you haven’t already, record the ARN of the certificate:
- Configure all environment variables (you may want to double check they are all properly set before going further):
- Prepare the manifests:
Create an EFS storage class
Create your EFS storage class with the following code:
Deploy IPFS servers
Complete the following steps:
- Deploy two independent IPFS servers in two different Availability Zones:
- Wait for the Application Load Balancer to be provisionned, and record its DNS address:
- Create a CNAME for your
DOMAIN_NAME
pointing to this DNS address. - Validate that you can now connect to the IPFS gateway using a URL similar to
https://<DOMAIN_NAME>/ipfs/Qme7ss3ARVgxv6rXqVPiikMJ8u2NLgmgszg13pYrDKEoiu
- Connect with user name
testuser
and passwordtestuserP4ssw0rd#
:
Deploy the IPFS-cluster
To deploy the IPFS cluster, complete the following steps:
- Download the
ipfs-cluster-service
binary that we will use to generate theipfs-cluster
configuration: - Prepare the configuration of each cluster peer and save them as configmaps:
- Deploy the ipfs-cluster:
- Check that you can see
** IPFS Cluster is READY **
in the logs of theipfs-cluster-deployment
pods.
Test the cluster
Now we can test the cluster.
- Download the
ipfs-cluster-ctl
binary: - Validate you can connect to the cluster:
The Network Load Balancer will forward the request to one of the IPFS cluster peers. If you repeat the last command multiple times you will connect to both pods and check that they can see each other.
- Let’s pin a CID:
Congratulations! We now have a working IPFS cluster.
Lockdown jumpbox
To prevent futher use of the AWS CLI from the jumpbox, delete the local credentials and configuration:
Conclusion
In this post, we showed how to deploy a production IPFS cluster on Amazon EKS. In Part 3 of this series, we show how we can use the IPFS setup that we have created to store NFT-related data.
To study how to make the proposed architecture serverless, you can also refer to this post: Deploying IPFS Cluster using AWS Fargate and Amazon EFS One Zone
About the Author
Guillaume Goutaudier is a Sr Partner Solution Architect at AWS. He helps companies build strategic technical partnerships with AWS. He is also passionate about blockchain technologies, and a member of the Technical Field Community for blockchain.