Kubernetes如何在容器运行之前将cfg文件复制到容器中? [英] kubernetes how to copy a cfg file into container before contaner running?
问题描述
我的服务需要一个cfg文件,需要在容器开始运行之前对其进行更改.因此,不适合将cfg打包到docker映像中. 我需要从群集复制到容器,然后容器中的服务启动并读取此cfg.
My service need a cfg file which need to be changed before containers start running. So it is not suitable to pack the cfg into docker image. I need to copy from cluster to container, and then the service in container start and reads this cfg.
我该怎么做?
推荐答案
I think for your use-case , Init Containers might be the best fit. Init Containers are like small scripts that you can run before starting your own containers in kubernetes pod , they must exit. You can have this config file updated in shared Persistent Volume between your Init container and your container.
以下文章提供了一个很好的示例,说明了如何完成此操作
Following article gives a nice example as to how this can be done
更新:
我从stackoverflow中找到了另一个可能与之相关的答案,并为您提供了更好的处理方法
I found another answer from stackoverflow which might be related and give you a better approach in handling this
这篇关于Kubernetes如何在容器运行之前将cfg文件复制到容器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!