try chatgpt provided chart for redis/keyDB
This commit is contained in:
135
redis/templates/statefulset.yaml
Normal file
135
redis/templates/statefulset.yaml
Normal file
@@ -0,0 +1,135 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
# templates/statefulset.yaml
|
||||
# -----------------------------------------------------------------------------
|
||||
{{""}}
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: {{ include "keydb-custom.fullname" . }}
|
||||
labels:
|
||||
app: {{ include "keydb-custom.name" . }}
|
||||
spec:
|
||||
serviceName: {{ include "keydb-custom.fullname" . }}-headless
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: {{ include "keydb-custom.name" . }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ include "keydb-custom.name" . }}
|
||||
spec:
|
||||
{{- if .Values.nodeAffinity }}
|
||||
affinity:
|
||||
nodeAffinity: {{ toYaml .Values.nodeAffinity | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- if .Values.podAntiAffinity.enabled }}
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
- labelSelector:
|
||||
matchExpressions:
|
||||
- key: "app"
|
||||
operator: In
|
||||
values:
|
||||
- {{ include "keydb-custom.name" . }}
|
||||
topologyKey: "kubernetes.io/hostname"
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: keydb
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- name: keydb
|
||||
containerPort: {{ .Values.service.port }}
|
||||
env:
|
||||
- name: KEYDB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "keydb-custom.fullname" . }}-auth
|
||||
key: password
|
||||
- name: KEYDB_CONF_FILE
|
||||
value: "/etc/keydb/keydb.conf"
|
||||
volumeMounts:
|
||||
- name: keydb-conf
|
||||
mountPath: /etc/keydb
|
||||
- name: data
|
||||
mountPath: /bitnami/keydb
|
||||
resources:
|
||||
{{ toYaml .Values.resources | nindent 12 }}
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
# Startup logic:
|
||||
# - pod index 0 starts as master
|
||||
# - pod index >0 will start and then configure REPLICAOF to master
|
||||
POD_NAME=$(hostname)
|
||||
# derive ordinal from pods named <release>-<ordinal>
|
||||
ORDINAL=${POD_NAME##*-}
|
||||
# start keydb-server in background to accept CONFIG/CLI commands
|
||||
keydb-server /etc/keydb/keydb.conf &
|
||||
sleep 1
|
||||
if [ "${ORDINAL}" != "0" ]; then
|
||||
# wait for master to be ready
|
||||
MASTER_HOST={{ include "keydb-custom.fullname" . }}-0.{{ include "keydb-custom.fullname" . }}-headless
|
||||
until nc -z ${MASTER_HOST} {{ .Values.service.port }}; do sleep 1; done
|
||||
# configure replication (use CLI to set replicaof)
|
||||
if [ -n "$KEYDB_PASSWORD" ]; then
|
||||
keydb-cli -a "$KEYDB_PASSWORD" REPLICAOF ${MASTER_HOST} {{ .Values.service.port }}
|
||||
else
|
||||
keydb-cli REPLICAOF ${MASTER_HOST} {{ .Values.service.port }}
|
||||
fi
|
||||
echo "Configured replicaof ${MASTER_HOST}:{{ .Values.service.port }}"
|
||||
# tail logs (block) to keep container running
|
||||
wait
|
||||
else
|
||||
# master: block on server process
|
||||
wait
|
||||
fi
|
||||
readinessProbe:
|
||||
{{- if .Values.readinessProbe.enabled }}
|
||||
exec:
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
# quick PING check
|
||||
if [ -n "$KEYDB_PASSWORD" ]; then
|
||||
keydb-cli -a "$KEYDB_PASSWORD" PING > /dev/null 2>&1 && exit 0 || exit 1
|
||||
else
|
||||
keydb-cli PING > /dev/null 2>&1 && exit 0 || exit 1
|
||||
fi
|
||||
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
|
||||
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
|
||||
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
|
||||
{{- end }}
|
||||
livenessProbe:
|
||||
{{- if .Values.livenessProbe.enabled }}
|
||||
exec:
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
if [ -n "$KEYDB_PASSWORD" ]; then
|
||||
keydb-cli -a "$KEYDB_PASSWORD" PING > /dev/null 2>&1 && exit 0 || exit 1
|
||||
else
|
||||
keydb-cli PING > /dev/null 2>&1 && exit 0 || exit 1
|
||||
fi
|
||||
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
|
||||
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
|
||||
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
|
||||
{{- end }}
|
||||
volumes:
|
||||
- name: keydb-conf
|
||||
configMap:
|
||||
name: {{ include "keydb-custom.fullname" . }}-conf
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
spec:
|
||||
accessModes: {{ toYaml .Values.persistence.accessModes | nindent 8 }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.persistence.size }}
|
||||
storageClassName: "{{ .Values.persistence.storageClass }}"
|
||||
Reference in New Issue
Block a user