我正在检查如何在 kubernet 上使用 statefullset 来部署我的服务。在 stateFullSet 中,我能够知道 pod 名称,因为它始终是 stateFullSet 名称 + 一个序列号,例如:
app-0
app-1
app-2
所以我想在每个 pod 的 configMap 中有一个特定的配置,并且 pod 会根据 pod 主机名读取配置映射。
它会是这样的:
spec:
containers:
- name: cgwcontainer
image: helioay/nginx
volumeMounts:
- name: config-volume
mountPath: /opt/app/config
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: "pod_host_name"
我已经看到我可以根据 POD 信息 "metadata.name" 获取 pod 主机名,但我不确定我是否能够将此信息用作 configMap 名称值。我知道可以设置环境变量,例如:
env:
- name: NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
除了 configMap 名称之外,是否可以使用类似的解决方案?
谢谢。