rook使用cephfs

前提

  • 默认安装好了kubernetes集群
  • 默认已经安装好了rook,安装rook参考上篇rook安装及使用ceph rbd
  • 注意: k8s out tree存储有两种方式csi及flexvolume,此文件使用flexvolume,不过csi才是未来。

创建文件系统

编排文件如下filesystem.yaml,其中failureDomain为host且replicated是3时,则osd至少在3个主机上,即ceph至少需要三个存储主机。

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
kind: CephFilesystem
metadata:
name: myfs
namespace: rook-ceph
spec:
# The metadata pool spec. Must use replication.
metadataPool:
replicated:
size: 3
# The list of data pool specs. Can use replication or erasure coding.
dataPools:
- failureDomain: host
replicated:
size: 3
# The metadata service (mds) configuration
metadataServer:
# The number of active MDS instances
activeCount: 1
# Whether each active MDS instance will have an active standby with a warm metadata cache for faster failover.
# If false, standbys will be available, but will not have a warm cache.
activeStandby: true
# The affinity rules to apply to the mds deployment
placement:
# nodeAffinity:
# requiredDuringSchedulingIgnoredDuringExecution:
# nodeSelectorTerms:
# - matchExpressions:
# - key: role
# operator: In
# values:
# - mds-node
# tolerations:
# - key: mds-node
# operator: Exists
# podAffinity:
# podAntiAffinity:
# A key/value list of annotations
annotations:
# key: value
resources:
# The requests and limits set here, allow the filesystem MDS Pod(s) to use half of one CPU core and 1 gigabyte of memory
# limits:
# cpu: "500m"
# memory: "1024Mi"
# requests:
# cpu: "500m"
# memory: "1024Mi"
1
kubectl apply -f filesystem.yaml

deployment直接使用

此deployment中的pod共享文件目录,即/var/lib/registry在三个pod中是都可以读写的。编排文件registry.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
apiVersion: apps/v1
kind: Deployment
metadata:
name: kube-registry
namespace: kube-system
labels:
k8s-app: kube-registry
kubernetes.io/cluster-service: "true"
spec:
replicas: 3
selector:
matchLabels:
k8s-app: kube-registry
template:
metadata:
labels:
k8s-app: kube-registry
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: registry
image: registry:2
imagePullPolicy: Always
resources:
limits:
cpu: 100m
memory: 100Mi
env:
# Configuration reference: https://docs.docker.com/registry/configuration/
- name: REGISTRY_HTTP_ADDR
value: :5000
- name: REGISTRY_HTTP_SECRET
value: "Ple4seCh4ngeThisN0tAVerySecretV4lue"
- name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
value: /var/lib/registry
volumeMounts:
- name: image-store
mountPath: /var/lib/registry
ports:
- containerPort: 5000
name: registry
protocol: TCP
livenessProbe:
httpGet:
path: /
port: registry
readinessProbe:
httpGet:
path: /
port: registry
volumes:
- name: image-store
flexVolume:
driver: ceph.rook.io/rook
fsType: ceph
options:
fsName: myfs # name of the filesystem specified in the filesystem CRD.
clusterNamespace: rook-ceph # namespace where the Rook cluster is deployed
# by default the path is /, but you can override and mount a specific path of the filesystem by using the path attribute
# the path must exist on the filesystem, otherwise mounting the filesystem at that path will fail
#path: /some/path/inside/cephfs
1
kubectl apply -f registry.yaml

通过pv及pvc使用

创建pv

pv编排文件如下pv.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
apiVersion: v1
kind: PersistentVolume
metadata:
name: cephfs-pv1
spec:
capacity:
storage: 5Gi
storageClassName: cephfs
accessModes:
- ReadWriteMany
flexVolume:
driver: ceph.rook.io/rook
fsType: ceph
options:
clusterNamespace: rook-ceph
fsName: myfs
path: /some/bigdata/flex
1
kubectl apply -f pv.yaml

创建pvc

pvc编排文件如下pvc.yaml

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

创建deployment

deployment编排文件如下registry2.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
68
69
70
71
72
73
74
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: kube-registry
kubernetes.io/cluster-service: "true"
name: kube-registry
spec:
selector:
matchLabels:
k8s-app: kube-registry
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
k8s-app: kube-registry
kubernetes.io/cluster-service: "true"
spec:
containers:
- env:
- name: REGISTRY_HTTP_ADDR
value: :5000
- name: REGISTRY_HTTP_SECRET
value: Ple4seCh4ngeThisN0tAVerySecretV4lue
- name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
value: /var/lib/registry
image: registry:2
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: registry
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
name: registry
ports:
- containerPort: 5000
name: registry
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: registry
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
cpu: 100m
memory: 100Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/lib/registry
name: image-store
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: image-store
persistentVolumeClaim:
claimName: pvc-nas
1
kubectl apply -f registry2.yaml
  • 注意:虽然pv和pvc写了大小,但是在此文件系统中可用大于此值,无法做限制。