Created
May 9, 2024 07:28
-
-
Save initcron/697e0ab0bc074b5465d2d1b83bbc6cdb to your computer and use it in GitHub Desktop.
Redis Statefulset with PVC Templaet and 3 Replicas
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 | |
labels: | |
app: redis | |
spec: | |
selector: | |
matchLabels: | |
role: master | |
app: redis | |
serviceName: "redis" | |
replicas: 3 | |
volumeClaimTemplates: | |
- metadata: | |
name: redis-data | |
spec: | |
accessModes: [ "ReadWriteOnce" ] | |
storageClassName: "standard" | |
resources: | |
requests: | |
storage: 100Mi | |
template: | |
metadata: | |
labels: | |
role: master | |
app: redis | |
annotations: | |
spec: | |
initContainers: | |
- name: init-redis | |
image: redis:4.0.9 | |
command: | |
- bash | |
- "-c" | |
- | | |
set -ex | |
# Generate mysql server-id from pod ordinal index. | |
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1 | |
ordinal=${BASH_REMATCH[1]} | |
# Copy appropriate conf.d files from config-map to emptyDir. | |
if [[ $ordinal -eq 0 ]]; then | |
cp /mnt/config-map/master.conf /etc/redis.conf | |
else | |
cp /mnt/config-map/slave.conf /etc/redis.conf | |
fi | |
volumeMounts: | |
- name: conf | |
mountPath: /etc | |
subPath: redis.conf | |
- name: config-map | |
mountPath: /mnt/config-map | |
containers: | |
- name: redis | |
image: redis:4.0.9 | |
command: ["redis-server"] | |
args: ["/etc/redis.conf"] | |
env: | |
- name: ALLOW_EMPTY_PASSWORD | |
value: "yes" | |
ports: | |
- name: redis | |
containerPort: 6379 | |
volumeMounts: | |
- name: redis-data | |
mountPath: /data | |
- name: conf | |
mountPath: /etc/ | |
subPath: redis.conf | |
volumes: | |
- name: conf | |
emptyDir: {} | |
- name: config-map | |
configMap: | |
name: redis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment