首页 > 其他分享 >【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例

时间:2023-08-03 22:07:39浏览次数:41  
标签:PV 示例 AKS 创建 001 test Disk

问题描述

在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例

 

问题解答

在Azure Kubernetes Service(AKS)的官方网站中,关于存储的选项介绍中,并没有具体的yaml实例来创建PV, PVC。特别是使用自定义的Disk的情况。

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例_Azure

本文将根据以上图片中的 Azure Managed Disk + Persistent Volume + Persistent Volume Claim (Storage Class 使用 default )+ Pod 方案,一一在AKS集群中创建。

 

第一步:通过Azure门户,创建 Managed Disk,把资源放置在与AKS 资源组中

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例_Azure_02

1: 进入Managed Disk的创建页面:https://portal.azure.cn/#create/Microsoft.ManagedDisk

2: Resource Group 资源组选择与AKS系统资源相同,如 MC_xxxxx_xxxxxx_<region name>

3: Disk name,自定义字符串,如 test-pv-001-disk

4: Availability Zone 需要选择Zone 1,避免出现 “cannot be attached to the VM because it is not in zone '1'.”的错误。

其他则使用默认。创建成功后,进入下一步。

 

第二步:创建PV,并且使用第一步中的Disk URI

文件 mypvtest.yaml 内容为:

# the relates PV
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: test-pv-001
spec:
  capacity:
    storage: 200Gi
  azureDisk:
    diskName: test-pv-001-disk
    diskURI: >-
      /subscriptions/<subscriptions id>/resourceGroups/<resource gorup name>/providers/Microsoft.Compute/disks/test-pv-001-disk
    cachingMode: ReadWrite
    fsType: ''
    readOnly: false
    kind: Managed
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: default
  volumeMode: Filesystem
status:
  phase: Bound

以上yaml文件定义了名为 test-pv-001的PV, 大小为200GiB,使用的Disk在第一步中创建,然后把 Disk的 Resource ID 设置到 diskURI 。

使用 kubectl apply -f mypvtest.yaml 部署PV到AKS中

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例_Pod_03

 

第三步:创建PVC

文件 mypvctest.yaml 的内容为:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-pvc-001
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 200Gi
  volumeName: test-pv-001
  storageClassName: default
  volumeMode: Filesystem

使用 kubectl apply -f mypvctest.yaml 部署PVC到AKS中

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例_Pod_04

查看PV, PVC状态

  • kubectl get pv
  • kubectl get pvc

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例_Pod_05

 

第四步:创建Pod,并且指定PVC的mount路径

POD的yaml文件内容为:(文件名mypodtest.yaml)

apiVersion: v1
kind: Pod
metadata:
  name: mypod-pv-pvc-test
spec:
  nodeSelector:
    kubernetes.io/os: linux
  containers:
  - image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
    name: mypod-pv-pvc-test
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 250m
        memory: 256Mi
    volumeMounts:
      - name: testazure
        mountPath: /mnt/testazure
  volumes:
    - name: testazure
      persistentVolumeClaim:
        claimName: test-pvc-001

定义vlumnes的名称为 testazure并且指定PVC, 然后在Container中定义volumeMounts路径

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例_Pod_06

 至此, Managed Disk + PV + PVC + POD 试验成功。

 


附录:在创建POD中遇见的错误

查看POD一直处于Container Creating , 于是用 describe 查看POD日志

kubectl describe pod <pod name>


一:Warning FailedAttachVolume Disk Not Found

错误消息: AttachVolume.Attach failed for volume "lbpv-test-001" : rpc error: code = NotFound desc = Volume not found, failed with error: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 404, RawError: {"error":{"code":"ResourceNotFound","message":"The Resource 'Microsoft.Compute/disks/lbpv-test-001' under resource group 'MC_xxx_xxx_xxx' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"}}

错误原因:没有提前创建 Disk资源。在Azure中创建PV中使用的Disk后,问题解决。

 

二:Warning  FailedAttachVolume --- cannot be attached to the VM because it is not in zone '1'

