I have tried using kustomize to load properties file as a configmap.
For that, I created a sample set as in github link.
With base files:
#kustomize build base
apiVersion: v1
data:
config: |-
dbport=1234
dcname=sfsdf
dbssl=false
locktime=300
domainuser=
kind: ConfigMap
metadata:
labels:
owner: sara
name: database-configmap
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
owner: sara
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
owner: sara
template:
metadata:
labels:
app: nginx
owner: sara
spec:
containers:
- image: nginx
name: nginx
With external file:
#kustomize build file
apiVersion: v1
data:
config: "dbport=156767\r\ndcname=dfsd\r\ndbssl=false\r\nlocktime=300\r\ndomainuser=somedts"
kind: ConfigMap
metadata:
labels:
env: dev
owner: sara
name: dev-database-configmap
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
env: dev
owner: sara
name: dev-nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
env: dev
owner: sara
template:
metadata:
labels:
app: nginx
env: dev
owner: sara
spec:
containers:
- image: nginx
name: nginx
If you observe the configmap |
is removed and also replaced by \r\n
as a single string.
How to fix this alignment?
Posting this as community wiki, feel free to edit and expand.
As @mdaniel mentioned in comment:
You can check this by getting the configmap details from kubernetes cluster in
json
and see that they are stored in the same way (except for additional\r
which is mentioned above):and
There's an answer on StackOverflow which shortly shows the difference between \n , \r and \r\n.