This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.22.4. 示例:配置 Redis
对于真实示例,您可以使用 ConfigMap 配置 Redis。要将 Redis 注入用于将 Redis 用作缓存的推荐配置,Red Hat Redis 配置文件应包含以下内容:
maxmemory 2mb maxmemory-policy allkeys-lru
maxmemory 2mb
maxmemory-policy allkeys-lru
如果您的配置文件位于 example-files/redis/redis-config 中,创建一个带有它的 ConfigMap :
创建指定配置文件的
ConfigMap:oc create configmap example-redis-config \ --from-file=example-files/redis/redis-config$ oc create configmap example-redis-config \ --from-file=example-files/redis/redis-configCopy to Clipboard Copied! Toggle word wrap Toggle overflow 验证结果:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,创建使用此 ConfigMap 的 pod:
创建类似以下内容的 pod 定义,并将它保存到文件中,如 redis-pod.yaml :
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建 pod:
oc create -f redis-pod.yaml
$ oc create -f redis-pod.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
新创建的 pod 有一个 ConfigMap 卷,它会将 example-redis-config ConfigMap 的 redis-config 键放入一个名为 redis.conf 的文件中。此卷挂载到 Redis 容器中的 /redis-master 目录,将配置文件放在 /redis-master/redis.conf 中,这是镜像查找 master 的 Redis 配置文件的位置。
如果您使用 oc exec 进入此 pod 并运行 redis-cli 工具,则可以检查是否正确应用了配置: