kubectl 创建pvc_创建pvc报错 spec: Forbidden: field is immutable after creation

在尝试使用kubectl通过yaml文件创建PersistentVolumeClaim (PVC)时,遇到'Forbidden: field is immutable after creation'错误。问题源于已存在同名的PV或PVC,需要先删除旧资源,然后才能成功创建新的。通过运行kubectl get pvc确认存在同名PVC,并使用kubectl delete删除相关资源,之后重新应用yaml文件,成功创建了PVC和相关部署。
摘要由CSDN通过智能技术生成

使用yaml来创建pvc资源,出现如下报错

[root@hz-project]# kubectl apply -f mysql-deployment.yaml

service "wordpress-mysql" configured

deployment "wordpress-mysql" configured

The PersistentVolumeClaim "mysql-pv-claim" is invalid: spec: Forbidden: field is immutable after creation

原因:创建重名PV或PVC

当原来的PV或PVC还在,而你又创建了一个新的PV, 并与原来的重名,则会得到如下错误:The persistentvolumeclaim "mysql-pv-claim" is invalid: spec: forbidden: is immutable after creation except resources.requests for bound claims. 这时,你需要将原来的PV或PVC删掉,再重新创建新的。

检查当前pvc资源

[root@hz-project]# kubectl get pvc

NAME STATUS VOLUME CAPACITY ACCESSMODES AGE

mysql-pv-claim Pending 1d

确实存在同名的pvc资源,首先删除然后再创建,此次没有发生报错

[root@hz-project]# kubectl delete -f mysql-deployment.yaml

service "wordpress-mysql" deleted

persistentvolumeclaim "mysql-pv-claim" deleted

deployment "wordpress-mysql" deleted

[root@hz-project]# kubectl apply -f mysql-deployment.yaml

service "wordpress-mysql" created

persistentvolumeclaim "mysql-pv-claim" created

deployment "wordpress-mysql" created

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值