RuoYi-Cloud/deployment/redis/redis-stateful-set.yaml

99 lines
2.8 KiB
YAML

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
labels:
app: redis
namespace: redis
spec:
serviceName: redis
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
initContainers:
- name: config
image: redis:7.0.6
command: [ "sh", "-c" ]
args:
- |
cp /tmp/redis/redis.conf /etc/redis/redis.conf
echo "finding master..."
MASTER_FDQN=`hostname -f | sed -e 's/redis-[0-9]\./redis-0./'`
if [ "$(redis-cli -h sentinel -p 5000 ping)" != "PONG" ]; then
echo "master not found, defaulting to redis-0"
if [ "$(hostname)" = "redis-0" ]; then
echo "this is redis-0, not updating config..."
else
echo "updating redis.conf..."
echo "\nslaveof $MASTER_FDQN 6379" >> /etc/redis/redis.conf
fi
else
echo "sentinel found, finding master"
MASTER="$(redis-cli -h sentinel -p 5000 sentinel get-master-addr-by-name mymaster | grep -E '(^redis-\d{1,})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})')"
echo "master found : $MASTER, updating redis.conf"
echo "slaveof $MASTER 6379" >> /etc/redis/redis.conf
fi
volumeMounts:
- name: redis-config
mountPath: /etc/redis/
- name: config
mountPath: /tmp/redis/
containers:
- name: redis
image: redis:7.0.6
command: [ "redis-server" ]
args: [ "/etc/redis/redis.conf" ]
ports:
- containerPort: 6379
name: redis
volumeMounts:
- name: data
mountPath: /data
- name: redis-config
mountPath: /etc/redis/
resources:
limits:
memory: 1100Mi
requests:
memory: 1100Mi
volumes:
- name: redis-config
emptyDir: { }
- name: config
configMap:
name: redis-config
volumeClaimTemplates:
- metadata:
name: data
spec:
storageClassName: hostpath
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
---
apiVersion: v1 # API version
kind: Service # Type of the kubernetes resource
metadata:
name: redis # Name of the kubernetes resource
labels: # Labels that will be applied to this resource
app: redis
namespace: redis
spec:
selector:
app: redis # The service exposes Pods with label `app=redis`
ports:
- name: redis-port
port: 6379
nodePort: 30079
type: NodePort