Skip to content

Commit

Permalink
remove kubectl
Browse files Browse the repository at this point in the history
  • Loading branch information
morga471 committed Dec 19, 2024
1 parent 4907b11 commit 29893ab
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 127 deletions.
21 changes: 1 addition & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ The module configures an eks cluster with additional components after the cluste
- A gp2-encrypted storage class is created
- An efs storage class is created
- This storage class is returned as the `rwx_storage_class`
- cluster-autoscaler
- Monitors cpu/memory usage by components being deployed to the clsuter.
- When the cluster is out of capacity, the autoscaler will add nodes to the cluster up to the maximum size of the node group.
- When the autoscaler detects excess capacity, the autoscaler will cause EKS to migrate pods running on the node to a different node and then remove the node from the cluster.

When selecting which version of the cluster-autoscaler to install, use the one that is closest to the same version as the `cluster_version` or slightly higher.
The cluster-autoscaler uses the kuberentes scheduling algorithm to appropriate scale the cluster, and if the autoscaler version sufficiently divirges from the kubernetes version, the autoscaler will scale the node groups incorrectly.

A successful apply will yield:
Apply complete! Resources: 14 added, 0 changed, 0 destroyed.
Expand Down Expand Up @@ -45,7 +38,6 @@ sys 0m2.015s
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.14.0 |
| <a name="requirement_http"></a> [http](#requirement\_http) | >= 2.1.0 |
| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | >= 1.14.0 |
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.23.0 |

## Providers
Expand All @@ -54,40 +46,33 @@ sys 0m2.015s
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.73.0 |
| <a name="provider_http"></a> [http](#provider\_http) | 3.4.5 |
| <a name="provider_kubectl"></a> [kubectl](#provider\_kubectl) | 1.14.0 |
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.33.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_efs"></a> [efs](#module\_efs) | git@github.e.it.census.gov:terraform-modules/aws-efs.git | master |
| <a name="module_images"></a> [images](#module\_images) | git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade |

## Resources

| Name | Type |
|------|------|
| [kubectl_manifest.deploy_cluster_roles](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource |
| [kubernetes_manifest.deploy_cluster_roles](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
| [kubernetes_namespace.operators](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource |
| [kubernetes_storage_class.ebs_encrypted](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/storage_class) | resource |
| [kubernetes_storage_class.efs_sc](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/storage_class) | resource |
| [kubernetes_storage_class.gp3_encrypted](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/storage_class) | resource |
| [aws_ebs_default_kms_key.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ebs_default_kms_key) | data source |
| [aws_kms_key.ebs_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_key) | data source |
| [http_http.cluster_roles](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source |
| [kubectl_file_documents.access_documents](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/data-sources/file_documents) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | EKS cluster name name component used through out the EKS cluster describing its purpose (ex: dice-dev) | `string` | n/a | yes |
| <a name="input_eks_managed_node_groups_autoscaling_group_names"></a> [eks\_managed\_node\_groups\_autoscaling\_group\_names](#input\_eks\_managed\_node\_groups\_autoscaling\_group\_names) | List of the autoscaling group names created by EKS managed node groups | `list(string)` | n/a | yes |
| <a name="input_kubectl_image_tag"></a> [kubectl\_image\_tag](#input\_kubectl\_image\_tag) | The version of bitnami/kubectl image to use. | `string` | `"1.30.4"` | no |
| <a name="input_oidc_provider_arn"></a> [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | The ARN of the OIDC Provider if `enable_irsa = true` | `string` | n/a | yes |
| <a name="input_operators_ns"></a> [operators\_ns](#input\_operators\_ns) | Namespace to create where operators will be installed. | `string` | `"operators"` | no |
| <a name="input_profile"></a> [profile](#input\_profile) | AWS config profile | `string` | `""` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | n/a | yes |
| <a name="input_security_group_all_worker_mgmt_id"></a> [security\_group\_all\_worker\_mgmt\_id](#input\_security\_group\_all\_worker\_mgmt\_id) | The security group representing all of the worker nodes in the cluster. | `string` | n/a | yes |
| <a name="input_subnets"></a> [subnets](#input\_subnets) | Specify the subnets used by this cluster | `list(string)` | n/a | yes |
Expand All @@ -99,10 +84,6 @@ sys 0m2.015s

| Name | Description |
|------|-------------|
| <a name="output_kubectl_image_full_path"></a> [kubectl\_image\_full\_path](#output\_kubectl\_image\_full\_path) | The full URI to access the kubectl image including the registry/repository:tag |
| <a name="output_kubectl_image_registry"></a> [kubectl\_image\_registry](#output\_kubectl\_image\_registry) | The registry portion of the URI to access the kubectl image |
| <a name="output_kubectl_image_repository"></a> [kubectl\_image\_repository](#output\_kubectl\_image\_repository) | The repository portion of the URI to access the kubectl image |
| <a name="output_kubectl_image_tag"></a> [kubectl\_image\_tag](#output\_kubectl\_image\_tag) | The tag portion of the URI to access the kubectl image |
| <a name="output_module_name"></a> [module\_name](#output\_module\_name) | The name of this module. |
| <a name="output_module_version"></a> [module\_version](#output\_module\_version) | The version of this module. |
| <a name="output_rwo_storage_class"></a> [rwo\_storage\_class](#output\_rwo\_storage\_class) | Kubernetes storage class that supports read/write once. |
Expand Down
5 changes: 5 additions & 0 deletions aws_data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "aws_ebs_default_kms_key" "current" {}

data "aws_kms_key" "ebs_key" {
key_id = data.aws_ebs_default_kms_key.current.key_arn
}
24 changes: 2 additions & 22 deletions copy_images.tf → copy_images.tf.off
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
locals {
# autoscaler_key = format("%v#%v", "cluster-autoscaler", var.cluster_autoscaler_tag)
kubectl_key = format("%v#%v", "kubectl", var.kubectl_image_tag)

image_config = [
# {
# enabled = true
# dest_path = null
# name = "cluster-autoscaler"
# source_image = "autoscaling/cluster-autoscaler"
# source_registry = "registry.k8s.io"
# source_tag = null
# tag = var.cluster_autoscaler_tag
# },
{
enabled = true
dest_path = null
Expand All @@ -20,7 +10,7 @@ locals {
source_registry = "docker.io"
source_tag = var.kubectl_image_tag
tag = var.kubectl_image_tag
},
}
]
}

Expand All @@ -32,18 +22,8 @@ module "images" {
image_config = local.image_config
tags = {}

### optional
## account_alias = ""
## account_id = ""
## destination_password = ""
## destination_username = ""
## override_prefixes = {}
## region = ""
## source_password = ""
## source_username = ""

enable_lifecycle_policy = true
lifecycle_policy_all = true
force_delete = true

lifecycle_policy_keep_count = 3
}
28 changes: 10 additions & 18 deletions eks_console_access.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,22 @@ locals {
},
]
cluster_roles_map = { for cr in local.cluster_roles : cr.name => cr }
all_access_documents = flatten([
for cr_name, cr_data in local.cluster_roles_map : [
yamldecode(data.http.cluster_roles[cr_name].body)
] if cr_data.enabled
])
}


# Fetch the YAML files from the specified URLs
data "http" "cluster_roles" {
for_each = local.cluster_roles_map
url = each.value.url
}

data "kubectl_file_documents" "access_documents" {
for_each = { for k, v in local.cluster_roles_map : k => v if v.enabled }

content = data.http.cluster_roles[each.key].body
}

locals {
all_access_documents = flatten([
for cr_name, cr_data in local.cluster_roles_map : [
for doc in data.kubectl_file_documents.access_documents[cr_name].manifests : doc
] if cr_data.enabled
])
}

resource "kubectl_manifest" "deploy_cluster_roles" {
count = length(local.all_access_documents)
# Apply the Kubernetes manifests to the cluster
resource "kubernetes_manifest" "deploy_cluster_roles" {
for_each = { for idx, doc in local.all_access_documents : idx => doc }

yaml_body = local.all_access_documents[count.index]
manifest = each.value
}
6 changes: 0 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
data "aws_ebs_default_kms_key" "current" {}

data "aws_kms_key" "ebs_key" {
key_id = data.aws_ebs_default_kms_key.current.key_arn
}

locals {
base_tags = {
"eks-cluster-name" = var.cluster_name
Expand Down
46 changes: 23 additions & 23 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ output "rwx_storage_class" {
value = kubernetes_storage_class.efs_sc.metadata[0].name
}

################################################################################
# Details about kubectl image
################################################################################

output "kubectl_image_full_path" {
description = "The full URI to access the kubectl image including the registry/repository:tag"
value = module.images.images[local.kubectl_key].dest_full_path
}

output "kubectl_image_registry" {
description = "The registry portion of the URI to access the kubectl image"
value = module.images.images[local.kubectl_key].dest_registry
}

output "kubectl_image_repository" {
description = "The repository portion of the URI to access the kubectl image"
value = module.images.images[local.kubectl_key].dest_repository
}

output "kubectl_image_tag" {
description = "The tag portion of the URI to access the kubectl image"
value = module.images.images[local.kubectl_key].tag
}
# ################################################################################
# # Details about kubectl image
# ################################################################################

# output "kubectl_image_full_path" {
# description = "The full URI to access the kubectl image including the registry/repository:tag"
# value = module.images.images[local.kubectl_key].dest_full_path
# }

# output "kubectl_image_registry" {
# description = "The registry portion of the URI to access the kubectl image"
# value = module.images.images[local.kubectl_key].dest_registry
# }

# output "kubectl_image_repository" {
# description = "The repository portion of the URI to access the kubectl image"
# value = module.images.images[local.kubectl_key].dest_repository
# }

# output "kubectl_image_tag" {
# description = "The tag portion of the URI to access the kubectl image"
# value = module.images.images[local.kubectl_key].tag
# }
4 changes: 0 additions & 4 deletions requirements.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ terraform {
source = "hashicorp/http"
version = ">= 2.1.0"
}
kubectl = {
source = "gavinbunney/kubectl"
version = ">= 1.14.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.23.0"
Expand Down
47 changes: 13 additions & 34 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ variable "region" {
type = string
}

variable "profile" {
description = "AWS config profile"
type = string
default = ""
}

variable "vpc_id" {
description = "Specify the VPC id that is used by this cluster"
type = string
Expand All @@ -30,17 +24,17 @@ variable "security_group_all_worker_mgmt_id" {
type = string
}

# tflint-ignore: terraform_unused_declarations
variable "eks_managed_node_groups_autoscaling_group_names" {
description = "List of the autoscaling group names created by EKS managed node groups"
type = list(string)
}
# # tflint-ignore: terraform_unused_declarations
# variable "eks_managed_node_groups_autoscaling_group_names" {
# description = "List of the autoscaling group names created by EKS managed node groups"
# type = list(string)
# }

# tflint-ignore: terraform_unused_declarations
variable "oidc_provider_arn" {
description = "The ARN of the OIDC Provider if `enable_irsa = true`"
type = string
}
# # tflint-ignore: terraform_unused_declarations
# variable "oidc_provider_arn" {
# description = "The ARN of the OIDC Provider if `enable_irsa = true`"
# type = string
# }

variable "operators_ns" {
description = "Namespace to create where operators will be installed."
Expand All @@ -60,23 +54,8 @@ variable "tags" {
default = {}
}

variable "kubectl_image_tag" {
description = "The version of bitnami/kubectl image to use."
type = string
default = "1.30.4"
}

# # helm add repo autoscaler "https://kubernetes.github.io/autoscaler"
# # helm search repo -l autoscaler/cluster-autoscaler
# variable "cluster_autoscaler_chart_version" {
# description = "The helm chart of the cluster-autoscaler most closely matching the Kuberentes version. Review output of `helm add repo autoscaler 'https://kubernetes.github.io/autoscaler'` (if the repo hasn't been added previously) and `helm search repo -l autoscaler/cluster-autoscaler`"
# type = string
# default = "9.37.0"
# }

# # helm show values --version [cluster_autoscaler_chart_version] autoscaler/cluster-autoscaler | grep tag:
# variable "cluster_autoscaler_tag" {
# description = "Image tag of cluster-autoscaler associated with the cluster_autoscaler_chart_version helm chart. `helm show values --version [cluster_autoscaler_chart_version] autoscaler/cluster-autoscaler | grep tag:`"
# variable "kubectl_image_tag" {
# description = "The version of bitnami/kubectl image to use."
# type = string
# default = "v1.30.0"
# default = "1.30.4"
# }

0 comments on commit 29893ab

Please sign in to comment.