Created
September 7, 2023 03:33
-
-
Save initcron/20fbe6e23ab339a5fb2edf65d429aefd to your computer and use it in GitHub Desktop.
Redis StatefulSet with VolumeClaimTemplate
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: 2 | |
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 | |
volumeClaimTemplates: | |
- metadata: | |
name: redis-data | |
spec: | |
accessModes: [ "ReadWriteOnce" ] | |
resources: | |
requests: | |
storage: 50Mi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment