NFS
nfs-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: nfs-client
nfs-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: managed-nfs-storage
provisioner: fuseim.pri/ifs
parameters:
archiveOnDelete: "false"
yum install -y nfs-common nfs-utils
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: nfs-client
name: nfs-client-provisioner
labels:
app: 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: quay.io/external_storage/nfs-client-provisioner:latest
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: fuseim.pri/ifs
- name: NFS_SERVER
value: 192.168.153.103
- name: NFS_PATH
value: /nfs/data
volumes:
- name: nfs-client-root
nfs:
server: 192.168.153.103
path: /nfs/data
nfs-rdac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
namespace: nfs-client
---
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
namespace: nfs-client
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
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
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
namespace: nfs-client
roleRef:
kind: Role
name: leader-locking-nfs-client-provisioner
apiGroup: rbac.authorization.k8s.io
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
test-pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: test-pod
spec:
containers:
- name: test-pod
image: gcr.io/google_containers/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
[root@hadoop03 NFS]# kubectl get pvc -n nfs-client
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
test-claim Bound pvc-fe723990-9bf4-46bd-bd41-ee7751f9c995 1Mi RWX managed-nfs-stora ge 3h7m
[root@hadoop03 NFS]# kubectl get pv -n nfs-client
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv 5Gi RWX Retain
pvc-fe723990-9bf4-46bd-bd41-ee7751f9c995 1Mi RWX Delete Bound nfs-client/te st-claim managed-nfs-storage 159m
[root@hadoop03 NFS]# kubectl get pv -n nfs-client
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv 5Gi RWX Retain Bound default/test-pvc manual 7h23m
pvc-fe723990-9bf4-46bd-bd41-ee7751f9c995 1Mi RWX Delete Bound nfs-client/test-claim managed-nfs-storage 160m
[root@hadoop03 NFS]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
managed-nfs-storage fuseim.pri/ifs Delete [添加链接描述](https://blog.csdn.net/BigData_Mining/article/details/96973871)Immediate false 3h21m
manual kubernetes.io/no-provisioner Delete WaitForFirstConsumer false 2d2h
sc rookieops/nfs Delete Immediate false 3h52m
[root@hadoop03 NFS]#
[root@hadoop03 NFS]# kubectl get pods -n nfs-client
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-764f44f754-tgbqr 1/1 Running 2 (160m ago) 3h19m
test-pod 1/1 Running 2 (160m ago) 122m
[root@hadoop03 NFS]#
[root@hadoop03 data]# ll
total 0
drwxrwxrwx 3 root root 17 2021-11-11 17:07:06 default-datadir-zk-0-pvc-4936aa57-68e9-4a52-ad40-1f26d67f5cee
drwxrwxrwx 2 root root 6 2021-11-11 17:07:25 default-datadir-zk-1-pvc-25d7ca60-1b7f-4c99-a6ae-8ad1aecc82f8
drwxrwxrwx 2 root root 20 2021-11-11 15:13:43 nfs-client-test-claim-pvc-fe723990-9bf4-46bd-bd41-ee7751f9c995
[root@hadoop03 data]# pwd
/nfs/data
修改 storageclass 默认
### 修改 gluster-heketi 为默认sc
kubectl patch storageclass gluster-heketi -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
转自:https://blog.csdn.net/BigData_Mining/article/details/96973871