From 73630c45dacc2c6a32fcedfd3854ccc0308aba4a Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Tue, 14 Nov 2023 10:09:36 +0100 Subject: [PATCH] kustomize + helm now managed by argocd --- apps/homeassistant/ingress.yaml | 2 -- apps/homeassistant/kustomization.yaml | 17 ++++++++++ apps/homeassistant/pvc.yaml | 2 -- infrastructure/argocd/argocd-cm.patch.yaml | 3 ++ infrastructure/argocd/kustomization.yaml | 10 +++++- .../backup/base/db-backup.cronjob.yaml | 32 +++++++++++++++++++ kluster-deployments/README.md | 5 +++ .../homeassistant/application.yaml | 18 +++++++++++ .../homeassistant/kustomization.yaml | 4 +++ kluster-deployments/kustomization.yaml | 3 +- 10 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 apps/homeassistant/kustomization.yaml create mode 100644 infrastructure/argocd/argocd-cm.patch.yaml create mode 100644 infrastructure/backup/base/db-backup.cronjob.yaml create mode 100644 kluster-deployments/README.md create mode 100644 kluster-deployments/homeassistant/application.yaml create mode 100644 kluster-deployments/homeassistant/kustomization.yaml diff --git a/apps/homeassistant/ingress.yaml b/apps/homeassistant/ingress.yaml index 501796b..ad71bb3 100644 --- a/apps/homeassistant/ingress.yaml +++ b/apps/homeassistant/ingress.yaml @@ -2,7 +2,6 @@ apiVersion: traefik.containo.us/v1alpha1 kind: IngressRoute metadata: name: homeassistant-ingress - namespace: homeassistant spec: entryPoints: - websecure @@ -22,7 +21,6 @@ apiVersion: traefik.containo.us/v1alpha1 kind: Middleware metadata: name: homeassistant-websocket - namespace: homeassistant spec: headers: customRequestHeaders: diff --git a/apps/homeassistant/kustomization.yaml b/apps/homeassistant/kustomization.yaml new file mode 100644 index 0000000..b5d63f1 --- /dev/null +++ b/apps/homeassistant/kustomization.yaml @@ -0,0 +1,17 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ingress.yaml +- pvc.yaml + +namespace: homeassistant + + +helmCharts: + - name: home-assistant + releaseName: homeassistant + # namespace: rmoll-harbor-poc + version: 13.4.2 + valuesFile: values.yaml + repo: https://k8s-at-home.com/charts/ + \ No newline at end of file diff --git a/apps/homeassistant/pvc.yaml b/apps/homeassistant/pvc.yaml index 4470983..1bec2d4 100644 --- a/apps/homeassistant/pvc.yaml +++ b/apps/homeassistant/pvc.yaml @@ -2,7 +2,6 @@ apiVersion: v1 kind: PersistentVolume metadata: - namespace: homeassistant name: homeassistant-nfs labels: directory: homeassistant @@ -20,7 +19,6 @@ spec: apiVersion: v1 kind: PersistentVolumeClaim metadata: - namespace: homeassistant name: homeassistant-nfs spec: storageClassName: slow diff --git a/infrastructure/argocd/argocd-cm.patch.yaml b/infrastructure/argocd/argocd-cm.patch.yaml new file mode 100644 index 0000000..5fbef3c --- /dev/null +++ b/infrastructure/argocd/argocd-cm.patch.yaml @@ -0,0 +1,3 @@ +- op: add + path: /data/kustomize.buildOptions + value: --enable-helm diff --git a/infrastructure/argocd/kustomization.yaml b/infrastructure/argocd/kustomization.yaml index 944bfec..72b9def 100644 --- a/infrastructure/argocd/kustomization.yaml +++ b/infrastructure/argocd/kustomization.yaml @@ -8,7 +8,15 @@ resources: - ingress.yaml - argo-apps.application.yaml - ### apply patches from file patchesStrategicMerge: - known-hosts.configmap.yaml + + +## patch to add entries from argocd.configmap.yaml to the configmap +patches: + - target: + kind: ConfigMap + name: argocd-cm + namespace: argocd + path: argocd-cm.patch.yaml diff --git a/infrastructure/backup/base/db-backup.cronjob.yaml b/infrastructure/backup/base/db-backup.cronjob.yaml new file mode 100644 index 0000000..6482455 --- /dev/null +++ b/infrastructure/backup/base/db-backup.cronjob.yaml @@ -0,0 +1,32 @@ +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + name: postgres-backup +spec: + # Backup the database every day at 2AM + schedule: "0 2 * * *" + jobTemplate: + spec: + template: + spec: + containers: + - name: postgres-backup + image: postgres:12 + command: ["/bin/sh"] + args: ["-c", 'echo "$PGPASS" > /root/.pgpass && chmod 600 /root/.pgpass && pg_dump -U postgres_admin -h postgres test_database > /var/backups/backup-$(date +"%m-%d-%Y-%H-%M").sql'] + env: + - name: PGPASS + valueFrom: + secretKeyRef: + name: pgpass + key: pgpass + volumeMounts: + - mountPath: /var/backups + name: postgres-storage + restartPolicy: Never + volumes: + - name: postgres-storage + hostPath: + # Ensure the file directory is created. + path: /var/volumes/postgres-backups + type: DirectoryOrCreate \ No newline at end of file diff --git a/kluster-deployments/README.md b/kluster-deployments/README.md new file mode 100644 index 0000000..498210b --- /dev/null +++ b/kluster-deployments/README.md @@ -0,0 +1,5 @@ +### Argo-apps collection + +The applications and configurations specified in this folder represent the argo-specific configuration needed to deploy apps. The actual configuration of each app is located in its own folder under `/apps/`. + +Since each `application` is a kubernetes CRD they can be bundled through a kustomize setup. \ No newline at end of file diff --git a/kluster-deployments/homeassistant/application.yaml b/kluster-deployments/homeassistant/application.yaml new file mode 100644 index 0000000..60ed3a4 --- /dev/null +++ b/kluster-deployments/homeassistant/application.yaml @@ -0,0 +1,18 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: homeassistant-application + namespace: argocd +spec: + project: default + source: + repoURL: https://github.com/moll-re/k3s-infra.git + targetRevision: HEAD + path: apps/homeassistant + destination: + server: https://kubernetes.default.svc + namespace: homeassistant + syncPolicy: + automated: + prune: true + selfHeal: true \ No newline at end of file diff --git a/kluster-deployments/homeassistant/kustomization.yaml b/kluster-deployments/homeassistant/kustomization.yaml new file mode 100644 index 0000000..0b082ba --- /dev/null +++ b/kluster-deployments/homeassistant/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- application.yaml \ No newline at end of file diff --git a/kluster-deployments/kustomization.yaml b/kluster-deployments/kustomization.yaml index 2a71070..94e6f76 100644 --- a/kluster-deployments/kustomization.yaml +++ b/kluster-deployments/kustomization.yaml @@ -8,4 +8,5 @@ resources: - argocd-imageupdate/ - whoami/ - journal/ - - immich/ \ No newline at end of file + - immich/ + - homeassistant/ \ No newline at end of file