ConfigMap
Example
Here’s an example of a ConfigMap.
.kubes/resources/shared/config_map.rb
name "demo-config-map"
data(
database: "mongodb",
database_uri: "mongodb://localhost:27017",
)
Produces:
.kubes/output/shared/config_map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: demo-config-map-cfbd534f91
labels:
app: demo
namespace: default
data:
database: mongodb
database_uri: mongodb://localhost:27017
Suffix Hash
A suffix hash based on the contents of the ConfigMap is automatically appended to the ConfigMap name. ConfigMaps used in Deployment and Pod containers fields that use the same name will also have the suffix automatically appended. This is done to trigger a rolling deployment. Here’s an example an deployment output with the hashed name.
.kubes/output/web/deployment.yaml:
# ..
spec:
template:
spec:
containers:
- name: demo-web
image: nginx
envFrom:
- configMapRef:
name: demo-config-map-cfbd534f91
You can disable the auto hasher behavior with:
Kubes.configure do |config|
# ...
config.suffix_hash = false
end
Files Helper
You can use a files
helper to load ConfigMap values from one or more files.
.kubes/resources/shared/config_map.rb
name "demo-secret"
files("files/configs.txt")
The files/configs.txt
should be in the same folder as the config_map.rb
definition. Example:
.kubes/resources/shared/files/configs.txt
CONFIG1=value1
CONFIG2=value2
DSL Methods
Here’s a list of more common methods:
- data
- binaryData
For a full list of the available methods, refer to the source itself syntax/config_map.rb.