k8s部署cloudreve、nfs与pvc版

一、二副本cloudreve部署nfs

1、环境(在nfs共享文件夹内创建挂载目录)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 创建挂载目录
sudo mkdir -p /srv/nfs4/cloudreve-storage
sudo mkdir -p /srv/nfs4/config
sudo mkdir -p /srv/nfs4/cloudreve/uploads
sudo mkdir -p /srv/nfs4/cloudreve/avatar
sudo chmod -R 777 /srv/nfs4

# 设置共享目录
vim /etc/exports

# /srv/nfs4 *(rw,no_subtree_check)
# /nfs/data/pv1 *(rw,sync,no_subtree_check)
# /nfs/data/pv2 *(rw,sync,no_subtree_check)
# /nfs/data/pv3 10.0.0.0/24(rw,sync,no_subtree_check)

2、cloudreve.yaml文件

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
apiVersion: apps/v1
kind: Deployment
metadata:
metadata: # 源数据
name: cloudreve # 当前deployment所属的名字
namespace: dev # 及ns
spec:
replicas: 2
selector:
matchLabels:
app: cloudreve
template:
metadata:
labels:
app: cloudreve
spec:
containers:
- name: cloudreve
image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:xavierniu_cloudreve_3.4.2
ports:
- containerPort: 5212
volumeMounts:
- name: cloudreve-storage
mountPath: /var/lib/cloudreve
- name: config-volume
mountPath: /cloudreve/config
- name: uploads-volume
mountPath: /cloudreve/uploads
- name: avatar-volume
mountPath: /cloudreve/avatar
stdin: true
tty: true
securityContext:
privileged: true
volumes:
- name: cloudreve-storage
nfs:
server: 58.49.144.8
path: /srv/nfs4/cloudreve-storage
- name: config-volume
nfs:
server: 58.49.144.8
path: /srv/nfs4/config
- name: uploads-volume
nfs:
server: 58.49.144.8
path: /srv/nfs4/cloudreve/uploads
- name: avatar-volume
nfs:
server: 58.49.144.8
path: /srv/nfs4/cloudreve/avatar

---
apiVersion: v1
kind: Service
metadata:
namespace: dev
name: cloudreve-service
spec:
selector:
app: cloudreve
ports:
- protocol: TCP
port: 9005
targetPort: 5212
sessionAffinity: ClientIP
type: NodePort

查看默认账户密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
kubectl logs cloudreve-598f69459c-nkbrd
___ _ _
/ __\ | ___ _ _ __| |_ __ _____ _____
/ / | |/ _ \| | | |/ _ | '__/ _ \ \ / / _ \
/ /___| | (_) | |_| | (_| | | | __/\ V / __/
\____/|_|\___/ \__,_|\__,_|_| \___| \_/ \___|

V3.4.2 Commit #a11f819 Pro=false
================================================

[Info] 2024-11-15 15:10:43 初始化数据库连接
[Info] 2024-11-15 15:10:43 开始进行数据库初始化...
[Info] 2024-11-15 15:10:43 初始管理员账号:admin@cloudreve.org
[Info] 2024-11-15 15:10:43 初始管理员密码:scoXZsMt
[Info] 2024-11-15 15:10:43 开始执行数据库脚本 [UpgradeTo3.4.0]
[Info] 2024-11-15 15:10:43 数据库初始化结束
[Info] 2024-11-15 15:10:43 初始化任务队列,WorkerNum = 10
[Info] 2024-11-15 15:10:43 初始化定时任务...
[Info] 2024-11-15 15:10:43 当前运行模式:M

二、PVC版本

1、创建PV卷

1.1、设置底层存储
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 创建目录
mkdir -pv /nfs/data/{pv1,pv2,pv3}
chmod 777 -R /nfs/data/{pv1,pv2,pv3}

# 暴露服务
vim /etc/exports

/nfs/data/pv1 *(rw,sync,no_subtree_check)
/nfs/data/pv2 *(rw,sync,no_subtree_check)
/nfs/data/pv3 10.0.0.0/24(rw,sync,no_subtree_check)

# 重启服务
systemctl restart nfs
systemctl enable nfs

# 生效
exportfs -rav

创建PV卷使用nfs类型(pv.yml)

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
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv1
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /nfs/data/pv1
server: 58.49.144.8

---

apiVersion: v1
kind: PersistentVolume
metadata:
name: pv2
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /nfs/data/pv2
server: 58.49.144.8

1.2、申请PVC(pvc.yml)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc1
namespace: dev
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc2
namespace: dev
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi

2、基于PVC申请后端容量创建

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
apiVersion: apps/v1
kind: Deployment
metadata:
metadata: # 源数据
name: cloudreve # 当前deployment所属的名字
namespace: dev # 及ns
spec:
replicas: 2
selector:
matchLabels:
app: cloudreve
template:
metadata:
labels:
app: cloudreve
spec:
containers:
- name: cloudreve
image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:xavierniu_cloudreve_3.4.2
ports:
- containerPort: 5212
volumeMounts:
- name: cloudreve-storage
mountPath: /var/lib/cloudreve
- name: cloudreve-storage
mountPath: /cloudreve/config
- name: cloudreve-storage
mountPath: /cloudreve/uploads
- name: cloudreve-storage
mountPath: /cloudreve/avatar
stdin: true
tty: true
securityContext:
privileged: true
volumes:
- name: cloudreve-storage
persistentVolumeClaim:
claimName: pvc1
readOnly: false
# 不可写true即可读不可写

---
# 暴露端口
apiVersion: v1
kind: Service
metadata:
name: cloudreve-service
namespace: dev
spec:
selector:
app: cloudreve
ports:
- protocol: TCP
# 宿主机端口
port: 9005
# 容器端口
targetPort: 5212
sessionAffinity: ClientIP # 设置会话亲和性使其转发到上一次访问的会话中
type: NodePort

三、效果

https://github.com/zznn-cloud/zznn-cloud-blog-images/raw/main/Qexo/24/11/image_bd516f0e473a2922cafd3ff154c7df7c.png