required value on persistentVolumeClaim

10/18/2018

hy folks

i made the yaml files to deploy my application and now i working with helm to deploy it automatically.However although all of my conf files dor kubernetes worked. i've a problem with helm and PVC. i ve checked on internet and i dont find where is my mistake :(

pvc-helm.yaml

{{- if .Values.persistence.enabled }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: {{ .Values.persistence.name }}
  namespace: {{ .Values.persistence.namespace }}
  spec:
    accessModes:
    - {{ .Values.persistence.accessModes | quote }}
    resources:
      requests:
        storage: {{ .Values.persistence.size | quote }}
{{- end }}  

values.yaml

persistence:
  enabled: true
  name: ds-pvc
  namespace: ds-svc
  storageClassName: standard
  storageClass: standard
  accessModes:
    - ReadWriteOnce
  size: 20Mi

when i run the command helm install cas/ --tls i get the error below

Error: release brawny-olm failed: PersistentVolumeClaim "ds-pvc" is invalid: [spec.accessModes: Required value: at least 1 access mode is required, spec.resources[storage]: Required value]

Do i've to set as well a PersistentVolume ?

-- morla
kubernetes
kubernetes-helm

2 Answers

10/22/2018

If you want to have optional values you should check if they have been defined

spec:
  {{- if .Values.persistence.accessModes }}
  accessModes:
  - {{ .Values.persistence.accessModes | quote }}
  {{- end }}

another option is define a default value on the values.yaml file

-- Carlos
Source: StackOverflow

10/18/2018

There are two issues in your helm chart:

1. spec level shouldn't be below metadata level. It has no relations to metadata, so spec is on the same level as metadata.

2. Value persistence.accessModes should be defined as a string, not as a list.

The correct files are:

pvc-helm.yaml

{{- if .Values.persistence.enabled }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: {{ .Values.persistence.name }}
  namespace: {{ .Values.persistence.namespace }}
spec:
  accessModes:
  - {{ .Values.persistence.accessModes | quote }}
  resources:
    requests:
      storage: {{ .Values.persistence.size | quote }}
{{- end }}

values.yaml

persistence:
  enabled: true
  name: ds-pvc
  namespace: default
  storageClassName: standard
  storageClass: standard
  accessModes: ReadWriteOnce
  size: 20Mi
-- nickgryg
Source: StackOverflow