### Install EKS Addons Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Example configuration for setting up EKS addons, referencing the AWS EKS Add-ons documentation. This demonstrates how to define addons within a Terraform configuration. ```yaml # https://docs.aws.amazon.com/eks/latest/userguide/eks-add-ons.html ``` -------------------------------- ### Minimal EKS Add-ons Setup Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Configure essential EKS add-ons with specified versions for a minimal setup. ```hcl vars: addons: vpc-cni: addon_version: "v1.16.0-eksbuild.1" coredns: addon_version: "v1.11.1-eksbuild.4" kube-proxy: addon_version: "v1.29.0-eksbuild.1" ``` -------------------------------- ### Node Group Configuration Example Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/submodules.md This example demonstrates the structure of the `node_groups` input variable, defining configurations for different node groups including instance types, desired sizes, and availability zones. ```HCL node_groups = { general = { instance_types = ["t3.large"] desired_group_size = 2 max_group_size = 10 availability_zones = ["us-east-1a", "us-east-1b"] } compute = { instance_types = ["c5.2xlarge"] desired_group_size = 1 availability_zones = ["us-east-1a"] } } ``` -------------------------------- ### Install and Run Pre-commit Hooks Locally Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/AGENTS.md Installs the pre-commit framework and runs all configured hooks, including terraform_fmt, terraform_docs, and tflint, to ensure code quality and consistency. ```bash pre-commit install && pre-commit run -a ``` -------------------------------- ### EKS Cluster Configuration Example Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/api-reference.md This snippet shows a comprehensive example of configuring an EKS cluster with various settings including region, Kubernetes version, access controls, node groups, add-ons, logging, and additional IAM roles. Ensure the necessary AWS provider and component versions are compatible. ```hcl component: terraform: eks/cluster: vars: region: us-east-1 cluster_kubernetes_version: "1.29" cluster_endpoint_private_access: true cluster_endpoint_public_access: true oidc_provider_enabled: true managed_node_groups_enabled: true node_groups: general: instance_types: ["t3.large"] desired_group_size: 2 min_group_size: 1 max_group_size: 10 addons: vpc-cni: addon_version: "v1.16.0-eksbuild.1" coredns: addon_version: "v1.11.1-eksbuild.4" aws-ebs-csi-driver: addon_version: "v1.27.0-eksbuild.1" enabled_cluster_log_types: - api - audit - authenticator map_additional_iam_roles: - rolearn: "arn:aws:iam::123456789012:role/DevOpsRole" groups: ["system:masters"] ``` -------------------------------- ### Check Installed EKS Add-ons Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md List all add-ons currently installed on your EKS cluster. ```bash aws eks list-addons --cluster-name --region us-east-1 ``` -------------------------------- ### EKS Ingress Controller Component Example Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Example configuration for an EKS Ingress Controller component, specifying dependencies on the EKS cluster and referencing cluster outputs for configuration. ```yaml components: terraform: eks/alb-ingress-controller: dependencies: - eks/cluster vars: cluster_name: !terraform.output eks/cluster.eks_cluster_id cluster_arn: !terraform.output eks/cluster.eks_cluster_arn ``` -------------------------------- ### Monitor node group health Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/outputs.md This example shows how to get the status of EKS node groups and filter for those that are not in an 'ACTIVE' state, useful for monitoring. ```bash STATUSES=$(terraform output -json eks_node_group_statuses) echo $STATUSES | jq '.[] | select(. != "ACTIVE")' ``` -------------------------------- ### Describe EKS Add-on Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md Retrieve detailed information about a specific EKS add-on installed on your cluster. ```bash aws eks describe-addon --cluster-name --addon-name vpc-cni ``` -------------------------------- ### Typical EKS Cluster Stack Configuration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Example of a typical stack configuration file for an EKS cluster component, showing metadata, dependencies, and variables including references to other components like VPC. ```yaml # stacks/prod/use1/eks-cluster.yaml components: terraform: eks/cluster: metadata: component: eks/cluster dependencies: - vpc vars: region: us-east-1 # References to other components vpc_component_name: vpc ``` -------------------------------- ### Enable EKS Capabilities (Argo CD, ACK, KRO) Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/UPGRADING.md Configure EKS Capabilities by adding them to your stack configuration. This example shows Argo CD with SSO integration, ACK with specific IAM policies, and KRO. ```yaml components: terraform: eks/cluster: vars: capabilities: argocd: type: ARGOCD configuration: argo_cd: namespace: argocd aws_idc: # Requires aws-sso component v3.0.1+ for this output idc_instance_arn: !terraform.output aws-sso core-gbl-root ssoadmin_instance_arn rbac_role_mapping: - role: ADMIN identity: - id: "" type: SSO_GROUP ack: type: ACK iam_policy_arns: - "arn:aws:iam::aws:policy/AmazonRDSFullAccess" - "arn:aws:iam::aws:policy/AmazonS3FullAccess" kro: type: KRO ``` -------------------------------- ### Combine Argo CD, ACK S3, and KRO Capabilities Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md This example demonstrates how to enable multiple capabilities (Argo CD, ACK S3, and KRO) simultaneously for an EKS cluster. Configure each capability with its specific settings. ```yaml components: terraform: eks/cluster: vars: capabilities: argocd: type: ARGOCD configuration: argo_cd: namespace: argocd aws_idc: idc_instance_arn: "arn:aws:sso:::instance/ssoins-1234567890abcdef" rbac_role_mapping: - role: ADMIN identity: - id: "12345678-1234-1234-1234-123456789012" type: SSO_GROUP ack-s3: type: ACK iam_policy_arns: - "arn:aws:iam::aws:policy/AmazonS3FullAccess" kro: type: KRO ``` -------------------------------- ### Node Group Configuration Example Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Defines a node group with specific EBS volume settings, instance types, and scaling parameters. This configuration is suitable for custom worker node setups. ```terraform { "block_device_map": { "/dev/xvda": { "ebs": { "encrypted": true, "volume_size": 20, "volume_type": "gp2" } } }, "desired_group_size": 1, "instance_types": [ "t3.medium" ], "kubernetes_version": null, "max_group_size": 100 } ``` -------------------------------- ### Kubernetes Version Management Mixin Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Example of using a mixin file (e.g., k8s-1-29.yaml) to manage Kubernetes version and addon versions. This promotes consistency and simplifies upgrades. ```yaml components: terraform: eks/cluster: vars: cluster_kubernetes_version: "1.29" addons: vpc-cni: addon_version: "v1.16.0-eksbuild.1" coredns: addon_version: "v1.11.1-eksbuild.4" kube-proxy: addon_version: "v1.29.0-eksbuild.1" # In stack file imports: - catalog/eks/cluster/mixins/k8s-1-29 components: terraform: eks/cluster: metadata: component: eks/cluster ``` -------------------------------- ### Configure EKS Addon Values Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Example of how to configure specific values for an EKS addon, such as setting the logging format for the aws-ebs-csi-driver. This uses the `configuration_values` input. ```yaml aws-ebs-csi-driver: configuration_values: '{"node": {"loggingFormat": "json"}}' ``` -------------------------------- ### Manage Addon Dependencies Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Set `addons_depends_on` to `true` to require Node Groups to be provisioned before addons. This example also shows an alternative CoreDNS addon version. ```yaml addons_depends_on: true addons: coredns: addon_version: "v1.8.7-eksbuild.1" ``` -------------------------------- ### Describe Log Groups for Monitoring Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Example bash command to list CloudWatch log groups for an EKS cluster. This is useful for configuring monitoring components to consume cluster logs. ```bash # Access logs for monitoring component aws logs describe-log-groups \ --log-group-name-prefix /aws/eks/my-cluster \ --region us-east-1 ``` -------------------------------- ### StorageClass Example for EKS Auto Mode EBS Migration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/UPGRADING.md Define a new StorageClass for Auto Mode that uses the ebs.csi.eks.amazonaws.com provisioner. This is necessary for migrating existing PersistentVolumeClaims. ```yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: gp3-auto-mode provisioner: ebs.csi.eks.amazonaws.com parameters: type: gp3 encrypted: "true" volumeBindingMode: WaitForFirstConsumer allowVolumeExpansion: true ``` -------------------------------- ### GitHub OIDC Provider Stack Configuration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Example configuration for a GitHub OIDC provider component, referencing the EKS cluster's OIDC issuer output. This enables GitHub Actions to authenticate with AWS. ```yaml components: terraform: github-oidc-provider: vars: github_oidc_provider_arn: !terraform.output eks/cluster.eks_cluster_identity_oidc_issuer ``` -------------------------------- ### AWS Provider Version Upgrade Steps Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/UPGRADING.md If upgrading the AWS provider from 5.x to 6.x, review the upgrade guide, update your lock file with `terraform init -upgrade`, and run `terraform plan` to identify breaking changes. ```bash terraform init -upgrade ``` -------------------------------- ### VPC Remote State Lookup with Explicit CIDR Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md This example demonstrates how to bypass the remote state lookup for VPC ingress by providing an explicit `vpc_cidr`. This is useful when the Terraform remote state backend might not be accessible. ```hcl allow_ingress_from_vpc_accounts: - tenant: core stage: network environment: use1 vpc_cidr: "10.0.0.0/16" # Explicit CIDR bypasses remote state ``` -------------------------------- ### List and Describe EKS Capabilities Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/UPGRADING.md Use these AWS CLI commands to list available capabilities on an EKS cluster and describe the details of a specific capability, such as Argo CD. ```bash # List capabilities on a cluster aws eks list-capabilities --cluster-name # Describe a specific capability aws eks describe-capability --cluster-name --capability-name argocd ``` -------------------------------- ### Explore Additional Test Options Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/README.md View available command-line options and configurations for running Terraform tests with Atmos. Use this to understand advanced test execution parameters. ```sh atmos test --help ``` -------------------------------- ### List Available EKS Addons Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Use this command to list all available addons for a specific Kubernetes version, including their type and publisher. This helps in identifying compatible addons for your EKS cluster. ```shell EKS_K8S_VERSION=1.29 # replace with your cluster version aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION \ --query 'addons[].{MarketplaceProductUrl: marketplaceInformation.productUrl, Name: addonName, Owner: owner Publisher: publisher, Type: type}' --output table ``` -------------------------------- ### Review Applied Configuration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Inspect the current state of the EKS cluster configuration using `terraform show` or by examining the state of a specific resource like the EKS cluster. ```bash terraform show terraform state show 'module.eks_cluster.aws_eks_cluster.default[0]' ``` -------------------------------- ### Fargate-Only EKS Cluster Configuration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Configuration for a Fargate-only EKS cluster. This setup disables managed node groups and configures Fargate profiles for workloads and add-ons. ```hcl component: terraform: eks/cluster: vars: region: us-east-1 cluster_kubernetes_version: "1.29" # No managed node groups managed_node_groups_enabled: false # Fargate profiles for workloads fargate_profiles: system: kubernetes_namespace: kube-system kubernetes_labels: {} app: kubernetes_namespace: production kubernetes_labels: workload-type: app # Deploy add-ons to Fargate deploy_addons_to_fargate: true addons: vpc-cni: addon_version: "v1.16.0-eksbuild.1" coredns: addon_version: "v1.11.1-eksbuild.4" ``` -------------------------------- ### Check Available Add-on Versions Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md Verify which versions of a specific EKS add-on are available for a given Kubernetes version and region. ```bash aws eks describe-addon-versions \ --kubernetes-version 1.29 \ --addon-name vpc-cni \ --region us-east-1 ``` -------------------------------- ### Get Nodes in EKS Cluster Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md Use this command to list nodes in your EKS cluster and view their wide output, including IP addresses and OS images. ```bash kubectl get nodes -o wide ``` -------------------------------- ### Get EKS Cluster Details Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/README.md Use the AWS CLI to describe a specific EKS cluster. Replace with your actual cluster identifier and specify the correct region. ```bash aws eks describe-cluster --name --region us-east-1 ``` -------------------------------- ### EKS Add-ons with Storage Support Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Set up EKS add-ons including CSI drivers for EBS and EFS storage support. ```hcl vars: addons: vpc-cni: addon_version: "v1.16.0-eksbuild.1" coredns: addon_version: "v1.11.1-eksbuild.4" kube-proxy: addon_version: "v1.29.0-eksbuild.1" aws-ebs-csi-driver: addon_version: "v1.27.0-eksbuild.1" aws-efs-csi-driver: addon_version: "v1.7.7-eksbuild.1" ``` -------------------------------- ### Initialize TFLint Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/AGENTS.md Initializes the TFLint static analysis tool for Terraform. This command downloads necessary plugins based on the configuration in .tflint.hcl. ```bash tflint --init ``` -------------------------------- ### Get node role ARNs for IAM policy attachments Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/outputs.md This snippet retrieves the ARNs of managed node worker roles, which can then be iterated over using jq to attach IAM policies. ```bash NODE_ROLES=$(terraform output -json eks_managed_node_workers_role_arns) echo $NODE_ROLES | jq . ``` -------------------------------- ### Get EKS Addon Configuration Schema Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Retrieve the JSON Schema for an EKS addon's configuration options. This is useful for understanding and setting addon-specific parameters like logging formats. ```shell aws eks describe-addon-configuration \ --addon-name aws-ebs-csi-driver \ --addon-version v1.20.0-eksbuild.1 | jq '.configurationSchema | fromjson' ``` -------------------------------- ### Configure Kube-Proxy Addon Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Specify the addon version for kube-proxy. Set `addon_version` to `null` to use the latest version. ```yaml kube-proxy: addon_version: "v1.25.6-eksbuild.1" ``` -------------------------------- ### Update Self-Managed KRO Leader Election Namespace Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/UPGRADING.md Use this Helm command to upgrade the self-managed KRO installation and set the leader election namespace to 'kube-system'. This is the first step in a gradual KRO migration. ```bash helm upgrade --install kro \ oci://ghcr.io/awslabs/kro/kro-chart \ --namespace kro \ --set leaderElection.namespace=kube-system ``` -------------------------------- ### Check Available Versions for Specific EKS Addons Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md This command allows you to check the available versions for a specific EKS addon, such as vpc-cni, kube-proxy, coredns, aws-ebs-csi-driver, and aws-efs-csi-driver. It also indicates the default version for compatibility. ```shell EKS_K8S_VERSION=1.29 # replace with your cluster version echo "vpc-cni:" && aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION --addon-name vpc-cni \ --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table echo "kube-proxy:" && aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION --addon-name kube-proxy \ --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table echo "coredns:" && aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION --addon-name coredns \ --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table echo "aws-ebs-csi-driver:" && aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION --addon-name aws-ebs-csi-driver \ --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table echo "aws-efs-csi-driver:" && aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION --addon-name aws-efs-csi-driver \ --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table ``` -------------------------------- ### Configure EKS Add-on with Custom Values Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Customize add-on configurations, such as replica counts and resource limits for CoreDNS, or sidecar settings for EBS CSI driver. ```hcl vars: addons: coredns: addon_version: "v1.11.1-eksbuild.4" configuration_values: | { "replicaCount": 3, "resources": { "limits": { "cpu": "100m", "memory": "150Mi" } } } aws-ebs-csi-driver: addon_version: "v1.27.0-eksbuild.1" configuration_values: | { "sidecars": { "snapshotter": { "forceEnable": false } } } ``` -------------------------------- ### Configure VPC CNI Addon Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Specify the addon version for VPC CNI. Set `addon_version` to `null` to use the latest version. ```yaml vpc-cni: addon_version: "v1.12.2-eksbuild.1" ``` -------------------------------- ### Generate README from YAML and Terraform Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/AGENTS.md Regenerates the main README.md file using Atmos and terraform-docs. Ensure README.yaml is up-to-date with any input/output changes. ```bash atmos docs generate readme ``` -------------------------------- ### Plan Terraform Changes Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md Review the changes Terraform will make to your infrastructure before applying them. Useful for debugging failed applies. ```bash terraform plan ``` -------------------------------- ### Configure Node Group with Custom User Data Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Define custom user data scripts for node groups, including pre- and post-joining commands, and extra arguments for kubelet. ```hcl vars: node_groups: custom: instance_types: ["t3.large"] desired_group_size: 2 node_userdata: before_cluster_joining_userdata: | #!/bin/bash yum update -y yum install -y custom-monitoring-agent bootstrap_extra_args: "--max-pods 110" kubelet_extra_args: "--max-pods=110 --log-level=2" after_cluster_joining_userdata: | #!/bin/bash kubectl set env deployment/metrics-server -n kube-system ``` -------------------------------- ### Generate Simple README from YAML and Terraform Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/AGENTS.md Regenerates a simplified README.md file specifically for the src directory. This is useful for component-level documentation. ```bash atmos docs generate readme-simple ``` -------------------------------- ### Check Launch Template for EKS Cluster Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md This command helps identify the launch template associated with an EKS cluster by filtering EC2 instances based on cluster tags. ```bash aws ec2 describe-launch-templates --filters "Name=tag:eks:cluster-name,Values=" ``` -------------------------------- ### Remote State Reference Pattern Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Demonstrates the pattern for referencing outputs from other components using remote state. This allows for dynamic configuration based on other infrastructure. ```yaml eks_cluster: vars: some_var: !terraform.output other-component.output_name vars: vpc_id: !terraform.output vpc.vpc_id subnet_ids: !terraform.output vpc.private_subnet_ids ``` -------------------------------- ### Enable EKS Auto Mode with Upgrade Flag Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/UPGRADING.md Set auto_mode_enabled to true and auto_mode_upgrade to true to enable Auto Mode and manage the transition of addons. Existing addons and node groups are kept in place during this process. ```yaml components: terraform: eks/cluster: vars: auto_mode_enabled: true auto_mode_upgrade: true # Keep existing node groups running during transition managed_node_groups_enabled: true # Keep existing Karpenter IAM role for now karpenter_iam_role_enabled: true ``` -------------------------------- ### Verify Pods on Old Nodes Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/UPGRADING.md Before removing managed node groups, verify that no pods (except DaemonSets) are running on the old nodes. This ensures a smooth transition to Auto Mode nodes. ```bash kubectl get pods --all-namespaces -o wide | grep -v auto ``` -------------------------------- ### Use Latest EKS Add-on Versions Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Configure EKS add-ons to automatically use the latest available versions by setting `addon_version` to null. ```hcl vars: addons: vpc-cni: addon_version: null # Use latest coredns: addon_version: null # Use latest ``` -------------------------------- ### Check cluster version Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/outputs.md A simple command to output the current version of the EKS cluster. ```bash terraform output -raw eks_cluster_version ``` -------------------------------- ### Configure AWS EBS CSI Driver Addon Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Specify the addon version for the AWS EBS CSI driver. Set `addon_version` to `null` to use the latest version. Optionally disable the EBS Snapshotter. ```yaml aws-ebs-csi-driver: addon_version: "v1.19.0-eksbuild.2" configuration_values: '{"sidecars":{"snapshotter":{"forceEnable":false}}}' ``` -------------------------------- ### NodeUserdata Configuration Type Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/types.md Defines the structure for node initialization scripts. Use this to specify shell scripts to run before or after cluster joining, and extra arguments for bootstrap or kubelet. ```hcl object({ before_cluster_joining_userdata = optional(string) bootstrap_extra_args = optional(string) kubelet_extra_args = optional(string) after_cluster_joining_userdata = optional(string) }) ``` -------------------------------- ### Kubernetes 1.29 Add-on Versions and Configuration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/README.md This snippet defines the Kubernetes version and specific versions for various EKS add-ons, along with custom configurations for CoreDNS and the EBS CSI driver. It's intended for use in a mixin file to manage add-on versions separately from the main cluster configuration. ```yaml components: terraform: eks/cluster: vars: cluster_kubernetes_version: "1.29" # You can set all the add-on versions to `null` to use the latest version, # but that introduces drift as new versions are released. As usual, we recommend # pinning the versions to a specific version and upgrading when convenient. # Determine the latest version of the EKS add-ons for the specified Kubernetes version # EKS_K8S_VERSION=1.29 # replace with your cluster version # ADD_ON=vpc-cni # replace with the add-on name # echo "${ADD_ON}:" && aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION --addon-name $ADD_ON \ # --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table # To see versions for all the add-ons, wrap the above command in a for loop: # for ADD_ON in vpc-cni kube-proxy coredns aws-ebs-csi-driver aws-efs-csi-driver; do # echo "${ADD_ON}:" && aws eks describe-addon-versions --kubernetes-version $EKS_K8S_VERSION --addon-name $ADD_ON \ # --query 'addons[].addonVersions[].{Version: addonVersion, Defaultversion: compatibilities[0].defaultVersion}' --output table # done # To see the custom configuration schema for an add-on, run the following command: # aws eks describe-addon-configuration --addon-name aws-ebs-csi-driver \ # --addon-version v1.20.0-eksbuild.1 | jq '.configurationSchema | fromjson' # See the `coredns` configuration below for an example of how to set a custom configuration. # https://docs.aws.amazon.com/eks/latest/userguide/eks-add-ons.html # https://docs.aws.amazon.com/eks/latest/userguide/managing-add-ons.html#creating-an-add-on addons: # https://docs.aws.amazon.com/eks/latest/userguide/cni-iam-role.html # https://docs.aws.amazon.com/eks/latest/userguide/managing-vpc-cni.html # https://docs.aws.amazon.com/eks/latest/userguide/cni-iam-role.html#cni-iam-role-create-role # https://aws.github.io/aws-eks-best-practices/networking/vpc-cni/#deploy-vpc-cni-managed-add-on vpc-cni: addon_version: "v1.16.0-eksbuild.1" # set `addon_version` to `null` to use the latest version # https://docs.aws.amazon.com/eks/latest/userguide/managing-kube-proxy.html kube-proxy: addon_version: "v1.29.0-eksbuild.1" # set `addon_version` to `null` to use the latest version # https://docs.aws.amazon.com/eks/latest/userguide/managing-coredns.html coredns: addon_version: "v1.11.1-eksbuild.4" # set `addon_version` to `null` to use the latest version ## override default replica count of 2. In very large clusters, you may want to increase this. configuration_values: '{"replicaCount": 3}' # https://docs.aws.amazon.com/eks/latest/userguide/csi-iam-role.html # https://aws.amazon.com/blogs/containers/amazon-ebs-csi-driver-is-now-generally-available-in-amazon-eks-add-ons # https://docs.aws.amazon.com/eks/latest/userguide/managing-ebs-csi.html#csi-iam-role # https://github.com/kubernetes-sigs/aws-ebs-csi-driver aws-ebs-csi-driver: addon_version: "v1.27.0-eksbuild.1" # set `addon_version` to `null` to use the latest version # If you are not using [volume snapshots](https://kubernetes.io/blog/2020/12/10/kubernetes-1.20-volume-snapshot-moves-to-ga/#how-to-use-volume-snapshots) # (and you probably are not), disable the EBS Snapshotter # See https://github.com/aws/containers-roadmap/issues/1919 configuration_values: '{"sidecars":{"snapshotter":{"forceEnable":false}}}' aws-efs-csi-driver: addon_version: "v1.7.7-eksbuild.1" # set `addon_version` to `null` to use the latest version # Set a short timeout in case of conflict with an existing efs-controller deployment create_timeout: "7m" ``` -------------------------------- ### Configure CoreDNS Addon with Replica Count Override Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Specify the addon version for CoreDNS and override the default replica count. Set `addon_version` to `null` to use the latest version. ```yaml coredns: addon_version: "v1.9.3-eksbuild.2" configuration_values: '{"replicaCount": 3}' ``` -------------------------------- ### EKS Cluster Environment Variable Integration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Demonstrates standard Terraform and AWS environment variables used for authentication, behavior control, and parallelism when integrating with the EKS cluster component. ```bash # AWS authentication export AWS_REGION=us-east-1 export AWS_PROFILE=my-profile # Terraform behavior export TF_LOG=DEBUG export TF_INPUT=false # Parallelism export TF_CLI_ARGS="-parallelism=20" # State locking export TF_SKIP_REMOTE_TESTS=true ``` -------------------------------- ### View Logs for a Specific Pod Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md Use this command to view the logs of a specific pod running in the kube-system namespace. ```bash kubectl logs -n kube-system ``` -------------------------------- ### Terraform Plan with Error Filtering Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/README.md Run a Terraform plan and filter the output for errors to quickly identify potential issues. ```bash terraform plan | grep -i error ``` -------------------------------- ### View EKS Cluster API Logs Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/README.md Tail the logs for the EKS cluster's API server in real-time. This command is helpful for monitoring API requests and troubleshooting issues. ```bash aws logs tail /aws/eks//api --follow ``` -------------------------------- ### Label Module Usage for Resource Naming Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Utilizes the cloudposse/label/null module for consistent resource naming and tagging. Ensure the 'enabled' variable is set appropriately. ```hcl module "karpenter_label" { source = "cloudposse/label/null" version = "0.25.0" enabled = local.karpenter_iam_role_enabled attributes = ["karpenter"] context = module.this.context } ``` -------------------------------- ### List All Pods in EKS Cluster Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md This command retrieves a list of all pods across all namespaces in your EKS cluster. ```bash kubectl get pods -A ``` -------------------------------- ### Run Terratest Suite Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/AGENTS.md Executes the Terratest suite located in the test/ directory. This command deploys and destroys real AWS resources, so ensure AWS credentials are configured. ```bash atmos test run ``` -------------------------------- ### GitHub Actions Workflow for EKS Deployment Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md This workflow automates the deployment of an EKS cluster using Terraform. It checks out code, sets up Terraform, and runs plan and apply steps. ```yaml name: Deploy EKS Cluster on: push: branches: [main] pull_request: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: hashicorp/setup-terraform@v2 with: terraform_version: 1.5.0 - name: Terraform Plan run: | cd stacks/prod/use1 terraform init terraform plan env: AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }} AWS_WEB_IDENTITY_TOKEN_FILE: /tmp/web-identity-token - name: Terraform Apply if: github.event_name == 'push' run: | cd stacks/prod/use1 terraform apply -auto-approve ``` -------------------------------- ### Import Terraform Resource Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/error-handling.md Manually import an existing AWS resource into your Terraform state. ```bash terraform import aws_eks_cluster.cluster ``` -------------------------------- ### EKS Node Userdata Configuration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/api-reference.md Configures userdata for EKS node initialization. Use this to run custom scripts or pass arguments before, during, or after the node joins the cluster. ```hcl node_userdata = optional(object({ before_cluster_joining_userdata = optional(string) bootstrap_extra_args = optional(string) kubelet_extra_args = optional(string) after_cluster_joining_userdata = optional(string) }), {}) ``` -------------------------------- ### Add Custom EKS Addon Configuration Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/src/README.md Define a new EKS addon by adding its configuration to the `addons` map. Specify the addon version required. ```yaml addons: my-addon: addon_version: "..." ``` -------------------------------- ### Retrieve cluster configuration for kubectl Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/outputs.md Use this snippet to fetch essential cluster details like ID, endpoint, and certificate data to configure kubectl for interacting with the EKS cluster. ```bash CLUSTER_ID=$(terraform output -raw eks_cluster_id) ENDPOINT=$(terraform output -raw eks_cluster_endpoint) CA_DATA=$(terraform output -raw eks_cluster_certificate_authority_data) # Configure kubectl context aws eks update-kubeconfig --region us-east-1 --name $CLUSTER_ID ``` -------------------------------- ### Fargate Profile Module Usage Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/integration.md Create Fargate profiles by iterating over a local map, specifying subnet IDs, cluster name, Kubernetes namespace, and labels. ```hcl module "fargate_profile" { source = "cloudposse/eks-fargate-profile/aws" version = "1.3.1" for_each = local.fargate_profiles subnet_ids = local.private_subnet_ids cluster_name = local.eks_cluster_id kubernetes_namespace = each.value.kubernetes_namespace kubernetes_labels = each.value.kubernetes_labels } ``` -------------------------------- ### Check Module Outputs Source: https://github.com/cloudposse-terraform-components/aws-eks-cluster/blob/main/_autodocs/configuration.md Retrieve key identifiers and versions for the EKS cluster, node groups, and add-ons using `terraform output` commands. ```bash terraform output eks_cluster_id terraform output eks_node_group_ids terraform output eks_addons_versions ```