kubernetes - 在 K8S 中,有什么方法可以获取在 initcontainer 期间动态生成的 env 文件?
问题描述
我打算有一个initcontainer来处理一些加密的东西,然后生成一个源文件,由容器获取。源文件将动态生成,VARS 将是动态的,这意味着我永远不会知道 VAR 名称或其内容。这也意味着我不能使用 k8s env。文件名将始终相同。
我知道我可以从我的应用程序中更改 Dockerfile 并包含一个入口点以在运行工作负载以获取文件之前执行脚本,但是,这仍然是唯一的选择吗?没有办法在k8s中实现这一点吗?
我的容器可以挂载由initcontainer创建文件的目录。但它不能以某种方式获取文件?
apiVersion: v1
kind: Pod
metadata:
name: pod-init
namespace: default
spec:
nodeSelector:
env: sm
initContainers:
name: genenvfile
image: busybox
imagePullPolicy: Always
command: ["/bin/sh"]
# just an example, there will be a software here that will translate some encrypted stuff into VARS and then append'em to a file
args: ["-c", "echo MYVAR=func > /tmp/sm/filetobesourced"]
volumeMounts:
- mountPath: /tmp/sm
name: tmpdir
containers:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
imagePullPolicy: IfNotPresent
name: mypod-cm
tty: true
volumeMounts:
- mountPath: /tmp/sm
readOnly: true
name: tmpdir
volumes:
name: tmpdir
emptyDir:
medium: Memory
我想的一步一步是:
- initcontainer挂载 /tmp/sm 并生成一个名为 /tmp/sm/filetobesourced 的文件
- 容器挂载 /tmp/sm
- 容器源 /tmp/sm/filetobesourced
- 工作负载使用上一步获取的所有变量运行
我错过了完成第三步的事情吗?
解决方案
command
将主容器上的和/或更改为args
更像bash -c 'source /tmp/sm/filetobesourced && exec whatevertheoriginalcommandwas'
.
推荐阅读
- java - Hibernate 无法在自定义方言中注册 MySQL 的“LIMIT”功能
- mysql - 如何解决 xampp 中的错误 mysql 意外关闭
- elixir - 启动使用酒厂构建的 Phoenix 项目:进程错误 ~p 退出值:~n~p~n
- python - 为什么“ActionsChains”方法在 Selenium for python 中对我不起作用?
- javascript - 节点计划不适用于对象变量?
- sql - SQL Server - “ALL”是一个特殊值吗?
- python - 从没有字节顺序标记的 CSV 导入数据
- c++ - SDL2如何在窗口调整大小后缩放鼠标坐标?
- ssh - 无法在 gitlab 中使用 ssh 对远程 vps 进行身份验证
- python - mac 错误 20 在 0 深度查找:无法获取本地颁发者证书