OSS
httpshelp.aliyun.comdocument_detail86543.html
使用说明
配置 OSS 静态存储卷的说明如下:
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
|