troubleshoot:PVC动态扩容报错
2023-02-18 16:34:31 时间
一.问题描述
动态扩容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.
解决方法
:要支持动态扩容需要满足两个条件:
- 后端底层存储支持卷扩展(后端存储保证足够资源) ;
- 需要在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动态扩容成功。
相关文章
- Idea导出jar包运行报错:找不到主清单属性解决方法
- 云原生架构(三)简单样例
- 云原生架构(二)环境搭建(Mac上安装Istio---Docker+Kubernetes+Istio一条龙)
- 云原生架构(一)原理概览
- 云原生架构学习计划
- 服务端架构演进史
- 领域驱动架构及其演变史(EBI、DDD、端口适配、洋葱、整洁)
- 软件架构(六)MVC架构历史
- 软件架构(五)分层架构
- 软件架构(三)名词解释:架构、设计、风格、模式
- 软件架构(二)编程语言的历史
- 软件架构(四)单体架构(Monolithic Architecture)
- 软件架构(一)概览
- Seata的技术调研
- Sagas论文原文读后总结
- P8+架构师养成计划
- IDEA 报错 project is already registered
- DDD领域驱动设计落地实践(十分钟看完,半小时落地)
- 【5分钟】W10 64bit系统本地安装postgresql 11
- 程序员如何成为架构师