nfs 无法空间限额,相当于有个 provisioner 远程帮忙挂载

1 安装 nfs 客户端

最好每个节点都安装

yum -y install nfs-utils

1.1 测试

1
2
3
showmount -e 10.1.1.1
Export list for 10.1.1.1:
/data/nfs_data *

2 部署驱动

下载此目录所有文件

2.1 修改配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-client-provisioner
labels:
app: nfs-client-provisioner
namespace: nfs
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: willdockerhub/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: 10.1.1.1 # nfs地址
- name: NFS_PATH
value: /data/nfs_data # nfs目录
volumes:
- name: nfs-client-root
nfs:
server: 10.1.1.1 # nfs地址
path: /data/nfs_data # nfs目录
1
2
3
4
kubectl apply -f . -n nfs
kubectl get pod -n nfs
NAME READY STATUS RESTARTS AGE
nfs-client-provisioner-6fddfdfd9f-7rwh6 1/1 Running 0 6d23h

3 Storageclass

创建 Storageclass

1
2
3
4
5
6
7
8
9
cat sc.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-client
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
parameters:
archiveOnDelete: "false"
kubectl apply -f sc.yaml -n nfs

4 验证

4.1 创建 pvc

1
2
3
4
5
6
7
8
9
10
11
12
13
cat pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-claim
spec:
storageClassName: nfs-client
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Mi
kubectl apply -f pvc.yaml -n nfs

查看

1
2
3
kubectl get pvc -n nfs
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
test-claim Bound pvc-8c1a55c4-eb09-4aca-8a2a-9cbbddb12706 1Mi RWX nfs-client 6d23h

4.2 创建 pod

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cat pod.yaml
kind: Pod
apiVersion: v1
metadata:
name: nfs-pod
namespace: nfs
spec:
containers:
- name: nfs-pod
image: nginx
volumeMounts:
- name: pvc
mountPath: "/mnt"
volumes:
- name: pvc
persistentVolumeClaim:
claimName: nfs-pvc
kubectl apply -f pod.yaml -n nfs

查看

1
2
3
kubectl get pod -n nfs
NAME READY STATUS RESTARTS AGE
nfs-pod 1/1 Running 0 16h

5 静态创建

5.1 创建 pv

1
2
3
4
5
6
7
8
9
10
11
12
13
14
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv #pv的名字
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 2Mi #容量大小
nfs:
path: /data/nfs_data/pvc-test #该/data/nfs_data/为nfs固定目录,不可变;
server: 10.1.1.1 #nfs server地址
persistentVolumeReclaimPolicy: Retain #回收策略,默认为Retain,删除pvc后,pv可以继续用。建议手动创建pv都使用该策略。
volumeMode: Filesystem

5.2 pvc 绑定 pv

1
2
3
4
5
6
7
8
9
10
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
volumeName: nfs-pv
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi

5.3 查看

1
2
3
kubectl get pvc -n gfs
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nfs-pvc Bound nfs-pv 1Gi RWO 12m