nfs-provisioner

2022-03-07 21:15:56 浏览数 (1)

nfs-provisioner-deploy.yaml

代码语言:yaml复制
kind: Deployment
apiVersion: apps/v1
metadata:
  name: nfs-provisioner
spec:
  selector:
    matchLabels:
      app: nfs-provisioner
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-provisioner
    spec:
      serviceAccount: nfs-provisioner
      containers:
        - name: nfs-provisioner
          image: registry.cn-hangzhou.aliyuncs.com/xzjs/nfs-subdir-external-provisioner:v4.0.0
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: "500m"
              memory: "2Gi"
            requests:
              cpu: "500m"
              memory: "2Gi"
          volumeMounts:
            - name: nfs-storage		#provisioner名称,请确保该名称与 nfs-provisioner-sc.yaml文件中的provisioner名称保持一致
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: nfs-client
            - name: NFS_SERVER
              value: 10.20.12.15		#nfs服务端IP地址
            - name: NFS_PATH
              value: /app/nfs_data		#nfs挂载卷
      volumes:
        - name: nfs-storage
          nfs:
            server: 10.20.12.15		#nfs服务端IP地址
            path: /app/nfs_data		#nfs挂载卷

rbac授权

nfs-provisioner-rbac.yaml

代码语言:yaml复制
kind: ServiceAccount
apiVersion: v1
metadata:
  name: nfs-provisioner

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-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"]
  - apiGroups: [""]
    resources: ["services", "endpoints"]
    verbs: ["get"]
  - apiGroups: ["extensions"]
    resources: ["podsecuritypolicies"]
    resourceNames: ["nfs-provisioner"]
    verbs: ["use"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-provisioner
    namespace: default
roleRef:
  kind: ClusterRole
  name: nfs-provisioner-runner
  apiGroup: rbac.authorization.k8s.io

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-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-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-provisioner
    namespace: default
roleRef:
  kind: Role
  name: leader-locking-nfs-provisioner
  apiGroup: rbac.authorization.k8s.io

nfs-provisioner-sc.yaml

代码语言:yaml复制
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: nfs-storage
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"   #设置为默认的sc
provisioner: nfs-storage    #动态卷名称,必须和上面的provisioner变量中设置一致
parameters:
  archiveOnDelete: "true"   #设置为false时删除PVC不会保留数据,true则保留数据

0 人点赞