Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.6.0 #14

Merged
merged 60 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
1c44394
Upgrade Terraform AWS IAM module to 5.32.1.
jbronn Dec 14, 2023
7b19135
Upgrade Terraform AWS EKS module to 19.21.0.
jbronn Dec 14, 2023
9c220ba
Upgrade `cert-manager` to 1.13.3.
jbronn Dec 14, 2023
1dc70fd
Upgrade AWS EBS/EFS CSI controllers and Nvidia device plugin to their…
jbronn Dec 14, 2023
0306664
Refactor into separate source files.
jbronn Dec 14, 2023
c4e986b
Have AWS module manage EKS KMS resources by default.
jbronn Dec 14, 2023
06d7d56
Take into account that KMS resource has a count now.
jbronn Dec 15, 2023
b88f382
Rename AWS data from `default` to `current`.
jbronn Dec 15, 2023
82f1bbb
Use AWS partition when refrencing ARNs.
jbronn Dec 15, 2023
e033182
Attempt to fix EFS CSI node policy to be compatible with managed KMS …
jbronn Dec 15, 2023
0b7e627
Enable default KMS key policy by default so it's possible to create e…
jbronn Dec 15, 2023
b2036f5
Add `cluster_addons_overrides` variable to allow further customizatio…
jbronn Dec 15, 2023
453ef0c
Add variables to support specifying Fargate profiles.
jbronn Dec 15, 2023
e83d4be
Add passthrough variables for controlling creation of cluster/node se…
jbronn Dec 15, 2023
76c5daa
Add `aws_auth_roles` variable to enable customization.
jbronn Dec 15, 2023
35558cf
Remove default `preserve` flag to EKS add-ons.
jbronn Dec 15, 2023
7c9802d
Add ability to use Karpenter.
jbronn Dec 15, 2023
1b60faa
Fix references to Karpenter module.
jbronn Dec 15, 2023
5156b10
Automatically configure CoreDNS to run on Fargate when profiles are p…
jbronn Dec 15, 2023
4020bbd
Allow disabling of the EFS CSI driver optional.
jbronn Dec 18, 2023
90f0bcf
Install the `eks-pod-identity-agent` cluster addon by default.
jbronn Dec 18, 2023
bb110ba
Use `set` statements instead of YAML for EFS CSI Helm chart values.
jbronn Dec 18, 2023
438d073
Revert 90f0bcfd72072cbd3f5a43832e5dda08e898ea1c.
jbronn Dec 18, 2023
c374e21
Need to add a count to the EFS storage class resource.
jbronn Dec 18, 2023
3ba55e8
Add toggle variables to make EBS CSI Driver and Load Balancer Control…
jbronn Dec 18, 2023
c6b9b56
Remove `repository_{username,password}` variables in attempt to elimi…
jbronn Dec 18, 2023
273a7c1
* Install `karpenter-crd` chart to ensure Karpenter's CRDs are manage…
jbronn Dec 19, 2023
ab0055b
Switch to using the NVIDIA GPU Operator, via Helm chart, instead of j…
jbronn Dec 19, 2023
70e353e
Add custom values variables for EBS/EFS CSI, AWS Load Balancer, and `…
jbronn Dec 19, 2023
44de663
Upgrade Terraform AWS IAM module to 5.33.0.
jbronn Dec 19, 2023
128fe57
Don't assume `kube-system` is running on Fargate when profiles are pr…
jbronn Dec 19, 2023
6f7279f
Turns out that ECR credentials are required for Karpenter artifacts.
jbronn Dec 19, 2023
9098d4b
Ditto.
jbronn Dec 19, 2023
26d21cd
Add Karpenter outputs.
jbronn Dec 19, 2023
7c3ebe1
Add Karpenter instance profile outputs.
jbronn Dec 19, 2023
6de78e4
Make it possible to disable CoreDNS from cluster addons.
jbronn Dec 19, 2023
fa093ee
Set `enable_karpenter_instance_profile_creation=true` by default.
jbronn Dec 20, 2023
c00766c
Ignore changes in `repository_password` for Karpenter's `helm_release…
jbronn Dec 20, 2023
93ed06e
Enable Karpenter's webhooks by default.
jbronn Dec 20, 2023
696e3c7
Rename variable to `lb_controller_values` for consistency; upgrade AW…
jbronn Dec 20, 2023
51e4ba1
Upgrade Karpenter version to 0.33.1 and its Helm chart values accordi…
jbronn Dec 20, 2023
bf8b380
Attempt to omit AWS ECR credentials by using `docker logout public.ec…
jbronn Dec 20, 2023
e99cc19
Attempt Karpenter 0.32.4 instead.
jbronn Dec 20, 2023
036046e
Support customizing whether to wait for all `helm_release` resources.
jbronn Dec 20, 2023
00c7d5c
No longer need to custom lifecycle to workaround ECR repository passw…
jbronn Dec 20, 2023
179da5f
Attempt Karpenter 0.33.1 and update chart values; add Karpenter's IRS…
jbronn Dec 20, 2023
471efa6
Use pre-release branch of `aws-eks` module to support Karpenter 0.32+.
jbronn Dec 20, 2023
0ccc853
Fix formatting.
jbronn Dec 20, 2023
8029982
Fix Karpenter GitHub module source.
jbronn Dec 20, 2023
09b74d0
Karpenter webhook has been deprecated, don't re-enable.
jbronn Dec 20, 2023
5cf46e2
Allow customizing the Karpenter namespace.
jbronn Dec 20, 2023
03aa298
Add variables to support customizing the namespaces of all `helm_rele…
jbronn Dec 21, 2023
7e9e463
Use the Pod Identity Role ARN.
jbronn Dec 21, 2023
6628584
More Karpenter fixes to support it using the pod-based identity.
jbronn Dec 21, 2023
dfecc34
Bring back Karpenter IRSA annotation.
jbronn Dec 21, 2023
ad829d4
Only have Helm create new namespaces when it's not `kube-system`.
jbronn Dec 21, 2023
442302e
Have `karpenter` module use the `iam_role_attach_cni_policy` variable.
jbronn Dec 21, 2023
68de63f
Use valid namespace name for NVIDIA GPU Operator.
jbronn Dec 21, 2023
7877e16
Inline EFS CSI driver policy again and remove separate security group…
jbronn Dec 21, 2023
6a4a2f9
Fix resource name.
jbronn Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ This module provides an opinionated way to configure an AWS EKS cluster using:
Here's an example using a VPC defined using the [terraform-aws-vpc](https://github.com/terraform-aws-modules/terraform-aws-vpc) module:

