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

使用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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。