《Windows Azure Platform 系列文章目录》
本文介绍的是动态创建存储账户
即用户不需要提前创建好存储账户,由AKS自己管理
Azure AKS 通过NFS File Share挂载的时候,NFS 4.1只支持高级性能层的Azure存储账户。
1.创建名为 azure-file-sc.yaml
的文件,复制下面的内容
注意:skuName为高级性能,协议为nfs
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: my-azurefile
provisioner: file.csi.azure.com # replace with "kubernetes.io/azure-file" if aks version is less than 1.21
allowVolumeExpansion: true
mountOptions:
- nconnect=4
- noresvport
- actimeo=30
- rsize=262144
- wsize=262144
parameters:
skuName: Premium_LRS
protocol: nfs
2.使用kubectl apply来创建Storage Class
kubectl apply -f azure-file-sc.yaml
3.创建名为azure-file-pvc.yaml的文件,复制下面的内容
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-azurefile spec: accessModes: - ReadWriteMany storageClassName: my-azurefile resources: requests: storage: 100Gi
4.使用kubectl apply来创建pvc
kubectl apply -f azure-file-pvc.yaml
5.执行命令,查看PVC状态:
kubectl get pvc my-azurefile
6.执行结果:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE my-azurefile Bound pvc-9514f5fd-e7fc-462a-8733-5402ec2026bb 100Gi RWX my-azurefile 83s
7.创建azure-pvc-files.yaml文件,复制下面的内容:
挂载点为: /mnt/azure
kind: Pod apiVersion: v1 metadata: name: mypod spec: containers: - name: mypod image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine resources: requests: cpu: 100m memory: 128Mi limits: cpu: 250m memory: 256Mi volumeMounts: - mountPath: /mnt/azure name: volume readOnly: false volumes: - name: volume persistentVolumeClaim: claimName: my-azurefile
8.使用kubectl apply创建pod
kubectl apply -f azure-pvc-files.yaml
9.使用命令:
kubectl get pod
查看pod运行情况
NAME READY STATUS RESTARTS AGE mypod 1/1 Running 0 4s
10.我们进入pod,查看挂载点
kubectl exec mypod -it -- sh
11.执行命令:
/ # cd /mnt/azure /mnt/azure # touch aaa.txt /mnt/azure # ls aaa.txt /mnt/azure # touch AAA.txt /mnt/azure # ls AAA.txt aaa.txt /mnt/azure # touch bb.txt /mnt/azure # touch BB.txt /mnt/azure # ls AAA.txt BB.txt aaa.txt bb.txt