8

How to patch "db.password" in the following cm with kustomize?

comfigmap:

apiVersion: v1
data:
  dbp.conf: |-
    {
      "db_properties": {
        "db.driver": "com.mysql.jdbc.Driver",
        "db.password": "123456",
        "db.user": "root"
      }
    }

kind: ConfigMap
metadata:
  labels: {}
  name: dbcm
Lior
  • 81
  • 1
  • 3

2 Answers2

1

you can create new file with updated values and use command replace along wih create

kubectl create configmap NAME --from-file file.name -o yaml --dry-run | kubectl replace -f -
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
1

create a placeholder in your file and replace it with real data while applying kustomize

your code will be like this:

#!/bin/bash
sed -i "s/PLACE-HOLDER/123456/g" db_config.yaml
kustomize config.yaml >> kustomizeconfig.yaml
kubectl apply -f kustomizeconfig.yaml -n foo

And the db_config file will be:

apiVersion: v1
data:
  dbp.conf: |-
    {
      "db_properties": {
        "db.driver": "com.mysql.jdbc.Driver",
        "db.password": "PLACE_HODLER",
        "db.user": "root"
      }
    }

kind: ConfigMap
metadata:
  labels: {}
  name: dbcm

NB: This should be running on the pipeline to have the config file cloned from repo, so the real file won't be updated.

star
  • 691
  • 7
  • 12