练习环境:https://www.katacoda.com/courses/kubernetes/playground
您可以按照以下步骤使用存储在ConfigMap中的数据配置Redis缓存。
首先从redis-config文件创建ConfigMap
curl -OL https://k8s.io/examples/pods/config/redis-config
kubectl create configmap example-redis-config --from-file=redis-config
检查创建的ConfigMap :
kubectl get configmap example-redis-config -o yaml
现在使用存储在ConfigMap中的配置数据创建一个pod specification:
kubectl create -f https://k8s.io/examples/pods/config/redis-pod.yaml
在本例中,配置卷挂载在redis-master上。 它使用path将redis-config key 添加到名为redis.conf的文件中。 因此,redis配置的文件路径是 /redis-master/redis.conf.
在这里,镜像将为redis master查找配置文件。
使用kubectl exec进入pod并运行redis-cli工具来验证配置是否正确应用
kubectl exec -it redis redis-cli
127.0.0.1:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "2097152"
127.0.0.1:6379> CONFIG GET maxmemory-policy
1) "maxmemory-policy"
2) "allkeys-lru"