Skip to content

Commit b407a01

Browse files
authored
docs(configure-redis-using-configmap): update for clarity (#25712)
* docs(configure-redis-using-configmap): update for clarity Signed-off-by: Jai Govindani <[email protected]> * fix(configure-redis-using-configmap): incorrect volumeMount index Signed-off-by: Jai Govindani <[email protected]> * fix(configure-redis-using-configmap): show Pod status as Running, separate commands from output Signed-off-by: Jai Govindani <[email protected]> * fix(configure-redis-using-configmap): typo Signed-off-by: Jai Govindani <[email protected]> * fix(configure-redis-using-configmap): configmap name Signed-off-by: Jai Govindani <[email protected]>
1 parent 9a9c2f3 commit b407a01

File tree

2 files changed

+182
-40
lines changed

2 files changed

+182
-40
lines changed

content/en/docs/tutorials/configuration/configure-redis-using-configmap.md

Lines changed: 174 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ This page provides a real world example of how to configure Redis using a Config
1515
## {{% heading "objectives" %}}
1616

1717

18-
* Create a `kustomization.yaml` file containing:
19-
* a ConfigMap generator
20-
* a Pod resource config using the ConfigMap
21-
* Apply the directory by running `kubectl apply -k ./`
18+
* Create a ConfigMap with Redis configuration values
19+
* Create a Redis Pod that mounts and uses the created ConfigMap
2220
* Verify that the configuration was correctly applied.
2321

2422

@@ -38,82 +36,218 @@ This page provides a real world example of how to configure Redis using a Config
3836

3937
## Real World Example: Configuring Redis using a ConfigMap
4038

41-
You can follow the steps below to configure a Redis cache using data stored in a ConfigMap.
39+
Follow the steps below to configure a Redis cache using data stored in a ConfigMap.
4240

43-
First create a `kustomization.yaml` containing a ConfigMap from the `redis-config` file:
44-
45-
{{< codenew file="pods/config/redis-config" >}}
41+
First create a ConfigMap with an empty configuration block:
4642

4743
```shell
48-
curl -OL https://k8s.io/examples/pods/config/redis-config
49-
50-
cat <<EOF >./kustomization.yaml
51-
configMapGenerator:
52-
- name: example-redis-config
53-
files:
54-
- redis-config
44+
cat <<EOF >./example-redis-config.yaml
45+
apiVersion: v1
46+
kind: ConfigMap
47+
metadata:
48+
name: example-redis-config
49+
data:
50+
redis-config: ""
5551
EOF
5652
```
5753

58-
Add the pod resource config to the `kustomization.yaml`:
54+
Apply the ConfigMap created above, along with a Redis pod manifest:
55+
56+
```shell
57+
kubectl apply -f example-redis-config.yaml
58+
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/config/redis-pod.yaml
59+
```
60+
61+
Examine the contents of the Redis pod manifest and note the following:
62+
63+
* A volume named `config` is created by `spec.volumes[1]`
64+
* The `key` and `path` under `spec.volumes[1].items[0]` exposes the `redis-config` key from the
65+
`example-redis-config` ConfigMap as a file named `redis.conf` on the `config` volume.
66+
* The `config` volume is then mounted at `/redis-master` by `spec.containers[0].volumeMounts[1]`.
67+
68+
This has the net effect of exposing the data in `data.redis-config` from the `example-redis-config`
69+
ConfigMap above as `/redis-master/redis.conf` inside the Pod.
5970

6071
{{< codenew file="pods/config/redis-pod.yaml" >}}
6172

73+
Examine the created objects:
74+
6275
```shell
63-
curl -OL https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/config/redis-pod.yaml
76+
kubectl get pod/redis configmap/example-redis-config
77+
```
6478

65-
cat <<EOF >>./kustomization.yaml
66-
resources:
67-
- redis-pod.yaml
68-
EOF
79+
You should see the following output:
80+
81+
```shell
82+
NAME READY STATUS RESTARTS AGE
83+
pod/redis 1/1 Running 0 8s
84+
85+
NAME DATA AGE
86+
configmap/example-redis-config 1 14s
6987
```
7088

71-
Apply the kustomization directory to create both the ConfigMap and Pod objects:
89+
Recall that we left `redis-config` key in the `example-redis-config` ConfigMap blank:
7290

7391
```shell
74-
kubectl apply -k .
92+
kubectl describe configmap/example-redis-config
7593
```
7694

77-
Examine the created objects by
95+
You should see an empty `redis-config` key:
96+
7897
```shell
79-
> kubectl get -k .
80-
NAME DATA AGE
81-
configmap/example-redis-config-dgh9dg555m 1 52s
98+
Name: example-redis-config
99+
Namespace: default
100+
Labels: <none>
101+
Annotations: <none>
102+
103+
Data
104+
====
105+
redis-config:
106+
```
82107

83-
NAME READY STATUS RESTARTS AGE
84-
pod/redis 1/1 Running 0 52s
108+
Use `kubectl exec` to enter the pod and run the `redis-cli` tool to check the current configuration:
109+
110+
```shell
111+
kubectl exec -it redis -- redis-cli
112+
```
113+
114+
Check `maxmemory`:
115+
116+
```shell
117+
127.0.0.1:6379> CONFIG GET maxmemory
118+
```
119+
120+
It should show the default value of 0:
121+
122+
```shell
123+
1) "maxmemory"
124+
2) "0"
125+
```
126+
127+
Similarly, check `maxmemory-policy`:
128+
129+
```shell
130+
127.0.0.1:6379> CONFIG GET maxmemory-policy
131+
```
132+
133+
Which should also yield its default value of `noeviction`:
134+
135+
```shell
136+
1) "maxmemory-policy"
137+
2) "noeviction"
138+
```
139+
140+
Now let's add some configuration values to the `example-redis-config` ConfigMap:
141+
142+
{{< codenew file="pods/config/example-redis-config.yaml" >}}
143+
144+
Apply the updated ConfigMap:
145+
146+
```shell
147+
kubectl apply -f example-redis-config.yaml
148+
```
149+
150+
Confirm that the ConfigMap was updated:
151+
152+
```shell
153+
kubectl describe configmap/example-redis-config
85154
```
86155

87-
In the example, the config volume is mounted at `/redis-master`.
88-
It uses `path` to add the `redis-config` key to a file named `redis.conf`.
89-
The file path for the redis config, therefore, is `/redis-master/redis.conf`.
90-
This is where the image will look for the config file for the redis master.
156+
You should see the configuration values we just added:
91157

92-
Use `kubectl exec` to enter the pod and run the `redis-cli` tool to verify that
93-
the configuration was correctly applied:
158+
```shell
159+
Name: example-redis-config
160+
Namespace: default
161+
Labels: <none>
162+
Annotations: <none>
163+
164+
Data
165+
====
166+
redis-config:
167+
----
168+
maxmemory 2mb
169+
maxmemory-policy allkeys-lru
170+
```
171+
172+
Check the Redis Pod again using `redis-cli` via `kubectl exec` to see if the configuration was applied:
94173

95174
```shell
96175
kubectl exec -it redis -- redis-cli
176+
```
177+
178+
Check `maxmemory`:
179+
180+
```shell
97181
127.0.0.1:6379> CONFIG GET maxmemory
182+
```
183+
184+
It remains at the default value of 0:
185+
186+
```shell
98187
1) "maxmemory"
99-
2) "2097152"
188+
2) "0"
189+
```
190+
191+
Similarly, `maxmemory-policy` remains at the `noeviction` default setting:
192+
193+
```shell
100194
127.0.0.1:6379> CONFIG GET maxmemory-policy
195+
```
196+
197+
Returns:
198+
199+
```shell
101200
1) "maxmemory-policy"
102-
2) "allkeys-lru"
201+
2) "noeviction"
103202
```
104203

105-
Delete the created pod:
204+
The configuration values have not changed because the Pod needs to be restarted to grab updated
205+
values from associated ConfigMaps. Let's delete and recreate the Pod:
206+
106207
```shell
107208
kubectl delete pod redis
209+
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/pods/config/redis-pod.yaml
108210
```
109211

212+
Now re-check the configuration values one last time:
110213

214+
```shell
215+
kubectl exec -it redis -- redis-cli
216+
```
111217

112-
## {{% heading "whatsnext" %}}
218+
Check `maxmemory`:
113219

220+
```shell
221+
127.0.0.1:6379> CONFIG GET maxmemory
222+
```
114223

115-
* Learn more about [ConfigMaps](/docs/tasks/configure-pod-container/configure-pod-configmap/).
224+
It should now return the updated value of 2097152:
116225

226+
```shell
227+
1) "maxmemory"
228+
2) "2097152"
229+
```
230+
231+
Similarly, `maxmemory-policy` has also been updated:
117232

233+
```shell
234+
127.0.0.1:6379> CONFIG GET maxmemory-policy
235+
```
118236

237+
It now reflects the desired value of `allkeys-lru`:
119238

239+
```shell
240+
1) "maxmemory-policy"
241+
2) "allkeys-lru"
242+
```
243+
244+
Clean up your work by deleting the created resources:
245+
246+
```shell
247+
kubectl delete pod/redis configmap/example-redis-config
248+
```
249+
250+
## {{% heading "whatsnext" %}}
251+
252+
253+
* Learn more about [ConfigMaps](/docs/tasks/configure-pod-container/configure-pod-configmap/).
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: example-redis-config
5+
data:
6+
redis-config: |
7+
maxmemory 2mb
8+
maxmemory-policy allkeys-lru

0 commit comments

Comments
 (0)