I have a ConfigMap as following:
kind: ConfigMap
apiVersion: v1
metadata:
name: health-ip
data:
ip.json: |-
[
1.1.1.1,
2.2.2.2
]
I want to modify/append or patch a small piece of this configuration by adding ip 3.3.3.3
to the ConfigMap so that it becomes:
kind: ConfigMap
apiVersion: v1
metadata:
name: health-ip
data:
ip.json: |-
[
1.1.1.1,
2.2.2.2,
3.3.3.3
]
How can it do this using kubectl patch
or equivalent?
There is no way to add without replace. As mentioned in comment by zerkms, configmaps
does not undestand structure data.
You have a couple of options to achive what you want:
1. Keep a "template" file of your configmap, update and apply when you need;
2. Automate the first task with a script that reads the configmap value and append the new value.
3. Use the kubectl path
passing the whole ip list.