参考文档:https://v1-27.docs.kubernetes.io/zh-cn/docs/tutorials/configuration/configure-redis-using-configmap/
cat <<EOF >./example-redis-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: example-redis-config
data:
redis-config: ""
EOF
#由 spec.volumes[1] 创建一个名为 config 的卷
#spec.volumes[1].items[0] 下的 key 和 path 会将来自 example-redis-config ConfigMap 中的 redis-config 密钥公开在 config 卷上一个名为 redis.conf 的文件中。
#然后 config 卷被 spec.containers[0].volumeMounts[1] 挂载在 /redis-master。
#pod内容示例:
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis:5.0.4
command:
- redis-server
- "/redis-master/redis.conf"
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
resources:
limits:
cpu: "0.1"
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: example-redis-config
items:
- key: redis-config
path: redis.conf
#创建configmap
kubectl apply -f example-redis-config.yaml
#创建pod redis
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml

又来这个错?搜了下默认是从docker hub拉取,可能是仓库地址的配置问题,这里先不纠结这个
我们更新下直接拉取docker的 reids 镜像
yum update -y
yum makecache
docker pull redis
# 运行后进入pod
kubectl apply -f redis-pod.yaml
kubectl exec -it redis -- redis-cli

通过ConfigMap修改redis配置
[root@weihengmaster1 configmap]# vim example-redis-config.yaml
#添加 maxmemory 和 maxmemory-policy 配置项
apiVersion: v1
kind: ConfigMap
metadata:
name: example-redis-config
data:
redis-config: |
maxmemory 2mb
maxmemory-policy allkeys-lru
#修改后别忘了更新到 configmap 资源中
[root@weihengmaster1 configmap]# kubectl apply -f example-redis-config.yaml
configmap/example-redis-config configured
[root@weihengmaster1 configmap]#
更新成功:

测试完毕清理资源
kubectl delete pod/redis configmap/example-redis-config
