Kubernetes:定义来自不同节点的卷挂载
Kubernetes: define volume mount from different node
我有 2 个节点:
- 节点-0
- 节点 1.
我创建了一个文本文件 hello.txt,其中一行内容为“hello=Dwain”,位于 /opt/data/index.html .文本文件 hello.txt 是在 node-1.
中创建的
我的默认节点是node-0。我必须创建 persistentVolume(pv1)、persistentVolumeClaim(pvc1) 和 pod(pod1)。在名称为 pv1 的 persistentVolume 中,我需要在集群节点 node-1 上定义卷路径 /opt/data/index.html。我需要在 persistentVolume、persistentVolumeClaim 和 pod 中指定 nodeAffinity 吗?
您需要在PersistentVolumeSpec
中设置NodeAffinity
。
// NodeAffinity defines constraints that limit what nodes this volume can be accessed from.
// This field influences the scheduling of pods that use this volume.
// +optional
NodeAffinity *VolumeNodeAffinity `json:"nodeAffinity,omitempty" protobuf:"bytes,9,opt,name=nodeAffinity"`
此 NodeAffinity
将确保您的 pod
在您的特定节点中运行。
我有 2 个节点:
- 节点-0
- 节点 1.
我创建了一个文本文件 hello.txt,其中一行内容为“hello=Dwain”,位于 /opt/data/index.html .文本文件 hello.txt 是在 node-1.
中创建的我的默认节点是node-0。我必须创建 persistentVolume(pv1)、persistentVolumeClaim(pvc1) 和 pod(pod1)。在名称为 pv1 的 persistentVolume 中,我需要在集群节点 node-1 上定义卷路径 /opt/data/index.html。我需要在 persistentVolume、persistentVolumeClaim 和 pod 中指定 nodeAffinity 吗?
您需要在PersistentVolumeSpec
中设置NodeAffinity
。
// NodeAffinity defines constraints that limit what nodes this volume can be accessed from.
// This field influences the scheduling of pods that use this volume.
// +optional
NodeAffinity *VolumeNodeAffinity `json:"nodeAffinity,omitempty" protobuf:"bytes,9,opt,name=nodeAffinity"`
此 NodeAffinity
将确保您的 pod
在您的特定节点中运行。