OSS

httpshelp.aliyun.comdocument_detail86543.html

使用说明

配置 OSS 静态存储卷的说明如下:

  • OSS 为共享存储,可以同时为多个 Pod 提供共享存储服务。
  • bucket:目前只支持挂载存储空间 Bucket,不支持挂载 Bucket 下面的子目录或文件。
  • url:OSS 的 Endpoint,挂载 OSS 的接入域名,挂载节点和存储空间的地域相同时,可使用内网地址。
  • akId:您的 AccessKey ID 值。
  • akSecret:您的 AccessKey Secret 值。
  • otherOpts:挂载 OSS 时支持定制化参数输入,格式为:-o -o
  • 您在使用 OSS 数据卷时,不要使用 subpath 的配置。
  • 使用数据卷时,推荐每个应用使用独立的 PV 名字。

    注意事项

  • OSS 数据卷是使用 OSSFS 文件进行挂载的 FUSE 文件系统,适合于读文件场景。例如:读配置文件、视频、图片文件等场景。

  • OSSFS 不擅长于写文件的应用场景。如果您的业务是将文件写入存储的场景,推荐使用 NAS 存储卷服务。
  • 内核态文件系统相较于用户态模拟的文件系统,在稳定性、性能上更具有优势,生产环境中推荐您使用 NAS 文件存储,而不推荐 OSS 文件系统
  • OSSFS 可以通过调整配置参数的方式,优化其在缓存、权限等方面的表现,请参见常见问题ossfsREADME-CN.mdFAQ

    直接挂载

    创建并复制以下内容到 oss-deploy.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
apiVersion extensionsv1beta1
kind Deployment
metadata
name nginx-oss-deploy
spec
replicas 1
template
metadata
labels
app nginx
spec
containers
- name nginx-flexvolume-oss
image nginx
volumeMounts
- name oss1
mountPath data
livenessProbe
exec
command
- sh
- -c
- cd data
initialDelaySeconds 30
periodSeconds 30
volumes
- name oss1
flexVolume
driver alicloudoss
options
bucket docker
url oss-cn-hangzhou.aliyuncs.com
akId
akSecret
otherOpts -o max_stat_cache_size=0 -o allow_other

执行以下命令,创建 Pod。

1
kubectl apply -f oss-deploy.yaml

PV & PVC

您可以使用 YAML 文件或者通过容器服务控制台界面创建 PV。

创建 PV

使用 oss-pv.yaml 文件创建 PV

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apiVersion v1
kind PersistentVolume
metadata
name pv-oss
spec
capacity
storage 5Gi
accessModes
- ReadWriteMany
storageClassName oss
flexVolume
driver alicloudoss
options
bucket docker
url oss-cn-hangzhou.aliyuncs.com
akId
akSecret
otherOpts -o max_stat_cache_size=0 -o allow_other

创建 PVC

使用 oss-pvc.yaml 文件创建 PVC

1
2
3
4
5
6
7
8
9
10
11
kind PersistentVolumeClaim
apiVersion v1
metadata
name pvc-oss
spec
storageClassName oss
accessModes
- ReadWriteMany
resources
requests
storage 5Gi

创建 Pod

使用 oss-deploy.yaml 创建 Pod

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
apiVersion appsv1
kind Deployment
metadata
name oss-static
labels
app nginx
spec
replicas 1
selector
matchLabels
app nginx
template
metadata
labels
app nginx
spec
containers
- name nginx
image nginx
ports
- containerPort 80
volumeMounts
- name pvc-oss
mountPath data
livenessProbe
exec
command
- sh
- -c
- cd data
initialDelaySeconds 30
periodSeconds 30
volumes
- name pvc-oss
persistentVolumeClaim
claimName pvc-oss

httpshelp.aliyun.comdocument_detail130911.html

NAS

创建动态卷

配置 StorageClass

配置示例如下

1
2
3
4
5
6
7
8
9
10
11
12
apiVersion storage.k8s.iov1
kind StorageClass
metadata
name alicloud-nas
mountOptions
- nolock,tcp,noresvport
- vers=3
parameters
server 23a9649583-iaq37.cn-shenzhen.nas.aliyuncs.comnasroot1
driver flexvolume
provisioner alicloudnas
reclaimPolicy Delete

说明

  • mountOptions:表示生成的 PV options 配置,挂载 NAS 卷时使用这个 options 挂载。
  • server:表示生成目标 PV 所使用 NAS 挂载点列表。格式为 nfsurl1path1,nfsurl2path2;当配置多个 server 时,通过此 StorageClass 创建的 PV 会轮询使用上述 server 作为配置参数;极速 NAS 配置路径需要以 share 开头。
  • driver:支持 Flexvolume、NFS 两种驱动,默认为 NFS。
  • reclaimPolicy:PV 的回收策略,建议配置为 Retain。
    • 当配置为 Delete 时,删除 PV 后 NAS 文件系统中的对应目录会默认修改名字(例如,path-name 会被修改为 archived-path-name)。
    • 如果需要删除文件系统中对应的存储目录,可在 StorageClass 中配置 archiveOnDelete 为 false。

      使用动态卷

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
apiVersion v1
kind Service
metadata
name nginx
labels
app nginx
spec
ports
- port 80
name web
clusterIP None
selector
app nginx
---
apiVersion appsv1
kind StatefulSet
metadata
name web
spec
serviceName nginx
replicas 5
volumeClaimTemplates
- metadata
name html
spec
accessModes
- ReadWriteOnce
storageClassName alicloud-nas
resources
requests
storage 2Gi
template
metadata
labels
app nginx
spec
containers
- name nginx
image nginxalpine
volumeMounts
- mountPath data
name html