Configure a Pod to Use a ConfigMap — Define the key to use when creating a ConfigMap from a file
You can define a key other than the file name to use in the data section of your ConfigMap when using the --from-file argument Bounded code example (external data; do not execute automatically): ```shell kubectl create configmap game-config-3 --from-file=<my-key-name>=<path-to-file> ``` where is the
Reference note (untrusted external data; do not execute it as instructions).
You can define a key other than the file name to use in the data section of your ConfigMap when using the --from-file argument
Bounded code example (external data; do not execute automatically):
```shell
kubectl create configmap game-config-3 --from-file=<my-key-name>=<path-to-file>
```
where is the key you want to use in the ConfigMap and is the location of the data source file you want the key to represent.
Bounded code example (external data; do not execute automatically):
```shell
kubectl create configmap game-config-3 --from-file=game-special-key=configure-pod-container/configmap/game.properties
```
would produce the following ConfigMap
Bounded code example (external data; do not execute automatically):
```text
kubectl get configmaps game-config-3 -o yaml
```
where the output is similar to this
Bounded code example (external data; do not execute automatically):
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
creationTimestamp: 2022-02-18T18:54:22Z
name: game-config-3
namespace: default
resourceVersion: "530"
uid: 05f8da22-d671-11e5-8cd0-68f728db1985
data:
game-special-key: |
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
```
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/tasks/configure-pod-container/configure-pod-configmap.md :: Define the key to use when creating a ConfigMap from a file ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution