1 部署驱动

参考官网的,需要自己改镜像

1
2
3
4
5
6
7
8
helm install smb-csi . -n kube-system
kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
csi-attacher-smb-0 1/1 Running 0 16h
csi-provisioner-smb-0 2/2 Running 0 16h
csi-smb-2dfnn 2/2 Running 0 16h
csi-smb-nn5pp 2/2 Running 0 16h
csi-smb-q9pln 2/2 Running 0 16h

2 Storageclass

创建 Secret

1
kubectl create secret -n kube-system generic smbcreds --from-literal username=${username} --from-literal password="${password}"

创建 Storageclass

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
cat sc.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-smb
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: smb
mountOptions:
- dir_mode=0777 # 权限配置等
- file_mode=0777
- uid=1001
- gid=1001
- noperm
- mfsymlinks
- cache=strict
- noserverino # 防止数据损坏
csi:
driver: smb.csi.k8s.io
readOnly: false
volumeHandle: unique-volumeid # 要唯一
volumeAttributes:
source: "${nas 存储业务地址}"
nodeStageSecretRef:
name: smbcreds
namespace: kube-system
kubectl apply -f sc.yaml -n kube-system

3 验证

3.1 创建 pvc

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

查看

1
2
3
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-smb Bound pvc-df3ed2a7-6086-450d-8c17-ff40ab9a1fb4 1Gi RWO csi-smb 16h

3.2 创建 pod

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

查看

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