如何修复 kubernetes nfs 挂载错误没有这样的文件或目录
Posted
技术标签:
【中文标题】如何修复 kubernetes nfs 挂载错误没有这样的文件或目录【英文标题】:How to fix kubernetes nfs mount error no such file or directory 【发布时间】:2019-09-11 10:22:00 【问题描述】:我正在尝试在部署了其他 k8s 服务的同一集群中使用 NFS
卷。但是使用NFS
的服务之一失败了
Output: mount.nfs: mounting nfs.default.svc.cluster.local:/opt/shared-shibboleth-idp failed, reason given by server: No such file or directory
nfs PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: nfs.default.svc.cluster.local # nfs is from svc include "nfs.name" .
path: "/opt/shared-shibboleth-idp"
nfs service
的描述
➜ helm git:(ft-helm) ✗ kubectl describe svc nfs
Name: nfs
Namespace: default
Labels: app=nfs
chart=nfs-1.0.0
heritage=Tiller
Annotations: <none>
Selector: role=nfs
Type: ClusterIP
IP: 10.19.251.72
Port: mountd 20048/TCP
TargetPort: 20048/TCP
Endpoints: 10.16.1.5:20048
Port: nfs 2049/TCP
TargetPort: 2049/TCP
Endpoints: 10.16.1.5:2049
Port: rpcbind 111/TCP
TargetPort: 111/TCP
Endpoints: 10.16.1.5:111
还有nfs deployment
➜ helm git:(ft-helm) ✗ kubectl describe replicationcontrollers telling-quoll-nfs
Name: telling-quoll-nfs
Namespace: default
Selector: role=nfs
Labels: app=nfs
chart=nfs-1.0.0
heritage=Tiller
Annotations: <none>
Replicas: 1 current / 1 desired
Pods Status: 1 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: role=nfs
Containers:
nfs:
Image: k8s.gcr.io/volume-nfs:0.8
Ports: 20048/TCP, 2049/TCP, 111/TCP
Host Ports: 0/TCP, 0/TCP, 0/TCP
Environment: <none>
Mounts:
/exports from nfs (rw)
Volumes:
nfs:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: nfs-pv-provisioning-demo
ReadOnly: false
Events: <none>
以及它的使用地点
volumeMounts:
# names must match the volume names below
- name: RELEASE-NAME-shared-shib
mountPath: "/opt/shared-shibboleth-idp"
;
;
volumes:
- name: RELEASE-NAME-shared-shib
persistentVolumeClaim:
claimName: nfs
;
;
k8s version
➜ helm git:(ft-helm) ✗ kubectl version
Client Version: version.InfoMajor:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-20T04:49:16Z", GoVersion:"go1.12.6", Compiler:"gc", Platform:"darwin/amd64"
Server Version: version.InfoMajor:"1", Minor:"13+", GitVersion:"v1.13.7-gke.8", GitCommit:"7d3d6f113e933ed1b44b78dff4baf649258415e5", GitTreeState:"clean", BuildDate:"2019-06-19T16:37:16Z", GoVersion:"go1.11.5b4", Compiler:"gc", Platform:"linux/amd64"
【问题讨论】:
有时您可能需要手动创建文件夹或目录。 您能否确认/opt/shared-shibboleth-idp
目录存在于您的nfs 上并且可以访问
@PatrickW /opt
存在,但 shared-shibboleth-idp
不存在。这正是我想要安装的
所以挂载操作只能挂载已有的卷和路径。该目录不需要存在于 pod 上,但它必须存在于 nfs 上
我必须想办法在 Helm 中手动创建它
【参考方案1】:
正如Patrick W
和damitj07
制作的cmets中提到的:
在尝试挂载之前必须手动创建文件夹或目录,否则Kubernetes会因为目标目录不存在而报错。
【讨论】:
以上是关于如何修复 kubernetes nfs 挂载错误没有这样的文件或目录的主要内容,如果未能解决你的问题,请参考以下文章
Amazon EKS (NFS) 到 Kubernetes pod。无法挂载卷
NFS/hostPath 在 kubernetes 中挂载为非 root
KUBERNETES05_NFS坏境搭建PVPVC挂载目录ConfigMap挂载文件Secret挂载敏感信息