From 797b4da72fb2253caeee61b977bb4733bd40eb44 Mon Sep 17 00:00:00 2001 From: A B Date: Tue, 13 May 2025 14:09:26 +0000 Subject: [PATCH] Added nas DB --- k8s/core/postgresql/kustomization.yaml | 8 +- k8s/core/postgresql/nas.yaml | 142 +++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 k8s/core/postgresql/nas.yaml diff --git a/k8s/core/postgresql/kustomization.yaml b/k8s/core/postgresql/kustomization.yaml index 53c9d7e..8371331 100644 --- a/k8s/core/postgresql/kustomization.yaml +++ b/k8s/core/postgresql/kustomization.yaml @@ -6,7 +6,7 @@ resources: - app.yaml - external-secrets.yaml - main-db.yaml - - nas-db.yaml + - nas.yaml helmCharts: @@ -18,3 +18,9 @@ helmCharts: valuesFile: pgadmin4-values.yaml includeCRDs: true + - name: cloudnative-pg + repo: https://cloudnative-pg.github.io/charts + version: 0.23.2 + releaseName: cnpg + namespace: psql + includeCRDs: true diff --git a/k8s/core/postgresql/nas.yaml b/k8s/core/postgresql/nas.yaml new file mode 100644 index 0000000..6720a92 --- /dev/null +++ b/k8s/core/postgresql/nas.yaml @@ -0,0 +1,142 @@ +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: immich-pv + namespace: immich +spec: + capacity: + storage: 50Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + storageClassName: nfs-storage + nfs: + server: nas.homenet + path: /mnt/storage/Storage/k8s/immich/db-vector + readOnly: false + volumeMode: Filesystem + +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: nfs-storage +provisioner: kubernetes.io/no-provisioner +reclaimPolicy: Retain +volumeBindingMode: Immediate + +--- +apiVersion: v1 +data: + password: cG9zdGdyZXM= + username: cG9zdGdyZXM= +kind: Secret +metadata: + name: immich-db-pass + namespace: immich +type: kubernetes.io/basic-auth + +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: immich + namespace: immich +spec: + description: "PostgreSQL cluster for Immich with vector support" + imageName: ghcr.io/tensorchord/cloudnative-pgvecto.rs:14-v0.3.0 + enableSuperuserAccess: true + instances: 1 + startDelay: 300 + primaryUpdateStrategy: unsupervised + + postgresql: + parameters: + shared_buffers: "512MB" + max_wal_size: "2GB" + wal_compression: "on" + shared_preload_libraries: + - "vectors.so" + pg_hba: + - host all all 0.0.0.0/0 md5 + + bootstrap: + initdb: + database: immich + owner: postgres + dataChecksums: true + secret: + name: immich-db-pass + postInitApplicationSQL: + - ALTER SYSTEM SET search_path TO "$user", public, vectors; + - SET search_path TO "$user", public, vectors; + - CREATE EXTENSION IF NOT EXISTS "vectors"; + - ALTER SCHEMA vectors OWNER TO "postgres"; + - GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA vectors TO "postgres"; + - GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "postgres"; + - CREATE EXTENSION IF NOT EXISTS cube; + - CREATE EXTENSION IF NOT EXISTS earthdistance; + + storage: + size: 50Gi + storageClass: nfs-storage + pvcTemplate: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Gi + storageClassName: nfs-storage + volumeMode: Filesystem + + # Настройки ресурсов + resources: + requests: + memory: "1Gi" + cpu: "500m" + limits: + memory: "2Gi" + cpu: "1000m" + + affinity: + enablePodAntiAffinity: true + nodeAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + preference: + matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - nas.homenet + + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - home.homenet + - nas.homenet + + tolerations: + - key: cnpg.io/cluster + effect: NoSchedule + value: immich-db + operator: Equal + + additionalPodAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.component + operator: In + values: + - "pg-cluster" + topologyKey: topology.kubernetes.io/zone + + monitoring: + enablePodMonitor: true