我正在尝试使用 Ansible 在 Kubernetes 集群服务器(K3S)上安装 Unifi,并在尝试定义持久卷声明时遇到了麻烦。
我在用Kubernetes.Core 模块我把我的任务定义为:
- name: Define storage space for Unifi
kubernetes.core.k8s:
state: present
definition:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: unifi-cluster-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 100Mi
但是,当我运行我的剧本时出现以下错误:
TASK [unifi : Define storage space for Unifi]
***********************************************************************
fatal: [central.example.com]: FAILED! => {"changed": false, "msg":
"Failed to create object: b'{\"kind\":\"Status\",\"apiVersion\":\"v1\",
\"metadata\":{},\"status\":\"Failure\",\"message\":\"PersistentVolumeClaim
\\\\\"unifi-cluster-pvc\\\\\" is invalid: spec.resources[storage]: Required
value\",\"reason\":\"Invalid\",\"details\":{\"name\":\"unifi-cluster-pvc\",
\"kind\":\"PersistentVolumeClaim\",\"causes\":[{\"reason\":\"FieldValueRequired\",
\"message\":\"Required value\",\"field\":\"spec.resources[storage]\"}]},\"code\":422}\\n'",
"reason": "Unprocessable Entity"}
有人可以解释发生了什么事吗?
因为如果我创建一个名为 yaml 文件,test.yml
其内容如下:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: unifi-cluster-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 100Mi
kubectl apply -f test.yml
并在我的控制器上运行命令:
然后我收到回复:
persistentvolumeclaim/unifi-cluster-pvc created
答案1
该错误表明resource
需要阻止来创建 PVC。
好像你错过了缩进的PVC定义文件位于resources
阻止,因为resources
是spec
。您可以按照以下方式更新任务
- name: Define storage space for Unifi
kubernetes.core.k8s:
state: present
definition:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: unifi-cluster-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 100Mi
有关 pvc 定义的更多详细信息,请查看 Kubernetes 官方文档持久卷声明。