Kubernetes如何在容器运行之前将cfg文件复制到容器中? [英] kubernetes how to copy a cfg file into container before contaner running?

查看:136
本文介绍了Kubernetes如何在容器运行之前将cfg文件复制到容器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务需要一个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

https://medium.com/@jmarhee/using-initcontainers-to-pre-populate-volume-data-in-kubernetes-99f628cd4519

更新:

我从stackoverflow中找到了另一个可能与之相关的答案,并为您提供了更好的处理方法

I found another answer from stackoverflow which might be related and give you a better approach in handling this

我可以使用从容器中的init容器创建的配置图

这篇关于Kubernetes如何在容器运行之前将cfg文件复制到容器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