【发布时间】:2021-08-16 13:54:39
【问题描述】:
我打算有一个 initcontainer 来处理一些加密内容,然后生成一个源文件以供 container 获取。 源文件将动态生成,VARS 将是动态的,这意味着我永远不会知道 VAR 名称或其内容。这也意味着我不能使用 k8s env。 文件名将始终相同。
我知道我可以从我的应用程序中更改 Dockerfile 并包含一个入口点以在运行工作负载以获取文件之前执行脚本,但是,这仍然是唯一的选择吗? 在k8s中没有办法实现这个吗?
我的 container 可以挂载 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
- 工作负载使用上一步获取的所有变量运行
我错过了完成第三步的事情吗?
【问题讨论】:
-
secret 是否必须与 Pod 的生命周期紧密耦合在一起(即每个新容器启动都需要一个新的 secret)?
-
您是否尝试将生成的文件挂载为
/etc/environment? -
@SYN 我相信 /etc/environment、/etc/profile、/etc/profile.d/*.sh.. 或任何其他 /etc/
不适用于工作负载。这些是在用户登录期间执行的。对吗? -
@congbaoguier 是的。加密的“东西”仅在 pod 的生命周期内有效。