我无法创建一个可以在不同pod中使用的持久卷(1次写入,另一次读取)。
尝试直接在pod规范中使用gcePersistentDisk
,例如k8s页面上的示例(加readOnly
):
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: gcr.io/google_containers/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
readOnly: true
volumes:
- name: test-volume
gcePersistentDisk:
pdName: my-data-disk
fsType: ext4
readOnly: true
然后在第二个pod规范中除readOnly
之外完全相同...但出现NoDiskConflict
错误。
第二种方法是使用PersistentVolume
和PersistentVolumeClaim
,如下所示:
apiVersion: v1
kind: PersistentVolume
metadata:
name: data-standard
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
gcePersistentDisk:
fsType: ext4
pdName: data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-standard-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
但现在我收到一个错误告诉我:
MountVolume.MountDevice failed for volume "kubernetes.io/gce-pd/xxx" (spec.Name: "yyy") pod "6ae34476-6197-11e7-9da5-42010a840186" (UID: "6ae34476-6197-11e7-9da5-42010a840186") with: mount failed: exit status 32 Mounting command: mount Mounting arguments: /dev/disk/by-id/google-gke-cluster-xxx /var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gke-cluster-xxx [ro] Output: mount: wrong fs type, bad option, bad superblock on /dev/sdb, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so.
Error syncing pod, skipping: timeout expired waiting for volumes to attach/mount for pod "default"/"my-deployment". list of unattached/unmounted volumes=[data]
那么使用具有多个pod的GCE磁盘的正确方法是什么。
PS:Kubernetes 1.6.6
答案 0 :(得分:5)
根据https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes,GCE磁盘不支持ReadWriteMany。我不确定这是否解释了这个问题,但我建议你尝试另一种兼容的卷类型。
答案 1 :(得分:2)
而不是ReadWriteMany
,您可以使用ReadOnlyMany
吗?
访问模式:
ReadWriteOnce - 卷可以由单个节点以读写方式挂载
ReadOnlyMany - 卷可以由多个节点以只读方式挂载
ReadWriteMany - 卷可以由多个节点以读写方式挂载
GCE永久磁盘不支持ReadWriteMany
以下是提供商和支持的访问模式列表:
https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
答案 2 :(得分:0)
我想,您应该可以使用PV和PVC来做到这一点。让我们举一个例子,您有一个PV和PVC。我不太确定多工作者节点体系结构。我是minikube用户。 在这里查看-https://github.com/kubernetes/kubernetes/issues/60903
现在您拥有PV和PVC,两个状态都已绑定。现在,您将在pod / deployment资源定义中使用该声明,并在pvc名称中使用相同的声明名称。这会将音量附加到两个吊舱。
---
#pv defination:
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv0
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
capacity:
storage: 5Gi
hostPath:
path: /path_on_node
type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim0
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
volumeName: pv0
---
# pod1
volumeMounts:
- mountPath: /container_path
name: vol0
subPath: sub_path_on_pv(say pod1 so on disk data will be written at /path_on_node/pod1
volumes:
- name: vol0
persistentVolumeClaim:
claimName: claim0
---
# pod2
volumeMounts:
- mountPath: /container_path
name: vol2
subPath: sub_path_on_pv(say pod2 so on disk data will be written at /path_on_node/pod2
volumes:
- name: vol2
persistentVolumeClaim:
claimName: claim0