本文介绍了如何将volumeClaimTemplates提取到单独的PersistentVolumeClaim yaml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个StatefulSet定义

apiVersion: v1
kind: StatefulSet
metadata:
  name: web
spec:
  ...
  volumeClaimTemplates:
  — metadata:
      name: www
    spec:
      resources:
        requests:
          storage: 1Gi

这将为我创建一个PersistentVolumeClaim(PVC),每个容器的PersistentVolume(PV)为1 GiB.

This will create me a PersistentVolumeClaim (PVC) with a PersistentVolume (PV) of 1 GiB for each pod.

我怎么写这样的东西

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: www
spec:
  ...
  resources:
    requests:
      storage: 1Gi
...

并将其与StatefulSet连接,仍然可以为每个吊舱创建PVC和PV?

and connect it with the StatefulSet in a way that it still creates a PVC and PV for each pod?

推荐答案

我猜在您的问题中,您使用的是此网站,因此我将遵循其命名约定.

I am guessing that in your question you are using statfulset example from this website so I will follow its naming convention.

我要为您提供的解决方案已经过我自己的测试,并且似乎可行.

The solution I am about to present you was tested by myself and it seems to work.

k8s api参考您可以找到以下定义:

In k8s api reference you can find the folllowing definition:

因此,这意味着只要您具有特定名称的volumeclaim,staefulset便会使用它而无需创建新名称.这意味着您可以手动创建一些pv/pvc,statefulset将使用它们.

So this means that as long as you have volumeclaim with specific name, staefulset will use it without creating a new one. This means that you can create some pv/pvc manually and statefulset will use them.

您需要做的就是正确命名您的pvc.这个名字应该是什么样子?这是第一部分:

All you need to do is to correctly name your pvcs. How is this name supposed to look like?Here is the first part:

volumeClaimTemplates:
  - metadata:
      name: www        <-here is the first part

第二部分是广告连播名称.

and the second part is a pod name.

(请在 can-i-rely-上查看此Stack问题on-volumeclaimtemplates-naming-convention .)

这两个部分结合在一起创建了pvc的名称(用破折号分隔),例如

These two parts combined together create a name of pvc (separated with dash) e.g.

www-web-0        <- this is how you are supposed to name one of your pvcs
│   └ second part (pod name)
└ first part

如果您已经拥有(自动配置的)PVC,请使用

If you already have (automatically provisioned) PVCs, use

kubectl get pvc <pvcname> -oyaml > pvcname.yaml
kubectl get pv  <pvname>  -oyaml > pvname.yaml

将其规格保存到磁盘.然后您可以运行:

to save its specification to disk. Then you can run:

kubectl apply -f pvcname.yaml
kubectl apply -f pvname.yaml

应用pvc/pv配置.请记住,某些yaml文件在运行kubectl apply之前可能需要进行一些修改.

to apply pvc/pv configuration. Remember that some yaml files may require slight modifications before running kubectl apply.

这篇关于如何将volumeClaimTemplates提取到单独的PersistentVolumeClaim yaml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 11:26