如何在Kubernetes集群动态使用 NAS 持久卷
生活随笔
收集整理的這篇文章主要介紹了
如何在Kubernetes集群动态使用 NAS 持久卷
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 介紹:
本文介紹的動態生成NAS存儲卷的方案:在一個已有文件系統上,自動生成一個目錄,這個目錄定義為目標存儲卷;
鏡像地址:registry.cn-hangzhou.aliyuncs.com/acs/alicloud-nas-controller:v1.11.5.4-433631d-aliyun
默認生成資源:
生成的PV名字為:pvc-${pvc-uid}
生成目錄的名字:namespace-pvcname-pvname
可以再pvc的annotations中如下聲明,自定義名字:
生成的pv、目錄名字為下面定義的名字。
2. 部署NAS Controller
創建alicloud-nas-controller,實現動態provider nas pv;
創建alicloud-nas storageclass,為nas pv provision 提供模板;
StorageClass使用說明:
drivertype: 用來表示生成pv存儲類型,可選nfs, flexvolume.nfs: 默認選項,表示使用k8s原生NFS驅動掛載;flexvolume: 表示使用阿里云提供的Flexvolume NAS驅動掛載;nfsversion: 掛載nfs使用的版本,支持3,4.0.默認為4.0;drivertype為flexvolume的時候在這里配置;為nfs的時候通過mountOptions 配置;options:為掛載nfs的可選項配置;drivertype為flexvolume的時候在這里配置;為nfs的時候通過mountOptions 配置;StorageClass舉例:
## 使用kubernetes提供的NFS驅動,并配置mountOptions,reclaimPolicy為Delete; apiVersion: storage.k8s.io/v1 kind: StorageClass metadata:name: alicloud-nas-nfs mountOptions: - vers=4.0 - noresvport provisioner: alicloud/nas reclaimPolicy: Delete## 使用阿里云提供的Flexvolume NAS驅動,配置nfs版本、options; apiVersion: storage.k8s.io/v1 kind: StorageClass metadata:name: alicloud-nas-flex provisioner: alicloud/nas reclaimPolicy: Delete parameters:drivertype: flexvolumenfsversion: "3"options: "noresvport"3. 創建應用-Deployment:
kind: PersistentVolumeClaim apiVersion: v1 metadata:name: replace-user-idannotations:pv-name-created: replace-user-id spec:storageClassName: alicloud-nasaccessModes:- ReadWriteManyresources:requests:storage: 5Gi --- apiVersion: extensions/v1beta1 kind: Deployment metadata:name: "deploy-nas" spec:replicas: 1strategy:type: Recreatetemplate:metadata:labels:app: deploy-nasspec:containers:- name: "nginx"image: "nginx"volumeMounts:- name: pvc-nasmountPath: "/data"volumes:- name: pvc-naspersistentVolumeClaim:claimName: replace-user-id執行: # userID="hello-123" # cat deploy.yaml | sed "s/replace-user-id/\"$userID\"/g" | kubectl create -f -# kubectl get pod | grep deploy-nas deploy-nas-85696b6bfc-t5dmh 1/1 Running 0 28m# kubectl get pvc | grep hell hello-123 Bound hello-123 5Gi RWX alicloud-nas-flex 28m# kubectl get pv | grep hell hello-123 5Gi RWX Delete Bound default/hello-123 alicloud-nas-flex 28m# Nas目錄下查看生成目錄: # ls -l | grep hello drwxrwxrwx 2 root root 4096 2月 19 09:58 hello-1234. 創建應用-StatefulSet:
使用volumeTemplateClaim不支持使用pv-name-created配置pv名字;
apiVersion: v1 kind: Service metadata:name: nginxlabels:app: nginx spec:ports:- port: 80name: webclusterIP: Noneselector:app: nginx --- apiVersion: apps/v1beta1 kind: StatefulSet metadata:name: web spec:replicas: 2serviceName: "nginx"template:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:alpinevolumeMounts:- mountPath: "/data"name: pvc-stsvolumeClaimTemplates:- metadata:name: pvc-stsspec:accessModes:- ReadWriteOncestorageClassName: alicloud-nas-flexresources:requests:storage: 2Gi創建后查看: # kubectl get pod | grep web web-0 1/1 Running 0 7s web-1 1/1 Running 0 4s# kubectl get pvc | grep web pvc-sts-web-0 Bound pvc-65ab251a-33ec-11e9-a151-00163e066784 2Gi RWO alicloud-nas-flex 13m pvc-sts-web-1 Bound pvc-8437c50e-33ed-11e9-a151-00163e066784 2Gi RWO alicloud-nas-flex 5m# kubectl get pv | grep web pvc-65ab251a-33ec-11e9-a151-00163e066784 2Gi RWO Delete Bound default/pvc-sts-web-0 alicloud-nas-flex 13m pvc-8437c50e-33ed-11e9-a151-00163e066784 2Gi RWO Delete Bound default/pvc-sts-web-1 alicloud-nas-flex 5m# Nas目錄下查看生成目錄: # ls -l | grep sts drwxrwxrwx 2 root root 4096 2月 19 10:16 default-pvc-sts-web-0-pvc-65ab251a-33ec-11e9-a151-00163e066784 drwxrwxrwx 2 root root 4096 2月 19 10:24 default-pvc-sts-web-1-pvc-8437c50e-33ed-11e9-a151-00163e0667845. 創建應用-Pod:
kind: PersistentVolumeClaim apiVersion: v1 metadata:name: replace-user-idannotations:pv-name-created: replace-user-id spec:storageClassName: alicloud-nas-flexaccessModes:- ReadWriteManyresources:requests:storage: 5Gi --- apiVersion: v1 kind: Pod metadata:name: "nas-pod" spec:containers:- name: "nginx"image: "nginx"volumeMounts:- name: pvc-nasmountPath: "/data"volumes:- name: pvc-naspersistentVolumeClaim:claimName: replace-user-id # userID="pod-123" # cat pod.yaml | sed "s/replace-user-id/\"$userID\"/g" | kubectl create -f -# kubectl get pod | grep pod nas-pod 1/1 Running 0 32s# kubectl get pvc | grep pod pod-123 Bound pod-123 5Gi RWX alicloud-nas-flex 44s# kubectl get pv | grep pod pod-123 5Gi RWX Delete Bound default/pod-123 alicloud-nas-flex 48s# ls -l | grep pod drwxrwxrwx 2 root root 4096 2月 19 10:54 pod-123?
原文鏈接
本文為云棲社區原創內容,未經允許不得轉載。
總結
以上是生活随笔為你收集整理的如何在Kubernetes集群动态使用 NAS 持久卷的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CVE漏洞—PHPCMS2008 /ty
- 下一篇: 基于TensorFlow.js的Java