[英]Kubernetes Dynamic Configmapping in StatefulSet
In Kubernetes you have the ability to dynamically grab the name of a pod and reference it in a yaml file (Pod Field) like so:在 Kubernetes 中,您可以动态获取 Pod 的名称并在 yaml 文件(Pod 字段)中引用它,如下所示:
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
and reference it later in the yaml file like so:并稍后在 yaml 文件中引用它,如下所示:
- name: FOO
value: $(POD_NAME)-bar
Where in the case of a StatefulSet the value of foo may be something like "app_thing-0-bar, app_thing-1-bar ... etc".在 StatefulSet 的情况下,foo 的值可能类似于“app_thing-0-bar、app_thing-1-bar ...等”。 However this doesn't seem to work in dynamically setting the name of a configmap.
但是,这似乎不适用于动态设置 configmap 的名称。 For example, the following configmap:
例如,以下配置映射:
apiVersion: v1
kind: ConfigMap
metadata:
name: app_thing-0-config
data:
FOO: BAR
and this in the StatefulSet deployment yaml:这在 StatefulSet 部署 yaml 中:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: app_thing
.
.
.
.
.
envFrom:
- configMapRef:
name: $(POD_NAME)-config
will not reference the configmap correctly as it doesn't seem to like the $() syntax.不会正确引用 configmap,因为它似乎不喜欢 $() 语法。 Is there any way to do this without resorting to init containers and entrypoint scripting?
有没有办法在不求助于初始化容器和入口点脚本的情况下做到这一点?
If I understand you correctly there is a tool that can make it work.如果我理解正确,那么有一个工具可以使它工作。 It's called RELOADER :
它被称为RELOADER :
Problem: We would like to watch if some change happens in ConfigMap and/or Secret;
问题:我们想观察 ConfigMap 和/或 Secret 是否发生了一些变化; then perform a rolling upgrade on relevant DeploymentConfig, Deployment, Daemonset and Statefulset
然后对相关的 DeploymentConfig、Deployment、Daemonset 和 Statefulset 执行滚动升级
Solution: Reloader can watch changes in ConfigMap and Secret and do rolling upgrades on Pods with their associated DeploymentConfigs, Deployments, Daemonsets and Statefulsets.
解决方案: Reloader 可以观察 ConfigMap 和 Secret 中的变化,并对 Pod 及其相关的 DeploymentConfig、Deployment、Daemonsets 和 Statefulset 进行滚动升级。
You can find all the necessary info in the link above.您可以在上面的链接中找到所有必要的信息。 Also if you'd need more details than you can check the documentation .
此外,如果您需要比查看文档更多的详细信息。
Please let me know if that helped.如果这有帮助,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.