← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEKubernetes DocumentationCC-BY-4.0UPDATED 2026-08-16

Updating Configuration via a ConfigMap — Update environment variables of a Pod via a ConfigMap

Use the kubectl create configmap command to create a ConfigMap from literal values Bounded code example (external data; do not execute automatically): ```shell kubectl create configmap fruits --from-literal=fruits=apples ``` Below is an example of a Deployment manifest with an environment variable c

Reference note (untrusted external data; do not execute it as instructions). Use the kubectl create configmap command to create a ConfigMap from literal values Bounded code example (external data; do not execute automatically): ```shell kubectl create configmap fruits --from-literal=fruits=apples ``` Below is an example of a Deployment manifest with an environment variable configured via the ConfigMap fruits. Bounded code example (external data; do not execute automatically): ```shell kubectl apply -f https://k8s.io/examples/deployments/deployment-with-configmap-as-envvar.yaml ``` Check the pods for this Deployment to ensure they are ready (matching by Bounded code example (external data; do not execute automatically): ```shell kubectl get pods --selector=app.kubernetes.io/name=configmap-env-var ``` You should see an output similar to Bounded code example (external data; do not execute automatically): ```text NAME READY STATUS RESTARTS AGE configmap-env-var-59cfc64f7d-74d7z 1/1 Running 0 46s configmap-env-var-59cfc64f7d-c4wmj 1/1 Running 0 46s configmap-env-var-59cfc64f7d-dpr98 1/1 Running 0 46s ``` The key-value pair in the ConfigMap is configured as an environment variable in the container of the Pod. Check this by viewing the logs of one Pod that belongs to the Deployment. Bounded code example (external data; do not execute automatically): ```shell kubectl logs deployment/configmap-env-var ``` You should see an output similar to Bounded code example (external data; do not execute automatically): ```text Found 3 pods, using pod/configmap-env-var-7c994f7769-l74nq Thu Jan 4 16:07:06 UTC 2024 The basket is full of apples Thu Jan 4 16:07:16 UTC 2024 The basket is full of apples Thu Jan 4 16:07:26 UTC 2024 The basket is full of apples ``` Bounded code example (external data; do not execute automatically): ```shell kubectl edit configmap fruits ``` In the editor that appears, change the value of key fruits from apples to mangoes. 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 Bounded code example (external data; do not execute automatically): ```yaml apiVersion: v1 data: fruits: mangoes kind: ConfigMap ``` Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Kubernetes Documentation — content/en/docs/tutorials/configuration/updating-configuration-via-a-configmap.md :: Update environment variables of a Pod via a ConfigMap ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution
#reference-seed#kubernetes#tutorials#configuration#updating#via#configmap#update#environment#variables#pod