华为CCE k8s 使用nfs-subdir-external-provisioner 创建pvc时自动创建pv

  1. 在集群中选择一个节点安装nfs,

2.编写nfs-client-provisioner.yaml

复制代码
apiVersion: v1
kind: Namespace
metadata:
  name: nfs-client-provisioner
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  namespace: nfs-client-provisioner
---
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
    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
  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
  namespace: nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    namespace: nfs-client-provisioner
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  namespace: nfs-client-provisioner
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: swr.cn-east-3.myhuaweicloud.com/mmwz/nfs-subdir-external-provisioner:v4.0.2
          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.0.91 #nfs服务器ip
            - name: NFS_PATH
              value: /opt/datanfs/k8s #nfs服务器共享目录
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.0.91 #nfs服务器ip
            path: /opt/datanfs/k8s #nfs服务器共享目录
      imagePullSecrets:
        - name: default-secret      


---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-storage
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
parameters:
  pathPattern: "${.PVC.namespace}/${.PVC.name}"
reclaimPolicy: Retain
volumeBindingMode: Immediate    

3.编写xxx-nfs-pvc.yaml

复制代码
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: guanwang-nfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 3Gi
  storageClassName: nfs-storageclass
相关推荐
提子拌饭13313 小时前
风息时钟:鸿蒙Flutter 实现的自然风格时钟应用
flutter·华为·架构·开源·harmonyos
航Hang*17 小时前
Windows Server 配置与管理——第3章:文件系统管理
运维·服务器·windows·vmware
无限进步_18 小时前
【C++】电话号码的字母组合:从有限处理到通用解法
开发语言·c++·ide·windows·git·github·visual studio
见山是山-见水是水18 小时前
Flutter 框架跨平台鸿蒙开发 - AR植物养护助手
flutter·华为·ar·harmonyos
私人珍藏库18 小时前
【Windows】PDF超能助手(1.0.13)
windows·pdf·工具·软件·多功能
仟人斩18 小时前
Windows 下把 VSCode 加入右键菜单(注册表方案)
windows·vscode·上下文菜单
autumn200519 小时前
Flutter 框架跨平台鸿蒙开发 - 历史人物对话
服务器·flutter·华为·harmonyos
大强同学19 小时前
对比 VS Code:Zed 编辑器编码体验全面解析
人工智能·windows·编辑器·ai编程
autumn200519 小时前
Flutter 框架跨平台鸿蒙开发 - 社区闲置循环
flutter·华为·harmonyos
chenbin___19 小时前
在鸿蒙手机上,measure 和 measureInWindow 返回的 y / pageY 在滑动组件后值不变问题
华为·智能手机·harmonyos