用来保存应用的配置文件内容
一、创建configmap对象
1.新建yaml文件
vi redis-cm.yaml
2.编写redis的配置内容
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-conf
namespace: dev
data:
redis-config: |
maxmemory 2mb
3.创建redis的ConfigMap对象
kubectl apply -f redis-cm.yaml
二、绑定ConfigMap对象
1.新建yaml文件
vi redis-pod.yaml
2.编写redis的pod内容 把redis的配置文件挂载到已经创建的ConfigMap对象上
apiVersion: v1
kind: Pod
metadata:
name: redis
namespace: dev
spec:
containers:
- name: redis
image: redis
command:
- redis-server
- "/redis-master/redis.conf" #指的是redis容器内部的位置
ports:
- containerPort: 6379
volumeMounts:
- mountPath: /data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: redis-conf
items:
- key: redis-config
path: redis.conf
3.创建pod
kubectl apply -f redis-pod.yaml
三、测试
kubectl exec -it redis -n dev -- redis-cli
127.0.0.1:6379> CONFIG GET maxmemory
更新cm对象
kubectl edit cm redis-conf -n dev
把maxmemory值从2mb改为10mb
由于redis不支持热更新,所以要重启pod才能看到变化