[英]How to update this configmap with kubectl patch command, without kubectl edit command
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下面是一个
k8s
configmap
的配置,我需要用kubectl patch
命令来更新,但是不知道怎么做
# 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我在
google
网站上搜索找到类似的方法来处理它,但它不起作用
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
所以,我认为我当前的问题是如何在
jq
中escaped
符号后继续工作
Here's how you can update the ConfigMap in the question:以下是如何更新问题中的 ConfigMap:
myconfig=$(mktemp) \
&& kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' \
| jq '.Paralbac.Sources[1].Status = true' \
| jq '.Paralbac.Sources[1].ServiceURL = "https://192.168.123.177:45663"' > myconfig \
&& kubectl create configmap debug-config --from-file=config.json=myconfig --dry-run=client -o yaml | kubectl replace -f - \
&& rm myconfig
Now do kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' | jq
现在执行
kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' | jq
kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' | jq
will show you the updated config.json in the ConfigMap. kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' | jq
将在 ConfigMap 中向您显示更新后的config.json 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.