跳转至

OpstreeRedis

简介

Redis Operator 可以在 Kubernetes 平台上一键部署一个高可用的 Redis 集群,实现对 Redis 集群的自动化运维

img

配置如下:

bind 0.0.0.0
protected-mode yes
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile "/var/run/redis.pid"
# Generated by CONFIG REWRITE
save 3600 1
save 300 100
save 60 10000
user default on nopass ~* &* +@all
dir "/data"

监控数据

redis operator dashboard: https://github.com/OT-CONTAINER-KIT/redis-operator/blob/master/dashboards/redis-operator-cluster.json

实例

Redis 集群

apiVersion: redis.redis.opstreelabs.in/v1beta1
kind: RedisCluster
metadata:
  annotations:
    meta.helm.sh/release-name: redis
    meta.helm.sh/release-namespace: aipaas-system
  name: aipaas-redis-cluster
  namespace: aipaas-system
  labels:
    app.aipaas.io/component: cluster
    app.aipaas.io/instance: redis-cluster
    app.aipaas.io/part-of: redis
    app.kubernetes.io/managed-by: Helm
    helm.sh/app-version: v7.0.5
    helm.sh/chart: chart-redis-5.10.0
    helm.sh/managed-by: Helm
spec:
  persistenceEnabled: false
  redisLeader:
    affinity:
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchLabels:
                  app.aipaas.io/component: cluster
                  app.aipaas.io/instance: redis-cluster
                  app.aipaas.io/part-of: redis
              namespaces:
                - aipaas-system
              topologyKey: kubernetes.io/hostname
            weight: 1
    livenessProbe:
      failureThreshold: 3
      initialDelaySeconds: 1
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 1
    pdb: {}
    readinessProbe:
      failureThreshold: 3
      initialDelaySeconds: 1
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 1
    redisConfig:
      additionalRedisConfig: redis-cluster-ext-config
    replicas: 3
  kubernetesConfig:
    image: 'aipaas-middleware/redis:v7.0.5'
    imagePullPolicy: IfNotPresent
    imagePullSecrets:
      - name: aipaas-image-pull-secrets
    resources:
      limits:
        cpu: '1'
        memory: 1500Mi
      requests:
        cpu: 200m
        memory: 150Mi
  securityContext:
    fsGroup: 0
    runAsUser: 0
  redisFollower:
    affinity:
      podAntiAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchLabels:
                  app.aipaas.io/component: cluster
                  app.aipaas.io/instance: redis-cluster
                  app.aipaas.io/part-of: redis
              namespaces:
                - aipaas-system
              topologyKey: kubernetes.io/hostname
            weight: 1
    livenessProbe:
      failureThreshold: 3
      initialDelaySeconds: 1
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 1
    pdb: {}
    readinessProbe:
      failureThreshold: 3
      initialDelaySeconds: 1
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 1
    redisConfig:
      additionalRedisConfig: redis-cluster-ext-config
    replicas: 3
  clusterSize: 3
  redisExporter:
    enabled: true
    image: 'aipaas-middleware/redis-exporter:v1.44.0'
    imagePullPolicy: IfNotPresent
  tolerations:
    - effect: NoSchedule
      key: no-pod
      operator: Equal
      value: 'true'
    - effect: NoSchedule
      key: redis
      operator: Exists
  clusterVersion: v7

配置文件:

kind: ConfigMap
apiVersion: v1
metadata:
  name: redis-cluster-ext-config
  namespace: aipaas-system
  labels:
    app.aipaas.io/component: cluster
    app.aipaas.io/instance: redis-cluster
    app.aipaas.io/part-of: redis
    app.kubernetes.io/managed-by: Helm
    helm.sh/app-version: v7.0.5
    helm.sh/chart: chart-redis-5.10.0
    helm.sh/managed-by: Helm
  annotations:
    meta.helm.sh/release-name: redis
    meta.helm.sh/release-namespace: aipaas-system
data:
  redis-external.conf: |
    tcp-keepalive 400
    slowlog-max-len 158
    stream-node-max-bytes 2048
    save ""