如何使用 kubectl patch 命令更新此配置映射,而不使用 kubectl edit 命令
下面是一个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"
}
]
}
}
我在 google
网站上搜索找到类似的方法来处理 它,但是不起作用
我尝试了这个命令,但不起作用:
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 -
我将命令减少到这里:
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"
所以,我认为我当前的问题是如何在 escaped
符号之后继续工作jq
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是更新问题中的 ConfigMap 的方法:
现在执行 kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' | jq 将向您显示 ConfigMap 中更新后的 config.json。
Here's how you can update the ConfigMap in the question:
Now do
kubectl get configmap debug-config -o jsonpath='{.data.config\.json}' | jq
will show you the updated config.json in the ConfigMap.