3

【Azure K8S | AKS】在不丢失文件/不影响POD运行的情况下增加PVC的大小 - 路边两盏灯

 1 year ago
source link: https://www.cnblogs.com/lulight/p/17612531.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【Azure K8S | AKS】在不丢失文件/不影响POD运行的情况下增加PVC的大小 - 路边两盏灯 - 博客园

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

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

2127802-20230807190122438-1087133580.png

例如:在创建一个简单的 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"}}}}'

第一步:获取需要修改的PVC名称及当前状态

kubectl get pvc

kubectl get pv
2127802-20230807191449921-1152412932.png

PS: 需要查看挂载在POD后,文件夹的使用情况,请使用:kubectl exec -it <mypod-pv-pvc-test> -- df -h </mnt/testazure> 

第二步:执行 kubectl patch pvc 指令

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

2127802-20230807191859520-1584423373.png

 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。

2127802-20230807192403175-1600973324.png

查看POD中,Mount目录的使用情况:kubectl exec -it <mypod-pv-pvc-test> -- df -h </mnt/testazure> 

2127802-20230807192550425-810830536.png

修改成功。容量增大!

附录:修改PVC的容量只能增大,不能减小

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

附录:在Linux中创建大Size文件的快速命令

#  dd if=/dev/zero of=500M.file bs=10M count=50
#  bs=10M表示每一次读写10MB数据,count=50表示读写 50次,这样就指定了生成文件的大小为500M。 
2127802-20230807193148662-614721450.png

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK