- 創(chuàng)建 RBAC 資源
保存為 nfs-provisioner-rbac.yaml:
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
namespace: default
---
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"]
- apiGroups: [""]
resources: ["persistentvolumeclaims/status"]
verbs: ["update"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: run-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
namespace: default
roleRef:
kind: ClusterRole
name: nfs-client-provisioner-runner
apiGroup: rbac.authorization.k8s.io
- 創(chuàng)建 Deployment
保存為 nfs-provisioner-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-client-provisioner
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nfs-client-provisioner
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccountName: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: k8s.gcr.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: nfs.io/nfs
- name: NFS_SERVER
value: 192.168.1.100 # 替換為你的 NFS 服務(wù)器地址
- name: NFS_PATH
value: /exported/path # 替換為你的 NFS 共享路徑
volumes:
- name: nfs-client-root
nfs:
server: 192.168.1.100 # 替換為你的 NFS 服務(wù)器地址
path: /exported/path # 替換為你的 NFS 共享路徑
- 創(chuàng)建 StorageClass
保存為 nfs-storageclass.yaml:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-storage-class
provisioner: nfs.io/nfs
parameters:
archiveOnDelete: "false" # 刪除 PVC 時是否保留數(shù)據(jù)
4.創(chuàng)建一個 PVC 測試: 保存以下內(nèi)容為 test-pvc.yaml:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
spec:
storageClassName: nfs-storage-class
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi