Skip to main content
How To Make Your AWS EKS Cluster Use Fargate Using Pulumi And Golang
  1. Blog/

How To Make Your AWS EKS Cluster Use Fargate Using Pulumi And Golang

·2 mins·
Infrastructure as Code with Pulumi and Go - This article is part of a series.
Part 4: This Article

At re:Invent, AWS introduced the ability to run EKS pods on AWS Fargate, and Fargate is cheaper than hosting Kubernetes yourself. In the last post I created an EKS cluster, so this one adds a Fargate profile to it.

The complete project is available on GitHub.

Configuration
#

The Fargate profile needs a name, a Kubernetes namespace to target, and an IAM role for pod execution. Add this to the YAML file from the previous post:

fargate:profile-name: EKSFargateProfile
fargate:namespace: example
fargate:execution-role-arn: "arn:aws:iam::ACCOUNTID:role/EKSFargatePodExecutionRole"

For details on creating the IAM role, check the AWS docs. You can use the command line (e.g., pulumi config set fargate:profile-name "EKSFargateProfile") or edit the YAML file directly. The file is named Pulumi.<name of your project>.yaml.

Adding the Fargate profile
#

This code extends the previous post. It reads the profile name and namespace from the YAML file, references the cluster and subnets from earlier posts, and calls eks.NewFargateProfile() to attach the profile to your cluster.

// Create an EKS Fargate Profile
fargateProfileName := getEnv(ctx, "fargate:profile-name", "unknown")

selectors := make([]map[string]interface{}, 1)
namespaces := make(map[string]interface{})
namespaces["namespace"] = getEnv(ctx, "fargate:namespace", "unknown")
selectors[0] = namespaces

fargateProfileArgs := &eks.FargateProfileArgs{
    ClusterName:         clusterName,
    FargateProfileName:  fargateProfileName,
    Tags:                tags,
    SubnetIds:           subnets["subnet_ids"],
    Selectors:           selectors,
    PodExecutionRoleArn: getEnv(ctx, "fargate:execution-role-arn", "unknown"),
}

fargateProfile, err := eks.NewFargateProfile(ctx, fargateProfileName, fargateProfileArgs)
if err != nil {
    fmt.Println(err.Error())
    return err
}

ctx.Export("FARGATE-PROFILE-ID", fargateProfile.ID())

Running the code
#

Run pulumi up to add the Fargate profile. If you’re using the same project and stack, Pulumi knows the cluster already exists and will only create the new profile.

$ pulumi up
Previewing update (builderstack):

     Type                       Name                  Plan
     pulumi:pulumi:Stack        builder-builderstack
 +   └─ aws:eks:FargateProfile  EKSFargateProfile     create

Outputs:
  + FARGATE-PROFILE-ID: output<string>

Resources:
    + 1 to create
    5 unchanged

Do you want to perform this update? yes
Updating (builderstack):

     Type                       Name                  Status
     pulumi:pulumi:Stack        builder-builderstack
 +   └─ aws:eks:FargateProfile  EKSFargateProfile     created

Outputs:
    CLUSTER-ID        : "myEKSCluster"
  + FARGATE-PROFILE-ID: "myEKSCluster:EKSFargateProfile"
    SUBNET-IDS        : [
        [0]: "subnet-0a1909bec2e936bd7"
        [1]: "subnet-09d229c2eb8061979"
    ]
    VPC-ID            : "vpc-0437c750acf1050c3"

Resources:
    + 1 created
    5 unchanged

Duration: 2m27s

Permalink: https://app.pulumi.com/retgits/builder/builderstack/updates/4

The permalink at the bottom takes you to the Pulumi console where you can see all the details of the execution and the resources that were created.

Cover image by Gerd Altmann from Pixabay

Infrastructure as Code with Pulumi and Go - This article is part of a series.
Part 4: This Article

Related

Serverless - From Microservice to Functions

·1 min
Using serverless requires us to change our mindset on how we build apps and requires us to unlearn things we learned building apps in the past. At AWS re:Invent I got a chance to do a VMware Code session and talk about how we took part of our ACME Fitness Shop and transformed it into serverless functions with AWS Lambda.

Serverless - The Wrath of Containers

·1 min
Containers were this awesome technology that ushered in the Cloud era and with a lot of new FaaS tools coming along, companies are wondering if they should jump the container ship altogether. As it turns out, containers definitely have value in Serverless. In this session we will take an existing containerized app and move it into AWS Fargate, look at the cost of running it, and how we can monitor it.

Deploying Flogo Apps to Lambda with the Serverless Framework (Part 2)

·4 mins
I can hear you think “Part 2?! So there actually is a part 1?” 😱 The answer to that is, yes, there most definitely is a part 1 (but you can safely ignore that 😅). In that part I went over deploying Flogo apps built with the Flogo Web UI using the Serverless Framework. Now, with the Go API that we added to Flogo, you can mix triggers and activities from Flogo (and the community) with your regular Go code and deploy using the Serverless Framework.