How to change the value of the nested key in deployed configmap yml using kubectl

37 views Asked by At

My deployed sample configmap yml file

apiVersion: v1
data:
  config.yml: |
    version: 0.1

    log:
      level: info
      formatter: text
      fields:
        service: registry
        environment: staging

    storage:
      cache:
        blobdescriptor: inmemory
      filesystem:
        rootdirectory: /var/lib/registry
        maxthreads: 100
      delete:
        enabled: true
      maintenance:
        uploadpurging:
          enabled: true
          age: 168h
          interval: 24h
          dryrun: false
        readonly:
          enabled: false

    auth:
      token:
        realm: http://test/tokens
        service: Docker Registry
        issuer: test.svc
        rootcertbundle: /opt/tls.crt

    http:
      addr: 0.0.0.0:5000
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-name: ief6e3
    meta.helm.sh/release-namespace: test
  creationTimestamp: "2023-10-20T09:37:23Z"
  labels:
    app.kubernetes.io/managed-by: Helm
  name: test-config
  namespace: test
  resourceVersion: "6303013"
  uid: 24a9ddc6-71e1-4675-80ca-123456
  • I want to change the readonly -> enabled property to true and then apply the yml
  • I have used the tried the following command kubectl create configmap test-config -n test --from-literal=config.yml.storage.maintenance.readonly.enabled='true' -o yaml --dry-run=client | kubectl replace -f - , but it replaces whole config.yml value

kubectl edit cm test-0 -n iem -o yaml | sed -e 's/\(maintenance:\n[[:space:]]*readonly:\n[[:space:]]*enabled:\) false/\1 true/'| kubectl apply -f - , but it doesn't change the valu

Is there are any other ways to update the readonly -> enabled property to true and then applfy the changes in deployed configmap using command only.

0

There are 0 answers