在连接到 GCE 上的外部 NFS 服务器的 GKE 上创建 Kubernetes 持久卷
Create a Kubernetes Persistent Volume on GKE connected to an external NFS server on GCE
我在 GCE 的虚拟机上有一个 NFS 服务器 运行。 NFS 服务器 /etc/exports 文件已配置为允许 K8s 集群挂载。我尝试创建持久卷 (PV) 和持久卷声明 (PVC),并添加了 spec.containers.volumeMounts 和 spec.volumes 条目。基本上,Google 提供一个新磁盘而不是连接到 NFS 服务器。
在我添加的部署文件中:
volumeMounts:
- name: nfs-pvc-data
mountPath: "/mnt/nfs"
volumes:
- name: nfs-pvc-data
persistentVolumeClaim:
claimName: nfs-pvc
nfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
namespace: comms
labels:
volume: nfs-pv
spec:
capacity:
storage: 10G
#volumeMode: Filesystem
accessModes:
- ReadOnlyMany
mountOptions:
- hard
- nfsvers=4.2
nfs:
path: /
server: 10.xxx.xx.xx
readOnly: false
nfs-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
namespace: comms
#spec: # The PVC is stuck on ready as long as spec.selector exists in the yaml
#selector:
#matchLabels:
#volume: nfs-pv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1G
我能够使用以下 PV 和 PVC YAML 在 Kubernetes 集群外部安装 NFS 服务器。
apiVersion: v1
kind: PersistentVolume
metadata:
name: gce-nfs
namespace: comms
spec:
capacity:
storage: 1Mi
accessModes:
- ReadWriteMany
nfs:
server: 10.xxx.xxx.xxx
path: "/"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: gce-nfs
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: 1Mi
然后在部署 YAML 中,我将以下内容添加到容器部分:
volumeMounts:
- name: nfs-pvc-data
mountPath: "/mnt/nfs"
volumes:
- name: nfs-pvc-data
persistentVolumeClaim:
claimName: gce-nfs
pod/container 将引导连接到外部 NFS 服务器。
我在 GCE 的虚拟机上有一个 NFS 服务器 运行。 NFS 服务器 /etc/exports 文件已配置为允许 K8s 集群挂载。我尝试创建持久卷 (PV) 和持久卷声明 (PVC),并添加了 spec.containers.volumeMounts 和 spec.volumes 条目。基本上,Google 提供一个新磁盘而不是连接到 NFS 服务器。
在我添加的部署文件中:
volumeMounts:
- name: nfs-pvc-data
mountPath: "/mnt/nfs"
volumes:
- name: nfs-pvc-data
persistentVolumeClaim:
claimName: nfs-pvc
nfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
namespace: comms
labels:
volume: nfs-pv
spec:
capacity:
storage: 10G
#volumeMode: Filesystem
accessModes:
- ReadOnlyMany
mountOptions:
- hard
- nfsvers=4.2
nfs:
path: /
server: 10.xxx.xx.xx
readOnly: false
nfs-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
namespace: comms
#spec: # The PVC is stuck on ready as long as spec.selector exists in the yaml
#selector:
#matchLabels:
#volume: nfs-pv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1G
我能够使用以下 PV 和 PVC YAML 在 Kubernetes 集群外部安装 NFS 服务器。
apiVersion: v1
kind: PersistentVolume
metadata:
name: gce-nfs
namespace: comms
spec:
capacity:
storage: 1Mi
accessModes:
- ReadWriteMany
nfs:
server: 10.xxx.xxx.xxx
path: "/"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: gce-nfs
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: 1Mi
然后在部署 YAML 中,我将以下内容添加到容器部分:
volumeMounts:
- name: nfs-pvc-data
mountPath: "/mnt/nfs"
volumes:
- name: nfs-pvc-data
persistentVolumeClaim:
claimName: gce-nfs
pod/container 将引导连接到外部 NFS 服务器。