1. Using aws eks with efs

    TypeScript

    To create an AWS EKS cluster with EFS, you will go through several steps:

    1. Create an EFS file system.
    2. Create an EFS access point.
    3. Set up an EKS cluster.
    4. Set up a node group for your EKS cluster.
    5. Mount the EFS file system in the EKS nodes.

    Below is a Pulumi program in TypeScript to set up an EKS cluster with an EFS file system. In this program, we will create the necessary AWS resources using Pulumi's @pulumi/aws and @pulumi/awsx libraries. The major resources involved will be:

    • AWS EFS FileSystem: This is the resource that represents the EFS file system in AWS.
    • AWS EFS AccessPoint: An access point is an application-specific view into an EFS file system that applies an operating system user and group, and a file system path, to any file system request made through the access point.
    • AWS EKS Cluster: This resource is responsible for setting up the Kubernetes cluster on AWS.
    • AWS EKS Node Group: This represents a group of nodes registered to the EKS cluster.

    The code is segmented into respective resource sections for clarity, with comments explaining each part.

    import * as aws from "@pulumi/aws"; import * as eks from "@pulumi/eks"; import * as pulumi from "@pulumi/pulumi"; // Create an EFS FileSystem. const fileSystem = new aws.efs.FileSystem("my-filesystem", { // Optionally configure additional properties here }); // Create an EFS AccessPoint. const accessPoint = new aws.efs.AccessPoint("my-access-point", { fileSystemId: fileSystem.id, posixUser: { uid: 1001, gid: 1001 }, rootDirectory: { path: "/export/my-access-point", creationInfo: { ownerUid: 1001, ownerGid: 1001, permissions: "755" } } }, { dependsOn: [fileSystem] }); // Set up an EKS cluster. // Create a VPC for our cluster. const vpc = new awsx.ec2.Vpc("my-vpc", { numberOfAvailabilityZones: 2 }); // Create an EKS cluster with the default configuration. const cluster = new eks.Cluster("my-cluster", { vpcId: vpc.id, subnetIds: vpc.publicSubnetIds, instanceType: "t2.medium", desiredCapacity: 2, minSize: 1, maxSize: 2, storageClasses: "efs", // Custom storage class that we'll define later. }, { providers: { kubernetes: k8sProvider } }); // The code below is boilerplate, taken from the Pulumi EKS examples. // It knows how to create an EKS cluster and the corresponding k8s provider. const k8sProvider = cluster.provider; // Create a Kubernetes StorageClass for the EFS file system. const storageClass = new k8s.storage.v1.StorageClass("my-storage-class", { metadata: { name: "efs" }, provisioner: "efs.csi.aws.com" }, { provider: k8sProvider }); // Export the EKS cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig; // Export the EFS file system's ID. export const efsId = fileSystem.id; // Note: To mount the EFS file system in the EKS nodes, you would typically use a Kubernetes DaemonSet or Deployment. // This will require the EFS CSI driver for Kubernetes, which can be deployed using a Helm chart.

    What this code does is create an EFS FileSystem and an AccessPoint that defines an OS user and group, and a directory within the EFS file system. Then, it creates a VPC and deploys an EKS cluster with a node group into that VPC. It sets up a Kubernetes StorageClass backed by EFS, which can be used by pods to store persistent data.

    To connect your EKS pods to the EFS file system, you need to use the EFS CSI driver, which can be installed on your EKS cluster. Once installed, you can use Kubernetes resources such as PersistentVolumes (PVs) and PersistentVolumeClaims (PVCs) to mount the EFS file system paths inside your pods.

    Please ensure you have the AWS CLI configured and Pulumi CLI installed and set up to interact with your AWS account to use this program. Remember that operating costs are associated with these resources on AWS, and you will be billed for the resources used in your account.