This page is generated from skills/eks-build/references/lessons-learned.md. Edit the source, not this page.
Lessons Learned: EKS Deployment Patterns
Table of Contents
- 1. before_compute Is Mandatory
- 2. Two-Phase Module Architecture
- 3. Addon Version Pinning
- 4. Multus CNI Is BROKEN
- 5. Kyverno Gotchas
- 6. ArgoCD EKS Capability
- 7. GitOps Bridge Pattern
- 8. IRSA vs Pod Identity
- 9. Velero Configuration
- 10. ACK and KRO
- 11. Deployment Order
- 12. Use HashiCorp Terraform, NOT OpenTofu
- 13. Terraform Operational Notes
- 14. Automated Validation Findings
- 15. Pod Identity Destroy Ordering
- 16. EFS CSI Driver Operational Notes
- 17. Karpenter Dedicated Submodule
- 18. Pod Identity IAM Policy Name Collision
- 19. ArgoCD Namespace Race Condition
- 20. EKS Capability Destroy Hangs Terraform
- 21. CIS Policies Cannot Be Deployed as Helm Chart
- 22. Pattern 2a Custom-Addons Require Real Git Repo
- 23. Karpenter Controller IAM Policy Size Limit
- 24. kubectl Provider Fails at Plan From Empty
Consolidated findings from two EKS deployment patterns:
- Pattern 1 (terraform-eks): Full Terraform with eks-blueprints-addons, two-phase module architecture
- Pattern 2 (argocd-eks): ArgoCD EKS Capability + ACK + GitOps Bridge
1. before_compute Is Mandatory
Patterns: Both
vpc-cni and eks-pod-identity-agent MUST have before_compute: true. Without it, EKS managed addons and node groups are created in parallel. Nodes finish before the CNI installs, fail health checks with NodeCreationFailure: NetworkPluginNotReady, and stay NotReady.
eks_addons:
vpc-cni:
most_recent: true
before_compute: true
eks-pod-identity-agent:
most_recent: true
before_compute: true
State migration note: Adding before_compute: true to an existing addon moves the Terraform resource key. Use terraform import for in-place migration, or do a clean destroy+apply cycle.
2. Two-Phase Module Architecture
Patterns: Pattern 1 only
Problem
LBC and Gatekeeper register webhooks with failurePolicy: Fail before their pods have ready endpoints. The single eks-blueprints-addons module deploys all Helm releases in parallel. Other addons hit these webhooks and get rejected.
Why wait: true alone fails
wait: true only blocks when Terraform marks that resource as done. It does NOT prevent sibling helm_release resources in the same module from starting simultaneously.
Fix
Split into two module calls:
- Phase 1 (
module.eks_addons_webhooks): LBC + Gatekeeper only, withwait: true - Phase 2 (
module.eks_addons): Everything else, withdepends_on = [module.eks_addons_webhooks]
Phase 1 also needs depends_on = [module.eks_cluster] so all EKS managed addons are ACTIVE before any Helm release starts.
Trade-off
The module graph is instantiated twice, but with HashiCorp Terraform v1.14.5, plan still completes in under 2 minutes. Do NOT use OpenTofu -- see Section 12.
3. Addon Version Pinning
Patterns: Both
Module defaults are stale
The eks-blueprints-addons module ships chart defaults that lag significantly behind current releases. Always look up the latest versions from authoritative sources (see version-matrix.md).
Rules
- ALWAYS override chart versions from config YAML; never rely on module defaults
- Versions pinned at plan time go stale by deployment day. Re-verify before every apply.
- cluster-autoscaler image.tag MUST match EKS K8s minor version
- LBC requires explicit vpcId -- IMDS fallback fails with hop-limit restrictions
4. Multus CNI Is BROKEN
Patterns: Both (currently DISABLED)
- Thick-plugin pod-lookup race: Multus queries the K8s API for pod metadata before the pod is registered. ALL new pod creation fails.
- Impact: Existing pods survive, but no new pods can start anywhere in the cluster.
Recovery (if accidentally enabled)
- SSM to all nodes:
rm -f /etc/cni/net.d/00-multus.conf - Delete DaemonSet:
kubectl delete ds kube-multus-ds -n kube-system - Restart stuck pods, disable in config, re-apply
Do not enable until upstream fixes the thick-plugin race.
5. Kyverno Gotchas
Patterns: Both
Webhook blocks other addons
During install/upgrade, Kyverno's validating webhook has no endpoints while pods start. This blocks pod creation for other addons. If a deployment gets stuck, wait for Kyverno to stabilize, then kubectl rollout restart the stuck deployment.
TLS cert incompatibility on major version upgrades
Fix: delete ALL secrets AND all pods in the kyverno namespace simultaneously:
kubectl delete secrets --all -n kyverno && kubectl delete pods --all -n kyverno
ArgoCD sync strategy (Pattern 2)
Use Replace=true syncOption, NOT ServerSideApply=true. SSA conflicts with selfHeal: true + --force.
6. ArgoCD EKS Capability
Patterns: Pattern 2 only
- Fully managed external service -- no pods in the cluster.
- ArgoCD CRDs are installed automatically; ApplicationSets are applied via
kubectl apply. - Use cluster ARN as the destination server (not
https://kubernetes.default.svc). - AppProjects need
sourceNamespaces: [argocd].
Go templates
missingkey=zerois essential. Without it, any missing annotation fails the entire ApplicationSet.- Use
index .metadata.annotations "key-name"for keys with dots or hyphens.
7. GitOps Bridge Pattern
Patterns: Pattern 2 only
Terraform writes cluster metadata to a K8s Secret annotated with argocd.argoproj.io/secret-type: cluster. ArgoCD's clusters generator reads these annotations and exposes them as template variables in ApplicationSets.
eks-blueprints-addonsprovidesgitops_metadataoutput with all IRSA ARNs, SA names, and namespaces.- Annotation keys use module-specific names (e.g.,
cluster_autoscaler_iam_role_arn). Always check the module'sgitops_metadataoutput for exact key names.
8. IRSA vs Pod Identity
Patterns: Both
| Feature | IRSA | Pod Identity |
|---|---|---|
| Trust policy | OIDC provider URL required | Service: pods.eks.amazonaws.com |
| SA annotation | eks.amazonaws.com/role-arn required | Not needed |
| Session tagging | Not supported | Auto-tags (cluster, namespace, SA) |
| Prerequisites | OIDC provider | eks-pod-identity-agent addon |
- Pod Identity is preferred for new workloads (simpler, better auditing).
- EKS managed addons: use Pod Identity with separate
aws_eks_pod_identity_associationresources, except EBS CSI (addon-catalog.md) -- see Section 15. - Helm-based addons (LBC, External DNS, Velero): IRSA via eks-blueprints-addons.
- Karpenter: Pod Identity via dedicated submodule -- see Section 17.
- When both are configured for the same SA, Pod Identity takes precedence.
9. Velero Configuration
Patterns: Both
Three-part config: S3 bucket + auth (IRSA or Pod Identity) + Helm chart.
| Setting | Value | Reason |
|---|---|---|
credentials.useSecret | false | When using Pod Identity or IRSA |
s3_backup_location | S3 bucket ARN | Required for IRSA policy |
CRD name collision
ACK DynamoDB controller installs a Backup CRD that conflicts with Velero's. Always use the full API group: backup.velero.io.
10. ACK and KRO
Patterns: Both
ACK
- EKS Capability: no pods in cluster. Creates and reconciles AWS resources from K8s CRs.
- Field naming follows AWS SDK Go convention:
blockPublicACLs(notblockPublicAcls). Always verify against the installed CRD schema. - Use
services.k8s.aws/deletion-policy=retainwhen migrating from ACK-managed to Terraform-managed resources.
KRO
- EKS Capability available but the controller may not reconcile new
ResourceGraphDefinitionresources in all cases. RGDs may stayInactive. - Workaround: Use ACK resources directly instead of KRO orchestration if RGDs are not activating.
11. Deployment Order
Patterns: Pattern 2
1. terraform apply (cluster, IAM, capabilities, GitOps Bridge secret)
2. kubectl apply argocd-projects.yaml
3. kubectl apply addons applicationset.yaml
4. kubectl apply custom-addons applicationset.yaml
5. kubectl apply tenants applicationset.yaml
For Pattern 1, a single terraform apply handles everything (two-phase module architecture manages internal ordering). For a first deploy into an empty account, a plan from empty passes with lazy_load = true on the kubectl provider (Section 24). Do not split the first deploy with -target: a targeted first step can create an add-on without its separate Pod Identity association (seen with EBS CSI before its role moved into the add-on entry; addon-catalog.md).
12. Use HashiCorp Terraform, NOT OpenTofu
Patterns: Both
Problem
OpenTofu v1.10.6 has a severe performance regression with depends_on module graphs. The two-phase module architecture causes tofu plan to take 30+ minutes (vs < 2 min with Terraform v1.14.5).
Evidence
| Binary | Version | Plan time (113 resources) | CPU |
|---|---|---|---|
| OpenTofu | v1.10.6 | 30+ min | 145-177% |
| Terraform | v1.14.5 | < 2 min | Normal |
Fix
- Use HashiCorp Terraform v1.14.5+
- Verify:
terraform --versionmust showTerraform v1.x.x, NOTOpenTofu - Common gotcha: macOS Homebrew aliases
terraformtotofu. Fix withbrew install hashicorp/tap/terraform && brew link --overwrite terraform - After switching: run
terraform init -reconfigure -upgradeto re-register providers
13. Terraform Operational Notes
Patterns: Both
depends_on vs implicit references
module.eks_cluster.cluster_name -> waits only for the cluster resource
depends_on = [module.eks_cluster] -> waits for ALL resources in the module
wait: true scope
Within a single module, wait: true on one helm_release does NOT delay sibling helm_release resources. Ordering requires separate module calls with depends_on.
Deployment Timing (HashiCorp Terraform v1.14.5)
Pattern 1: Full Terraform
| Phase | Duration |
|---|---|
terraform plan | < 2 min |
terraform apply (total) | ~18 min |
| -- EKS cluster creation | ~9 min |
| -- Node group creation | ~2 min |
| -- Phase 1 (LBC + Gatekeeper) | ~3 min |
| -- Phase 2 (all other addons) | ~4 min |
terraform destroy | ~10 min |
Pattern 2: ArgoCD + Terraform
| Phase | Duration |
|---|---|
terraform apply (total) | ~16 min |
| -- EKS cluster creation | ~10 min |
| -- ArgoCD EKS Capability | ~5 min |
| -- Remaining (IAM, GitOps Bridge) | ~1 min |
| ArgoCD auto-sync | ~5 min |
terraform destroy | ~15 min |
14. Automated Validation Findings
Patterns: Both
GuardDuty addon auto-installed
AWS auto-installs aws-guardduty-agent when GuardDuty EKS Runtime Monitoring is enabled. Not managed by Terraform. Expect 5 or 6 managed addons depending on GuardDuty config.
ACK S3 bucket re-deploy handling (Pattern 2)
When running destroy/apply cycles, ACK S3 buckets may persist. On re-deploy, ACK enters ACK.Terminal with Resource already exists.
Fix: Delete the pre-existing bucket before re-deploy:
aws s3 rb s3://<CLUSTER_NAME>-velero-backups-<ACCOUNT_ID> --force
LBC webhook TLS CA mismatch (Pattern 2) -- ~20% recurrence rate
The LBC Helm chart uses genCA/genSignedCert. ArgoCD's partial sync can regenerate CA and cert independently, causing caBundle mismatch.
Fix: Delete stuck ArgoCD apps -- ApplicationSet recreates them:
kubectl delete application aws-load-balancer-controller gatekeeper -n argocd
external-secrets startup latency
The cert-controller and webhook pods show 0/1 Ready for ~90 seconds. This is normal startup behavior during initial certificate generation.
15. Pod Identity Destroy Ordering
Patterns: Pattern 1
Problem
When Pod Identity IAM roles are created by separate modules and role ARNs are passed to the EKS addon config, terraform destroy may delete IAM roles before the addons that reference them. Through the terraform-aws-modules/eks addons map this does not happen: the add-on depends on the role through that input, so destroy removes the add-on first. Separate associations stay the convention for every add-on but EBS CSI.
Fix
Create Pod Identity associations as separate aws_eks_pod_identity_association resources:
resource "aws_eks_pod_identity_association" "efs_csi" {
cluster_name = module.eks_cluster.cluster_name
namespace = "kube-system"
service_account = "efs-csi-controller-sa"
role_arn = module.efs_csi_pod_identity.iam_role_arn # example: a role module shaped like ebs_csi_pod_identity (addon-catalog.md)
}
Destroy: the separate association goes before its role. EBS CSI is the exception: its role goes in the add-on entry's pod_identity_association, so EKS creates the association with the add-on (addon-catalog.md). Create order: role -> addon with its association. For EBS CSI the module's preserve defaults to true, so removing only the add-on leaves its association; a full destroy removes it with the cluster.
16. EFS CSI Driver Operational Notes
Patterns: Both
DNS propagation delay
After creating EFS mount targets, DNS resolution takes ~5 minutes to propagate. Pods mounting EFS immediately will fail with Failed to resolve.
Security groups
EFS mount targets must allow NFS (TCP 2049) inbound from the node security group.
TLS on arm64
The efs-proxy binary does not work reliably on arm64 Karpenter-provisioned nodes. Workaround: use nodeSelector: kubernetes.io/arch: amd64 for pods that require EFS TLS.
EFS access points
Non-root containers cannot write to root-owned EFS directories. Create an EFS access point with PosixUser and CreationInfo set to the container's uid/gid.
17. Karpenter Dedicated Submodule
Patterns: Both (validated)
Why not eks-blueprints-addons
The eks-blueprints-addons Karpenter integration has issues: stale chart default, missing CRDs, deprecated settings keys.
Recommended approach
Use terraform-aws-modules/eks/aws//modules/karpenter:
module "karpenter" {
source = "terraform-aws-modules/eks/aws//modules/karpenter"
version = "<LOOK_UP>" # Look up latest from Terraform Registry
cluster_name = module.eks_cluster.cluster_name
enable_inline_policy = true # controller policy can exceed the 6,144-character managed policy limit (Section 23)
create_pod_identity_association = true
node_iam_role_use_name_prefix = false
node_iam_role_name = "${local.cluster_config.name}-karpenter-node"
node_iam_role_additional_policies = {
AmazonSSMManagedInstanceCore = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
iam_role_permissions_boundary_arn = try(local.cluster_config.permissions_boundary, null) # only if the customer named this role in question 30
node_iam_role_permissions_boundary = try(local.cluster_config.permissions_boundary, null) # only if the customer named this role in question 30
tags = local.tags
}
In Pattern 1, then deploy the Helm chart via helm_release with depends_on = [module.eks_addons_webhooks] (Section 2) and NodePool/EC2NodeClass via kubectl_manifest; in Pattern 2 via ArgoCD. Tag private subnets and the node security group (the EKS module's node_security_group_tags, not the cluster primary SG) with karpenter.sh/discovery: <cluster-name>; only one security group should carry the tag, because Karpenter attaches every security group that matches its selector, and two security groups tagged kubernetes.io/cluster/<name> on one node break the AWS Load Balancer Controller.
EC2 Spot Service-Linked Role
Karpenter needs AWSServiceRoleForEC2Spot. Create before deploying:
aws iam create-service-linked-role --aws-service-name spot.amazonaws.com
Stale public.ecr.aws login (403)
Pattern: 1 (Terraform helm_release. Pattern 2 pulls the chart through ArgoCD)
The Karpenter chart is public, so an anonymous pull works, but only while the machine running Terraform has no public.ecr.aws entry in its Helm registry config or Docker config. An earlier helm registry login or docker login public.ecr.aws leaves a token that lasts 12 hours; once it expires, Helm sends it instead of pulling anonymously and terraform plan (the helm provider locates the chart while planning) or apply fails:
Unable to locate chart oci://public.ecr.aws/karpenter/karpenter: ... response status code 403: denied: Your authorization token has expired. Reauthenticate and try again.
Fix: log the helm provider in with a fresh token on every run (helm provider 3.x list syntax; 2.x used a registry { } block). The ephemeral resource needs Terraform 1.10+ and hashicorp/aws >= 6.31.0, so not terraform-aws-modules/eks v20, which caps aws < 6.0:
ephemeral "aws_ecrpublic_authorization_token" "public_ecr" {
region = "us-east-1" # ECR Public issues tokens in us-east-1 only, whatever the cluster region
}
provider "helm" {
registries = [
{
url = "oci://public.ecr.aws"
username = ephemeral.aws_ecrpublic_authorization_token.public_ecr.user_name
password = ephemeral.aws_ecrpublic_authorization_token.public_ecr.password
}
]
kubernetes = {
# as generated in providers.tf
}
}
The provider login also writes this token to Helm's default registry config (the path helm env HELM_REGISTRY_CONFIG prints), even when registry_config_path is set, so other Helm pulls from public.ecr.aws on that machine can hit the same 403 after 12 hours; recover with the logout below.
- Prefer the ephemeral resource. Below hashicorp/aws 6.31.0 use the
data "aws_ecrpublic_authorization_token"form in the sameregistrieslist (on aws 5.x, which has noregionargument, through aus-east-1provider alias); its token is stored in state (and in a saved plan, so applying a saved plan can reuse it past its 12 hours). Do not use resource-levelrepository_username/repository_password:repository_passwordis stored in state and cannot take an ephemeral value. - The identity running Terraform needs
ecr-public:GetAuthorizationTokenandsts:GetServiceBearerToken. - Partitions without ECR Public, and air-gapped builds, mirror the chart instead: see customization-guide.md Section 1 (pull-through cache rule for
public.ecr.aws, Helm chart mirroring). There, drop this block; a private-ECR chart mirror needs its own registry login (ephemeral "aws_ecr_authorization_token"). - One-off recovery outside Terraform:
helm registry logout public.ecr.aws(anddocker logout public.ecr.aws).
18. Pod Identity IAM Policy Name Collision
Patterns: Both
Problem
The terraform-aws-modules/eks-pod-identity/aws module creates IAM policies with hardcoded default names. Multiple projects in the same account collide.
Fix
Always set a cluster-prefixed policy name:
module "ebs_csi_pod_identity" {
source = "terraform-aws-modules/eks-pod-identity/aws"
version = "<LOOK_UP>" # Look up latest from Terraform Registry
name = "${local.cluster_config.name}-ebs-csi"
use_name_prefix = false
attach_aws_ebs_csi_policy = true
aws_ebs_csi_policy_name = "${local.cluster_config.name}-EBS_CSI"
permissions_boundary_arn = try(local.cluster_config.permissions_boundary, null) # only if the customer named this role in question 30
tags = local.tags
}
| Addon | Parameter | Example |
|---|---|---|
| EBS CSI | aws_ebs_csi_policy_name | "${local.cluster_config.name}-EBS_CSI" |
| EFS CSI | aws_efs_csi_policy_name | "${local.cluster_config.name}-EFS_CSI" |
| FSx CSI | aws_fsx_lustre_csi_policy_name | "${local.cluster_config.name}-FSx_Lustre_CSI" |
19. ArgoCD Namespace Race Condition
Patterns: Pattern 2a
Problem
The ArgoCD EKS Capability creates the argocd namespace asynchronously. If the GitOps Bridge secret creation races it, the apply fails.
Fix
Make the namespace resource conditional -- only create when ArgoCD capability is disabled:
resource "kubernetes_namespace_v1" "argocd" {
count = local.argocd_idc_enabled ? 0 : 1
metadata { name = local.argocd_namespace }
depends_on = [module.eks_cluster]
}
20. EKS Capability Destroy Hangs Terraform
Patterns: All patterns using EKS Capabilities
Problem: The provider's delete operation for capabilities hangs indefinitely during terraform destroy.
Fix: Add a null_resource with destroy-time provisioner that deletes capabilities via the EKS API before Terraform attempts deletion. Include sleep 180 for ArgoCD capability deletion time.
Workaround: Stop the hung terraform destroy first: interrupt it once (Ctrl-C or SIGINT) and wait for it to exit. List the capabilities and show them to the user with the intent to destroy; if the user declines any capability, stop, since the destroy removes the cluster it runs on. Deleting a capability "removes the capability infrastructure but retains all resources that were managed by the capability", so ask the user whether to delete or keep the Kubernetes resources each capability manages (for ACK, deleting them deletes the AWS resources by default), and do that before you delete the capability. Wait until the deleted capabilities are no longer listed, remove only the aws_eks_capability resources from state, then show the destroy plan and apply it only after the user approves it:
aws eks list-capabilities --cluster-name <cluster> --query 'capabilities[].[capabilityName,status]' --output text # show the user, get their yes
aws eks delete-capability --cluster-name <cluster> --capability-name <name> # only the names the user approved
aws eks list-capabilities --cluster-name <cluster> --query 'capabilities[].[capabilityName,status]' --output text # repeat until they are gone; on DELETE_FAILED stop and report it to the user
terraform state list | grep -E '(^|\.)aws_eks_capability\.' | xargs -I{} terraform state rm {}
terraform plan -destroy -out=destroy.tfplan
terraform apply destroy.tfplan # only after the user approves the plan above
21. CIS Policies Cannot Be Deployed as Helm Chart
Patterns: Pattern 2a, 2b
Problem: Kyverno CIS policies use JMESPath {{ }} delimiters that Helm interprets as Go templates.
Fix: Deploy via kubectl_manifest resources in the custom-addons Terraform module.
22. Pattern 2a Custom-Addons Require Real Git Repo
Patterns: Pattern 2a
Problem: Custom-addons ApplicationSets use ArgoCD's git directory generator, which requires a real, accessible git repository URL.
Fix: For resources needed at deploy time (Velero S3, CIS policies), create them in Terraform rather than relying on ArgoCD custom-addons.
23. Karpenter Controller IAM Policy Size Limit
Patterns: Both
Problem: The controller IAM policy that the terraform-aws-modules/eks/aws//modules/karpenter submodule generates (Section 17) can exceed the 6,144-character limit on a customer managed policy (IAM does not count white space). Apply then fails with LimitExceeded: Cannot exceed quota for PolicySize: 6144.
Fix: Set enable_inline_policy = true on the submodule (available since v21.8.0). The controller policy is then created as an inline role policy, whose limit is 10,240 characters across all inline policies on the role. Upstream Karpenter has split its controller policy into several policies (aws/karpenter-provider-aws PR 8690), but the submodule does not follow that split yet (terraform-aws-modules/terraform-aws-eks issue 3637 is open, checked 2026-10-30), so the inline policy is the mitigation until it does.
24. kubectl Provider Fails at Plan From Empty
Patterns: Pattern 1
Problem: The first terraform plan into an empty account fails with Error: kubectl provider: configure failed ... no configuration has been provided, try setting KUBERNETES_MASTER environment variable. The alekc/kubectl provider (since v2.3.0) builds its client at configure time, and host and the CA come from the cluster module's outputs, which are unknown until the cluster exists. load_config_file = false does not help.
Fix: Set lazy_load = true in the kubectl provider block in providers.tf. The client is then built on first use, and a plan from an empty account passes. The trade-off: a wrong host or token shows up as a less specific error at the first kubectl_manifest, not at configure.
provider "kubectl" {
host = module.eks_cluster.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks_cluster.cluster_certificate_authority_data)
load_config_file = false
lazy_load = true # host and CA are unknown until the cluster exists
exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
args = ["eks", "get-token", "--cluster-name", module.eks_cluster.cluster_name, "--region", local.region]
}
}