OpenShift 和持久性 Redis 配置

OpenShift and persistent Redis config

我已成功部署 Redis (persistent) image on my OpenShift installation. Now I want to persist the Redis configuration, and I have followed this 说明。

然而,Redis 是在一个容器中用这个命令启动的: /opt/rh/rh-redis32/root/usr/bin/redis-server *:6379

我看到它 should be started with the first argument 作为配置文件的路径,以便在启动时配置自身。

如何在 OpenShift 中实现这一点?

我不确定你是否应该尝试那种东西 ;) 但是您可以使用该解决方法(在生产中不使用它可能是个好主意)

首先创建下载你的配置文件:

$ curl -o redis.conf http://download.redis.io/redis-stable/redis.conf
$ curl -o run-redis https://raw.githubusercontent.com/sclorg/redis-container/master/3.2/root/usr/bin/run-redis

然后编辑 redis.conf 并更改您想要的值

$ vi redis.conf

现在编辑 运行-redis 并将最后一行替换为 :

exec ${REDIS_PREFIX}/bin/redis-server /tmp/redis.conf --daemonize no "$@" 2>&1

$ vi run-redis

现在您必须从这些文件创建一个 configMap :

$ oc create configmap myredisconfig --from-file=redis.conf --from-file=run-redis

并将configmap挂载到容器中:

$ oc volume dc/redis --add --name=conf --type=configmap --configmap-name=myredisconfig --mount-path=/tmp 

最后编辑redis dc:

假设我在 redis.conf

中将端口 6379 更改为端口 5000
  • 添加 spec.template.spec.containers.command :
spec:
  containers:
  - command:
    - /tmp/run-redis
  • 将spec.template.spec.volumes.configMap.defaultMode改为444
  - configMap:
      defaultMode: 444
      name: myredisconfig
    name: conf
  • 如果您使用带有健康检查的映像,请不要忘记更改端口以检查您的新端口,否则它将失败 (spec.template.spec.containers.livenessProbe.tcpSocket.port)
    livenessProbe:
      failureThreshold: 3
      initialDelaySeconds: 30
      periodSeconds: 10
      successThreshold: 1
      tcpSocket:
        port: 5000
  • 现在更改 readinessProbe,在测试命令中添加“-p $PORT”:
    readinessProbe:
      exec:
        command:
        - /bin/sh
        - -i
        - -c
        - test "$(redis-cli -h 127.0.0.1 -p 5000 -a $REDIS_PASSWORD ping)" == "PONG"
  • 不要忘记将 ContainerPort: 6379 更改为您的新端口,否则您将无法将其暴露给服务和路由 (spec.template.spec.ports)
 ports:
    - containerPort: 5000
      protocol: TCP
$ oc edit dc redis

希望对您有所帮助 :)

我使用部署配置中指定的 运行 命令解决了这个问题:

 containers:
        - name: redis
          image: >-
            centos/redis-32-centos7@sha256:7289ff47dd1c5bd24e6eefaf18cfbacf5ad68c0768f1b727a79c026bbef5a038
          command:
            - /opt/rh/rh-redis32/root/usr/bin/redis-server
            - /redis-master/redis.conf

因为这完全覆盖了所提供的 Docker 图像的默认启动行为,所以我不得不将 dir 和 requirepass 配置添加到我的配置映射中:

dir /var/lib/redis/data
requirepass srid
maxmemory 2mb
maxmemory-policy allkeys-lru