From cdddf441fea401035261f92ac6d700061bb10e57 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Mon, 7 Apr 2025 21:55:53 -0400 Subject: [PATCH] latest --- charts/infrastructure/Chart.yaml | 2 +- .../templates/docker-registry.yml | 49 ++++++++++++++++++ charts/infrastructure/values.yaml | 7 +++ dns.tf | 3 +- infra-charts-values/pihole.yaml | 50 +++++++++++++++++++ modules.tf | 21 ++++++++ plugins.tf | 30 ----------- tf-modules/k8s-helm-charts/charts.tf | 25 ++++++++++ tf-modules/k8s-helm-charts/outputs.tf | 12 +++++ tf-modules/k8s-helm-charts/variables.tf | 27 ++++++++++ values.yaml | 5 ++ 11 files changed, 198 insertions(+), 33 deletions(-) create mode 100644 charts/infrastructure/templates/docker-registry.yml create mode 100644 charts/infrastructure/values.yaml create mode 100644 infra-charts-values/pihole.yaml create mode 100644 modules.tf delete mode 100644 plugins.tf create mode 100644 tf-modules/k8s-helm-charts/charts.tf create mode 100644 tf-modules/k8s-helm-charts/outputs.tf create mode 100644 tf-modules/k8s-helm-charts/variables.tf create mode 100644 values.yaml diff --git a/charts/infrastructure/Chart.yaml b/charts/infrastructure/Chart.yaml index ca51876..9322196 100644 --- a/charts/infrastructure/Chart.yaml +++ b/charts/infrastructure/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v2 name: cluster description: An infrastructure collection of manifests for homelab type: application -version: 0.1.0 +version: 0.1.1 diff --git a/charts/infrastructure/templates/docker-registry.yml b/charts/infrastructure/templates/docker-registry.yml new file mode 100644 index 0000000..14a0415 --- /dev/null +++ b/charts/infrastructure/templates/docker-registry.yml @@ -0,0 +1,49 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: registry +spec: + selector: + matchLabels: + app: registry + replicas: 1 + template: + metadata: + labels: + app: registry + spec: + containers: + - name: registry + image: "{{ .Values.registry.image }}" + ports: + - containerPort: 5000 + volumeMounts: + - name: storage + mountPath: /var/lib/registry + env: + - name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY + value: /var/lib/registry + resources: + requests: + cpu: 0.1 + memory: 250Mi + volumes: + - name: storage + nfs: + server: "{{ .Values.global.nfs.server }}" + path: "{{ .Values.global.nfs.rootPath }}/docker-registry" +--- +apiVersion: v1 +kind: Service +metadata: + name: registry + annotations: + metallb.universe.tf/loadBalancerIPs: "{{ .Values.registry.ip }}" +spec: + type: LoadBalancer + ports: + - port: 80 + targetPort: 5000 + selector: + app: registry diff --git a/charts/infrastructure/values.yaml b/charts/infrastructure/values.yaml new file mode 100644 index 0000000..3effd8f --- /dev/null +++ b/charts/infrastructure/values.yaml @@ -0,0 +1,7 @@ +# pihole: +# ip: 10.0.100.100 +# image: pihole/pihole:latest + +registry: + ip: 10.0.100.101 + image: registry:2 \ No newline at end of file diff --git a/dns.tf b/dns.tf index 6999bad..8b18898 100644 --- a/dns.tf +++ b/dns.tf @@ -26,8 +26,7 @@ locals { } ] ]) - current_date = formatdate("YYYY-MM-DD", timestamp()) - record_comment = "Updated by Terraform at ${local.current_date}" + record_comment = "Updated by Terraform" } output "myip" { diff --git a/infra-charts-values/pihole.yaml b/infra-charts-values/pihole.yaml new file mode 100644 index 0000000..5e3bba8 --- /dev/null +++ b/infra-charts-values/pihole.yaml @@ -0,0 +1,50 @@ +# This is the values.yaml I used on my k3s raspberrypi cluster + +# if you have a problem with serviceWeb Pods not building you might need to checkout this issue: +# https://github.com/MoJo2600/pihole-kubernetes/issues/230 + +ingress: + enabled: true + +persistentVolumeClaim: + enabled: true + +serviceWeb: + loadBalancerIP: 192.168.178.201 + annotations: + metallb.universe.tf/allow-shared-ip: pihole-svc + type: LoadBalancer + +serviceDns: + loadBalancerIP: 192.168.178.201 + annotations: + metallb.universe.tf/allow-shared-ip: pihole-svc + type: LoadBalancer + +serviceDhcp: + loadBalancerIP: 192.168.178.201 + annotations: + metallb.universe.tf/allow-shared-ip: pihole-svc + type: LoadBalancer + +podDnsConfig: + enabled: true + policy: "None" + nameservers: + - 127.0.0.1 + - 8.8.8.8 + +#! use an existing secret in a prod env +adminPassword: "0n4BQ2l7Dbu3ViYgd4wu" + +resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi + +extraEnvVars: { + DNSMASQ_USER: "root" +} \ No newline at end of file diff --git a/modules.tf b/modules.tf new file mode 100644 index 0000000..b393f0e --- /dev/null +++ b/modules.tf @@ -0,0 +1,21 @@ + +resource "helm_release" "local-chart-infrastructure" { + name = "infrastructure" + chart = "charts/infrastructure" + namespace = "default" + set = [{ + name = "ns.metallb" + value = module.k8s-helm-charts.namespaces.plugins.metallb + }] + values = [file("./values.yaml")] + timeout = 120 + force_update = true +}` + +module "k8s-helm-charts" { + source = "./tf-modules/k8s-helm-charts" +} + +output "ns" { + value = module.k8s-helm-charts.namespaces +} diff --git a/plugins.tf b/plugins.tf deleted file mode 100644 index 86faa84..0000000 --- a/plugins.tf +++ /dev/null @@ -1,30 +0,0 @@ -resource "helm_release" "plugin-external-secrets" { - name = "external-secrets" - chart = "external-secrets" - repository = "https://charts.external-secrets.io" - version = "0.14.2" - atomic = true - namespace = "plugin-external-secrets" - create_namespace = true -} - - -resource "helm_release" "plugin-metallb" { - name = "metallb" - chart = "metallb" - repository = "https://metallb.github.io/metallb" - version = "0.14.9" - atomic = true - namespace = "plugin-metallb" - create_namespace = true -} - -resource "helm_release" "local-chart-infrastructure" { - name = "infrastructure" - chart = "charts/infrastructure" - namespace = "default" - set = [{ - name = "ns.metallb" - value = helm_release.plugin-metallb.namespace - }] -} diff --git a/tf-modules/k8s-helm-charts/charts.tf b/tf-modules/k8s-helm-charts/charts.tf new file mode 100644 index 0000000..55ebcc1 --- /dev/null +++ b/tf-modules/k8s-helm-charts/charts.tf @@ -0,0 +1,25 @@ +resource "helm_release" "plugins" { + for_each = var.plugins + name = each.key + chart = each.key + repository = each.value.repository + version = each.value.version + atomic = true + namespace = "plugin-${each.key}" + create_namespace = true +} + +resource "helm_release" "infra" { + for_each = var.infra + name = each.key + chart = each.key + repository = each.value.repository + version = each.value.version + atomic = true + namespace = "infra-${each.key}" + create_namespace = true +} + + + + diff --git a/tf-modules/k8s-helm-charts/outputs.tf b/tf-modules/k8s-helm-charts/outputs.tf new file mode 100644 index 0000000..36fcf09 --- /dev/null +++ b/tf-modules/k8s-helm-charts/outputs.tf @@ -0,0 +1,12 @@ +output "namespaces" { + value = { + plugins = { + for k, v in helm_release.plugins : + k => v.namespace + } + infra = { + for k, v in helm_release.infra : + k => v.namespace + } + } +} diff --git a/tf-modules/k8s-helm-charts/variables.tf b/tf-modules/k8s-helm-charts/variables.tf new file mode 100644 index 0000000..c69d7d1 --- /dev/null +++ b/tf-modules/k8s-helm-charts/variables.tf @@ -0,0 +1,27 @@ +variable "plugins" { + type = map(object({ + repository = string + version = string + values = optional(list(string), []) + })) + default = { + "external-secrets" : { + repository = "https://charts.external-secrets.io" + version = "0.14.2" + }, + "metallb" : { + repository = "https://metallb.github.io/metallb" + version = "0.14.9" + } + } +} + + +variable "infra" { + type = map(object({ + repository = string + version = string + values = optional(list(string), []) + })) + default = {} +} diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..ba8b0b4 --- /dev/null +++ b/values.yaml @@ -0,0 +1,5 @@ +global: + timezone: America/Toronto + nfs: + server: 10.0.10.1 + rootPath: /mnt/EightTerra/k3s-cluster/direct-mounts \ No newline at end of file