Kubectl更新configMap [英] Kubectl update configMap
问题描述
我正在使用以下命令创建configMap.
I am using the following command to create a configMap.
kubectl create configmap test --from-file=./application.properties --from-file=./mongo.properties --from-file=./logback.xml
现在,我已经从mongo.properties中修改了一个键的值,我需要在kubernetes中对其进行更新.
Now, I have modified a value for a key from mongo.properties which i need to update in kubernetes.
选项1:-
kubectl edit test
在这里,它将打开整个文件.但是,我只想更新mongo.properties,因此只想看mongo.properties.还有其他办法吗?
Here, it opens the entire file. But, I want to just update mongo.properties and hence want to see only the mongo.properties. Is there any other way?
注意:-我不想在单独的configMap中拥有mongo.properties.
Note :- I dont want to have mongo.properties in a separate configMap.
谢谢
推荐答案
不,您不能.
在kubernetes中替换将仅替换该configmap中的所有内容.您不能只更新一个文件或其中的一个属性.
Replace in kubernetes will simply replace everything in that configmap. You can't just update one file or one single property in it.
但是,如果您与客户端Api进行检查,则会发现您是否创建了一个包含大量文件的configmap.然后,这些文件将存储为HashMap,其中key是默认文件名,value是编码为字符串的文件内容.因此,您可以基于HashMap中的现有键值对编写自己的函数.
However, if you check with the client Api, you will find if you create a configmap with lots of files. Then, those files will be stored as a HashMap, where key is file name by default, value is the file content encoded as a string. So you can write your own function based on existing key-value pair in HashMap.
这是我到目前为止所发现的,如果您发现已有解决此问题的方法,请告诉我:)
This is what I found so far, if you find there is already existing method to deal with this issue, please let me know :)
仅供参考,如果您只想更新一个或几个属性,则可以使用补丁.但是,实现起来有点困难.
FYI, if you want to update just one or few properties, it is possible if you use patch. However, it is a little bit hard to implement.
这篇关于Kubectl更新configMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!