我喜欢yaml的可读性,所以我正在尝试这个(没有json(-你知道为什么它运行时没有错误,但不更新/更改任何内容吗?
kubectl patch configmap/config-domain -n knative-serving --type merge -p '
data:
example.com:""
'
这是有效的,但我不知道为什么:
kubectl patch configmap/config-network -n knative-serving --type merge -p '
data:
autoTLS: Enabled
httpProtocol: Redirected
'
这是一个带有两个键key1
和key2
的示例cm
,输出格式为yaml
:
k get cm my-config -o yaml
apiVersion: v1
data:
key1: config1
key2: config2
kind: ConfigMap
metadata:
creationTimestamp: "2021-06-22T14:15:07Z"
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
.: {}
f:key1: {}
f:key2: {}
manager: kubectl-create
operation: Update
time: "2021-06-22T14:15:07Z"
name: my-config
namespace: default
resourceVersion: "755842"
selfLink: /api/v1/namespaces/default/configmaps/my-config
uid: 18d87151-ae27-4aa1-8cf1-eee609c0dd7f
修补cm
:
k patch cm my-config -p $'data:n key1: "new_config1"'
configmap/my-config patched
这是更新的cm
:
k get cm my-config -o yaml
apiVersion: v1
data:
key1: new_config1 #<----------this is updated
key2: config2
kind: ConfigMap
metadata:
creationTimestamp: "2021-06-22T14:15:07Z"
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
.: {}
f:key2: {}
manager: kubectl-create
operation: Update
time: "2021-06-22T14:15:07Z"
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
f:key1: {}
manager: kubectl-patch
operation: Update
time: "2021-06-22T14:16:11Z"
name: my-config
namespace: default
resourceVersion: "755928"
selfLink: /api/v1/namespaces/default/configmaps/my-config
uid: 18d87151-ae27-4aa1-8cf1-eee609c0dd7f
类似地,您可以在json
中对cm
进行o/p,也可以在以json
格式打印cm
之后构建查询。