3

I'm trying to create a new PersistentVolume in Kubernets (version 1.14), but it returns me the following error:

The PersistentVolume "postgres-pv-volume" is invalid:
* spec.persistentvolumesource: Forbidden: is immutable after creation
* nodeAffinity: Invalid value: "null": field is immutable

Here's my YAML:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgres-pv-volume
  namespace: is-app
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /vols/is-app
    server: storage-server
    readOnly: false

I cannot find anything about those faulty values in the documentation. What's wrong with my configuration?

Djent
  • 89
  • 4
  • 15

2 Answers2

1

Sample configuration for Persistent volume using NFS

apiVersion: v1
kind: Service
metadata:
  name: nfs-server
spec:
  # clusterIP: 10.3.240.20
  ports:
    - name: nfs
      port: 2049
    - name: mountd
      port: 20048
    - name: rpcbind
      port: 111
  selector:
    role: nfs-server


apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: <ClusterIP>
    path: "/"

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 10Gi

Refer here to check the Kubernetes NFS persistent volumes

Manikandan Ram
  • 389
  • 1
  • 14
  • In another namespace, I got very similar NFS volume, also without the nfs-server service, but created in Kubernetes 1.11. Why it still works? Something changed with the requirements? – Djent Nov 28 '19 at 13:02
  • Could you show its yaml definition ? (`kubectl get pv your-pv-in-k8s-1.11 -o yaml`) NFS volume without using NFS server ? What is representing the resource that you're referring to as `server: storage-server` in your `PV` definition ? – mario Nov 28 '19 at 14:20
  • Updated the answer. – Manikandan Ram May 16 '22 at 08:13
0
The PersistentVolume "postgres-pv-volume" is invalid:
* spec.persistentvolumesource: Forbidden: is immutable after creation
* nodeAffinity: Invalid value: "null": field is immutable

It looks like for some reason nodeAffinity: field is required in spec: section of your PersistentVolume definition and it is automatically added by the generator and assigned with the value of null. Value of this field is immutable i.e. cannot be changed once created. You can check what is the exact output by creating only yaml manifest of your PV resource. You can do it by adding --dry-run -o yaml options.

Do you have any NFS server behind DNS name storage-server available in the default namespace of your k8s cluster ? We need more info about your environment setup to be able to help you. Do you use on-premise k8s cluster or any cloud solution ? As you can read here (docs for v1.16) (but it looks exactly the same in v1.14 that you're using):

Note: For most volume types, you do not need to set this field. It is automatically populated for AWS EBS, GCE PD and Azure Disk volume block types. You need to explicitly set this for local volumes.

A PV can specify node affinity to define constraints that limit what nodes this volume can be accessed from. Pods that use a PV will only be scheduled to nodes that are selected by the node affinity.

As to your comment:

In another namespace, I got very similar NFS volume, also without the nfs-server service, but created in Kubernetes 1.11. Why it still works? Something changed with the requirements? – Djent 1 hour ago

You need to describe it more precisely so it can be compared but keep in mind that 1.11 is at the moment obsolete version which is not supported any more and I'm pretty sure there could've been some considerable changes introduced since that time. It's even impossible to check it on kubernetes.io website as it is not maintained any more (the oldest maintained version of k8s documentation is currently 1.12). If such configuration works for you on 1.11 cluster it probably means that it works quite differently in 1.14 if you're not able to implement it the same way.

mario
  • 525
  • 3
  • 8