From d9fad4fa927396e5d274747a05ae3d6f00b78628 Mon Sep 17 00:00:00 2001 From: aggarwalakshun Date: Wed, 17 Dec 2025 20:44:13 +0530 Subject: [PATCH] use statefulSets and readinessProbes instead of initContainers --- clusters/default/media/immich/immich-db.yml | 41 ++++++++++------- .../default/media/immich/immich-redis.yml | 23 ++++++++++ clusters/default/media/immich/immich-svc.yml | 14 +++--- clusters/default/media/immich/immich.yml | 45 +++++++------------ 4 files changed, 72 insertions(+), 51 deletions(-) create mode 100644 clusters/default/media/immich/immich-redis.yml diff --git a/clusters/default/media/immich/immich-db.yml b/clusters/default/media/immich/immich-db.yml index 4c19bd8..43f33b4 100644 --- a/clusters/default/media/immich/immich-db.yml +++ b/clusters/default/media/immich/immich-db.yml @@ -1,30 +1,33 @@ --- apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: - name: immich-db + name: immich-psql namespace: media spec: selector: matchLabels: - app: immich-db + app: immich-psql + serviceName: immich-psql + replicas: 1 template: metadata: labels: - app: immich-db + app: immich-psql spec: + initContainers: + - name: cleanup + image: busybox + command: ['sh', '-c', 'rm -rf /var/lib/postgresql/data/lost+found'] + volumeMounts: + - name: immich-db + mountPath: /var/lib/postgresql/data containers: - - name: redis - image: docker.io/valkey/valkey:8-bookworm@sha256:fea8b3e67b15729d4bb70589eb03367bab9ad1ee89c876f54327fc7c6e618571 - env: - - name: REDIS_HOSTNAME - value: "localhost" - ports: - - containerPort: 6379 - name: immich-psql image: ghcr.io/immich-app/postgres:14-vectorchord0.3.0-pgvectors0.2.0 ports: - containerPort: 5432 + name: postgres env: - name: POSTGRES_PASSWORD valueFrom: @@ -39,9 +42,13 @@ spec: value: "--data-checksums" volumeMounts: - mountPath: /var/lib/postgresql/data - name: immich - volumes: - - name: immich - nfs: - server: 10.0.0.10 - path: /home/akshun/immich-data + name: immich-db + volumeClaimTemplates: + - metadata: + name: immich-db + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 5Gi + storageClassName: longhorn diff --git a/clusters/default/media/immich/immich-redis.yml b/clusters/default/media/immich/immich-redis.yml new file mode 100644 index 0000000..eb78e64 --- /dev/null +++ b/clusters/default/media/immich/immich-redis.yml @@ -0,0 +1,23 @@ +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: immich-redis + namespace: media +spec: + selector: + matchLabels: + app: immich-redis + serviceName: immich-redis + replicas: 1 + template: + metadata: + labels: + app: immich-redis + spec: + containers: + - name: redis + image: docker.io/valkey/valkey:8-bookworm@sha256:fea8b3e67b15729d4bb70589eb03367bab9ad1ee89c876f54327fc7c6e618571 + ports: + - containerPort: 6379 + name: redis diff --git a/clusters/default/media/immich/immich-svc.yml b/clusters/default/media/immich/immich-svc.yml index 5c6b54f..69b3e44 100644 --- a/clusters/default/media/immich/immich-svc.yml +++ b/clusters/default/media/immich/immich-svc.yml @@ -36,26 +36,28 @@ spec: apiVersion: v1 kind: Service metadata: - name: immich-psql-service + name: immich-psql namespace: media spec: selector: - app: immich-db + app: immich-psql ports: - - protocol: TCP + - name: postgres port: 5432 targetPort: 5432 + clusterIP: None --- apiVersion: v1 kind: Service metadata: - name: immich-redis-service + name: immich-redis namespace: media spec: selector: - app: immich-db + app: immich-redis ports: - - protocol: TCP + - name: redis port: 6379 targetPort: 6379 + clusterIP: None diff --git a/clusters/default/media/immich/immich.yml b/clusters/default/media/immich/immich.yml index 9d33892..7820bed 100644 --- a/clusters/default/media/immich/immich.yml +++ b/clusters/default/media/immich/immich.yml @@ -16,48 +16,37 @@ spec: labels: app: immich-app spec: - initContainers: - - name: wait-for-redis - image: busybox - command: - - sh - - -c - - | - until nc -z -v -w30 immich-redis-service 6379; do - echo "Waiting for redis database to be ready..." - sleep 2 - done - - name: wait-for-psql - image: busybox - command: - - sh - - -c - - | - until nc -z -v -w30 immich-psql-service 5432; do - echo "Waiting for psql database to be ready" - sleep 2 - done containers: - name: immich-server image: ghcr.io/immich-app/immich-server:v2.3.1 + readinessProbe: + exec: + command: + - sh + - -c + - | + pg_isready -h immich-psql.media.svc.cluster.local -U postgres -p 5432 + initialDelaySeconds: 10 + periodSeconds: 5 + failureThreshold: 5 ports: - containerPort: 2283 env: - name: TZ value: "Asia/Kolkata" - name: REDIS_HOSTNAME - value: "immich-redis-service" - - name: DB_PASSWORD - valueFrom: - secretKeyRef: - name: immich-postgres-secret - key: password + value: "immich-redis.media.svc.cluster.local" - name: DB_USERNAME value: "postgres" - name: DB_DATABASE_NAME value: "immich" - name: DB_HOSTNAME - value: "immich-psql-service" + value: "immich-psql.media.svc.cluster.local" + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: immich-postgres-secret + key: password volumeMounts: - mountPath: /usr/src/app/upload name: pictures