【问题标题】:How to mount a configMap as a volume mount in a Stateful Set如何将 configMap 挂载为有状态集中的卷挂载
【发布时间】:2020-05-30 11:00:24
【问题描述】:
【问题讨论】:
标签:
kubernetes
configmap
kubernetes-pvc
kubernetes-statefulset
【解决方案1】:
这是一个最小的例子:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: example
spec:
selector:
matchLabels:
app: example
serviceName: example
template:
metadata:
labels:
app: example
spec:
containers:
- name: example
image: nginx:stable-alpine
volumeMounts:
- mountPath: /config
name: example-config
volumes:
- name: example-config
configMap:
name: example-configmap
---
apiVersion: v1
kind: ConfigMap
metadata:
name: example-configmap
data:
a: "1"
b: "2"
在容器中,可以在/config下找到文件a和b,内容分别为1和2。
一些解释:
您不需要 PVC 即可将 configmap 作为卷安装到您的 pod。 PersistentVolumeClaims 是永久性驱动器,您可以对其进行读取/写入。它们的使用示例是数据库,例如 Postgres。
另一方面,ConfigMaps 是存储在 Kubernetes 内部(在其 etcd 存储中)的只读键值结构,用于存储应用程序的配置。它们的值可以单独或全部作为环境变量或文件挂载。