Skip to content

Commit

Permalink
add kubecost addon (#6)
Browse files Browse the repository at this point in the history
Changes for adding Kubecost addon in Bootstrap
  • Loading branch information
ShibraAmin18 committed May 31, 2023
1 parent 546c5fe commit 85293a4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ module "eks_bootstrap" {
single_az_sc_config = [{ name = "infra-service-sc", zone = "us-east-2a" }]
kubeclarity_enabled = false
kubeclarity_hostname = ""
enable_kubecost = false
kubecost_hostname = ""
cert_manager_enabled = true
worker_iam_role_name = ""
worker_iam_role_arn = ""
ingress_nginx_enabled = true
metrics_server_enabled = false
external_secrets_enabled = true
Expand Down
56 changes: 56 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,59 @@ resource "helm_release" "kubeclarity" {
})
]
}

#Kubecost

data "aws_eks_addon_version" "kubecost" {
addon_name = "kubecost_kubecost"
# eks_cluster_version = var.eks_cluster_version != null ? var.eks_cluster_version :
kubernetes_version = data.aws_eks_cluster.eks.version
most_recent = true
}

resource "aws_eks_addon" "kubecost" {
count = var.enable_kubecost ? 1 : 0
cluster_name = var.eks_cluster_name
addon_name = "kubecost_kubecost"
addon_version = data.aws_eks_addon_version.kubecost.version
resolve_conflicts = "OVERWRITE"
service_account_role_arn = var.worker_iam_role_arn
preserve = true

}


resource "kubernetes_ingress_v1" "kubecost" {
count = var.enable_kubecost ? 1 : 0
wait_for_load_balancer = true
metadata {
name = "kubecost"
namespace = "kubecost"
annotations = {
"kubernetes.io/ingress.class" = "nginx"
"cert-manager.io/cluster-issuer"= var.cluster_issuer
}
}
spec {
rule {
host = var.kubecost_hostname
http {
path {
path = "/"
backend {
service {
name = "cost-analyzer-cost-analyzer"
port {
number = 9090
}
}
}
}
}
}
tls {
secret_name = "tls-kubecost"
hosts = [var.kubecost_hostname]
}
}
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ output "kubeclarity_hostname" {
value = var.kubeclarity_hostname
description = "Hostname for the kubeclarity."
}

output "kubecost_hostname" {
value = var.kubecost_hostname
description = "Hostname for the kubecost."
}
24 changes: 24 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ variable "worker_iam_role_name" {
type = string
}

variable "worker_iam_role_arn" {
description = "Specify the IAM role Arn for the nodes"
default = ""
type = string
}

variable "aws_node_termination_handler_enabled" {
description = "Enable or disable node termination handler"
default = false
Expand Down Expand Up @@ -260,3 +266,21 @@ variable "kubeclarity_namespace" {
default = "kubeclarity"
type = string
}
#-----------Kubecost ADDON-------------
variable "enable_kubecost" {
description = "Enable Kubecost add-on"
type = bool
default = true
}

variable "kubecost_hostname" {
description = "Specify the hostname for the kubecsot. "
default = ""
type = string
}

variable "cluster_issuer" {
description = "Specify the letsecrypt cluster-issuer for ingress tls. "
default = "letsencrypt-prod"
type = string
}

0 comments on commit 85293a4

Please sign in to comment.