当前位置: 首页 > article >正文

kubernetes-sigs / nfs-subdir-external-provisioner

创建 StatefulSet 应用时要求必须有且有一个默认 StorageClass,参考官网创建 StorageClass 对象但是里面的provisioner属性配置总是出现问题。

选择nfs作为网络存储系统搭建 StatefulSet ,但是nfs没有内部制备器,所以需要使用第三方存储供应商提供自己的外部制备器。

在这里插入图片描述


目标:创建nfs-clientStorageClass,以实现动态供给。

下载地址:https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner

deploy目录下修改配置,或者自己创建所需的三个文件,class.yaml 创建存储类:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-client # 存储类名字
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
  archiveOnDelete: "false" # pvc删除后,pv不删除(nfs共享目录不删除),设置true会删除

deployment.yaml 部署nfs-client-provisioner这里除了nfs配置信息还改了镜像地址,因为默认的镜像下载地址在国外。

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
  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: dyrnq/nfs-subdir-external-provisioner:v4.0.2 # dockerhub 地址:https://hub.docker.com/r/dyrnq/nfs-subdir-external-provisioner/tags
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: k8s-sigs.io/nfs-subdir-external-provisioner
            - name: NFS_SERVER
              value: 192.168.150.104 # nfs服务器IP,改成自己的
            - name: NFS_PATH
              value: /root/data/nfs # nfs服务器共享目录
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.150.104 # nfs服务器IP,改成自己的
            path: /root/data/nfs # nfs服务器共享目录

rbac.yaml 授权(连接k8s-api)

apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]
  - 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: default
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: default
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
  # replace with namespace where provisioner is deployed
  namespace: default
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: default
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

动态创建 NFS存储(动态存储):

kubectl apply -f class.yaml
kubectl apply -f deployment.yaml
kubectl apply -f rbac.yaml

将存储类设置为默认存储类:

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

创建成功kubectl get storageclass

NAME                   PROVISIONER                                   RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-client (default)   k8s-sigs.io/nfs-subdir-external-provisioner   Delete          Immediate           false                  90s

kubectl apply -f pvc.yaml创建pvc测试

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec: 
  storageClassName: "nfs-client"  #存储类的名字,只需要加这一个参数
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi

可以看到pv已经被自动创建kubectl get pv

NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM             STORAGECLASS   REASON   AGE
pvc-cf4ced81-07ad-4082-acba-3a26858d7acd   1Gi        RWX            Delete           Bound    default/nfs-pvc   nfs-client              33s

http://www.kler.cn/a/412557.html

相关文章:

  • Flink CDC 使用实践以及遇到的问题
  • mysql in查询大数据量业务无法避免情境下优化
  • 什么是MyBatis?
  • jvm核心组件介绍
  • 目标检测,图像分割,超分辨率重建
  • 调用 AWS Lambda 时如何传送字节数组
  • 2024年工信部大数据分析师证书报考条件是怎样的?有什么用
  • 【开源项目】2024最新PHP在线客服系统源码/带预知消息/带搭建教程
  • 野火直播 5.7.5x | 频道丰富,有国外频道,部分支持回看
  • python读txt文件时出现UnicodeDecodeError错误的解决
  • DataGuard 架构和概念整理
  • FBX福币交易所创业板指放量大涨2.73% 谷子经济概念持续爆发
  • Java全栈开发:宠物医院管理系统项目实战
  • 路由策略与路由控制实验
  • 模具监视器的特点有哪些
  • 服务限流、降级、熔断-SpringCloud
  • 鸿蒙中的Image组件如何引用网络图片
  • 吉利汽车x文心快码:AI最佳实践案例
  • Matlab 2016b安装教程附安装包下载
  • 电视网络机顶盒恢复出厂超级密码大全汇总
  • 深入理解 Java 基本语法之数组
  • 项目自动化部署,持续集成/持续交付(CI/CD)工具有那些?他们的优劣势分别是什么?共计15个工具进行对比分析。
  • C++虚函数面试题及参考答案
  • 如何为 ext2/ext3/ext4 文件系统的 /dev/centos/root 增加 800G 空间
  • ms-hot28 合并两个有序数组
  • 基于RAG的企业文档智能检索系统设计与实践