【问题标题】:How to mount a configMap as a volume mount in a Stateful Set如何将 configMap 挂载为有状态集中的卷挂载
【发布时间】:2020-05-30 11:00:24
【问题描述】:

我没有看到在 statefulset 中将 configMap 挂载为卷的选项,根据 https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#statefulset-v1-apps 只有 PVC 可以与 "StatefulSet" 相关联。但是 PVC 没有 configMaps 的选项。

【问题讨论】:

    标签: 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下找到文件ab,内容分别为12

    一些解释: 您不需要 PVC 即可将 configmap 作为卷安装到您的 pod。 PersistentVolumeClaims 是永久性驱动器,您可以对其进行读取/写入。它们的使用示例是数据库,例如 Postgres。

    另一方面,ConfigMaps 是存储在 Kubernetes 内部(在其 etcd 存储中)的只读键值结构,用于存储应用程序的配置。它们的值可以单独或全部作为环境变量或文件挂载。

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-24
      • 2016-03-10
      相关资源
      最近更新 更多