Kubernetes storage on GCP: mapping values not allowed in this context error

5/26/2019

I am trying to create a 10Gi disk on Google's Kubernetes Service and using their example file:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

I get the error:

$ kubectl apply -f pv-volume.yml
Error: error parsing pv-volume.yml error converting YAML to JSON: line 4: mapping values not allowed in this context

Anyone know what I am doing wrong?

-- user2471435
google-cloud-platform
kubernetes

1 Answer

5/27/2019

I have pasted your yaml to GKE and everything looks ok. However, there are a few things which may caused this error.

1) A few days ago there was some gcloud updates, check if all components are up to date - gcloud components update

2) Typo in yaml (some TAB or enter). To make sure the file do not contains any whitespace download it directly from k8s.io

kubectl apply -f https://k8s.io/examples/pods/storage/pv-volume.yaml
persistentvolume/task-pv-volume created

3) Vi formating issue. The only way i was able to get the same issue was when i copied yaml code directly to vi without :set paste or i to turn on insert mode and then ctrl+v

But then yaml code looks like:

kind: PersistentVolume
apiVersion: v1
metadata:
          name: task-pv-volume
            labels:
                        type: local
                        spec:
                                  storageClassName: manual
                                    capacity:
                                                storage: 10Gi
                                                  accessModes:
                                                              - ReadWriteOnce
                                                                  hostPath:
                                                                              path: "/mnt/data"

\===

Please let know if you still have issue while apply directly from k8s.io

-- PjoterS
Source: StackOverflow