diff --git a/README.md b/README.md index 15b04a8..f0eccfe 100644 --- a/README.md +++ b/README.md @@ -7,84 +7,123 @@ |------|---------| | [terraform](#requirement\_terraform) | >= 1.0.0 | | [aws](#requirement\_aws) | >= 4.23 | -| [helm](#requirement\_helm) | >= 2.6 | -| [kubernetes](#requirement\_kubernetes) | >= 2.13 | ## Providers -| Name | -|------| -| aws | -| kubernetes | +| Name | Version | +|------|---------| +| aws | >= 4.23 | +| kubernetes | >= 2.13 | +| helm | >= 2.6 | +| kubectl | >= 1.7.0 | ## Modules | Name | Source | Version | |------|--------|---------| -| [k8s\_addons](#module\_k8s\_addons) | ./addons/helm | n/a | +| [k8s\_addons](#module\_k8s\_addons) | ./addons/helm | 0.0.1 | ## Resources -| Resource Type | Name | Use | -|------|-----|---------| -|null_resource| kubectl | Connect to aws EKS cluster from terminal where the aws cli is configured | -Sample null_resource -```bash -resource "null_resource" "kubectl" { - depends_on = [local_file.kubeconfig] - provisioner "local-exec" { - command = "export KUBE_CONFIG_PATH=${path.cwd}/config/kubeconfig && aws eks update-kubeconfig --name ${module.eks.cluster_name} --region ${local.region}" - } -} -``` +| Name | Use | +|------|-----| +|helm_release| A terraform resource to deploy helm charts on kubernetes cluster | ## Inputs +- Availabel Flags for helm command are [here](https://github.com/clouddrove/terraform-helm-eks-addons/blob/master/addons/helm/main.tf#L2-L33). | Name | Description | Default | Required | |------|-------------|---------|:--------:| -|enable_metrics_server| Set this to true to install metrics-server helmchart on eks cluster | False | Yes | -|enable_cluster_autoscaler| Set this to true to install cluster-autoscaler helmchart on eks cluster | False | Yes | -|enable_aws_load_balancer_controller| Set this to true to install aws-load-balancer-controller helmchart on eks cluster | False | Yes | -|enable_aws_node_termination_handler| Set this to true to install aws-node-termination-handler helmchart on eks cluster | False | Yes | -|enable_aws_efs_csi_driver| Set this to true to install aws-efs-csi-driver helmchart on eks cluster | False | Yes | -|metrics_server_helm_config | Flags for helm command | {values = "addons/addon-name/config/addon-name.yaml"} | No | -|cluster_autoscaler_helm_config | Flags for helm command | {values = "addons/addon-name/config/addon-name.yaml"} | No | -|aws_load_balancer_controller_helm_config | Flags for helm command | {values = "addons/addon-name/config/addon-name.yaml"} | No | -|aws_node_termination_handler_helm_config | Flags for helm command | {values = "addons/addon-name/config/addon-name.yaml"} | No | -|aws_efs_csi_driver_helm_config | Flags for helm command | {values = "addons/addon-name/config/addon-name.yaml"} | No | +|metrics_server| Set this to true to install metrics-server helmchart on eks cluster | False | Yes | +|metrics_server_helm_config | Flags for helm command | {values = "addons/metrics-server/config/metrics_server.yaml"} | No | +|cluster_autoscaler| Set this to true to install cluster-autoscaler helmchart on eks cluster | False | Yes | +|cluster_autoscaler_helm_config | Flags for helm command | {values = "addons/cluster-autoscaler/config/cluster_autoscaler.yaml"} | No | +|aws_load_balancer_controller| Set this to true to install aws-load-balancer-controller helmchart on eks cluster | False | Yes | +|aws_load_balancer_controller_helm_config | Flags for helm command | {values = "addons/aws-load-balancer-controller/config/aws_load_balancer_controller.yaml"} | No | +|aws_node_termination_handler| Set this to true to install aws-node-termination-handler helmchart on eks cluster | False | Yes | +|aws_node_termination_handler_helm_config | Flags for helm command | {values = "addons/aws-node-termination-handler/config/aws_node_termination_handler.yaml"} | No | +|aws_efs_csi_driver| Set this to true to install aws-efs-csi-driver helmchart on eks cluster | False | Yes | +|aws_efs_csi_driver_helm_config | Flags for helm command | {values = "addons/aws-efs-csi-driver/config/aws_efs_csi_driver.yaml"} | No | +|aws_ebs_csi_driver| Set this to true to install aws-ebs-csi-driver helmchart on eks cluster | False | Yes | +|aws_ebs_csi_driver_helm_config | Flags for helm command | {values = "addons/aws-ebs-csi-driver/config/aws_ebs_csi_driver.yaml"} | No | +|karpenter| Set this to true to install karpenter helmchart on eks cluster | False | Yes | +|karpenter_helm_config | Flags for helm command | {values = "addons/karpenter/config/karpenter.yaml"} | No | +|calico_tigera| Set this to true to install Calico helmchart on eks cluster | False | Yes | +|calico_tigera_helm_config | Flags for helm command | {values = "addons/calico-tigera/config/calico-tigera-values.yaml"} | No | +|istio_ingress| Set this to true to install Istio-ingress helmchart on eks cluster | False | Yes | +|istio_manifests| Kubernetes yaml manifests to create `ingress` and `gateway` with specified `host` | addons/istio-ingress/config/manifest/*.yaml | Yes | +|istio_ingress_helm_config | Flags for helm command | {values = "addons/istio-ingress/config/override-values.yaml"} | No | +|kiali_server| Set this to true to install Kiali Dashboard helmchart on eks cluster | False | Yes | +|kiali_manifests| Includes VirtualService manifest file path and flag to install prometheus, grafana & jaeger | kiali_manifests {
kiali_virtualservice_file_path = addons/kiali-server/config/kiali_vs.yaml
enable_monitoring = true
}| Yes | +|kiali_server_helm_config | Flags for helm command | {values = "addons/kiali-server/config/kiali_server.yaml"} | No | +|k8s_pod_restart_info_collector| Set this to true to install k8s-pod-restart-info-collector helmchart on eks cluster | False | Yes | +|info_collector_slack_config | Details of slack channel where to send notification | n/a
an example is given [here](https://github.com/clouddrove/terraform-helm-eks-addons/blob/master/_examples/complete/variables.tf#L117-L126) | Yes | + -- Availabel Flags for helm command are [here](https://github.com/clouddrove/terraform-helm-eks-addons/blob/master/addons/helm/main.tf#L2-L33). ## Outputs No outputs. ## How to Use -An example of usage is given [here](https://github.com/clouddrove/terraform-helm-eks-addons/blob/master/_examples/complete/main.tf#L226-L254) and below also. -If you are running `terraform apply` from local then make sure to set `KUBE_CONFIG_PATH` as an environment variable with value `~/.kube/config` where aws cli is configured, i.e. `export KUBE_CONFIG_PATH=~/.kube/config` +- An example of complete usage is given [here](https://github.com/clouddrove/terraform-helm-eks-addons/blob/master/_examples/complete/main.tf#L190-L232) and below also. + +- Use below terraform module in your infrastructure's terraform script. ```bash -resource "null_resource" "kubectl" { - depends_on = [local_file.kubeconfig] - provisioner "local-exec" { - command = "aws eks update-kubeconfig --name my-eks-cluster --region us-east-1" - } +module "addons" { + source = "clouddrove/eks-addons/aws" + version = "1.3.0" + depends_on = [module.eks.cluster_id] + eks_cluster_name = module.eks.cluster_name + + metrics_server = true + cluster_autoscaler = true + aws_load_balancer_controller = true + aws_node_termination_handler = true + aws_efs_csi_driver = true + aws_ebs_csi_driver = true + karpenter = false + calico_tigera = false + + kiali_server = true + kiali_manifests = var.kiali_manifests + + istio_ingress = true + istio_manifests = var.istio_manifests + + k8s_pod_restart_info_collector = true + info_collector_slack_config = var.info_collector_slack_config } -module "addons" { - source = "../../addons" - depends_on = [null_resource.kubectl] +``` - eks_cluster_name = "my-eks-cluster" +## Known Issues + +- ### Istio Ingress + - Our `istio-ingress` addon creates an Application Load Balancer on AWS by using `aws-load-balancer-controller`. + - aws-load-balancer-controller adds a `finalizer` field in `ingress` resource to prevent its manual deletion. + - Another case is that, this ingress will be **non-deletable** if aws-load-balancer-controller gets deleted before deletion of ingress + - Terraform does not controlls order of destructure which is sometimes causing `aws-load-balancer-controller` helmchart uninstallation before istio-ingress deletion. + - The same issue will come when an appliaction uses ingress of type ALB; In this case we need to delete `istio-ingress` & ALB of applications manually by following some extra steps as shown below. + 1. Set `istio_ingress` to `false` in your terraform addon module. + 2. Run `terraform apply`, this will delete all the resource created by istio-ingress addon including istio-load-balancer. + 3. To delete ingress created by application run below command + ```bash + kubectl patch ingress ingressName -n namespace -p '{"metadata":{"finalizers":[]}}' --type=merge + ``` + 4. Now you can run `terraform destroy` for complete destruction. + +- ### Calico CNI + Our `calico-tigera` addon creates `trigera-operator` and `calico-node` out of which `calico-node` is being created using a manifest (calico-deployment.yaml). This manifest create two serviceAccounts (`calico-cni-plugin` & `calico-node`) which needs to be delete manually as shown below - + 1. Run `kubectl edit serviceAccount calico-cni-plugin -n calico-system` and delete `finalizer` block, then save and exit. + 2. Run `kubectl edit serviceAccount calico-node -n calico-system` and delete `finalizer` block, then save and exit. + 3. If both seriveAccount aren't deleted then run below command to delete them + ```bash + kubectl delete seriveAccount calico-cni-plugin calico-node -n calico-system + ``` - enable_metrics_server = true - enable_cluster_autoscaler = true - enable_aws_load_balancer_controller = true - enable_aws_node_termination_handler = true - enable_aws_efs_csi_driver = true -} -``` ## Feedback If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-helm-eks-addons/issues), or feel free to drop us an email at [hello@clouddrove.com](mailto:hello@clouddrove.com). diff --git a/_examples/basic/main.tf b/_examples/basic/main.tf index 723c970..f904ea5 100644 --- a/_examples/basic/main.tf +++ b/_examples/basic/main.tf @@ -187,63 +187,11 @@ data "aws_ami" "eks_default_arm" { } } -resource "local_file" "kubeconfig" { - depends_on = [ - module.eks.cluster_id - ] - content = < -## Requirements - -| Name | Version | -|------|---------| -| [terraform](#requirement\_terraform) | >= 1.0.0 | -| [aws](#requirement\_aws) | >= 4.23 | -| [helm](#requirement\_helm) | >= 2.6 | -| [kubernetes](#requirement\_kubernetes) | >= 2.13 | - -## Providers - -No providers. - -## Modules - -| Name | Source | Version | -|------|--------|---------| -| [addons](#module\_addons) | ../../ | n/a | -| [eks](#module\_eks) | terraform-aws-modules/eks/aws | 19.13.1 | -| [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | 4.0.1 | - -## Resources - -No resources. - -## Inputs - -No inputs. - -## Outputs - -No outputs. - diff --git a/_examples/complete/main.tf b/_examples/complete/main.tf index 17ed38c..14540e4 100644 --- a/_examples/complete/main.tf +++ b/_examples/complete/main.tf @@ -187,63 +187,11 @@ data "aws_ami" "eks_default_arm" { } } -resource "local_file" "kubeconfig" { - depends_on = [ - module.eks.cluster_id - ] - content = < diff --git a/addons/istio-ingress/config/gateway.yaml b/addons/istio-ingress/config/manifest/gateway.yaml similarity index 100% rename from addons/istio-ingress/config/gateway.yaml rename to addons/istio-ingress/config/manifest/gateway.yaml diff --git a/addons/istio-ingress/config/ingress.yaml b/addons/istio-ingress/config/manifest/ingress.yaml similarity index 100% rename from addons/istio-ingress/config/ingress.yaml rename to addons/istio-ingress/config/manifest/ingress.yaml diff --git a/addons/istio-ingress/config/virtual-service.yaml b/addons/istio-ingress/config/manifest/virtual-service.yaml similarity index 100% rename from addons/istio-ingress/config/virtual-service.yaml rename to addons/istio-ingress/config/manifest/virtual-service.yaml diff --git a/addons/istio-ingress/main.tf b/addons/istio-ingress/main.tf index 51a63e5..e9da12f 100644 --- a/addons/istio-ingress/main.tf +++ b/addons/istio-ingress/main.tf @@ -34,18 +34,14 @@ module "istio_ingress" { ] } -resource "null_resource" "istio_ingress_manifest" { +resource "kubectl_manifest" "istio_ingress_manifest" { depends_on = [module.istio_ingress] - provisioner "local-exec" { - command = "kubectl apply -f ${var.istio_manifests.istio_ingress_manifest_file_path} -n ${var.istio_ingress_default_helm_config.namespace}" - } + yaml_body = file("${var.istio_manifests.istio_ingress_manifest_file_path}") } -resource "null_resource" "istio_gateway_manifest" { - depends_on = [null_resource.istio_ingress_manifest] - provisioner "local-exec" { - command = "kubectl apply -f ${var.istio_manifests.istio_gateway_manifest_file_path} -n ${var.istio_ingress_default_helm_config.namespace}" - } +resource "kubectl_manifest" "istio_gateway_manifest" { + depends_on = [kubectl_manifest.istio_ingress_manifest] + yaml_body = file("${var.istio_manifests.istio_gateway_manifest_file_path}") } resource "kubernetes_namespace_v1" "istio_system" { @@ -55,4 +51,3 @@ resource "kubernetes_namespace_v1" "istio_system" { name = local.istio_base.helm_config["namespace"] } } - diff --git a/addons/istio-ingress/variables.tf b/addons/istio-ingress/variables.tf index 50eb2f1..b81900a 100644 --- a/addons/istio-ingress/variables.tf +++ b/addons/istio-ingress/variables.tf @@ -69,4 +69,4 @@ variable "istio_ingress_default_helm_config" { namespace = "istio-system" description = "Istio Ingress helm Chart deployment configuration" } -} +} \ No newline at end of file diff --git a/addons/istio-ingress/versions.tf b/addons/istio-ingress/versions.tf index 55fba73..5f011d1 100644 --- a/addons/istio-ingress/versions.tf +++ b/addons/istio-ingress/versions.tf @@ -6,5 +6,13 @@ terraform { source = "hashicorp/kubernetes" version = ">= 2.10" } + helm = { + source = "hashicorp/helm" + version = ">= 2.6" + } + kubectl = { + source = "gavinbunney/kubectl" + version = ">= 1.7.0" + } } } diff --git a/main.tf b/main.tf index 0a40cb2..c203a18 100644 --- a/main.tf +++ b/main.tf @@ -6,7 +6,6 @@ module "metrics_server" { addon_context = local.addon_context } - module "cluster_autoscaler" { count = var.cluster_autoscaler ? 1 : 0 source = "./addons/cluster-autoscaler" diff --git a/versions.tf b/versions.tf index a02a4a7..08b59c6 100644 --- a/versions.tf +++ b/versions.tf @@ -10,5 +10,13 @@ terraform { source = "hashicorp/time" version = ">= 0.8" } + helm = { + source = "hashicorp/helm" + version = ">= 2.6" + } + kubectl = { + source = "gavinbunney/kubectl" + version = ">= 1.7.0" + } } }