diff --git a/.env.dev b/.env.dev index 0c807eb9..bae77065 100644 --- a/.env.dev +++ b/.env.dev @@ -28,4 +28,8 @@ LOGSTASH_INDEX= #=================== SLACK WEB HOOK =================== SLACK_WEBHOOK_URL= SLACK_LOGGING=false -REDIS_URL= \ No newline at end of file + +REDIS_HOST= +REDIS_PORT=6379 +REDIS_USERNAME= +REDIS_PASSWORD= diff --git a/kubernetes/base/kustomization.yml b/kubernetes/base/kustomization.yml index f9a26a3f..a588e9ff 100644 --- a/kubernetes/base/kustomization.yml +++ b/kubernetes/base/kustomization.yml @@ -5,4 +5,4 @@ resources: - service.yml - ingress.yml - secrets.yml -# - redis.yml +- redis.yml diff --git a/kubernetes/base/redis.yml b/kubernetes/base/redis.yml index 0da55443..10a24a79 100644 --- a/kubernetes/base/redis.yml +++ b/kubernetes/base/redis.yml @@ -1,9 +1,21 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: defi-providers-redis-pvc +spec: + accessModes: + - ReadWriteOnce + storageClassName: gp3 + resources: + requests: + storage: 1G +--- apiVersion: apps/v1 kind: Deployment metadata: name: defi-providers-redis spec: - replicas: 0 + replicas: 1 selector: matchLabels: component: defi-providers-redis @@ -14,27 +26,36 @@ spec: spec: containers: - name: defi-providers-redis - image: redis:7.0.11 + image: redis:7 imagePullPolicy: Always - args: ["--requirepass", "$(REDIS_PASS)"] + args: ["--requirepass", "$(REDIS_PASSWORD)"] resources: requests: - cpu: 250m - memory: 512Mi + cpu: 100m + memory: 512M limits: cpu: 1000m - memory: 1Gi + memory: 1G ports: - name: redis-port containerPort: 6379 env: - name: MASTER value: "true" - - name: REDIS_PASS + - name: REDIS_PASSWORD valueFrom: secretKeyRef: name: defi-providers-secrets - key: REDIS_PASS + key: REDIS_PASSWORD + volumeMounts: + - name: redis-data + mountPath: /data + volumes: + - name: redis-data + persistentVolumeClaim: + claimName: defi-providers-redis-pvc + strategy: # temporary hack around "ReadWriteOnce" access mode issue (https://stackoverflow.com/a/62230273/4725013) + type: Recreate --- apiVersion: v1 kind: Service diff --git a/src/app.config.ts b/src/app.config.ts index 11cc305f..bf003ab5 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -1,4 +1,3 @@ -import { resolve } from 'path'; import * as dotenv from 'dotenv'; dotenv.config(); dotenv.config({ path: `.env.${process.env.APP_ENV || 'dev'}` }); @@ -14,7 +13,10 @@ const { LOGSTASH_HOST, LOGSTASH_INDEX, BASE_URL = './blockchainCache/', - REDIS_URL, + REDIS_HOST, + REDIS_PORT, + REDIS_USERNAME, + REDIS_PASSWORD, } = process.env; const config = { @@ -28,7 +30,10 @@ const config = { SLACK_WEBHOOK_URL, SLACK_LOGGING, BASE_URL, - REDIS_URL, + REDIS_HOST, + REDIS_PORT, + REDIS_USERNAME, + REDIS_PASSWORD, }; const nodeUrls: { [key: string]: string } = {}; diff --git a/src/util/redis.ts b/src/util/redis.ts index 617cb24a..2b9827c9 100644 --- a/src/util/redis.ts +++ b/src/util/redis.ts @@ -1,13 +1,13 @@ import { createClient } from 'redis'; import { log } from './logger/logger'; import { config } from '../app.config'; -const { REDIS_URL } = config; +const { REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD } = config; let client; function Redis() { - if (!client && REDIS_URL) { + if (!client && REDIS_HOST) { client = createClient({ - url: REDIS_URL, + url: `redis://${REDIS_USERNAME}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}`, }); client.connect(); }