挂载CFS文件存储
更新时间:2024-09-25
挂载CFS文件存储
文件存储CFS(Cloud File Storage)是百度智能云提供的安全、可扩展的文件存储服务。通过标准的文件访问协议,为云上的计算资源提供无限扩展、高可靠、全球共享的文件存储能力。本文为您介绍挂载CFS文件存储。更多CFS相关信息,请参见CFS说明。
前提条件
请确保您已经创建CFS并已获得CFS挂载地址(CFS Server)。
注意:
- CFS为共享存储,一个CFS可以挂载到多个BCI实例上。此时,如果多个BCI同时修改相同数据,请进行同步与冲突保护。
- 在删除所有使用此挂载点的BCI实例前,请勿删除CFS挂载点,否则可能会造成操作系统无响应。
配置示例
CFS Volume
Plain Text
1apiVersion: v1
2kind: Pod
3metadata:
4 name: test-pd
5spec:
6 containers:
7 - image: registry.k8s.io/test-webserver
8 name: test-container
9 volumeMounts:
10 - mountPath: /my-cfs-data
11 name: test-volume
12 volumes:
13 - name: test-volume
14 nfs:
15 server: my-cfs-server.example.com #此为cfs挂载点
16 path: / #此为server端目录,cfs中为根目录不可变更
17 readOnly: true
CFS PVC
Plain Text
1apiVersion: v1
2kind: PersistentVolumeClaim
3metadata:
4 name: cfs
5spec:
6 accessModes:
7 - ReadWriteMany
8 storageClassName: ""
9 resources:
10 requests:
11 storage: 1Mi
12 volumeName: cfs
CFS PV
Plain Text
1apiVersion: v1
2kind: PersistentVolume
3metadata:
4 name: cfs
5spec:
6 capacity:
7 storage: 1Mi
8 accessModes:
9 - ReadWriteMany
10 nfs:
11 server: cfs-server.default.svc.cluster.local #此为cfs挂载点
12 path: "/" #此为server端目录,cfs中为根目录不可变更
13 mountOptions: #当前不支持指定挂载选项
14 - cfsvers=4.2
使用CFS PVC的Deployment
Plain Text
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: cfs-web
5spec:
6 replicas: 2
7 selector:
8 matchLabels:
9 role: web-frontend
10 template:
11 metadata:
12 labels:
13 role: web-frontend
14 spec:
15 containers:
16 - name: web
17 image: nginx
18 ports:
19 - name: web
20 containerPort: 80
21 volumeMounts:
22 # name must match the volume name below
23 - name: cfs
24 mountPath: "/usr/share/nginx/html"
25 volumes:
26 - name: cfs
27 persistentVolumeClaim:
28 claimName: cfs