我需要能够将自定义环境变量分配给 Pod 的每个副本。一个变量应该是一些随机的 uuid,另一个唯一的数字。怎么可能实现呢?我更愿意继续使用带有副本的“部署”。如果这不是开箱即用的,如何通过自定义复制 Controller / Controller 管理器来实现?是否有可用的钩子(Hook)来实现此目的?
最佳答案
If this is not feasible out of the box, how can it be achieved by customizing replication controller/controller manager? Are there hooks available to achieve this?
最好的选择是结合使用 initContainer:
和/或自定义(可能被覆盖)入口点 command:
。除了名称和其他一些琐碎的更改之外,所有 Pod 都将是彼此的副本。任何针对每个 Pod 的特定行为均由 Pod 中的容器本身负责。
containers:
- image: whatever
command:
- bash
- -c
- |
export RANDOM_UUID=`uuidgen`
export UNIQ=/usr/bin/generate-some-awesome-sauce
exec /usr/local/bin/dockerfile-entrypoint.sh or whatever else
关于controller - Kubernetes Pod 动态环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53844291/