Building a Kubernetes cluster from scratch is hard, which is why managed services exist. In the previous post I added subnets to a VPC. This post uses that VPC to create an AWS EKS cluster.
The complete project is available on GitHub.
Configuration #
At minimum, you need a cluster name, a Kubernetes version, and an IAM role. Specifying which log types to send to CloudWatch is optional but helpful for debugging. Add this to the YAML file from the previous post:
eks:cluster-name: myEKSCluster
eks:k8s-version: "1.14"
eks:cluster-role-arn: "arn:aws:iam::ACCOUNTID:role/ServiceRoleForAmazonEKS"
eks:cluster-log-types: "api,audit,authenticator,scheduler,controllerManager"You can use the command line (e.g., pulumi config set eks:cluster-name "myEKSCluster") or edit the YAML file directly. The file is named Pulumi.<name of your project>.yaml.
Creating the cluster #
This code extends the previous post. It reads the cluster name and log types from the YAML file, uses the subnets created earlier, and calls eks.NewCluster() to create the EKS cluster in your existing VPC.
// Create an EKS cluster
clusterName := getEnv(ctx, "eks:cluster-name", "unknown")
enabledClusterLogTypes := strings.Split(getEnv(ctx, "eks:cluster-log-types", "unknown"), ",")
clusterArgs := &eks.ClusterArgs{
Name: clusterName,
Version: getEnv(ctx, "eks:k8s-version", "unknown"),
RoleArn: getEnv(ctx, "eks:cluster-role-arn", "unknown"),
Tags: tags,
VpcConfig: subnets,
EnabledClusterLogTypes: enabledClusterLogTypes,
}
cluster, err := eks.NewCluster(ctx, clusterName, clusterArgs)
if err != nil {
fmt.Println(err.Error())
return err
}
ctx.Export("CLUSTER-ID", cluster.ID())Running the code #
Run pulumi up to create the cluster. If you’re using the same project and stack, Pulumi knows the VPC already exists and will only create the EKS cluster. Fair warning: this can take a while. In my case it was almost 10 minutes.
$ pulumi up
Previewing update (builderstack):
Type Name Plan
pulumi:pulumi:Stack builder-builderstack
+ └─ aws:eks:Cluster myEKSCluster create
Outputs:
+ CLUSTER-ID: output<string>
Resources:
+ 1 to create
4 unchanged
Do you want to perform this update? yes
Updating (builderstack):
Type Name Status
pulumi:pulumi:Stack builder-builderstack
+ └─ aws:eks:Cluster myEKSCluster created
Outputs:
+ CLUSTER-ID: "myEKSCluster"
SUBNET-IDS: [
[0]: "subnet-<id>"
[1]: "subnet-<id>"
]
VPC-ID : "vpc-<id>"
Resources:
+ 1 created
4 unchanged
Duration: 9m55s
Permalink: https://app.pulumi.com/retgits/builder/builderstack/updates/3The 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