Pulumi EKS Components

4.2.0 · active · verified Fri Apr 17

Pulumi EKS (Elastic Kubernetes Service) is a component package for provisioning and managing Amazon EKS clusters and their associated resources (VPC, IAM, Node Groups, Fargate profiles, etc.) using Python, TypeScript, Go, or C#. It simplifies EKS cluster deployment by encapsulating common patterns and best practices. The current version is 4.2.0, with frequent updates that often reflect changes in the underlying Pulumi AWS provider.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart deploys a basic EKS cluster with two `t2.medium` worker nodes. It creates the necessary IAM roles and, by default, a new VPC and public subnets. Ensure your AWS credentials are configured and your AWS region is set via `pulumi config set aws:region <region-name>` or environment variables.

import pulumi
import pulumi_aws as aws
import pulumi_eks as eks
import os

# Ensure AWS region is configured.
# For a project, use `pulumi config set aws:region us-west-2`.
# For this quickstart to run, ensure AWS_REGION or AWS_DEFAULT_REGION env var is set,
# or you have a default region configured in your AWS credentials file.
if not pulumi.Config("aws").get("region") and not os.environ.get('AWS_REGION') and not os.environ.get('AWS_DEFAULT_REGION'):
    raise Exception("AWS region must be configured via `pulumi config set aws:region <region-name>` or environment variables.")

# Create an IAM role for the EKS Cluster and Node Groups.
# This role grants permissions for EKS to manage resources and for nodes to join the cluster.
eks_cluster_role = aws.iam.Role("eks-cluster-role",
    assume_role_policy=aws.iam.get_policy_document(
        statements=[aws.iam.GetPolicyDocumentStatementArgs(
            actions=["sts:AssumeRole"],
            principals=[aws.iam.GetPolicyDocumentStatementPrincipalArgs(
                type="Service",
                identifiers=["eks.amazonaws.com"],
            )],
        )]
    ).json
)

aws.iam.RolePolicyAttachment("eks-cluster-policy",
    role=eks_cluster_role.name,
    policy_arn="arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
)
aws.iam.RolePolicyAttachment("eks-vpc-cni-policy",
    role=eks_cluster_role.name,
    policy_arn="arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
)

# Create the EKS cluster.
# By omitting `vpc_id` and `subnet_ids`, pulumi-eks will create a new VPC and public subnets.
cluster = eks.Cluster("my-eks-cluster",
    role_arn=eks_cluster_role.arn,
    instance_type="t2.medium", # Default instance type for worker nodes
    desired_capacity=2,
    min_size=1,
    max_size=3,
    version="1.28" # Explicitly pin EKS Kubernetes version
)

# Export the cluster's name and kubeconfig
pulumi.export("cluster_name", cluster.name)
pulumi.export("kubeconfig", cluster.kubeconfig)

view raw JSON →