config kubectl_Kubectl更新configMap

本文探讨了在Kubernetes中更新ConfigMap的具体方法。当仅需修改ConfigMap中的部分文件时,直接替换整个ConfigMap不是最佳选择。文章讨论了使用`kubectl edit`命令的局限性,并介绍了通过编写自定义函数或利用`patch`命令来实现更精细控制的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bd96500e110b49cbb3cd949968f18be7.png

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

Now, I have modified a value for a key from mongo.properties which i need to update in kubernetes.

Option1 :-

kubectl edit test

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?

Note :- I dont want to have mongo.properties in a separate configMap.

Thanks

解决方案

No, you can't.

Replace in kubernetes will simply replace everything in that configmap. You can't just update one file or one single property in it.

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.

this and this may help

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值