Kubernetes ConfigMap Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 74: Line 74:


=Edit an Already Deployed ConfigMap=
=Edit an Already Deployed ConfigMap=
==Interactively==


  kubectl edit configmap myconfigmap
  kubectl edit configmap myconfigmap

Revision as of 19:29, 23 October 2019

External

Internal

Inspect a ConfigMap

kubectl get cm <name> -o yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: example
  ...
data:
  color: red
  shape: square

Create a ConfigMap with CLI

All three options presented below can be combined on one single command line:

Specify Key/Value Pairs on Command Line

kubectl create configmap example --from-literal=color=red --from-literal=shape=square

Multiple --from-literal= entries are allowed.

Use the Content of a File

The entire content of the file is keyed by default under the file name.

kubectl create configmap example --from-file=some-config-file.txt
apiVersion: v1
kind: ConfigMap
metadata:
  name: example
  ...
data:
  some-config-file.txt: |
    color=blue
    shape=circle

An arbitrary key, different from the file name, can be specified:

kubectl create configmap example --from-file=mykey=some-config-file.txt

Multiple --from-file= can be used.

Import all Files from a Directory

kubectl can be used to inspect a directory and create an individual ConfigMap entry for each file in the directory whose name is a valid ConfigMap key. In the example below, /tmp/config-dir contains two files: A.txt and B.txt.

kubectl create configmap example --from-file=/tmp/config-dir
apiVersion: v1
kind: ConfigMap
metadata:
  name: example
  ...
data:
  A.txt: |
    color=red
  B.txt: |
    shape=square

Edit an Already Deployed ConfigMap

Interactively

kubectl edit configmap myconfigmap