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

chore: Refactor examples to leverage terraform-aws-eks for cluster creation #1074

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
TERRAFORM_DOCS_VERSION: v0.16.0
TFSEC_VERSION: v1.22.0
TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/.terraform.d/plugin-cache
TFLINT_VERSION: v0.38.1
TFLINT_VERSION: v0.41.0

concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
Expand Down
61 changes: 0 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,71 +22,12 @@ For complete project documentation, please visit our [documentation site](https:

To view examples for how you can leverage EKS Blueprints, please see the [examples](https://github.com/aws-ia/terraform-aws-eks-blueprints/tree/main/examples) directory.

## Usage

The below demonstrates how you can leverage EKS Blueprints to deploy an EKS cluster, a managed node group, and various Kubernetes add-ons.

```hcl
module "eks_blueprints" {
source = "github.com/aws-ia/terraform-aws-eks-blueprints?ref=v4.12.0"
# EKS CLUSTER
cluster_version = "1.23"
vpc_id = "<vpcid>" # Enter VPC ID
private_subnet_ids = ["<subnet-a>", "<subnet-b>", "<subnet-c>"] # Enter Private Subnet IDs
# EKS MANAGED NODE GROUPS
managed_node_groups = {
mg_m5 = {
node_group_name = "managed-ondemand"
instance_types = ["m5.large"]
subnet_ids = ["<subnet-a>", "<subnet-b>", "<subnet-c>"]
}
}
}
module "eks_blueprints_kubernetes_addons" {
source = "github.com/aws-ia/terraform-aws-eks-blueprints//modules/kubernetes-addons?ref=v4.12.0"
eks_cluster_id = module.eks_blueprints.eks_cluster_id
# EKS Addons
enable_amazon_eks_vpc_cni = true
enable_amazon_eks_coredns = true
enable_amazon_eks_kube_proxy = true
enable_amazon_eks_aws_ebs_csi_driver = true
#K8s Add-ons
enable_argocd = true
enable_aws_for_fluentbit = true
enable_aws_load_balancer_controller = true
enable_cluster_autoscaler = true
enable_metrics_server = true
enable_prometheus = true
}
```

The code above will provision the following:

- ✅ A new EKS Cluster with a managed node group.
- ✅ Amazon EKS add-ons `vpc-cni`, `CoreDNS`, `kube-proxy`, and `aws-ebs-csi-driver`.
-`Cluster Autoscaler` and `Metrics Server` for scaling your workloads.
-`Fluent Bit` for routing logs.
-`AWS Load Balancer Controller` for distributing traffic.
-`Argocd` for declarative GitOps CD for Kubernetes.
-`Prometheus` for observability.

## Add-ons

EKS Blueprints makes it easy to provision a wide range of popular Kubernetes add-ons into an EKS cluster. By default, the [Terraform Helm provider](https://github.com/hashicorp/terraform-provider-helm) is used to deploy add-ons with publicly available [Helm Charts](https://artifacthub.io/).EKS Blueprints provides support for leveraging self-hosted Helm Chart as well.

For complete documentation on deploying add-ons, please visit our [add-on documentation](https://aws-ia.github.io/terraform-aws-eks-blueprints/latest/add-ons/)

## Submodules

The root module calls into several submodules which provides support for deploying and integrating a number of external AWS services that can be used in concert with Amazon EKS.
This includes Amazon Managed Prometheus and EMR on EKS. For complete documentation on deploying external services, please visit our [submodules documentation](https://aws-ia.github.io/terraform-aws-eks-blueprints/latest/modules/emr-on-eks/).

## Motivation

Kubernetes is a powerful and extensible container orchestration technology that allows you to deploy and manage containerized applications at scale. The extensible nature of Kubernetes also allows you to use a wide range of popular open-source tools, commonly referred to as add-ons, in Kubernetes clusters. With such a large number of tooling and design choices available however, building a tailored EKS cluster that meets your application’s specific needs can take a significant amount of time. It involves integrating a wide range of open-source tools and AWS services and requires deep expertise in AWS and Kubernetes.
Expand All @@ -99,8 +40,6 @@ EKS Blueprints for Terraform is maintained by AWS Solution Architects. It is not

To post feedback, submit feature ideas, or report bugs, please use the [Issues section](https://github.com/aws-ia/terraform-aws-eks-blueprints/issues) of this GitHub repo.

For architectural details, step-by-step instructions, and customization options, see our [documentation site](https://aws-ia.github.io/terraform-aws-eks-blueprints/).
bryantbiggs marked this conversation as resolved.
Show resolved Hide resolved

If you are interested in contributing to EKS Blueprints, see the [Contribution guide](https://github.com/aws-ia/terraform-aws-eks-blueprints/blob/main/CONTRIBUTING.md).

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,31 @@ locals {
}

#---------------------------------------------------------------
# EKS Cluster with terraform-aws-eks module
# EKS Blueprints
#---------------------------------------------------------------

module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 18.0"
version = "~> 18.30"

cluster_name = local.name
cluster_version = "1.23"
cluster_endpoint_private_access = true
cluster_name = local.name
cluster_version = "1.23"

vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

cluster_enabled_log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"]

eks_managed_node_group_defaults = {
instance_types = ["m6i.large", "m5.large", "m5n.large", "m5zn.large"]
create_security_group = false
}

eks_managed_node_groups = {
bottlerocket = {
ami_type = "BOTTLEROCKET_x86_64"
platform = "bottlerocket"
default = {
instance_types = ["m5.large"]

min_size = 1
max_size = 7
max_size = 3
desired_size = 1

update_config = {
max_unavailable_percentage = 33
}
}
}
}

#---------------------------------------------------------------
# Kubernetes Addons using Blueprints kubernetes-addons module
#---------------------------------------------------------------
tags = local.tags
}

module "eks_blueprints_kubernetes_addons" {
source = "../../modules/kubernetes-addons"
Expand All @@ -85,15 +70,26 @@ module "eks_blueprints_kubernetes_addons" {
eks_oidc_provider = module.eks.oidc_provider
eks_cluster_version = module.eks.cluster_version

# EKS Managed Add-ons
enable_amazon_eks_vpc_cni = true
enable_amazon_eks_coredns = true
enable_amazon_eks_kube_proxy = true

# Add-ons
enable_metrics_server = true
enable_cluster_autoscaler = true
enable_aws_cloudwatch_metrics = true
enable_metrics_server = true
enable_cluster_autoscaler = true

# NOTE: Agones requires a Node group in Public Subnets and enable Public IP
enable_agones = true
bryantbiggs marked this conversation as resolved.
Show resolved Hide resolved
agones_helm_config = {
name = "agones"
chart = "agones"
repository = "https://agones.dev/chart/stable"
version = "1.21.0"
namespace = "agones-system"

values = [templatefile("${path.module}/helm_values/agones-values.yaml", {
expose_udp = true
gameserver_namespaces = "{${join(",", ["default", "xbox-gameservers", "xbox-gameservers"])}}"
gameserver_minport = 7000
gameserver_maxport = 8000
})]
}

tags = local.tags
}
Expand All @@ -117,7 +113,6 @@ module "vpc" {
single_nat_gateway = true
enable_dns_hostnames = true

# Manage so we can name
manage_default_network_acl = true
default_network_acl_tags = { Name = "${local.name}-default" }
manage_default_route_table = true
Expand All @@ -126,13 +121,11 @@ module "vpc" {
default_security_group_tags = { Name = "${local.name}-default" }

public_subnet_tags = {
"kubernetes.io/cluster/${local.name}" = "shared"
"kubernetes.io/role/elb" = 1
"kubernetes.io/role/elb" = 1
}

private_subnet_tags = {
"kubernetes.io/cluster/${local.name}" = "shared"
"kubernetes.io/role/internal-elb" = 1
"kubernetes.io/role/internal-elb" = 1
}

tags = local.tags
Expand Down
76 changes: 31 additions & 45 deletions examples/ai-ml/ray/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,16 @@ provider "aws" {
}

provider "kubernetes" {
host = module.eks_blueprints.eks_cluster_endpoint
cluster_ca_certificate = base64decode(module.eks_blueprints.eks_cluster_certificate_authority_data)
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
token = data.aws_eks_cluster_auth.this.token

exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
# This requires the awscli to be installed locally where Terraform is executed
args = ["eks", "get-token", "--cluster-name", module.eks_blueprints.eks_cluster_id]
}
}

provider "helm" {
kubernetes {
host = module.eks_blueprints.eks_cluster_endpoint
cluster_ca_certificate = base64decode(module.eks_blueprints.eks_cluster_certificate_authority_data)
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
token = data.aws_eks_cluster_auth.this.token

exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
# This requires the awscli to be installed locally where Terraform is executed
args = ["eks", "get-token", "--cluster-name", module.eks_blueprints.eks_cluster_id]
}
}
}

Expand All @@ -35,6 +21,10 @@ provider "grafana" {
auth = "admin:${aws_secretsmanager_secret_version.grafana.secret_string}"
}

data "aws_eks_cluster_auth" "this" {
name = module.eks.cluster_id
}

data "aws_availability_zones" "available" {}
data "aws_caller_identity" "current" {}

Expand All @@ -45,10 +35,6 @@ data "aws_acm_certificate" "issued" {
statuses = ["ISSUED"]
}

data "aws_eks_cluster_auth" "this" {
name = module.eks_blueprints.eks_cluster_id
}

locals {
name = basename(path.cwd)
namespace = "ray-cluster"
Expand All @@ -66,14 +52,16 @@ locals {
#---------------------------------------------------------------
# EKS Blueprints
#---------------------------------------------------------------
module "eks_blueprints" {
source = "../../.."

module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 18.30"

cluster_name = local.name
cluster_version = "1.23"

vpc_id = module.vpc.vpc_id
private_subnet_ids = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets

#----------------------------------------------------------------------------------------------------------#
# Security groups used in this module created by the upstream modules terraform-aws-eks (https://github.com/terraform-aws-modules/terraform-aws-eks).
Expand Down Expand Up @@ -114,12 +102,13 @@ module "eks_blueprints" {
}
}

managed_node_groups = {
mg_5 = {
node_group_name = "managed-ondemand"
instance_types = ["m5.8xlarge"]
min_size = 3
subnet_ids = module.vpc.private_subnets
eks_managed_node_groups = {
default = {
instance_types = ["m5.large"]

min_size = 1
max_size = 3
desired_size = 1
}
}

Expand All @@ -132,10 +121,10 @@ module "eks_blueprints" {
module "eks_blueprints_kubernetes_addons" {
source = "../../../modules/kubernetes-addons"

eks_cluster_id = module.eks_blueprints.eks_cluster_id
eks_cluster_endpoint = module.eks_blueprints.eks_cluster_endpoint
eks_oidc_provider = module.eks_blueprints.oidc_provider
eks_cluster_version = module.eks_blueprints.eks_cluster_version
eks_cluster_id = module.eks.cluster_id
eks_cluster_endpoint = module.eks.cluster_endpoint
eks_oidc_provider = module.eks.oidc_provider
eks_cluster_version = module.eks.cluster_version
eks_cluster_domain = var.eks_cluster_domain

# Add-Ons
Expand Down Expand Up @@ -210,7 +199,7 @@ module "s3_bucket" {
data "aws_iam_policy_document" "irsa_policy" {
statement {
actions = ["s3:ListBucket"]
resources = ["${module.s3_bucket.s3_bucket_arn}"]
resources = [module.s3_bucket.s3_bucket_arn]
bryantbiggs marked this conversation as resolved.
Show resolved Hide resolved
}
statement {
actions = ["s3:*Object"]
Expand Down Expand Up @@ -241,7 +230,7 @@ data "aws_iam_policy_document" "irsa_policy" {

resource "aws_iam_policy" "irsa_policy" {
description = "IAM Policy for IRSA"
name_prefix = substr("${module.eks_blueprints.eks_cluster_id}-${local.namespace}-access", 0, 127)
name_prefix = substr("${module.eks.cluster_id}-${local.namespace}-access", 0, 127)
policy = data.aws_iam_policy_document.irsa_policy.json
}

Expand All @@ -250,8 +239,8 @@ module "cluster_irsa" {
kubernetes_namespace = local.namespace
kubernetes_service_account = "${local.namespace}-sa"
irsa_iam_policies = [aws_iam_policy.irsa_policy.arn]
eks_cluster_id = module.eks_blueprints.eks_cluster_id
eks_oidc_provider_arn = module.eks_blueprints.eks_oidc_provider_arn
eks_cluster_id = module.eks.cluster_id
eks_oidc_provider_arn = module.eks.oidc_provider_arn

depends_on = [module.s3_bucket]
}
Expand Down Expand Up @@ -335,7 +324,6 @@ module "vpc" {
single_nat_gateway = true
enable_dns_hostnames = true

# Manage so we can name
manage_default_network_acl = true
default_network_acl_tags = { Name = "${local.name}-default" }
manage_default_route_table = true
Expand All @@ -344,13 +332,11 @@ module "vpc" {
default_security_group_tags = { Name = "${local.name}-default" }

public_subnet_tags = {
"kubernetes.io/cluster/${local.name}" = "shared"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that needed for automatic subnet discovery by LBs or ingress controllers? or since in this example we don't use any then we can safely remove

"kubernetes.io/role/elb" = 1
"kubernetes.io/role/elb" = 1
}

private_subnet_tags = {
"kubernetes.io/cluster/${local.name}" = "shared"
"kubernetes.io/role/internal-elb" = 1
"kubernetes.io/role/internal-elb" = 1
}

tags = local.tags
Expand Down
2 changes: 1 addition & 1 deletion examples/ai-ml/ray/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output "configure_kubectl" {
description = "Configure kubectl: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_blueprints.configure_kubectl
value = "aws eks --region ${local.region} update-kubeconfig --name ${module.eks.cluster_id}"
}

output "s3_bucket" {
Expand Down
2 changes: 1 addition & 1 deletion examples/analytics/spark-k8s-operator/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ module "eks_blueprints_kubernetes_addons" {
aws_for_fluent_bit_cw_log_group = "/${module.eks_blueprints.eks_cluster_id}/worker-fluentbit-logs" # Optional
create_namespace = true
values = [templatefile("${path.module}/helm-values/aws-for-fluentbit-values.yaml", {
region = "${data.aws_region.current.id}"
region = data.aws_region.current.id
aws_for_fluent_bit_cw_log = "/${module.eks_blueprints.eks_cluster_id}/worker-fluentbit-logs"
})]
set = [
Expand Down
4 changes: 0 additions & 4 deletions examples/ci-cd/gitlab-ci-cd/outputs.tf

This file was deleted.

Loading