将代码/文件直接注入Google Cloud Engine上Kubernetes中的容器中 [英] Inject code/files directly into a container in Kubernetes on Google Cloud Engine

查看:60
本文介绍了将代码/文件直接注入Google Cloud Engine上Kubernetes中的容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将代码/文件直接注入Google Cloud Engine上Kubernetes的容器中,类似于您可以通过Docker挂载主机文件/目录的方式,例如

How can I inject code/files directly into a container in Kubernetes on Google Cloud Engine, similar to the way that you can mount host files / directories with Docker, e.g.

docker run -d --name nginx -p 443:443 -v "/nginx.ssl.conf:/etc/nginx/conf.d/default.conf"

谢谢

推荐答案

我不确定您可以完全做到这一点. Kubernetes的工作方式与docker完全不同,并且对于与您可能已经习惯使用docker的主机"进行交互并不是一个理想的选择.

I'm not sure you can do that exactly. Kubernetes does things quite differently than docker, and isn't really ideal for interacting with the 'host' you are probably used to with docker.

我想到了一些替代可能性.首先,可能也是最不理想,但最接近您要求的是在容器运行后添加文件,方法是在容器规范中添加commandsargs,或者使用kubectl exec并回显内容放入文件中.第二个是在该文件已经存在的地方创建一个卷,例如创建GCE或EBS磁盘,添加该文件,然后在容器的规范中挂载该文件位置(只读).第三,将是在该文件或其他代码已经存在的地方创建一个新的Docker映像.

A few alternative possibilities come to mind. First, and probably least ideal but closest to what you are asking, would be to add the file after the container is running, either by adding commands or args to the pod spec, or using kubectl exec and echo'ing the contents into the file. Second would be to create a volume where that file already exists, e.g. create a GCE or EBS disk, add that file, and then mount the file location (read-only) in the container's spec. Third, would be to create a new docker image where that file or other code already exists.

对于第一个选项,kubectl exec将用于一次性工作,它不是非常可扩展/可重复的.运行时的任何创建/获取都会为容器的启动时间增加很多开销,因此我通常会选择第三个选项,只要文件或代码发生更改,便会构建一个新的Docker映像.更改的次数越多,您可能就越需要CI系统(例如无人机)来帮助实现流程自动化.

For the first option, the kubectl exec would be for one-off jobs, it isn't very scalable/repeatable. Any creation/fetching at runtime adds that much overhead to the start time for the container, so I normally go with the third option, building a new docker image whenever the file or code changes. The more you change it, the more you'll probably want a CI system (like drone) to help automate the process.

如果我应该使用更多详细信息扩展这些选项中的任何一个,请添加评论.

Add a comment if I should expand any of these options with more details.

这篇关于将代码/文件直接注入Google Cloud Engine上Kubernetes中的容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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