### Basic Karpenter Setup Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/spot-interruption-handling.md Configure the Karpenter module with essential parameters for EKS integration and interruption handling. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = "my-cluster" namespace = "karpenter" queue_interruption_prefix = "interruption-queue" rule_interruption_prefix = "Karpenter" cluster_identity_oidc_issuer = "https://oidc.eks.region.amazonaws.com/id/XXXXX" cluster_identity_oidc_issuer_arn = "arn:aws:iam::ACCOUNT:oidc-provider/oidc.eks.region.amazonaws.com/id/XXXXX" } ``` -------------------------------- ### Development Setup Configuration Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Example Terraform configuration for a development Karpenter setup with lower resource requests. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true namespace = "karpenter" cluster_identity_oidc_issuer = data.aws_eks_cluster.this.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn cluster_name = aws_eks_cluster.this.name settings = { logLevel = "debug" } values = yamlencode({ controller = { replicas = 1 resources = { requests = { cpu = "100m" memory = "128Mi" } } } }) } ``` -------------------------------- ### Terraform Plan Output Example Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/deployment-methods.md This example shows the expected output during a `terraform plan` when using the ArgoCD/Helm deployment. It confirms that the plan succeeds without requiring cluster API access and indicates that a Helm release containing the Application manifest will be created or updated. ```bash $ terraform plan # Succeeds without requiring cluster API access # Creates/updates Helm release containing Application manifest # Outputs: # - Helm release will be created/updated # - Application manifest template shown ``` -------------------------------- ### Production Setup Configuration Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Example Terraform configuration for a production Karpenter setup, including resource requests/limits and pod anti-affinity. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true namespace = "karpenter" cluster_identity_oidc_issuer = data.aws_eks_cluster.this.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn cluster_name = aws_eks_cluster.this.name settings = { logLevel = "info" } values = yamlencode({ controller = { replicas = 3 resources = { requests = { cpu = "500m" memory = "512Mi" } limits = { cpu = "1000m" memory = "1Gi" } } affinity = { podAntiAffinity = { requiredDuringSchedulingIgnoredDuringExecution = [ { labelSelector = { matchExpressions = [ { key = "app.kubernetes.io/name" operator = "In" values = ["karpenter"] } ] } topologyKey = "kubernetes.io/hostname" } ] } } } serviceMonitor = { enabled = true } }) irsa_tags = { Environment = "production" CostCenter = "platform" } } ``` -------------------------------- ### Multi-Controller Setup Configuration Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Example Terraform configuration for setting up multiple Karpenter controllers, leveraging internal leader election. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true namespace = "karpenter" # ... cluster and IRSA config ... values = yamlencode({ controller = { replicas = 2 # Both controllers will watch the same cluster # Karpenter uses leader election internally } webhook = { enabled = true port = 8443 } }) } ``` -------------------------------- ### ArgoCD/Helm Setup for Karpenter (Recommended) Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Deploy Karpenter via ArgoCD using the Helm provider. This method does not require plan-time API access. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true argo_enabled = true argo_helm_enabled = true cluster_name = aws_eks_cluster.main.name cluster_identity_oidc_issuer = aws_eks_cluster.main.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn namespace = "karpenter" argo_namespace = "argocd" argo_sync_policy = { automated = { prune = true selfHeal = true } syncOptions = [ "CreateNamespace=true" ] } } ``` -------------------------------- ### Standard IRSA Setup with Automatic Policies Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Configure Karpenter with automatic IAM role creation and default policy attachment. Set `irsa_role_create` and `irsa_policy_enabled` to true. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = aws_eks_cluster.main.name cluster_identity_oidc_issuer = aws_eks_cluster.main.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn namespace = "karpenter" # IRSA configuration (defaults) irsa_role_create = true irsa_role_name_prefix = "karpenter" service_account_create = true service_account_name = "karpenter" # Automatic policy creation irsa_policy_enabled = true # Creates default policies } ``` -------------------------------- ### Minimal Karpenter Setup with Helm Direct Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Deploy Karpenter to an existing EKS cluster with default settings using Helm. Outputs the Karpenter role ARN for reference. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = aws_eks_cluster.main.name cluster_identity_oidc_issuer = aws_eks_cluster.main.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn namespace = "karpenter" } # Output the role ARN for reference output "karpenter_role_arn" { value = module.karpenter.addon_irsa["karpenter"].iam_role_arn } ``` -------------------------------- ### ArgoCD/Kubernetes Setup for Karpenter Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Deploy Karpenter via ArgoCD using the Kubernetes provider. This method requires API access at plan time. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true argo_enabled = true argo_helm_enabled = false cluster_name = aws_eks_cluster.main.name cluster_identity_oidc_issuer = aws_eks_cluster.main.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn namespace = "karpenter" argo_namespace = "argocd" argo_sync_policy = { automated = {} } } ``` -------------------------------- ### Deep Merge Example Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Demonstrates how module defaults and user values are deep merged to produce a final configuration. The `memory` request is retained while `cpu` is added. ```yaml controller: replicas: 1 resources: requests: memory: "256Mi" ``` ```yaml controller: resources: requests: cpu: "100m" ``` ```yaml controller: replicas: 1 resources: requests: cpu: "100m" memory: "256Mi" ``` -------------------------------- ### Custom Webhook Configuration Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Example Terraform configuration for customizing the Karpenter webhook, including CA bundle and cert-manager integration. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" # ... cluster config ... values = yamlencode({ webhook = { enabled = true port = 8443 caBundle = base64encode(file("/path/to/ca.crt")) certManager = { enabled = true } } }) } ``` -------------------------------- ### Custom IRSA Role Setup Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Use an existing or custom-defined IAM role for Karpenter. Set `irsa_role_create` and `irsa_policy_enabled` to false and ensure the `aws_iam_role` and `aws_iam_role_policy_attachment` resources are correctly configured. ```hcl resource "aws_iam_role" "karpenter_custom" { name = "my-custom-karpenter-role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Effect = "Allow" Principal = { Federated = var.oidc_provider_arn } Action = "sts:AssumeRoleWithWebIdentity" Condition = { StringEquals = { "${replace(var.oidc_provider_url, "https://", "")}:sub" = "system:serviceaccount:karpenter:karpenter" } } } ] }) } resource "aws_iam_role_policy_attachment" "karpenter_custom" { role = aws_iam_role.karpenter_custom.name policy_arn = aws_iam_policy.karpenter_custom.arn } module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = aws_eks_cluster.main.name cluster_identity_oidc_issuer = aws_eks_cluster.main.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn namespace = "karpenter" # Use existing role irsa_role_create = false irsa_policy_enabled = false } ``` -------------------------------- ### IAM Policies Naming Convention Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/terraform-resources.md Provides examples of the naming convention for IAM policies. This is helpful for security auditing and for understanding the purpose of different IAM policies attached to Karpenter. ```plaintext karpenter-{policy_type}-{random_suffix} Examples: - karpenter-node-lifecycle-x1y2z3 - karpenter-resource-discovery-a1b2c3 ``` -------------------------------- ### Verify Karpenter CRDs Installation Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Use `kubectl` to list all Custom Resource Definitions and filter for those related to Karpenter. This command verifies that the necessary CRDs for Karpenter to function are present on the cluster. ```bash # Verify CRDs were installed kubectl get crd | grep karpenter # Should show: # - ec2nodeclasses.karpenter.sh # - nodepools.karpenter.sh # - nodeclaims.karpenter.sh # etc. ``` -------------------------------- ### Configure Production Environment for Karpenter with Terraform Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Implement a high-availability setup for Karpenter in a production environment. This configuration includes multiple controller replicas, defined resource requests and limits, pod anti-affinity for scheduling, and enables the ServiceMonitor for Prometheus integration. ```hcl module "karpenter_prod" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = aws_eks_cluster.prod.name namespace = "karpenter" settings = { logLevel = "info" } values = yamlencode({ controller = { replicas = 3 resources = { requests = { cpu = "500m" memory = "512Mi" } limits = { cpu = "2000m" memory = "2Gi" } } affinity = { podAntiAffinity = { requiredDuringSchedulingIgnoredDuringExecution = [ { labelSelector = { matchExpressions = [ { key = "app.kubernetes.io/name" operator = "In" values = ["karpenter"] } ] } topologyKey = "kubernetes.io/hostname" } ] } } } serviceMonitor = { enabled = true } }) irsa_tags = { Environment = "prod" CostCenter = "platform" } } ``` -------------------------------- ### Access Karpenter CRDs Installation Status Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Output the status of the Karpenter CRD Helm release. This helps in verifying if the Custom Resource Definitions have been successfully installed on the cluster. ```hcl output "karpenter_crds_status" { value = module.karpenter.crds.status } ``` -------------------------------- ### Checking Kubernetes CRDs Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Confirm that Karpenter Custom Resource Definitions (CRDs) are installed in your Kubernetes cluster. ```bash kubectl get crd | grep karpenter ``` -------------------------------- ### Passing User Credentials for Private Helm Repositories Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Illustrates how to pass username and password for authentication with private Helm repositories. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" helm_repo_url = "https://myregistry.example.com/karpenter" helm_repo_username = var.helm_repo_username helm_repo_password = var.helm_repo_password } ``` -------------------------------- ### ArgoCD/Helm Karpenter Configuration (CI/CD) Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Recommended configuration for CI/CD pipelines using ArgoCD and Helm. Enables automated synchronization policies. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true argo_enabled = true argo_helm_enabled = true cluster_name = var.cluster_name cluster_identity_oidc_issuer = var.oidc_issuer cluster_identity_oidc_issuer_arn = var.oidc_arn namespace = "karpenter" argo_namespace = "argocd" argo_sync_policy = { automated = {} } } ``` -------------------------------- ### Access Karpenter CRDs Chart Version Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Output the version of the Karpenter CRD Helm chart that was installed. This is useful for tracking the deployed version and for troubleshooting. ```hcl output "karpenter_crds_version" { value = module.karpenter.crds.version } ``` -------------------------------- ### Deploy Karpenter via ArgoCD using Helm Provider Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/module-overview.md Recommended for CI/CD, this method deploys the ArgoCD Application manifest using the Helm provider. It does not require API access at plan time. Ensure argo_enabled and argo_helm_enabled are set to true. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true argo_enabled = true argo_helm_enabled = true argo_sync_policy = { automated = {} } } ``` -------------------------------- ### Combined Usage of settings and values Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Shows how to use both `settings` for simple overrides and `values` for complex nested structures, with `values` being YAML encoded. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" # Direct map for simple overrides settings = { logLevel = "debug" } # YAML for complex nested structures values = yamlencode({ affinity = { ... } resources = { ... } }) } ``` -------------------------------- ### Save and Validate Karpenter Manifests Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Demonstrates how to save the outputted Karpenter manifests to a file and perform a dry-run validation using kubectl. ```bash # In separate script, save and validate: # echo "${output.karpenter_manifests}" > karpenter.yaml # kubectl apply -f karpenter.yaml --dry-run=client ``` -------------------------------- ### Terraform Apply with Environment Variables Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Apply Terraform configurations using environment-specific variable files. ```bash terraform apply -var-file=environments/prod.tfvars ``` -------------------------------- ### Minimal Karpenter Configuration (Helm) Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Use this minimal configuration when deploying Karpenter with Helm for basic functionality. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" cluster_name = var.cluster_name cluster_identity_oidc_issuer = var.oidc_issuer cluster_identity_oidc_issuer_arn = var.oidc_arn namespace = "karpenter" } ``` -------------------------------- ### Get AWS Caller Identity Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/terraform-resources.md Retrieves the current AWS account ID, ARN, and user ID. Use this when you need to reference the executing AWS principal's information within your Terraform configuration. ```hcl data "aws_caller_identity" "this" { count = var.enabled ? 1 : 0 } ``` ```hcl output "aws_account_id" { value = data.aws_caller_identity.this[0].account_id } ``` -------------------------------- ### Verify Karpenter Deployment and Resources Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Use these commands to check Terraform outputs, verify Kubernetes resources like deployments and pods, inspect the IRSA annotation on the service account, and view live Karpenter logs. ```bash # Check Terraform outputs terraform output karpenter_addon terraform output karpenter_irsa # Verify Kubernetes resources kubectl -n karpenter get deployment,pods,sa # Check IRSA annotation kubectl -n karpenter get sa karpenter -o jsonpath='{.metadata.annotations}' # View Karpenter logs kubectl -n karpenter logs -f deployment/karpenter ``` -------------------------------- ### Export Role ARN to SSM Parameter Store Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Use the `terraform output -raw` command to get the raw value of an output and then use it as input for other AWS CLI commands, such as `aws ssm put-parameter`. ```bash # Export role ARN to SSM Parameter Store aws ssm put-parameter \ --name /karpenter/role-arn \ --value $(terraform output -raw karpenter_role_arn) ``` -------------------------------- ### Enable Karpenter Monitoring and Logging Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Enable Prometheus monitoring and set the log level to debug for Karpenter using Helm values. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true # ... other config ... settings = { logLevel = "debug" } values = yamlencode({ serviceMonitor = { enabled = true labels = { prometheus = "kube-prometheus" } } }) } ``` -------------------------------- ### Verifying Helm Release and Status Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Check the status and list Helm releases for Karpenter within the 'karpenter' namespace. ```bash helm list -n karpenter ``` ```bash helm status karpenter -n karpenter ``` -------------------------------- ### Configure Karpenter Resource Requests and Limits Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Configure resource constraints for the Karpenter controller using Helm values. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = aws_eks_cluster.main.name # ... other config ... values = yamlencode({ controller = { replicas = 2 resources = { requests = { cpu = "250m" memory = "256Mi" } limits = { cpu = "1000m" memory = "1Gi" } } } }) } ``` -------------------------------- ### Data Flow for Spot Interruption Handling Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/spot-interruption-handling.md Illustrates the sequence of events from AWS EventBridge to pod graceful shutdown when a spot instance interruption is detected. ```text AWS EventBridge Events ↓ EventBridge Rules (pattern matching) ↓ SQS Queue (buffering) ↓ Karpenter Controller (pod eviction) ↓ Pod Graceful Shutdown ``` -------------------------------- ### Production Karpenter Configuration (High Availability) Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Production-ready configuration for high availability, setting controller replicas to 3 and defining resource requests/limits. Includes pod anti-affinity rules. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = var.cluster_name namespace = "karpenter" cluster_identity_oidc_issuer = var.oidc_issuer cluster_identity_oidc_issuer_arn = var.oidc_arn values = yamlencode({ controller = { replicas = 3 resources = { requests = { cpu = "500m", memory = "512Mi" } limits = { cpu = "1000m", memory = "1Gi" } } affinity = { podAntiAffinity = { requiredDuringSchedulingIgnoredDuringExecution = [{ labelSelector = { matchExpressions = [{ key = "app.kubernetes.io/name" operator = "In" values = ["karpenter"] }] } topologyKey = "kubernetes.io/hostname" }] } } } }) irsa_tags = { Environment = "prod" } } ``` -------------------------------- ### Assign Karpenter Outputs to Locals and Output Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Assign Karpenter outputs to local variables for easier access and then output a combined configuration object. ```hcl locals { karpenter_namespace = module.karpenter.addon.namespace karpenter_role_arn = module.karpenter.addon_irsa["karpenter"].iam_role_arn } output "cluster_config" { value = { karpenter_namespace = local.karpenter_namespace karpenter_role_arn = local.karpenter_role_arn } } ``` -------------------------------- ### Helm Direct Deployment Configuration Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/deployment-methods.md Configure the Karpenter module for direct Helm deployment by setting `enabled` to true and `argo_enabled` and `argo_helm_enabled` to false. Ensure cluster identity and name are correctly provided. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true argo_enabled = false argo_helm_enabled = false cluster_identity_oidc_issuer = data.aws_eks_cluster.this.identity[0].oidc[0].issuer cluster_identity_oidc_issuer_arn = aws_iam_openid_connect_provider.oidc.arn cluster_name = aws_eks_cluster.this.name namespace = "karpenter" } ``` -------------------------------- ### Check Karpenter Deployment Status via CLI Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Uses `terraform output -json` and `jq` to retrieve and display the Karpenter addon status from the command line. ```bash # Get status terraform output -json karpenter_addon | jq -r '.status' # Output: "deployed" ``` -------------------------------- ### Configure Karpenter Controller for Development Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Set the Karpenter controller to use minimal resources for development environments. This configuration reduces CPU and memory requests for the controller pods. ```hcl values = yamlencode({ controller = { replicas = 1 resources = { requests = { cpu = "50m", memory = "64Mi" } } } }) ``` -------------------------------- ### Enable Pod Identity Policies Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/iam-policies.md Configure Pod Identity by setting `pod_identity_role_create` and `pod_identity_policy_enabled` to `true`. The module will create the necessary default policies for the Pod Identity role. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" # ... other configuration ... pod_identity_role_create = true pod_identity_policy_enabled = true # Module creates same default policies for Pod Identity role } ``` -------------------------------- ### Checking Kubernetes Resources Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Verify the status of all Kubernetes resources in the 'karpenter' namespace and inspect the Service Account's IAM role ARN. ```bash kubectl -n karpenter get all ``` ```bash kubectl -n karpenter get sa karpenter -o yaml | grep role-arn ``` -------------------------------- ### List and Describe EventBridge Rules Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/spot-interruption-handling.md These AWS CLI commands help in listing EventBridge rules related to Karpenter and retrieving their details, which is useful for troubleshooting rule configurations. ```bash aws events list-rules --name-prefix Karpenter ``` ```bash aws events describe-rule --name KarpenterHealthEvent-abc123 ``` ```bash aws events list-targets-by-rule --rule KarpenterHealthEvent-abc123 ``` -------------------------------- ### Check Karpenter Version via CLI Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Uses `terraform output -json` and `jq` to retrieve and display the Karpenter addon version from the command line. ```bash # Get version terraform output -json karpenter_addon | jq -r '.version' # Output: "1.12.0" ``` -------------------------------- ### Karpenter Module File Structure Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md Overview of the directory structure for the Karpenter Terraform module, detailing the purpose of each file. ```plaintext . ├── main.tf # Module composition & data sources ├── addon.tf # Karpenter Helm deployment ├── addon-irsa.tf # IRSA configuration ├── crds.tf # CRD deployment ├── iam.tf # IAM policy documents ├── interruption.tf # SQS queue & EventBridge rules ├── variables.tf # Karpenter-specific variables ├── variables-common.tf # Shared variables ├── variables-addon.tf # Helm/ArgoCD variables ├── variables-addon-irsa.tf # IRSA variables ├── variables-crds.tf # CRD variables ├── versions.tf # Provider versions └── examples/basic/ # Basic usage example ``` -------------------------------- ### Verify Karpenter Service Account Annotation Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Use `kubectl` and `jq` to retrieve and verify the `eks.amazonaws.com/role-arn` annotation on the Karpenter service account. This confirms that IRSA is correctly configured. ```bash # Get service account kubectl -n karpenter get serviceaccount karpenter -o json | \ jq '.metadata.annotations."eks.amazonaws.com/role-arn"' # Should output the ARN from addon_irsa output # "arn:aws:iam::123456789012:role/karpenter-irsa" ``` -------------------------------- ### Access Full Karpenter Manifests Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Outputs the complete rendered Kubernetes manifests applied by the Helm chart. This can be used for inspection or applying manually. ```hcl output "karpenter_manifests" { value = module.karpenter.addon.manifest } ``` -------------------------------- ### Checking AWS EventBridge Rules Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/quick-reference.md List EventBridge rules in AWS that are prefixed with 'Karpenter' to ensure they are configured correctly. ```bash aws events list-rules --name-prefix Karpenter ``` -------------------------------- ### Create CloudWatch Alarms Based on Output Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Conditionally create a CloudWatch log alarm based on the `addon.status` output. The `count` meta-argument ensures the resource is only created if the condition is met. ```hcl resource "aws_cloudwatch_log_alarm" "karpenter_not_deployed" { count = module.karpenter.addon.status != "deployed" ? 1 : 0 alarm_name = "karpenter-deployment-failed" # ... alarm configuration ... } ``` -------------------------------- ### Terraform Plan for Helm Direct Deployment Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/deployment-methods.md A `terraform plan` command will contact the cluster API to check the current Helm release state and compare it with the Terraform state, showing any proposed updates. ```bash terraform plan # Contacts cluster API to check current release state # Compares with Terraform state # Shows what Helm would update ``` -------------------------------- ### Check Terraform State Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md If an addon status is 'undeployed', use `terraform state show` to inspect the Terraform state for the specific addon resource. ```bash # Check Terraform state terraform state show 'module.karpenter.addon' ``` -------------------------------- ### ArgoCD Progressive Sync Policy (Canary) Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/deployment-methods.md Configures progressive synchronization with options to prevent pruning of extra resources and respect ignore differences during syncs. ```hcl argo_sync_policy = { automated = {} syncOptions = [ "Prune=false", # Keep extra resources "RespectIgnoreDifferences=true" ] } ``` -------------------------------- ### Configure Karpenter Affinity and Tolerations Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Spread Karpenter controllers across nodes using affinity and tolerations in Helm values. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true # ... other config ... values = yamlencode({ controller = { replicas = 3 affinity = { podAntiAffinity = { preferredDuringSchedulingIgnoredDuringExecution = [ { weight = 100 podAffinityTerm = { labelSelector = { matchExpressions = [ { key = "app.kubernetes.io/name" operator = "In" values = ["karpenter"] } ] } topologyKey = "kubernetes.io/hostname" } } ] } } tolerations = [ { key = "node-role.kubernetes.io/control-plane" effect = "NoSchedule" } ] } }) } ``` -------------------------------- ### Configure Development Environment for Karpenter with Terraform Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/usage-examples.md Set up Karpenter for a development environment with minimal resource usage, enabling debug logging and a single controller replica. This configuration is suitable for testing and development purposes. ```hcl module "karpenter_dev" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true cluster_name = aws_eks_cluster.dev.name namespace = "karpenter" settings = { logLevel = "debug" } values = yamlencode({ controller = { replicas = 1 resources = { requests = { cpu = "50m" memory = "64Mi" } } } }) irsa_tags = { Environment = "dev" } } ``` -------------------------------- ### Deploy Karpenter via ArgoCD with Kubernetes Manifest Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/module-overview.md This method deploys Karpenter as an ArgoCD Application using the Kubernetes provider. It requires API access at plan time. Set argo_enabled to true and argo_helm_enabled to false. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" enabled = true argo_enabled = true argo_helm_enabled = false argo_sync_policy = { automated = {} syncOptions = ["CreateNamespace=true"] } } ``` -------------------------------- ### Override Addon Settings with `settings` Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/helm-chart-values.md Use the `settings` variable to add or override individual configuration settings for the Karpenter addon. ```hcl module "karpenter" { source = "git::https://github.com/lablabs/terraform-aws-eks-karpenter.git" # ... other config ... settings = { # Override a default setting logLevel = "debug" # Add new settings (not in defaults) metrics = { enabled = true port = 8080 } } } ``` -------------------------------- ### Retrieve Outputs via Terraform Output Command Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md Use the `terraform output` command to view all outputs, a specific output, or retrieve outputs in JSON format. Requires `jq` for JSON parsing. ```bash # Get all outputs terraform output # Get specific output terraform output karpenter_addon # Get JSON format terraform output -json karpenter_addon | jq '.status' ``` -------------------------------- ### Check Actual Release Status with Helm Source: https://github.com/lablabs/terraform-aws-eks-karpenter/blob/main/_autodocs/outputs.md When an addon status shows 'undeployed', use `helm list` and `helm status` commands to check the actual deployment status of the Helm release in the Kubernetes cluster. ```bash # Check actual release status helm list -n karpenter helm status karpenter -n karpenter ```