Setup EKS and flux 2 with Terraform

Joshua Callis
3 min readJul 27, 2021

Been looking at flux 2 and wondering where to start? what is new about it etc? and how you can provision a cluster in eks and flux 2 with Terraform?

You may be thinking why not just install flux2 via the CLI? well, doing it via the CLI is okay in some cases.

However as soon as you do that, it’s really easy to lose visibility of what you have done or for someone else to know, what if you have an issue? you’ve got no record of what has been applied.

If another developer wanted to spin up a new cluster with flux 2, they would have to do some manual work again… which just wastes time and can add to more confusion.

Terraform (this is not a sponsored post) allows you to provision infrastructure as code, meaning you can use version control such as Github to share the resources easily and to keep track on what has been done etc.

Right, enough of that tangent!

1. Install ekctl

brew install aws eksctl 

If brew install aws eksctl doesn’t work.

Run:

brew tap weaveworks/tap` — Then \brew install weaveworks/tap/eksctl`

(tap allows homebrew to ‘tap’ into another repository of formulae. Full docs here: https://github.com/Homebrew/brew/blob/master/docs/Taps.md)

Right, now ekctl is installed…

2. You can create the cluster.

I’m assuming you’ve already done (https://docs.aws.amazon.com/cli/latest/reference/configure/)

aws configure

and provided your iam credentials to interact with aws.

manifest -> cluster.yaml

eksctl create cluster -f cluster.yaml

The manifest will create a cluster in London with a t3.small ec2 instance(s). THIS IS AN EXAMPLE NOT PRODUCTION READY.

3. The terraform

IMPORTANT! Note, in order for the terraform to create the pods

flux2/helm etc. You need to give it access/permission to the cluster. See below.

The host and certificate etc, will be automatically pulled from the configured cluster. So, luckily we only need to provide the cluster name!

See full example here:

The required variables can be found here:

If you don’t you will likely receive a similar error to “the server could not find the requested resource (post namespaces)”.

You may have your own Makefile or method etc, but if not you can use this:

Then run

make plan

This will create a plan and let you know what will be created, you can review and if happy you can do the build for terraform to provision the manifests.

make build 

You should now have a cluster with version 1.20 and flux 2.

--

--

Joshua Callis

Converted DevOps Engineer at oso.sh, Previously a Senior Software Engineer.