gpt4 book ai didi

azure - 我可以通过标签或选择器而不是名称将 K8s 部署链接到 PVC 吗?

转载 作者:行者123 更新时间:2023-12-02 08:25:35 25 4
gpt4 key购买 nike

我在 Kubernetes 中有一个部署。在此部署中,我可以指定持久卷声明,如下所示:

  volumes:
- name: my-volume
persistentVolumeClaim:
claimName: my-claim

我有一个磁盘(准确地说是 Azure 磁盘),其中包含大量预处理数据,我可以在 Kubernetes 中将其公开为名为 my-claim 的 PVC。在下一步中,我将其链接到部署,如上所示。这种方法的问题是,我无法将部署扩展到多个 pod。

如何扩展此设置?我尝试复制该磁盘并将其创建为具有不同名称的第二个 PVC。这有效,但现在我没有找到一种方法来告诉 Kubernetes 部署,每个 pod 应该挂载这两个 PVC 之一。

我希望有一个选项可以使用通用标签来标记两个 PVC,然后将我的部署链接到该标签而不是 PVC 名称。是否存在类似的情况,或者我的方法完全错误?

谢谢!

最佳答案

I have a disk (an Azure disk to be precise) with lots of preprocessed data, which I can expose in Kubernetes as PVC with name my-claim. In the next step I link it to the deployment as shown above. The problem with this approach is, that I cannot scale the deployment to more than one pod.

在这里,您使用带有 Access ModePersistentVolumeClaim ReadWriteOnce(这是 Azure 磁盘的唯一选项,请参阅访问模式链接)

How can I scale this setup? I tried to duplicate the disk and create it as second PVC with a different name. This worked, but now I don't see a way to tell the Kubernetes deployment, that each pod should mount one of these two PVCs.

在这里,听起来您想要一个具有访问模式的卷ReadOnlyMany - 因此您需要考虑支持此访问模式的存储系统>.

I tried to duplicate the disk and create it as second PVC with a different name. This worked, but now I don't see a way to tell the Kubernetes deployment, that each pod should mount one of these two PVCs.

这不适用于 Deployment因为每个 pod 的模板都是相同的。但你可以用 StatefulSet 来做到这一点,使用 volumeClaimTemplates 声明您的 PVC - 然后每个 Pod 的 PVC 都具有唯一的、众所周知的身份

StatefulSet 的示例部分:

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

然后,如果您有 StatefulSet 的两个副本,它们将为您提供一个名为 my-pvc-0my-pvc-1 的 PVC,其中编号称为“序数”。 volumeClaimTemplate 仅在新的 PVC 不存在时创建它,因此,如果您创建了具有正确名称的 PVC - 将使用现有的 PVC。

替代存储解决方案

Azure 磁盘的替代存储解决方案是 Azure 文件。 Azure 文件支持访问模式ReadWriteOnceReadOnlyManyReadWriteMany。请参阅Dynamically create and use a persistent volume with Azure Files in Azure Kubernetes Service (AKS) .

可能还有其他更适合您的应用程序的存储替代方案。

关于azure - 我可以通过标签或选择器而不是名称将 K8s 部署链接到 PVC 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64936298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com