Updating Configuration via a ConfigMap [page]deterministic
This page provides a step-by-step example of updating configuration within a Pod via a ConfigMap and builds upon the [Configure a Pod to Use a ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) task. At the end of this tutorial, you will understand how to change the configuration for a running application. This tutorial uses the `alpine` and `nginx` images as examples.
##
You need to have the [curl](https://curl.se/) command-line tool for making HTTP requests from the terminal or command prompt. If you do not have `curl` available, you can install it. Check the documentation for your local operating system.
## * Update configuration via a ConfigMap mounted as a Volume * Update environment variables of a Pod via a ConfigMap * Update configuration via a ConfigMap in a multi-container Pod * Update configuration via a ConfigMap in a Pod possessing a Sidecar Container
## Update configuration via a ConfigMap mounted as a Volume {#rollout-configmap-volume}
Use the `kubectl create configmap` command to create a ConfigMap from [literal values](/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-literal-values):
```shell kubectl create configmap sport --from-literal=sport=football ```
Below is an example of a Deployment manifest with the ConfigMap `sport` mounted as a [volume](#gloss:volume) into the Pod's only container.
Create the Deployment:
```shell kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-volume.yaml ```
Check the pods for this Deployment to ensure they are ready (matching by [selector](#gloss:selector)):
```shell kubectl get pods --selector=app.kubernetes.io/name=configmap-volume ```
You should see an output similar to:
``` NAME READY STATUS RESTARTS AGE configmap-volume-6b976dfdcf-qxvbm 1/1 Running 0 72s configmap-volume-6b976dfdcf-skpvm 1/1 Running 0 72s configmap-volume-6b976dfdcf-tbc6r 1/1 Running 0 72s ```
On each node where one of these Pods is running, the kubelet fetches the data for that ConfigMap and translates it to files in a local volume. The kubelet then mounts that volume into the container, as specified in the Pod template. The code running in that container loads the information from the file and uses it to print a report to stdout. You can check this report by viewing the logs for one of the Pods in that Deployment:
```shell # Pick one Pod that belongs to the Deployment, and view its logs kubectl logs deployments/configmap-volume ```
You should see an output similar to:
``` Found 3 pods, using pod/configmap-volume-76d9c5678f-x5rgj Thu Jan 4 14:06:46 UTC 2024 My preferred sport is football Thu Jan 4 14:06:56 UTC 2024 My preferred sport is football Thu Jan 4 14:07:06 UTC 2024 My preferred sport is football Thu Jan 4 14:07:16 UTC 2024 My preferred sport is football Thu Jan 4 14:07:26 UTC 2024 My preferred sport is football ```
Edit the ConfigMap:
```shell kubectl edit configmap sport ```
In the editor that appears, change the value of key `sport` from `football` to `cricket`. Save your changes. The kubectl tool updates the ConfigMap accordingly (if you see an error, try again).
Here's an example of how that manifest could look after you edit it:
```yaml apiVersion: v1 data: sport: cricket kind: ConfigMap # You can leave the existing metadata as they are. # The values you'll see won't exactly match these. metadata: creationTimestamp: "2024-01-04T14:05:06Z" name: sport namespace: default resourceVersion: "1743935" uid: 024ee001-fe72-487e-872e-34d6464a8a23 ```
You should see the following output:
``` configmap/sport edited ```
Tail (follow the latest entries in) the logs of one of the pods that belongs to this Deployment:
```shell kubectl logs deployments/configmap-volume --follow ```
After few seconds, you should see the log output change as follows:
``` Thu Jan 4 14:11:36 UTC 2024 …(trimmed)