OpenShift和持久的Redisconfiguration

我在OpenShift安装中成功部署了Redis(持久)映像。 现在我想坚持Redisconfiguration,并且遵循了这个指示。

但是,Redis是在容器内使用此命令启动的: /opt/rh/rh-redis32/root/usr/bin/redis-server *:6379

我发现它应该以第一个参数作为configuration文件的path启动,以便在启动时进行自我configuration。

我怎样才能在OpenShift中实现这一点?

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

首先创build下载你的configuration文件:

 $ 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 

现在编辑run-redis并将最后一行replace为:

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

 $ vi run-redis 

现在你必须从这些文件创build一个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 
  • 现在改变准备探测器在testing命令中join“-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 

希望它帮助:)

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

  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和requirepassconfiguration添加到我的configuration映射中:

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