更新

更新

我遵循了这一点(https://matthewpalmer.net/kubernetes-app-developer/articles/kubernetes-volumes-example-nfs-persistent-volume.html) 链接并使用以下 yaml 文件在我的集群中安装了一个 NFS 服务器:

kind: Service
apiVersion: v1
metadata:
  name: nfs-service
spec:
  selector:
    role: nfs
  ports:
    # Open the ports required by the NFS server
    # Port 2049 for TCP
    - name: tcp-2049
      port: 2049
      protocol: TCP

    # Port 111 for UDP
    - name: udp-111
      port: 111
      protocol: UDP

---
kind: Pod
apiVersion: v1
metadata:
  name: nfs-server-pod
  labels:
    role: nfs
spec:
  containers:
    - name: nfs-server-container
      image: cpuguy83/nfs-server
      securityContext:
        privileged: true
      args:
        # Pass the paths to share to the Docker image
        - /exports

我通过以下命令安装了服务器:

kubectl create namespace nfs
kubectl apply -f nfs-server.yaml -n nfs

服务器安装顺利并正常运行。

我在所有节点上安装nfs-common,然后通过以下命令安装 nfs-client provisioner helm chart:

helm install stable/nfs-client-provisioner --set nfs.server=nfs-service --set nfs.path=/exported/path --name=nfs-client --namespace=nfs

但是 nfs-client 停留在 ContainerCreating 状态,这是描述的输出:

Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  nfs-client-root:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    nfs-service
    Path:      /exported/path
    ReadOnly:  false
  nfs-client-nfs-client-provisioner-token-k9n8n:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  nfs-client-nfs-client-provisioner-token-k9n8n
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason       Age   From                      Message
  ----     ------       ----  ----                      -------
  Warning  FailedMount  59m   kubelet, serflex-argus-1  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-rdc5765db89a64abf87610ba4d853f48d.scope
mount.nfs: Connection timed out
  Warning  FailedMount  57m  kubelet, serflex-argus-1  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-r0b472b9b183240bd8a4a3020bc13a129.scope
mount.nfs: Connection timed out
  Warning  FailedMount  55m  kubelet, serflex-argus-1  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-r8f149b9cfb4d414cb15834537f4fd88a.scope
mount.nfs: Connection timed out
  Warning  FailedMount  52m  kubelet, serflex-argus-1  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-r3f2e2388086f42f987f0e1475ef95385.scope
mount.nfs: Connection timed out
  Warning  FailedMount  50m  kubelet, serflex-argus-1  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-r8db7f40d8a7948598deae1fb07162372.scope
mount.nfs: Connection timed out
  Warning  FailedMount  48m  kubelet, serflex-argus-1  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-rff3d9f71b0e44148ba70c3f9f706d8e4.scope
mount.nfs: Connection timed out
  Warning  FailedMount  46m  kubelet, serflex-argus-1  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-r05af2a5659ad47bea7a0e7010d280444.scope
mount.nfs: Connection timed out
  Warning  FailedMount  20m (x5 over 56m)     kubelet, serflex-argus-1  Unable to attach or mount volumes: unmounted volumes=[nfs-client-root], unattached volumes=[nfs-client-nfs-client-provisioner-token-k9n8n nfs-client-root]: timed out waiting for the condition
  Warning  FailedMount  9m7s (x15 over 59m)   kubelet, serflex-argus-1  Unable to attach or mount volumes: unmounted volumes=[nfs-client-root], unattached volumes=[nfs-client-root nfs-client-nfs-client-provisioner-token-k9n8n]: timed out waiting for the condition
  Warning  FailedMount  3m20s (x15 over 43m)  kubelet, serflex-argus-1  (combined from similar events): MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs nfs-service:/exported/path /var/lib/kubelet/pods/811e6fd7-0e48-40a3-ad4d-2f677d49178c/volumes/kubernetes.io~nfs/nfs-client-root
Output: Running scope as unit: run-r27616bcceccc4ff194ac009997604d31.scope
mount.nfs: Connection timed out

我必须提到我正在运行 k8s v1.16。

我该如何解决这个问题?

更新

我不知道问题是什么,但是当我从 k8s 中删除 nfs 服务器并使用位于裸机上的服务器时,客户端开始正常工作。

答案1

确保你已经在所有发行版上安装了nfs-utils(rpm-base 发行版)或nfs-common(deb-based 发行版)软件包Kubernetes节点。

答案2

如果你使用 NFS v3,那么你还需要运行另一个端口和守护进程 -安装通常情况下,mountd 会选择一个随机端口号。因此,您必须将其固定/etc/sysconfig/nfs

MOUNTD_PORT=892

并且,正如@mario所提到的,确保所有端口都是 TCP。

对于使用 NFSv4.x 的客户端,您可能需要在命令行上指定它:

mount -vers=4.1 ....

或者

mountOptions:
 - tcp
 - nfsvers=4.1

信息deployment.yaml

答案3

不确定这个问题是否解决了。但是当我遇到这个问题时,执行下面的操作可以解决错误

systemctl 启用 nfs 服务器 rpcbind

相关内容