【问题标题】:Cannot connect NFS server with Azure AKS无法将 NFS 服务器与 Azure AKS 连接
【发布时间】:2022-01-13 20:35:47
【问题描述】:

我正在尝试在 Kubernetes 集群 (AKS) 内挂载 NFS 服务器(在 Azure 虚拟机中设置)。

基本上,我休学了本教程: https://docs.microsoft.com/en-us/azure/aks/azure-nfs-volume

到目前为止,一切似乎都很好。我已经使用 telnet telnet IP_ADDRESS_NFS_MACHINE 111telnet IP_ADDRESS_NFS_MACHINE 2049 测试了从 pod 到 NFS 机器的连接。 Telnet 已连接。

但由于某种原因,我在 pod 启动时遇到了错误: MountVolume.SetUp failed for volume "aks-nfs" : mount failed: exit status 32 而最重要的部分: Output: mount.nfs: access denied by server while mounting IP_ADDRESS:/export/data

我猜是权限问题。我尝试在部署 k8s 对象中使用securityContext。我已经将fsGroup 设置为33,因为我认为因为我的应用程序在apache 服务器下运行,这将是很好的附加GID。我不确定这部分。 从 NFS 服务器 /export/data 导出的部分 - 我将其命名为 www-data:www-data 并且它具有 777 的 chmod。但问题仍然存在。

这是我的部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: web
spec:
  replicas: 1
  selector:
    matchLabels:
      component: web
  template:
    metadata:
      labels:
        component: web
    spec:
      securityContext:
        fsGroup: 33
      containers:
        - name: web
          image: the_image
          ports:
            - containerPort: 80
          volumeMounts:
            - name: nfs-pv
              mountPath: /var/www/html/storage
      volumes:
        - name: nfs-pv
          persistentVolumeClaim:
            claimName: nfs-pvc

我的PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 10Gi
  selector:
    matchLabels:
      type: nfs

和pv:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: aks-nfs
  labels:
    type: nfs
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: xx.xxx.xx.xx
    path: /export/data

我的导出配置文件:

/export        10.240.0.0/16(rw,async,insecure,fsid=0,crossmnt,no_subtree_check)
/export        localhost(rw,async,insecure,fsid=0,crossmnt,no_subtree_check)

我不确定与挂载的 NFS 连接的进程所有者到底是什么。 感谢您提前提供帮助。

【问题讨论】:

  • 你可以为kubectl get pv aks-nfskubectl get pvc nfs-pvc添加输出吗?

标签: azure kubernetes nfs


【解决方案1】:

pv 定义不正确。
您不必定义该导出。

按此修改pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: aks-nfs
  labels:
    type: nfs
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: xx.xxx.xx.xx
    path: /export

并且在pvc 上使用pv 中定义的相同名称:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: aks-nfs 
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 10Gi
  selector:
    matchLabels:
      type: nfs

修改文件后,使用kubectl 重新应用它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-17
    • 2018-11-16
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    相关资源
    最近更新 更多