我可以依赖 volumeClaimTemplates 命名约定吗? [英] Can I rely on volumeClaimTemplates naming convention?

查看:43
本文介绍了我可以依赖 volumeClaimTemplates 命名约定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在带有 的裸元 kubernetes 1.7 中设置预定义的 PostgreSQL 集群本地 PV 启用.我有三个工作节点.我在每个节点上创建本地 PV 并成功部署有状态集(使用一些复杂的脚本来设置 Postgres 复制).

I want to setup a pre-defined PostgreSQL cluster in a bare meta kubernetes 1.7 with local PV enable. I have three work nodes. I create local PV on each node and deploy the stateful set successfully (with some complex script to setup Postgres replication).

但是我注意到在 volumeClaimTemplates 和 PersistentVolumeClaim 之间有一种命名约定.例如

However I'm noticed that there's a kind of naming convention between the volumeClaimTemplates and PersistentVolumeClaim. For example

apiVersion: apps/v1beta1 
kind: StatefulSet
  metadata:   
     name: postgres
  volumeClaimTemplates:
  - metadata:
      name: pgvolume

创建的 pvc 为 pgvolume-postgres-0, pgvolume-postgres-1, pgvolume-postgres-2 .

The created pvc are pgvolume-postgres-0, pgvolume-postgres-1, pgvolume-postgres-2 .

由于一些棘手,我手动创建 PVC 并绑定到选择器的目标 PV.我再次测试有状态集.看来 stateful set 很乐意使用这些 PVC.

With some tricky, I manually create PVC and bind to the target PV by selector. I test the stateful set again. It seems the stateful set is very happy to use these PVC.

我成功完成了我的测试,但我仍然有这个问题.我可以依赖 volumeClaimTemplates 命名约定吗?这是一个未记录的功能吗?

I finish my test successfully but I still have this question. Can I rely on volumeClaimTemplates naming convention? Is this an undocumented feature?

推荐答案

基于 statefulset API 参考

Based on the statefulset API reference

volumeClaimTemplates 是允许 pod 引用的声明列表.StatefulSet 控制器负责以维护 Pod 身份的方式将网络身份映射到声明.此列表中的每个声明必须在模板的一个容器中至少有一个匹配的(按名称)volumeMount.此列表中的声明优先于模板中具有相同名称的任何卷.

volumeClaimTemplates is a list of claims that pods are allowed to reference. The StatefulSet controller is responsible for mapping network identities to claims in a way that maintains the identity of a pod. Every claim in this list must have at least one matching (by name) volumeMount in one container in the template. A claim in this list takes precedence over any volumes in the template, with the same name.

所以我想你可以信赖它.

So I guess you can rely on it.

此外,您可以定义一个存储类来利用持久卷的动态配置,因此您不必手动创建它们.

Moreover, you can define a storage class to leverage dynamic provisioning of persistent volumes, so you won't have to create them manually.

  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: my-storage-class
      resources:
        requests:
          storage: 1Gi

请参考动态配置和存储类在 Kubernetes 中了解更多详情.

这篇关于我可以依赖 volumeClaimTemplates 命名约定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