Below is a k8s
configmap
configuration, I need to use the kubectl patch
command to update it, but don't know how to do it
# kubectl get configmap myconfig -o yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: debug-config
data:
config.json: |-
{
"portServiceDMS": 500,
"Buggdse": {
"Enable": false
},
"GHInterval": {
"Start": 5062,
"End": 6000
},
"LOPFdFhd": false,
"CHF": {
"DriverName": "mysql"
},
"Paralbac": {
"LoginURL": "https://127.0.0.1:7788",
"Sources": [
{
"ServiceName": "Hopyyu",
"Status": false,
"ServiceURL": "https://127.0.0.1:9090/ft/test"
},
{
"SourceName": "Bgudreg",
"Status": false, # need to patch here to true
"ServiceURL": "https://127.0.0.1:9090" # need to patch here to "https://192.168.123.177:45663"
}
]
}
}
I searched on google
site to find a similar way to deal with it, but it doesn't work
I tried this command and it doesn't work:
kubectl get cm myconfig -o json | jq -r '.data."config.json".Paralbac.Sources[1]={"SourceName": "Bgudreg", "Status": true, "ServiceURL": "https://192.168.123.177:45663"}' | kubectl apply -f -
I reduced the command to here:
kubectl get cm myconfig -o json | jq -r '.data."config.json" # it works (The double quotes are for escaping the dot)
kubectl get cm myconfig -o json | jq -r '.data."config.json".Paralbac # it can't work: jq: error (at <stdin>:18): Cannot index string with string "Paralbac"
So, I think my current problem is in how to keep working after escaped
symbols in jq