Lior
Lior

Reputation: 81

How to patch configmap in json file with kustomize?

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

Upvotes: 8

Views: 8848

Answers (2)

star
star

Reputation: 953

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.

Upvotes: 1

Harsh Manvar
Harsh Manvar

Reputation: 30120

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 -

Upvotes: 1

Related Questions