【Azure K8S | AKS】在不丢失文件/不影响POD运行的情况下增加PVC的大小
阅读原文时间:2023年10月13日阅读:1

问题描述

在前两篇文章中,创建了Disk + PV + PVC + POD 方案后,并且进入POD中增加文件。

  1. 【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例
  2. 【Azure K8S|AKS】进入AKS的POD中查看文件,例如PVC Volume Mounts使用情况

但是,当预定的文件夹已经被占用满之后,如何在不丢失旧文件,及不影响Pod的正常运行情况下,如何处理增加文件夹容量呢?

例如:在创建一个简单的 txt文件时,就出现了 sh: write error: No space left on device 错误消息。

问题解答

在AKS的官方文档中,介绍了使用 kubectl patch pvc指令来修改Storage Size,此处根据文档指引进行修改。 引用文档地址:https://docs.azure.cn/zh-cn/aks/azure-disk-csi#resize-a-persistent-volume-without-downtime

##示例指令:

Windows 窗口

kubectl patch pvc test-pvc-001 --type merge --patch '{\"spec\": {\"resources\": {\"requests\": {\"storage\": \"300Gi\"}}}}'

或其他:

kubectl patch pvc test-pvc-001 --type merge --patch '{"spec": {"resources": {"requests": {"storage": "300Gi"}}}}'

kubectl get pvc

kubectl get pv

PS: 需要查看挂载在POD后,文件夹的使用情况,请使用:kubectl exec -it -- df -h

执行:kubectl patch --type merge --patch '{\"spec\": {\"resources\": {\"requests\": {\"storage\": \"300Gi\"}}}}'

PS: 在没有对JSON内容中引号(")进行转换时,报错:Error from server (BadRequest): error decoding patch: invalid character 's' looking for beginning of object key string

查看PV, PVC中的Capacity(容量)是否修改为300Gi。并且查看AKS 门户上的Disk资源,是否已经修改到300Gi。

查看POD中,Mount目录的使用情况:kubectl exec -it  -- df -h 

修改成功。容量增大!

目前不支持收缩PVC。 尝试修补大小小于当前大小的现有 PVC 会导致以下错误消息:The persistentVolumeClaim "pvc-xxxxxxxx" is invalid: spec.resources.requests.storage: Forbidden: field can not be less than previous value.

#  dd if=/dev/zero of=500M.file bs=10M count=50

#  bs=10M表示每一次读写10MB数据,count=50表示读写 50次,这样就指定了生成文件的大小为500M。 

在不停机的情况下,调整永久性卷的大小 : https://docs.azure.cn/zh-cn/aks/azure-disk-csi#resize-a-persistent-volume-without-downtime

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章