英文:
How to update a config map in kubernetes?
问题
嗨,我正在使用一个从目录中的文件创建的配置映射。配置映射已挂载到容器中的 pod 卷中。有时候我需要更新我的配置映射。有没有办法可以做到这一点?目前我是删除配置映射,然后重新创建它,然后重新启动 pod。不确定这是否是最佳方式,因为在这里我们删除并创建了配置映射。
以下是脚本代码:
kubectl create ns k6
kubectl create configmap k6-scripts-configmap -n k6 --from-file /test/scripts/k6/
kubectl apply -f /test/config/k6/k6-deployment.yaml
在脚本中稍后,我需要更新配置映射,因为目录中的一些文件(/test/scripts/k6/
)需要更改。
kubectl delete configmap k6-scripts-configmap -n k6
kubectl create configmap k6-scripts-configmap -n k6 --from-file /test/scripts/k6/
kubectl rollout restart deployment k6 -n k6
您能告诉我我是否操作正确,或者是否可能无需删除配置映射而进行更新?此外,更新后是否应重新启动部署?
谢谢!
英文:
Hi I am using a config map which is created from the files in a directory.
The config map is mounted to the volume in the pods container. sometimes i need to update my config map . Any idea how can i do it ?. currently i am deleting the config map and recreating it and then restarting the pods. not sure if it is the best way because, here we delete and create a config map.
here is the shell script code
kubectl create ns k6
kubectl create configmap k6-scripts-configmap -n k6 --from-file /test/scripts/k6/
kubectl apply -f /test/config/k6/k6-deployment.yaml
later in the script i need to update the config map as some files in the directory (/test/scripts/k6/
) needs to be changed.
kubectl delete configmap k6-scripts-configmap -n k6
kubectl create configmap k6-scripts-configmap -n k6 --from-file /test/scripts/k6/
kubectl rollout restart deployment k6 -n k6
could you let me know if i am doing it correctly , or is it possible i can update the config map without deleting it ? Also after an update should i restart the deployment ?
thank you
答案1
得分: 2
你可以将部署和ConfigMap定义拆分为两个不同的文件。
然后,只更新configmap:
kubectl create configmap k6-scripts-configmap \
-n k6 --from-file /test/scripts/k6/ \
--dry-run -o yaml > configmap.yml
应用更改:
kubectl -n k6 apply -f configmap.yml
英文:
You can split the Deployment and the ConfigMap definition in 2 different files.
Then, update only the configmap:
kubectl create configmap k6-scripts-configmap \
-n k6 --from-file /test/scripts/k6/ \
--dry-run -o yaml > configmap.yml
Apply the changes:
kubectl -n k6 apply -f configmap.yml
答案2
得分: 1
方法:1
您可以使用以下命令来更新configmaps
kubectl create configmap k6-scripts-configmap -n k6 --from-file /test/scripts/k6/ -o yaml --dry-run=client | kubectl apply -f -
方法:2
如在文档中所解释,您也可以使用 Kubectl replace
。
注意:如果configmap不存在,kubectl replace 将失败。
方法:3
正如Chris Gillatt建议的那样,您可以使用 kubectl edit configmap <cfg-name>
。
方法:4
请参考Harsh Manvor的博客,了解如何在不重新启动POD的情况下自动更新configmap的信息。
英文:
We can use four methods to update configmaps.
Method : 1
You can use below command to update configmaps
kubectl create configmap k6-scripts-configmap -n k6 --from-file /test/scripts/k6/ -o yaml --dry-run=client | kubectl apply -f -
Method : 2
As explained in the document you can use Kubectl replace
also.
Note : kubectl replace fails if a configmap does not already exist.
Method : 3
As Chris Gillatt suggested you can use kubectl edit configmap <cfg-name>
Method : 4
Refer this blog by Harsh Manvor for information on auto updating configmap without restarting POD.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论