在Kubernetes中共同定位Pod和持久卷 [英] Co locate pods and persistent volumes in kubernetes
问题描述
我有一个分布在A和B两个区域的kubernetes集群.我正在使用nfs卷进行持久存储.我在两个区域中都有nfs卷.我正在创建一个有状态的2个副本集,这些副本将散布在这些区域中(我使用pod anti-affinity实现了此目的).现在,我希望区域A中的豆荚使用区域A中的卷,而区域B中的豆荚使用区域B中的卷.
I have a kubernetes cluster spread across two zones, A and B. I am using nfs volumes for persistent storage. I have nfs volumes in both the zones. I am creating a stateful set of 2 replicas which will be spread across these zones (I used pod anti-affinity to achieve this). Now I want the pods in zone A to use the volumes in zone A and ones in zone B to use the volumes in zone B.
我可以在持久卷中添加标签,并将持久卷声明与这些标签进行匹配.但是,如何确保Pod的PVC不绑定到另一个区域中的PV?
I can add labels to the persistent volumes and match the persistent volume claims with these labels. But how do I make sure that the pvc for a pod does not get bound to a pv in another zone?
推荐答案
您可以尝试使用特殊的内置标签failure-domain.beta.kubernetes.io/zone
将persistent volume claims (PVCs)
绑定到persistent volumes (PVs)
,并在两个区域之间的整个群集中拆分Kubernetes集群.如果手动创建卷,则可以使用failure-domain.beta.kubernetes.io/zone:zoneA
值对其进行标记,以确保将pod仅调度到与持久卷的区域相同的区域中的节点.
You can try to bind persistent volume claims (PVCs)
to persistent volumes (PVs)
and split Kubernetes pods across your cluster between two zones using the special built-in label failure-domain.beta.kubernetes.io/zone
. If you create volumes manually, it is possible to label them with failure-domain.beta.kubernetes.io/zone:zoneA
value, ensuring that pod is only scheduled to nodes in the same zone as the zone of the persistent volume.
例如,为节点和PV设置label
:
For example, to set label
for a Node and PV:
kubectl label node <node-name> failure-domain.beta.kubernetes.io/zone=zoneA
kubectl label pv <pv-name> failure-domain.beta.kubernetes.io/zone=zoneA
从官方Kubernetes中找到一些有用的信息文档.
Find some useful information from official Kubernetes documentation.
这篇关于在Kubernetes中共同定位Pod和持久卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!