NFS-Client-Provisioner部署
admin
2023-02-24 19:20:03
0

部署NFS-Client Provisioner的初衷,就是为了根据PVC的需求自动创建符合要求的PV。
首先,必须拥有自己的NFS Server, 而且k8s集群能够正常访问之。

之后,在k8s master上应用以下yaml文件:
1 RBAC.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: nfs-client-provisioner
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: nfs-client-provisioner
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
    # replace with namespace where provisioner is deployed
  namespace: nfs-client-provisioner
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: nfs-client-provisioner
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

2 Deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-client-provisioner
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: zbb.test/nfs
            - name: NFS_SERVER
              value: 10.0.0.31
            - name: NFS_PATH
              value: /netshare
      volumes:
        - name: nfs-client-root
          nfs:
            server: 10.0.0.31
            path: /netshare

注意修改env和volumes中关于NFS Server的参数

3 storageclass.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage
provisioner: zbb.test/nfs # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
  archiveOnDelete: "false"

注意:
1) storageclass中的provisioner必须与deployment中的定义一致!
2) 如果不把nfs-client-provisioner部署到默认名称空间中,需要将“# replace with namespace where provisioner is deployed”标注的namespace全部改为目标namespace名称
3)Storagelass的名称可以修改成自己想要的

查看已部署的Storagelass:

# kubectl get storageclass
# kubectl get cs

(参考<2>)将managednfs-storage这个storageclass设置为kubernetes的默认存储后端:

# kubectl patch storageclass managed-nfs-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

由此, 部署完成, 下面给出个测试示例:
4 test-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-claim
  annotations:
    volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Mi

5 test-pod.yaml

kind: Pod
apiVersion: v1
metadata:
  name: test-pod
spec:
  containers:
  - name: test-pod
    image: busybox:1.24
    command:
      - "/bin/sh"
    args:
      - "-c"
      - "touch /mnt/SUCCESS && exit 0 || exit 1"
    volumeMounts:
      - name: nfs-pvc
        mountPath: "/mnt"
  restartPolicy: "Never"
  volumes:
    - name: nfs-pvc
      persistentVolumeClaim:
        claimName: test-claim

到此, 可以查询测试结果,测试完成
此后就可以使用NFS动态供给PV啦,不需要手工创建咯

测试平台:kubernetes 1.16.3
OS: CentOS Linux release 7.7.1908 (Core)

参考资料:
<1> https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client
<2> https://www.cnblogs.com/robinunix/p/11133032.html

在此向参考资料的作者表示感谢!!

相关内容

热门资讯

雷达、机库、营房、燃料库、飞机... 据《华盛顿邮报》5月6日报道,通过卫星影像分析发现,自2月28日战事爆发以来,伊朗空袭已在中东美军军...
从买买买到租租租,“租用一代”... “五一”假期还在路上,年轻人已经“租”起来了。 “租三天,不到300块钱。”五一放假前一周,清清已给...
【品牌】摩托罗拉大折叠屏新机定... 此前联想预热将于5月19日19点举行联想天禧AI一体多端全场景新品超能之夜活动,届时将带来多款新品,...
常州欣隽益取得接线端子用快速冲... 国家知识产权局信息显示,常州欣隽益科技有限公司取得一项名为“接线端子用快速冲切装置”的专利,授权公告...
美媒:特朗普在结束伊朗战争问题... 据“国会山”网站5月6日报道,周二晚间,美国总统特朗普突然宣布终止旨在打破伊朗对霍尔木兹海峡掌控的军...
和创硅材料取得熔融石英制品擦洗... 国家知识产权局信息显示,东海县和创硅材料有限公司取得一项名为“一种熔融石英制品的擦洗脱泥装置”的专利...
美商务部长再就爱泼斯坦案接受国... 5月6日,美国商务部长卢特尼克“自愿”就其与爱泼斯坦的关系接受美国国会众议院监督与政府改革委员会的问...
“五一”小长假黄金零售市场新变... 【大河财立方 记者 孙凯杰】 “五一”小长假,黄金价格出现一波短暂调整,线下黄金零售市场热度如何?5...
以军3周来首次袭击黎巴嫩首都 据以色列总理内塔尼亚胡和国防部长卡茨当地时间5月6日晚发表的联合声明,以军当天对黎巴嫩首都贝鲁特南郊...
东莞移动:5G-A智擎护航, ... “五一”期间,松山湖草莓音乐节、广东国际汽车展示交易会·春季、2026茶园游会田园文化美食节、大岭山...