```
data "aws_availability_zones" "default" {}
data "aws_availability_zones" "current" {}

locals {
cluster_name = "test-eks"
vpc_azs = slice(data.aws_availability_zones.default.names, 0, 2)
vpc_azs = slice(data.aws_availability_zones.current.names, 0, 2)
vpc_cidr = "10.100.0.0/16"
vpc_subnets = cidrsubnets(local.vpc_cidr, 6, 6, 4, 4)

Expand Down
92 changes: 92 additions & 0 deletions cert-manager.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
## cert-manager
locals {
cert_manager = length(var.cert_manager_route53_zone_id) > 0
}

module "cert_manager_irsa" {
count = local.cert_manager ? 1 : 0
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.32.1"

role_name = "${var.cluster_name}-cert-manager-role"

oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = [
"cert-manager:cert-manager",
]
}
}
tags = var.tags
}

data "aws_iam_policy_document" "cert_manager" {
count = local.cert_manager ? 1 : 0
statement {
actions = [
"route53:GetChange"
]
resources = ["arn:${local.aws_partition}:route53:::change/*"]
}

statement {
actions = [
"route53:ChangeResourceRecordSets",
"route53:ListResourceRecordSets",
]
resources = ["arn:${local.aws_partition}:route53:::hostedzone/${var.cert_manager_route53_zone_id}"]
}
}

resource "aws_iam_policy" "cert_manager" {
count = local.cert_manager ? 1 : 0
name = "AmazonEKS_Cert_Manager_Policy-${var.cluster_name}"
description = "Provides permissions for cert-manager"
policy = data.aws_iam_policy_document.cert_manager[0].json
tags = var.tags
}

resource "aws_iam_role_policy_attachment" "cert_manager" {
count = local.cert_manager ? 1 : 0
role = "${var.cluster_name}-cert-manager-role"
policy_arn = aws_iam_policy.cert_manager[0].arn
depends_on = [
module.cert_manager_irsa[0]
]
}

resource "helm_release" "cert_manager" {
count = local.cert_manager ? 1 : 0
name = "cert-manager"
namespace = "cert-manager"
create_namespace = true
chart = "cert-manager"
repository = "https://charts.jetstack.io"
version = "v${var.cert_manager_version}"
keyring = "${path.module}/cert-manager-keyring.gpg"
verify = var.helm_verify

# Set up values so CRDs are installed with the chart, the service account has
# correct annotations, and that the pod's security context has permissions
# to read the account token:
# https://cert-manager.io/docs/configuration/acme/dns01/route53/#service-annotation
values = [
yamlencode({
"installCRDs" = true
"securityContext" = {
"fsGroup" = 1001
}
"serviceAccount" = {
"annotations" = {
"eks.amazonaws.com/role-arn" = "arn:${local.aws_partition}:iam::${local.aws_account_id}:role/${var.cluster_name}-cert-manager-role"
}
}
})
]

depends_on = [
module.cert_manager_irsa[0],
module.eks,
]
}
18 changes: 18 additions & 0 deletions cni.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Authorize VPC CNI via IRSA.
module "eks_vpc_cni_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.32.1"

role_name = "${var.cluster_name}-vpc-cni-role"
attach_vpc_cni_policy = true
vpc_cni_enable_ipv4 = true

oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["kube-system:aws-node"]
}
}

tags = var.tags
}
85 changes: 85 additions & 0 deletions ebs-csi.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
## EBS CSI Storage Driver

# Allow PVCs backed by EBS
module "eks_ebs_csi_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.32.1"

role_name = "${var.cluster_name}-ebs-csi-role"
attach_ebs_csi_policy = true

oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["kube-system:ebs-csi-controller-sa"]
}
}

tags = var.tags
}

resource "helm_release" "aws_ebs_csi_driver" {
name = "aws-ebs-csi-driver"
namespace = "kube-system"
chart = "aws-ebs-csi-driver"
repository = "https://kubernetes-sigs.github.io/aws-ebs-csi-driver"
version = var.ebs_csi_driver_version

values = [
yamlencode({
"controller" = {
"extraVolumeTags" = var.tags
"serviceAccount" = {
"annotations" = {
"eks.amazonaws.com/role-arn" = "arn:${local.aws_partition}:iam::${local.aws_account_id}:role/${var.cluster_name}-ebs-csi-role"
}
}
}
"image" = {
"repository" = "${var.csi_ecr_repository_id}.dkr.ecr.${local.aws_region}.amazonaws.com/eks/aws-ebs-csi-driver"
}
})
]

depends_on = [
module.eks_ebs_csi_irsa,
module.eks,
]
}

# Make EBS CSI with gp3 default storage driver
resource "kubernetes_storage_class" "eks_ebs_storage_class" {
metadata {
annotations = {
"storageclass.kubernetes.io/is-default-class" = "true"
}
labels = {}
name = "ebs-sc"
}

mount_options = []
parameters = {}
storage_provisioner = "ebs.csi.aws.com"
volume_binding_mode = "WaitForFirstConsumer"

depends_on = [
helm_release.aws_ebs_csi_driver,
]
}

# Don't want gp2 storageclass set as default.
resource "kubernetes_annotations" "eks_disable_gp2" {
api_version = "storage.k8s.io/v1"
kind = "StorageClass"
metadata {
name = "gp2"
}
annotations = {
"storageclass.kubernetes.io/is-default-class" = "false"
}
force = true

depends_on = [
kubernetes_storage_class.eks_ebs_storage_class
]
}
148 changes: 148 additions & 0 deletions efs-csi.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
## EFS CSI Storage Driver
resource "aws_security_group" "eks_efs_sg" {
name = "${var.cluster_name}-efs-sg"
description = "Security group for EFS clients in EKS VPC"
vpc_id = var.vpc_id

ingress {
description = "Ingress NFS traffic for EFS"
from_port = 2049
to_port = 2049
protocol = "tcp"
cidr_blocks = [var.vpc_cidr]
}

tags = var.tags
}

# Allow PVCs backed by EFS
module "eks_efs_csi_controller_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.32.1"

role_name = "${var.cluster_name}-efs-csi-controller-role"
attach_efs_csi_policy = true

oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = [
"kube-system:efs-csi-controller-sa",
]
}
}
tags = var.tags
}

module "eks_efs_csi_node_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.32.1"

role_name = "${var.cluster_name}-efs-csi-node-role"
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = [
"kube-system:efs-csi-node-sa",
]
}
}
tags = var.tags
}

data "aws_iam_policy_document" "eks_efs_csi_node" {
statement {
actions = [
"elasticfilesystem:DescribeMountTargets",
"ec2:DescribeAvailabilityZones",
]
resources = ["*"] # tfsec:ignore:aws-iam-no-policy-wildcards
}
}

resource "aws_iam_policy" "eks_efs_csi_node" {
name = "AmazonEKS_EFS_CSI_Node_Policy-${var.cluster_name}"
description = "Provides node permissions to use the EFS CSI driver"
policy = data.aws_iam_policy_document.eks_efs_csi_node.json
tags = var.tags
}

resource "aws_iam_role_policy_attachment" "eks_efs_csi_node" {
role = "${var.cluster_name}-efs-csi-node-role"
policy_arn = aws_iam_policy.eks_efs_csi_node.arn
depends_on = [
module.eks_efs_csi_node_irsa
]
}

resource "aws_efs_file_system" "eks_efs" {
creation_token = "${var.cluster_name}-efs"
encrypted = true
kms_key_id = var.kms_manage ? aws_kms_key.this[0].arn : module.eks.kms_key_arn
tags = var.tags
}

resource "aws_efs_mount_target" "eks_efs_private" {
count = length(var.private_subnets)
file_system_id = aws_efs_file_system.eks_efs.id
subnet_id = var.private_subnets[count.index]
security_groups = [aws_security_group.eks_efs_sg.id]
}

resource "helm_release" "aws_efs_csi_driver" {
name = "aws-efs-csi-driver"
namespace = "kube-system"
chart = "aws-efs-csi-driver"
repository = "https://kubernetes-sigs.github.io/aws-efs-csi-driver"
version = var.efs_csi_driver_version

values = [
yamlencode({
"controller" = {
"serviceAccount" = {
"annotations" = {
"eks.amazonaws.com/role-arn" = "arn:${local.aws_partition}:iam::${local.aws_account_id}:role/${var.cluster_name}-efs-csi-controller-role"
}
}
"tags" = var.tags
}
"image" = {
"repository" = "${var.csi_ecr_repository_id}.dkr.ecr.${local.aws_region}.amazonaws.com/eks/aws-efs-csi-driver"
}
"node" = {
"serviceAccount" = {
"annotations" = {
"eks.amazonaws.com/role-arn" = "arn:${local.aws_partition}:iam::${local.aws_account_id}:role/${var.cluster_name}-efs-csi-node-role"
}
}
}
})
]

depends_on = [
module.eks_efs_csi_controller_irsa,
module.eks,
]
}

resource "kubernetes_storage_class" "eks_efs_storage_class" {
metadata {
annotations = {}
name = "efs-sc"
labels = {}
}

mount_options = []
parameters = {
"provisioningMode" = "efs-ap"
"fileSystemId" = aws_efs_file_system.eks_efs.id
"directoryPerms" = "755"
"uid" = "0"
"gid" = "0"
}
storage_provisioner = "efs.csi.aws.com"

depends_on = [
helm_release.aws_efs_csi_driver,
]
}
Loading