For a real-world example, you can configure Redis using a ConfigMap. To
inject Redis with the recommended configuration for using Redis as a cache, the
Redis configuration file should contain the following:
 
maxmemory 2mb
maxmemory-policy allkeys-lru
 
 
If your configuration file is located at example-files/redis/redis-config,
create a ConfigMap with it:
 
- 
Create the ConfigMap specifying the configuration file:
$ oc create configmap example-redis-config \
    --from-file=example-files/redis/redis-config
 
 
 
- 
Verify the results:
$ oc get configmap example-redis-config -o yaml
apiVersion: v1
data:
  redis-config: |
    maxmemory 2mb
    maxmemory-policy allkeys-lru
kind: ConfigMap
metadata:
  creationTimestamp: 2016-04-06T05:53:07Z
  name: example-redis-config
  namespace: default
  resourceVersion: "2985"
  selflink: /api/v1/namespaces/default/configmaps/example-redis-config
  uid: d65739c1-fbbb-11e5-8a72-68f728db1985
 
 
 
 
Now, create a pod that uses this ConfigMap:
 
- 
Create a pod definition like the following and save it to a file, for example
redis-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: kubernetes/redis:v1
    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
 
 
 
- 
Create the pod:
$ oc create -f redis-pod.yaml
 
 
 
 
The newly-created pod has a ConfigMap volume that places the redis-config
key of the example-redis-config ConfigMap into a file called
redis.conf. This volume is mounted into the /redis-master directory in
the Redis container, placing our configuration file at
/redis-master/redis.conf, which is where the image looks for the Redis
configuration file for the master.
 
If you oc exec into this pod and run the redis-cli tool, you can check that
the configuration was applied correctly:
 
$ oc 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"