---
apiVersion: v1
kind: ConfigMap
metadata:
  name: helm-redis-master-config
  namespace: szzsj
data:
  redis.conf: |
    # 主服务器配置
    port 6379
    bind 0.0.0.0
    protected-mode no

    masterauth Mcache@4522
    appendonly yes
    # Disable RDB persistence, AOF persistence already enabled.
    save ""

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: helm-redis-replicas-config
  namespace: szzsj
data:
  redis.conf: |
    # 从服务器配置
    port 6379
    bind 0.0.0.0
    protected-mode no
    
    # 指定主服务器的地址和端口
    slaveof helm-redis-master.szzsj.svc.cluster.local 6379
    # 如果主服务器设置了密码，这里也需要设置
    masterauth Mcache@4522
    appendonly yes
    # Disable RDB persistence, AOF persistence already enabled.
    save ""

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helm-redis-master
  namespace: szzsj
spec:
  selector:
    matchLabels:
      app: helm-redis-master
  replicas: 1
  template:
    metadata:
      labels:
        app: helm-redis-master
    spec:
      containers:
        - name: helm-redis-master
          image: 172.10.125.92:8033/cmii/redis:6.0.20-alpine
          ports:
            - containerPort: 6379
          command:
            - "redis-server"
          args:
            - "--protected-mode"
            - "no"
            - "--masterauth"
            - "Mcache@4522"
            - "--requirepass"
            - "Mcache@4522"
            - "--include"
            - "/usr/local/etc/redis/redis.conf"
          volumeMounts:
            - name: config
              mountPath: /usr/local/etc/redis/redis.conf
              subPath: redis.conf
      volumes:
        - name: config
          configMap:
            name: helm-redis-master-config
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helm-redis-replicas
  namespace: szzsj
spec:
  selector:
    matchLabels:
      app: helm-redis-replicas
  replicas: 1  # 你可以根据需要设置副本数量
  template:
    metadata:
      labels:
        app: helm-redis-replicas
    spec:
      containers:
        - name: helm-redis-replicas
          image: 172.10.125.92:8033/cmii/redis:6.0.20-alpine
          command:
            - "redis-server"
          args:
            - "--slaveof"
            - "helm-redis-master.szzsj.svc.cluster.local"
            - "6379"
            - "--protected-mode"
            - "no"
            - "--masterauth"
            - "Mcache@4522"
            - "--requirepass"
            - "Mcache@4522"
            - "--include"
            - "/usr/local/etc/redis/redis.conf"
          ports:
            - containerPort: 6379
          volumeMounts:
            - name: config
              mountPath: /usr/local/etc/redis/redis.conf
              subPath: redis.conf
      volumes:
        - name: config
          configMap:
            name: helm-redis-replicas-config
---
apiVersion: v1
kind: Service
metadata:
  name: helm-redis-master
  namespace: szzsj
spec:
  ports:
    - port: 6379
      targetPort: 6379
  selector:
    app: helm-redis-master
---
apiVersion: v1
kind: Service
metadata:
  name: helm-redis-replicas
  namespace: szzsj
spec:
  ports:
    - port: 6379
      targetPort: 6379
  selector:
    app: helm-redis-replicas
---