ConfigMap

ConfigMap is a resource that allows you to leave your configuration outside a Docker image. It injects the configuration data as key-value pairs into pods. Its properties are similar to secrets, but, whereas secrets are used to store sensitive data, such as passwords, ConfigMaps are used to store insensitive configuration data.

Like secrets, ConfigMaps could be based on files, directories, or specified literal value. They also have a similar syntax to secrets but use kubectl create configmap:

// create configmap
# kubectl create configmap example --from-file=config/app.properties --from-file=config/database.properties
configmap "example" created

Since two config files are located in the same folder name, config, we could pass a config folder instead of specifying the files one by one. The equivalent command to the preceding command is kubectl create configmap example --from-file=config in this case.

If we describe the ConfigMap, it'll show the current information:

// check out detailed information for configmap
# kubectl describe configmap example
Name: example
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
app.properties:
----
name=DevOps-with-Kubernetes
port=4420
database.properties:
----
endpoint=k8s.us-east-1.rds.amazonaws.com
port=1521

We could use kubectl edit configmap <configmap_name> to update the configuration after creation.

We also could use literal as the input. The equivalent commands for the preceding example would be kubectl create configmap example --from-literal=app.properties.name=name=DevOps-with-Kubernetes. This isn't always very practical when we have many configurations in an app.

Let's see how to use this inside a pod. There are two ways to use ConfigMap inside a pod: by volume or environment variables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset