• Kubernetes 部署 nfs-subdir-external-provisioner


    概述

    官方GitHub及参考文档:GitHub - kubernetes-sigs/nfs-subdir-external-provisioner: Dynamic sub-dir volume provisioner on a remote NFS server.

    部署nfs-subdir-external-provisioner提供StorageClass服务

    步骤

    nfs 服务器准备

    /etc/exports

    1. # cat /etc/exports
    2. /nfsshare *(rw,no_root_squash,sync)

    install nfs-utils

    1. yum -y install nfs-utils
    2. systemctl enable --now nfs

    namespace

    1. apiVersion: v1
    2. kind: Namespace
    3. metadata:
    4. labels:
    5. kubernetes.io/metadata.name: nfs-server
    6. name: nfs-server
    7. spec:
    8. finalizers:
    9. - kubernetes

    class

    1. apiVersion: storage.k8s.io/v1
    2. kind: StorageClass
    3. metadata:
    4. name: nfs-client
    5. provisioner: k8s-sigs.io/nfs-subdir-external-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME'
    6. parameters:
    7. archiveOnDelete: "true"
    8. # 定义路径格式
    9. pathPattern: "${.PVC.namespace}/${.PVC.annotations.nfs.io/storage-path}"

    不同的呈现方式

    rbac

    1. apiVersion: v1
    2. kind: ServiceAccount
    3. metadata:
    4. name: nfs-client-provisioner
    5. # replace with namespace where provisioner is deployed
    6. namespace: nfs-server
    7. ---
    8. kind: ClusterRole
    9. apiVersion: rbac.authorization.k8s.io/v1
    10. metadata:
    11. name: nfs-client-provisioner-runner
    12. rules:
    13. - apiGroups: [""]
    14. resources: ["nodes"]
    15. verbs: ["get", "list", "watch"]
    16. - apiGroups: [""]
    17. resources: ["persistentvolumes"]
    18. verbs: ["get", "list", "watch", "create", "delete"]
    19. - apiGroups: [""]
    20. resources: ["persistentvolumeclaims"]
    21. verbs: ["get", "list", "watch", "update"]
    22. - apiGroups: ["storage.k8s.io"]
    23. resources: ["storageclasses"]
    24. verbs: ["get", "list", "watch"]
    25. - apiGroups: [""]
    26. resources: ["events"]
    27. verbs: ["create", "update", "patch"]
    28. ---
    29. kind: ClusterRoleBinding
    30. apiVersion: rbac.authorization.k8s.io/v1
    31. metadata:
    32. name: run-nfs-client-provisioner
    33. subjects:
    34. - kind: ServiceAccount
    35. name: nfs-client-provisioner
    36. # replace with namespace where provisioner is deployed
    37. namespace: nfs-server
    38. roleRef:
    39. kind: ClusterRole
    40. name: nfs-client-provisioner-runner
    41. apiGroup: rbac.authorization.k8s.io
    42. ---
    43. kind: Role
    44. apiVersion: rbac.authorization.k8s.io/v1
    45. metadata:
    46. name: leader-locking-nfs-client-provisioner
    47. # replace with namespace where provisioner is deployed
    48. namespace: nfs-server
    49. rules:
    50. - apiGroups: [""]
    51. resources: ["endpoints"]
    52. verbs: ["get", "list", "watch", "create", "update", "patch"]
    53. ---
    54. kind: RoleBinding
    55. apiVersion: rbac.authorization.k8s.io/v1
    56. metadata:
    57. name: leader-locking-nfs-client-provisioner
    58. # replace with namespace where provisioner is deployed
    59. namespace: nfs-server
    60. subjects:
    61. - kind: ServiceAccount
    62. name: nfs-client-provisioner
    63. # replace with namespace where provisioner is deployed
    64. namespace: nfs-server
    65. roleRef:
    66. kind: Role
    67. name: leader-locking-nfs-client-provisioner
    68. apiGroup: rbac.authorization.k8s.io

    deployment

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: nfs-client-provisioner
    5. labels:
    6. app: nfs-client-provisioner
    7. # replace with namespace where provisioner is deployed
    8. namespace: nfs-server
    9. spec:
    10. replicas: 1
    11. strategy:
    12. type: Recreate
    13. selector:
    14. matchLabels:
    15. app: nfs-client-provisioner
    16. template:
    17. metadata:
    18. labels:
    19. app: nfs-client-provisioner
    20. spec:
    21. serviceAccountName: nfs-client-provisioner
    22. containers:
    23. - name: nfs-client-provisioner
    24. # image: registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2
    25. image: registry.cn-beijing.aliyuncs.com/xngczl/nfs-subdir-external-provisione:v4.0.0
    26. volumeMounts:
    27. - name: nfs-client-root
    28. mountPath: /persistentvolumes
    29. env:
    30. - name: PROVISIONER_NAME
    31. value: k8s-sigs.io/nfs-subdir-external-provisioner
    32. # 设置高可用允许选举
    33. - name: ENABLE_LEADER_ELECTION
    34. value: "True"
    35. - name: NFS_SERVER
    36. value: 192.168.164.16
    37. - name: NFS_PATH
    38. value: /nfsshare
    39. volumes:
    40. - name: nfs-client-root
    41. nfs:
    42. server: 192.168.164.16
    43. path: /nfsshare

    验证命令

    kubectl logs -f --tail=20 nfs-client-provisioner-5856c5fc68-2r4k2  -n nfs-server                                                                                                                                      

    kubectl get sc

     测试

    pvc

    1. kind: PersistentVolumeClaim
    2. apiVersion: v1
    3. metadata:
    4. name: test-claim
    5. annotations:
    6. volume.beta.kubernetes.io/storage-class: "nfs-client"
    7. spec:
    8. storageClassName: nfs-client
    9. accessModes:
    10. - ReadWriteMany
    11. resources:
    12. requests:
    13. storage: 1Mi

    pod 

    1. kind: Pod
    2. apiVersion: v1
    3. metadata:
    4. name: test-pod
    5. spec:
    6. containers:
    7. - name: test-pod
    8. image: busybox:stable
    9. command:
    10. - "/bin/sh"
    11. args:
    12. - "-c"
    13. - "touch /mnt/SUCCESS && exit 0 || exit 1"
    14. volumeMounts:
    15. - name: nfs-pvc
    16. mountPath: "/mnt"
    17. restartPolicy: "Never"
    18. volumes:
    19. - name: nfs-pvc
    20. persistentVolumeClaim:
    21. claimName: test-claim

    Error

    No such file or directory

      Warning  FailedMount  15s (x8 over 79s)  kubelet            MountVolume.SetUp failed for volume "nfs-client-r                                                                                                            oot" : mount failed: exit status 32
    Mounting command: mount
    Mounting arguments: -t nfs 192.168.164.16:/nfsshare /etc/cni/net.d/pods/67154eef-96d4-46cc-af01-653496a4f1a7/vo                                                                                                            lumes/kubernetes.io~nfs/nfs-client-root
    Output: mount.nfs: mounting 192.168.164.16:/nfsshare failed, reason given by server: No such file or directory

    报错原因: 配置文件编写错误:

    修改正确的配置文件/etc/exports后,需要重启nfs服务生效。

    mount挂载文件,有坏超级块

    Mounting arguments: --description=Kubernetes transient mount for /data/kubernetes/kubelet/pods/2ca70aa9-433c-4d10-8f87-154ec9569504/volumes/kubernetes.io~nfs/nfs-client-root --scope -- mount -t nfs 172.16.41.7:/data/nfs_storage /data/kubernetes/kubelet/pods/2ca70aa9-433c-4d10-8f87-154ec9569504/volumes/kubernetes.io~nfs/nfs-client-root

    Output: Running scope as unit: run-rdcc7cfa6560845969628fc551606e69d.scope

    mount: /data/kubernetes/kubelet/pods/2ca70aa9-433c-4d10-8f87-154ec9569504/volumes/kubernetes.io~nfs/nfs-client-root: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount. helper program.

      Warning  FailedMount  10s  kubelet, node1.ayunw.cn  MountVolume.SetUp failed for volume "nfs-client-root" : mount failed: exit status 32

    Mounting command: systemd-run

    报错原因: 各个Kubernetes节点需要安装nfs-utils

    yum -y install nfs-utils 执行安装即可

    waiting for a volume to be created

      Normal  ExternalProvisioning  8s (x17 over 3m42s)  persistentvolume-controller  waiting for a volume to be created, either by external provisioner "k8s-sigs.io/nfs-subdir-external-provisioner" or manually created by system administrator

    pvc 一直处于pending状态,事件一直处于等待。

    检查class.yaml文件和deployment文件

    参考文档

    mount挂载文件,有坏超级块(解决方案) - 代码先锋网 (codeleading.com)

    k8s 使用新版NFS Provisioner配置subdir - 知乎 (zhihu.com)

    k8s-1.22.3版本中使用持久化卷之StorageClass+NFS (zhihu.com)

    k8s-1.22.3版本部署持久化存储之StorageClass+NFS_nfs部署storageclass_归海听雪的博客-CSDN博客

    K8s生产环境常见问题处理、答疑(连载、不定期更新)-阿里云开发者社区 (aliyun.com)

    Releases · kubernetes-sigs/nfs-subdir-external-provisioner (github.com)

    k8s学习: 部署动态 pvc(nfs-subdir-external-provisioner)_动态pvc_哈哈虎123的博客-CSDN博客

  • 相关阅读:
    JavaScript Web APIs第一天笔记
    万卷书 - 欧洲的门户 [The Gates of Europe]
    网络套接字编程
    【tio-websocket】10、单条TCP连接上下文—ChannelContext
    高频数据分析:使用数据透视
    LeetCode·20.有效的括号·栈模拟
    变量和数据类型
    深信服安全GPT 2.0升级,开启安全运营“智能驾驶”旅程
    SRRC认证的必要性:保障电子产品质量安全的重要措施
    『现学现忘』Git基础 — 18、Git对象的总结
  • 原文地址:https://blog.csdn.net/m0_59267075/article/details/133207323