美文网首页
创建pvc报错 spec: Forbidden: field i

创建pvc报错 spec: Forbidden: field i

作者: 运维之美 | 来源:发表于2019-12-13 13:38 被阅读0次

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

相关文章

网友评论

      本文标题:创建pvc报错 spec: Forbidden: field i

      本文链接:https://www.haomeiwen.com/subject/hesfnctx.html