Automatically manage Kubernetes add-ons with AWS EKS
TypeScriptWhen using Pulumi to manage Kubernetes add-ons with AWS EKS, you're generally going to be dealing with a few specific resources:
-
aws-native.eks.Addon
: This resource is used to represent an EKS add-on that can be automatically managed by EKS. These add-ons can include core components likekube-proxy
,CoreDNS
, and others that are part of the EKS initial setup. -
aws.eks.Cluster
: Represents an EKS Cluster on AWS. This is the foundational resource needed to start deploying managed add-ons onto. -
aws-native.eks.Cluster
: The AWS Native version of the EKS cluster resource. This can also be used to create an EKS cluster, and which one you use (this vsaws.eks.Cluster
) can depend on your preference for AWS Classic or AWS Native Pulumi resources.
For managing Kubernetes add-ons automatically with AWS EKS, we will define an EKS cluster first and then attach add-ons to the cluster. Let's go through the process step-by-step:
-
Define an EKS Cluster: Before you can attach add-ons, you need a running EKS cluster. We will use
aws.eks.Cluster
for this as it is a higher-level component abstracting some of the complexity involved in setting up an EKS cluster. -
Add Kubernetes Add-ons: With the cluster in place, you can use the
aws-native.eks.Addon
to manage add-ons. The EKS service simplifies the process of installing and updating add-ons by providing a managed version that is guaranteed to be compatible with your cluster. -
Resource Dependencies: Pulumi understands resource dependencies and ensures that resources are created in the necessary order. When you define an add-on, you reference the EKS cluster, which tells Pulumi that the cluster must be created before the add-ons can be attached.
Below, you'll find a TypeScript program which sets up an EKS cluster and attaches a managed
kube-proxy
add-on to it. Please ensure you have configured Pulumi with the correct AWS credentials and default region before running it.import * as eks from "@pulumi/eks"; import * as aws from "@pulumi/aws"; // Create an EKS cluster with default settings. // The specific version is important for compatibility with add-ons. const myCluster = new eks.Cluster("myCluster", { version: "1.21", // specify the desired Kubernetes version }); // Define a Kubernetes add-on for 'kube-proxy'. // The 'clusterName' matches the one provided when the EKS cluster was created. const kubeProxyAddon = new aws.eks.Addon("kube-proxy-addon", { addonName: "kube-proxy", clusterName: myCluster.eksCluster.name, addonVersion: "v1.21.2-eksbuild.2", // specify the compatible add-on version }); // Export the cluster's kubeconfig and the add-on's ARN. export const kubeconfig = myCluster.kubeconfig; export const addonArn = kubeProxyAddon.arn;
This program will:
- Establish an EKS cluster called "myCluster".
- Create a
kube-proxy
add-on attached to the cluster.
After running this program with
pulumi up
, you will have an EKS cluster with thekube-proxy
add-on managed by AWS EKS.For more information regarding the resources used above, you can check the Pulumi documentation:
Lastly, remember to destroy your resources with
pulumi destroy
when you no longer need them to avoid unnecessary charges on your AWS bill.-