Created
August 12, 2022 03:34
-
-
Save jithin-scaria/cdb5970a88ab5196949404eede5850ac to your computer and use it in GitHub Desktop.
Redis statefulSet yaml for redis cluster with startup script to do CLUSTER meet to synch the nodes if the pod ip changes on restart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: StatefulSet | |
metadata: | |
name: redis | |
namespace: redis | |
spec: | |
serviceName: redis | |
replicas: 6 | |
selector: | |
matchLabels: | |
app: redis | |
template: | |
metadata: | |
labels: | |
app: redis | |
spec: | |
initContainers: | |
- name: config | |
env: | |
- name: POD_PVC_PATH # env Variable name | |
valueFrom: | |
fieldRef: | |
apiVersion: v1 | |
fieldPath: metadata.name # assign pod name to env varaibles, ie, redis-0, redis-1 etc | |
image: redis:7.0.0-alpine | |
command: [ "sh", "-c" ] | |
args: | |
- | | |
if [ -f "/conf/redis.conf" ]; then | |
echo "config exists /conf/redis.conf .. not creating new" | |
if [ -f "/tmp/startup/redis-startup.sh" ];then | |
cp /tmp/startup/redis-startup.sh /conf/redis-startup.sh | |
fi | |
else | |
echo "config doesn't exist copying to /conf/redis.conf" | |
cp /tmp/conf/redis.conf /conf/redis.conf | |
fi | |
volumeMounts: | |
- name: storage | |
subPathExpr: $(POD_PVC_PATH)-conf # dedicated sub directory for conf | |
mountPath: /conf | |
- name: config | |
mountPath: /tmp/conf/ | |
containers: | |
- name: redis | |
env: | |
- name: POD_PVC_PATH # env Variable name | |
valueFrom: | |
fieldRef: | |
apiVersion: v1 | |
fieldPath: metadata.name # assign pod name to env varaibles, ie, redis-0, redis-1 etc | |
image: redis:7.0.0-alpine | |
command: [ "sh", "-c" ] | |
args: | |
- | | |
nohup sh /conf/redis-startup.sh & | |
redis-server /conf/redis.conf | |
resources: | |
requests: | |
memory: "100M" | |
limits: | |
memory: "2000M" | |
ports: | |
- containerPort: 6379 | |
name: redis | |
volumeMounts: | |
- name: storage | |
mountPath: /data | |
subPathExpr: $(POD_PVC_PATH)-data # dedicated sub directory for data | |
- name: storage | |
mountPath: /conf | |
subPathExpr: $(POD_PVC_PATH)-conf # dedicated sub directory for conf | |
- name: config-acl | |
mountPath: /conf/acl/ | |
volumes: | |
- name: config | |
configMap: | |
name: redis-config | |
- name: config-acl | |
configMap: | |
name: redis-acl | |
- name: storage | |
persistentVolumeClaim: | |
claimName: redis-pv-name # Name of the PVC created. | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: redis | |
namespace: redis | |
spec: | |
clusterIP: None | |
ports: | |
- port: 6379 | |
targetPort: 6379 | |
name: redis | |
selector: | |
app: redis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment