I am trying to install Unifi on a Kubernetes cluster server (K3S) using Ansible and ran into troubles when trying to define a persistent volume claim.
I am using Kubernetes.Core module and I have defined my task as:
- 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
However when I run my playbook then I get the following error:
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"}
Is there anyone who can explain what is going on?
Because if I create a yaml file called test.yml
with the following content:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: unifi-cluster-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 100Mi
and run the command: kubectl apply -f test.yml
on my controller
Then I get the message back:
persistentvolumeclaim/unifi-cluster-pvc created
The error is indicating that the
resource
block is required to create the PVC.Seems like you missed the indentation of the pvc definition file at
resources
block because theresources
is a sub block ofspec
. You can update the task as mentioned belowFor more detailed information about pvc definition check this official Kubernetes document on Persistent Volume Claim.