学习获取和修改 cm 中数据的方式。
[root@master ~]# kubectl describe cm configmap4 Name: configmap4 Namespace: default Labels: <none> Annotations: <none> Data ==== test.json: ---- { "name": "jiangbo", "age": 44 } test.properties: ---- name=jiangbo age=44 Events: <none> [root@master ~]# kubectl get cm configmap4 -o jsonpath='{.data.test\.json}' { "name": "jiangbo", "age": 44 } [root@master ~]# kubectl get cm configmap4 -o jsonpath='{.data.test\.properties}' name=jiangbo age=44 [root@master ~]#
[root@master ~]# kubectl get cm configmap4 -o jsonpath='{.data.test\.json}' | jq -r .name jiangbo [root@master ~]# source <(kubectl get cm configmap4 -o jsonpath='{.data.test\.properties}');echo $name jiangbo
[root@master ~]# sed -i 's/age=44/age=4444/g' config/test.properties [root@master ~]# kubectl create cm configmap4 --from-file=config -o yaml --dry-run=client | kubectl apply -f - configmap/configmap4 configured [root@master ~]# kubectl describe cm configmap4 Name: configmap4 Namespace: default Labels: <none> Annotations: <none> Data ==== test.json: ---- { "name": "jiangbo", "age": 44 } test.properties: ---- name=jiangbo age=4444 Events: <none>
[root@master ~]# kubectl get cm configmap4 -o yaml |sed 's/age=44/age=4444/g' | kubectl apply -f - configmap/configmap4 configured [root@master ~]# kubectl describe cm configmap4 Name: configmap4 Namespace: default Labels: <none> Annotations: <none> Data ==== test.json: ---- { "name": "jiangbo", "age": 44 } test.properties: ---- name=jiangbo age=4444 Events: <none>
介绍了获取和修改 cm 的方式。