Kubernetes yaml for configmap

A configmap is created in the Kubernetes cluster to represent all the configuration properties by one name.

The example below creates a configmap with the name myconfigmap, which has two key-value pairs. 

$ cat myconfigmap.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: myconfigmap
data:
  # key-value properties for configuration values
  dbtype: mysql
  # using pipe you can give json type structure as value
  dbproperties: |
    dbsize=700
    numdbentries=200

It has a key with the name dbtype of string type and has the value mysql.

You can use the pipe symbol to create a JSON-type value, as shown in the case of dbproperties key. Its value is a JSON object which further has key-value pairs. The keys in the JSON object are dbsize and numdbentries.

You can apply the configmap file using kubectl apply, as shown below.

$ kubectl apply -f myconfigmap.yaml
configmap/myconfigmap created

You can list the configmap using kubectl get command.

$ kubectl get configmap myconfigmap
NAME          DATA   AGE
myconfigmap   2      15s

You can get details of the configmap to see the keys, such as dbtype and dbproperties, and corresponding values.

$ kubectl describe configmap myconfigmap
Name:         myconfigmap
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
dbproperties:
----
dbsize=700
numdbentries=200

dbtype:
----
mysql

BinaryData
====

Events:  <none>