错误消息: AttachVolume.Attach failed for volume "lbpv-test-001" : rpc error: code = Internal desc = Attach volume /subscriptions/xxxx/xxx/xxx/providers/Microsoft.Compute/disks/lbpv-test-001 to instance aks-xxxx-vmss000004 failed with Retriable: false, RetryAfter: 0s, HTTPStatusCode: 400, RawError: {\r

  "error": {\r

    "code": "BadRequest",\r

    "message": "Disk xxxxxxx/lbpv-test-001 cannot be attached to the VM because it is not in zone '1'."

错误原因:创建Disk资源的时候,没有设置 Availability Zone 的值,根据消息提示,删除Disk后重建并且选择Zone值为1.

 


参考资料

在 Azure Kubernetes 服务 (AKS) 中通过 Azure 磁盘创建并使用卷 : https://docs.azure.cn/zh-cn/aks/azure-csi-disk-storage-provision#mount-disk-as-a-volume

Azure Kubernetes 服务 (AKS) 中的应用程序存储选项 : https://docs.azure.cn/zh-cn/aks/concepts-storage#persistent-volume-claims

 


当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

标签:PV,示例,AKS,创建,001,test,Disk
From: https://blog.51cto.com/u_13773780/6953372

相关文章

  • 网络工具示例
    如指定IP包长度大于100:tcpdump-ieth0-n'ip[2:2]>100'traceroute使用oot@zh-hz-hr-ygyradius~]#traceroute-I-p2000192.168.1.1tracerouteto192.168.1.1(192.168.1.1),30hopsmax,60bytepackets1gateway(192.168.3.250)3.987ms4.331......
  • 多语言API接口接入电商平台获得商品快递费用源代码演示示例
     商品快递费用API接口的作用是通过调用接口获取特定商品的快递费用信息。具体而言,该接口可以提供以下功能和作用:实时获取快递费用:通过API接口可以实时查询不同快递公司对于指定商品的运费费用。用户可以根据商品的重量、尺寸、寄送地址等信息,调用接口获取最准确的快递费用。便于物......
  • 微软工具:TCPView 可以查看网络和进程的关联信息,还是非常好用的
     ★微软工具:TCPViewhttps://docs.microsoft.com/zh-cn/sysinternals/downloads/tcpview  ......
  • 拉格朗日和kkt公式的应用示例 无论求解最大还是最小值,u都是>=0哈!最大是+ 最小是- 至少
    KKT这个公式一直觉得理解和使用起来很蛋疼,我又从国外站点找了一个例子帮助理解,见最后!https://o-o-sudo.github.io/numerical-methods/-kkt-lagrange-multiplier-to-kkt-condition.html 注意:拉格朗日里的lambda并没有要求>=0,kkt的u才有要求。           注意,国外这个......
  • 多语言演示API接口对接电商平台,优惠券查询源代码演示示例
     优惠券查询API接口的重要性可以从以下几个方面来说明:优惠券信息获取:优惠券查询API接口可以提供用户和开发者获取优惠券的详细信息,包括优惠券名称、类型、面值、使用规则、有效期等。这些信息对于用户来说非常重要,可以帮助他们选择适合自己的优惠券,并充分利用优惠券的优惠力度。优......
  • 多任务派发线程处理示例supplyAsync
    packagecom.cytc.test;importjava.util.ArrayList;importjava.util.List;importjava.util.Random;importjava.util.concurrent.CompletableFuture;importjava.util.concurrent.LinkedBlockingQueue;importjava.util.concurrent.ThreadPoolExecutor;importjava......
  • Cilium系列-10-启用 IPv6 BIG TCP和启用巨帧
    系列文章Cilium系列文章前言将Kubernetes的CNI从其他组件切换为Cilium,已经可以有效地提升网络的性能.但是通过对Cilium不同模式的切换/功能的启用,可以进一步提升Cilium的网络性能.具体调优项包括不限于:启用本地路由(NativeRouting)完全替换KubeProxyIP......
  • Cilium系列-10-启用 IPv6 BIG TCP和启用巨帧
    系列文章Cilium系列文章前言将Kubernetes的CNI从其他组件切换为Cilium,已经可以有效地提升网络的性能.但是通过对Cilium不同模式的切换/功能的启用,可以进一步提升Cilium的网络性能.具体调优项包括不限于:启用本地路由(NativeRouting)完全替换KubeProxyI......
  • 请求示例curl获取淘宝1688京东等电商平台商品详情数据API接口,批量采集
    获得页面使用命令:curlhttp://curl.haxx.se这是最简单的使用方法。用这个命令获得了http://curl.haxx.se指向的页面,同样,如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地。如果下载的是HTML文档,那么缺省的将只显示文件头部,即HTML文档的header。要全部显示,请加参数......
  • 电商API接口系列商品详情关键词搜索评论等数据,亲测有效,请求示例说明
    在电商运营活动中,价格是贯穿始终的关键因素,而品牌方有效利用价格数据也能够推动企业更好的发展。当品牌方能够精准获取商品的到手价时,有利于做好商品的定价复盘工作、后续的价格分析工作,也能够为后面的调价作参考;当品牌方能够全面掌握到商品的历史价时,就能够更好的把握商品不同时......