From dfd31382308943d78aecc144183cae7a5ea504ce Mon Sep 17 00:00:00 2001 From: Luka Krapic Date: Sun, 27 Oct 2024 21:10:02 +0100 Subject: [PATCH] feat: add nginx external ingress addons instalation feat: add nginx external ingress example --- examples/apps/nginx-external.yaml | 27 +++++++++++++++++++ examples/nginx-external/0-namespace.yaml | 5 ++++ examples/nginx-external/1-deployment.yaml | 21 +++++++++++++++ examples/nginx-external/2-service.yaml | 13 +++++++++ examples/nginx-external/3-ingress.yaml | 20 ++++++++++++++ examples/nginx-external/README.md | 11 ++++++++ examples/nginx-external/kustomization.yaml | 8 ++++++ .../addons/{0-versions.tf => 00-versions.tf} | 0 .../{1-variables.tf => 01-variables.tf} | 6 +++++ .../addons/{2-outputs.tf => 02-outputs.tf} | 0 ...3-metric-server.tf => 03-metric-server.tf} | 0 .../{4-pod-identity.tf => 04-pod-identity.tf} | 0 ...toscaller.tf => 05-cluster-autoscaller.tf} | 0 ...ebs-csi-driver.tf => 06-ebs-csi-driver.tf} | 0 .../addons/{7-efs-csi.tf => 07-efs-csi.tf} | 0 .../modules/addons/{8-lbc.tf => 08-lbc.tf} | 0 .../addons/{9-argocd.tf => 09-argocd.tf} | 0 .../addons/10-nginx-external-ingress.tf | 13 +++++++++ infrastructure/modules/addons/README.md | 2 ++ .../addons/values/nginx-external-ingress.yaml | 9 +++++++ 20 files changed, 135 insertions(+) create mode 100644 examples/apps/nginx-external.yaml create mode 100644 examples/nginx-external/0-namespace.yaml create mode 100644 examples/nginx-external/1-deployment.yaml create mode 100644 examples/nginx-external/2-service.yaml create mode 100644 examples/nginx-external/3-ingress.yaml create mode 100644 examples/nginx-external/README.md create mode 100644 examples/nginx-external/kustomization.yaml rename infrastructure/modules/addons/{0-versions.tf => 00-versions.tf} (100%) rename infrastructure/modules/addons/{1-variables.tf => 01-variables.tf} (90%) rename infrastructure/modules/addons/{2-outputs.tf => 02-outputs.tf} (100%) rename infrastructure/modules/addons/{3-metric-server.tf => 03-metric-server.tf} (100%) rename infrastructure/modules/addons/{4-pod-identity.tf => 04-pod-identity.tf} (100%) rename infrastructure/modules/addons/{5-cluster-autoscaller.tf => 05-cluster-autoscaller.tf} (100%) rename infrastructure/modules/addons/{6-ebs-csi-driver.tf => 06-ebs-csi-driver.tf} (100%) rename infrastructure/modules/addons/{7-efs-csi.tf => 07-efs-csi.tf} (100%) rename infrastructure/modules/addons/{8-lbc.tf => 08-lbc.tf} (100%) rename infrastructure/modules/addons/{9-argocd.tf => 09-argocd.tf} (100%) create mode 100644 infrastructure/modules/addons/10-nginx-external-ingress.tf create mode 100644 infrastructure/modules/addons/values/nginx-external-ingress.yaml diff --git a/examples/apps/nginx-external.yaml b/examples/apps/nginx-external.yaml new file mode 100644 index 0000000..1502398 --- /dev/null +++ b/examples/apps/nginx-external.yaml @@ -0,0 +1,27 @@ +--- +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: example-nginx-external + namespace: argocd + + # remove resources when deleting application + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: default + source: + repoURL: https://github.com/LukaK/aws-eks-infrastructure.git + targetRevision: main + path: examples/nginx-external + destination: + server: https://kubernetes.default.svc + syncPolicy: + automated: + prune: true # delete resources + selfHeal: true # drift override + syncOptions: + - Validate=true # validate deployment fields + - CreateNamespace=false # don't create namespaces automatically + - PrunePropagationPolicy=foreground + - PruneLast=true diff --git a/examples/nginx-external/0-namespace.yaml b/examples/nginx-external/0-namespace.yaml new file mode 100644 index 0000000..90f0ef4 --- /dev/null +++ b/examples/nginx-external/0-namespace.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: nginx-external-example diff --git a/examples/nginx-external/1-deployment.yaml b/examples/nginx-external/1-deployment.yaml new file mode 100644 index 0000000..3f74319 --- /dev/null +++ b/examples/nginx-external/1-deployment.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: myapp + namespace: nginx-external-example +spec: + selector: + matchLabels: + app: myapp + template: + metadata: + labels: + app: myapp + spec: + containers: + - name: echoserver + image: ealen/echo-server + ports: + - name: http + containerPort: 80 diff --git a/examples/nginx-external/2-service.yaml b/examples/nginx-external/2-service.yaml new file mode 100644 index 0000000..2117532 --- /dev/null +++ b/examples/nginx-external/2-service.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: myapp + namespace: nginx-external-example +spec: + type: ClusterIP + ports: + - port: 8080 + targetPort: http + selector: + app: myapp diff --git a/examples/nginx-external/3-ingress.yaml b/examples/nginx-external/3-ingress.yaml new file mode 100644 index 0000000..4148f40 --- /dev/null +++ b/examples/nginx-external/3-ingress.yaml @@ -0,0 +1,20 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: myapp + namespace: nginx-external-example +spec: + ingressClassName: external-nginx + rules: + - host: test.lukakrapic.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: myapp + port: + number: 8080 + diff --git a/examples/nginx-external/README.md b/examples/nginx-external/README.md new file mode 100644 index 0000000..b3606dd --- /dev/null +++ b/examples/nginx-external/README.md @@ -0,0 +1,11 @@ +# Nginx External Ingress + +Wait until `Address` field is populated in the ingress and get the value. +```bash +kubectl get ingress -n nginx-external-example +``` + +To test the example use +```bash +curl -i --header "Host: test.lukakrapic.com" http://ADDRESS +``` diff --git a/examples/nginx-external/kustomization.yaml b/examples/nginx-external/kustomization.yaml new file mode 100644 index 0000000..561b965 --- /dev/null +++ b/examples/nginx-external/kustomization.yaml @@ -0,0 +1,8 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - 0-namespace.yaml + - 1-deployment.yaml + - 2-service.yaml + - 3-ingress.yaml diff --git a/infrastructure/modules/addons/0-versions.tf b/infrastructure/modules/addons/00-versions.tf similarity index 100% rename from infrastructure/modules/addons/0-versions.tf rename to infrastructure/modules/addons/00-versions.tf diff --git a/infrastructure/modules/addons/1-variables.tf b/infrastructure/modules/addons/01-variables.tf similarity index 90% rename from infrastructure/modules/addons/1-variables.tf rename to infrastructure/modules/addons/01-variables.tf index 9b096d7..7da3b95 100644 --- a/infrastructure/modules/addons/1-variables.tf +++ b/infrastructure/modules/addons/01-variables.tf @@ -57,6 +57,12 @@ variable "argocd_chart_version" { default = "7.6.12" } +variable "nginx_chart_version" { + type = string + description = "Helm chart version for nginx" + default = "4.10.1" +} + variable "tags" { type = map(string) default = {} diff --git a/infrastructure/modules/addons/2-outputs.tf b/infrastructure/modules/addons/02-outputs.tf similarity index 100% rename from infrastructure/modules/addons/2-outputs.tf rename to infrastructure/modules/addons/02-outputs.tf diff --git a/infrastructure/modules/addons/3-metric-server.tf b/infrastructure/modules/addons/03-metric-server.tf similarity index 100% rename from infrastructure/modules/addons/3-metric-server.tf rename to infrastructure/modules/addons/03-metric-server.tf diff --git a/infrastructure/modules/addons/4-pod-identity.tf b/infrastructure/modules/addons/04-pod-identity.tf similarity index 100% rename from infrastructure/modules/addons/4-pod-identity.tf rename to infrastructure/modules/addons/04-pod-identity.tf diff --git a/infrastructure/modules/addons/5-cluster-autoscaller.tf b/infrastructure/modules/addons/05-cluster-autoscaller.tf similarity index 100% rename from infrastructure/modules/addons/5-cluster-autoscaller.tf rename to infrastructure/modules/addons/05-cluster-autoscaller.tf diff --git a/infrastructure/modules/addons/6-ebs-csi-driver.tf b/infrastructure/modules/addons/06-ebs-csi-driver.tf similarity index 100% rename from infrastructure/modules/addons/6-ebs-csi-driver.tf rename to infrastructure/modules/addons/06-ebs-csi-driver.tf diff --git a/infrastructure/modules/addons/7-efs-csi.tf b/infrastructure/modules/addons/07-efs-csi.tf similarity index 100% rename from infrastructure/modules/addons/7-efs-csi.tf rename to infrastructure/modules/addons/07-efs-csi.tf diff --git a/infrastructure/modules/addons/8-lbc.tf b/infrastructure/modules/addons/08-lbc.tf similarity index 100% rename from infrastructure/modules/addons/8-lbc.tf rename to infrastructure/modules/addons/08-lbc.tf diff --git a/infrastructure/modules/addons/9-argocd.tf b/infrastructure/modules/addons/09-argocd.tf similarity index 100% rename from infrastructure/modules/addons/9-argocd.tf rename to infrastructure/modules/addons/09-argocd.tf diff --git a/infrastructure/modules/addons/10-nginx-external-ingress.tf b/infrastructure/modules/addons/10-nginx-external-ingress.tf new file mode 100644 index 0000000..03f1132 --- /dev/null +++ b/infrastructure/modules/addons/10-nginx-external-ingress.tf @@ -0,0 +1,13 @@ +resource "helm_release" "external_nginx" { + name = "external-nginx" + + repository = "https://kubernetes.github.io/ingress-nginx" + chart = "ingress-nginx" + version = var.nginx_chart_version + + namespace = "ingress" + create_namespace = true + values = [file("values/nginx-external-ingress.yaml")] + + depends_on = [helm_release.aws_lbc] +} diff --git a/infrastructure/modules/addons/README.md b/infrastructure/modules/addons/README.md index f64be2f..46d59a7 100644 --- a/infrastructure/modules/addons/README.md +++ b/infrastructure/modules/addons/README.md @@ -37,6 +37,7 @@ No modules. | [helm_release.aws_lbc](https://registry.terraform.io/providers/hashicorp/helm/2.16.0/docs/resources/release) | resource | | [helm_release.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/helm/2.16.0/docs/resources/release) | resource | | [helm_release.efs_csi_driver](https://registry.terraform.io/providers/hashicorp/helm/2.16.0/docs/resources/release) | resource | +| [helm_release.external_nginx](https://registry.terraform.io/providers/hashicorp/helm/2.16.0/docs/resources/release) | resource | | [helm_release.metric_server](https://registry.terraform.io/providers/hashicorp/helm/2.16.0/docs/resources/release) | resource | ## Inputs @@ -50,6 +51,7 @@ No modules. | [ebs\_csi\_driver\_version](#input\_ebs\_csi\_driver\_version) | Version of the ebs csi driver. | `string` | `"v1.35.0-eksbuild.1"` | no | | [efs\_csi\_chart\_version](#input\_efs\_csi\_chart\_version) | Helm chart version for efs csi driver | `string` | `"3.0.8"` | no | | [metric\_server\_chart\_version](#input\_metric\_server\_chart\_version) | Helm chart version for metric server | `string` | `"3.12.1"` | no | +| [nginx\_chart\_version](#input\_nginx\_chart\_version) | Helm chart version for nginx | `string` | `"4.10.1"` | no | | [pod\_identity\_version](#input\_pod\_identity\_version) | Version of the pod identity agent | `string` | `"v1.3.2-eksbuild.2"` | no | | [region](#input\_region) | Aws region | `string` | `"eu-west-1"` | no | | [tags](#input\_tags) | n/a | `map(string)` | `{}` | no | diff --git a/infrastructure/modules/addons/values/nginx-external-ingress.yaml b/infrastructure/modules/addons/values/nginx-external-ingress.yaml new file mode 100644 index 0000000..da509e4 --- /dev/null +++ b/infrastructure/modules/addons/values/nginx-external-ingress.yaml @@ -0,0 +1,9 @@ +--- +controller: + ingressClassResource: + name: external-nginx + service: + annotations: + service.beta.kubernetes.io/aws-load-balancer-type: external + service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip + service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing