一.问题描述

动态扩容PVC的时候报错(kubectl edit pvc pvcname):“error: persistentvolumeclaims "pvvolume" could not be patched: persistentvolumeclaims "pvvolume" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize”

二.解决方法

配置一个10M大小的pvc,关于PVC的详细内容,请查看博客《Kubernetes(k8s)存储管理之数据卷volumes(四):持久卷Persistent Volume》https://www.cnblogs.com/renshengdezheli/p/16972289.html

[student@vms20 ~]$ vim 13.yaml

[student@vms20 ~]$ cat 13.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvvolume
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 10Mi
storageClassName: csi-hostpath-sc

创建PVC

[student@vms20 ~]$ kubectl apply -f 13.yaml
persistentvolumeclaim/pvvolume created [student@vms20 ~]$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvvolume Bound pvc-09b90084-aa96-4e10-a124-79c9af98ccc0 10Mi RWO csi-hostpath-sc 10s [student@vms20 ~]$ kubectl get pvc -o wide
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE
pvvolume Bound pvc-09b90084-aa96-4e10-a124-79c9af98ccc0 10Mi RWO csi-hostpath-sc 14s Filesystem

把PVC挂载到pod上,并创建pod

[student@vms20 ~]$ vim 13pod.yaml

[student@vms20 ~]$ cat 13pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: web-server
spec:
containers:
- name: myfrontend
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: mypvc
volumes:
- name: mypvc
persistentVolumeClaim:
claimName: pvvolume [student@vms20 ~]$ kubectl apply -f 13pod.yaml
pod/web-server created [student@vms20 ~]$ kubectl get pod | grep web-server
web-server 1/1 Running 0 20s

修改pvc的容量为70Mi,PVC动态扩容报错如下:

[student@vms20 ~]$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvvolume Bound pvc-09b90084-aa96-4e10-a124-79c9af98ccc0 10Mi RWO csi-hostpath-sc 14m #动态扩容PVC报错
[student@vms20 ~]$ kubectl edit pvc pvvolume --record
Flag --record has been deprecated, --record will be removed in the future
error: persistentvolumeclaims "pvvolume" could not be patched: persistentvolumeclaims "pvvolume" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize
You can run `kubectl replace -f /tmp/kubectl-edit-857302533.yaml` to try this update again.

解决方法要支持动态扩容需要满足两个条件

  1. 后端底层存储支持卷扩展(后端存储保证足够资源) ;
  2. 需要在StorageClass对象中设置allowVolumeExpansion为true。

可以看到storageclass此时ALLOWVOLUMEEXPANSION参数为false。

[student@vms20 ~]$ kubectl get storageclass
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
csi-hostpath-sc hostpath.csi.k8s.io Delete Immediate false 277d

编辑csi-hostpath-sc,把ALLOWVOLUMEEXPANSION修改为true

#添加参数allowVolumeExpansion: true
#######
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"csi-hostpath-sc"},"parameters":{"archiveOnDelete":"false"},"provisioner":"hostpath.csi.k8s.io"}
creationTimestamp: "2021-11-04T10:54:48Z"
name: csi-hostpath-sc
resourceVersion: "177035"
uid: a594f8fd-9c3d-49d3-85a4-085c89a7bb1c
parameters:
archiveOnDelete: "false"
provisioner: hostpath.csi.k8s.io
reclaimPolicy: Delete
volumeBindingMode: Immediate ####### [student@vms20 ~]$ kubectl edit storageclass csi-hostpath-sc
storageclass.storage.k8s.io/csi-hostpath-sc edited #现在ALLOWVOLUMEEXPANSION变为true了
[student@vms20 ~]$ kubectl get storageclass
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
csi-hostpath-sc hostpath.csi.k8s.io Delete Immediate true 277d

再次PVC动态扩容

[student@vms20 ~]$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvvolume Bound pvc-09b90084-aa96-4e10-a124-79c9af98ccc0 10Mi RWO csi-hostpath-sc 25m #现在pvc动态扩容:将所有位置的capacity:storage:10Mi修改为70Mi
[student@vms20 ~]$ kubectl edit pvc pvvolume --record
Flag --record has been deprecated, --record will be removed in the future
persistentvolumeclaim/pvvolume edited #PVC动态扩容成功
[student@vms20 ~]$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvvolume Bound pvc-09b90084-aa96-4e10-a124-79c9af98ccc0 70Mi RWO csi-hostpath-sc 27m

自此,PVC动态扩容成功。

troubleshoot:PVC动态扩容报错的更多相关文章

  1. LVM XFS增加硬盘分区容量最后一步的时候动态扩容报错

    在我们lvextend扩容完之后,想动态扩容时出现错误.我们可以用以下命令来进行操作. 若不是xfs我们可以用resize2fs,这里报错了 [root@Mysql01-213-66 ~]# resi ...

  2. C语言扩展动态内存报错:realloc(): invalid next size: 0x0000000002365010 ***

    晚上被这个内存扩展崩溃的问题折腾的有点崩溃,当答案揭晓的那一刻,恍然大悟,原来如此简单. 练习题目:输入一个字符串,根据字母进行排序,说白了就是一个简单的冒泡 #include <stdio.h ...

  3. Spring Data Solr创建动态域报错:org.springframework.data.solr.UncategorizedSolrException

    今天在项目中使用Spring Data Solr导入动态域数据报错, 控制台打印错误信息如下 Exception in thread "main" org.springframew ...

  4. lvm逻辑卷扩容报错解决

    报错: [root@centos21 space]# resize2fs /dev/centos/root resize2fs (-Dec-) resize2fs: Bad magic number ...

  5. spark on yarn 动态资源分配报错的解决:org.apache.hadoop.yarn.exceptions.InvalidAuxServiceException: The auxService:spark_shuffle does not exist

    组件:cdh5.14.0 spark是自己编译的spark2.1.0-cdh5.14.0 第一步:确认spark-defaults.conf中添加了如下配置: spark.shuffle.servic ...

  6. iOS 加载动态库报错问题

    dyld: Library not loaded: @rpath Referenced from: Reason: no suitable image found.  Did find: 要么使用静态 ...

  7. Qt打开外部程序和文件夹需要注意的细节(Qt调用VC写的动态库,VC需要用C的方式输出函数,否则MinGW32编译过程会报错)

    下午写程序中遇到几个小细节,需要在这里记录一下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 QProcess *process = new QProcess(this ...

  8. eclipse 创建maven 项目 动态web工程报错

    Eclipse 创建maven 项目 动态web工程 注:Eclipse版本为(Version: Mars.1 Release (4.5.1))maven版本为(apache-maven-3.3.9) ...

  9. Struts1应用、实现简单计算器、使用DispatchAction、显示友好的报错信息、使用动态Form简化开发

    实现简单的支持加.减.乘.除的计算器 复制一份Struts1Demo修改:Struts1Calc 方案1: Struts1Calc 创建ActionForm: CalcForm extends Act ...

  10. vue项目使用echarts按需引入实现地图动态显示效果时,报错:TypeError: Cannot read property 'dataToPoint' of undefined

    vue项目使用echarts按需引入实现地图动态显示效果时,报错:TypeError: Cannot read property 'dataToPoint' of undefined 借鉴了该大神的文 ...

随机推荐

  1. 阿里云SLB的http强制转https

    公司的要求:要求强制http转https 我的环境是: 域名<--->slb的ip<-->源服务器nginx 具体做法是: 第一步:证书放到slb的https上,通过443端口 ...

  2. 为什么 CRM 能帮助装备制造企业进行数字化转型?

    CRM确实能帮助装备制造企业进行数字化转型,体现在销售管理端,能方便的服务于"客户需求"为主旨的数字化转型思想,用客户的需求来指导生产等.但这个说法有点片面,毕竟那只是客户管理部分 ...

  3. POJ1651 Multiplication Puzzle (区间DP)

    这道题的妙处在于把原问题看成矩阵连乘问题,求这些矩阵相乘的最小乘法次数,比如一个i*k矩阵乘一个k*j的矩阵,他们的乘法次数就是i*k*j (联想矩阵乘法的三层循环),题目说的取走一张牌,类似于矩阵相 ...

  4. AVX图像算法优化系列二: 使用AVX2指令集加速查表算法。

    查表算法,无疑也是一种非常常用.有效而且快捷的算法,我们在很多算法的加速过程中都能看到他的影子,在图像处理中,尤其常用,比如我们常见的各种基于直方图的增强,可以说,在photoshop中的调整菜单里8 ...

  5. python基础--简单数据类型预览

    为了适应更多的使用场景,将数据划分为多种类型,每种类型都有各自的特点和使用场景, 帮助计算机高效的处理和展示数据.(比如数字用于数学运算.字符串用于信息传递.页面文字展示等) 1.数字类型   整型 ...

  6. tListener监听器

    1.概念 监听器:专门用于对其他对象身上发生的事件或状态改变进行监听和相应处理的对象,当被监视的对象发生情况时,立即采取相应的行动. Servlet监听器:Servlet规范中定义的一种特殊类,它用于 ...

  7. lnmp配置laravel访问环境报错锦集

    1.laravel配置域名访问变成下载,实际就是Nginx没有识别到.php文件.把.php文件的配置加到Nginx即可 .... # 这一段放到项目的Nginx.conf配置文件里面 locatio ...

  8. CUDA/CUDNN下载安装以及适配pytorch和tensorflow

    CUDA以及CUDNN下载安装 在https://developer.nvidia.com/cuda-toolkit-archive可以找到各个版本的cuda,个人建议下载cuda11.0(也就是2年 ...

  9. 19.-哈希算法&注册登录

    一.哈希算法 哈希: 给定明文-计算出一段定长的-不可逆的值 定长输出:不管明文输入多少,哈希都是定长的 不可逆:无法反向计算出对应的明文 雪崩效应:输入改变,输出必然变 md5:32位16进制   ...

  10. 三、celery执行定时任务

    三.Celery执行定时任务 设定时间让celery执行一个 定时任务,product_task.py from celery_task import send_email from datetime ...