掌舵EBS和NFS之间的持久卷类型选择?

时间:2019-02-18 11:10:23

标签: if-statement kubernetes-helm persistent-storage

我在普罗米修斯·赫尔姆(Prometheus Helm)图表中的“ if”语句方面需要帮助。我要实现的是在EBS或NFS中具有持久卷的Prometheus图表。它适用于EBS,但不适用于NFS。我认为问题出在我的if语句逻辑上。

当我设置storageClass:“ nfs” values.yaml时,我得到了错误:

Error: release prometheus failed: PersistentVolume "prometheus-alertmanager" is invalid: spec: Required value: must specify a volume type

在我的values.yaml文件中,我有:

  persistentVolume:
    enabled: true
    accessModes:
      - ReadWriteOnce
    annotations: {}
    existingClaim: ""
    mountPath: /data
    subPath: "alertmanager/"
    size: 4Gi
    ReclaimPolicy: "Recycle"
    storageClass: "aws"
    volumeID: "vol-xxx"
    fs_mounts:
      path: /data/alertmanager
      server: 127.0.0.1

Prometheus服务器的区别在于子路径和fs_mounts下的路径。

在我的alertmanager-pv中,我有:

{{- if not .Values.alertmanager.statefulSet.enabled -}}
{{- if and .Values.alertmanager.enabled .Values.alertmanager.persistentVolume.enabled -}}
apiVersion: v1
kind: PersistentVolume
metadata:
  name: prometheus-alertmanager
spec:
  capacity:
    storage: {{ .Values.alertmanager.persistentVolume.size }}
  accessModes:
{{ toYaml .Values.alertmanager.persistentVolume.accessModes | indent 4 }}
  persistentVolumeReclaimPolicy: "{{ .Values.alertmanager.persistentVolume.ReclaimPolicy }}"
{{- if (eq "aws" .Values.alertmanager.persistentVolume.storageClass) }}
  storageClassName: "gp2"
  awsElasticBlockStore:
    fsType: "ext4"
    volumeID: {{ .Values.alertmanager.persistentVolume.volumeID }}
{{- if (eq "nfs" .Values.alertmanager.persistentVolume.storageClass) }}
  StorageClassName: "nfs"
    mountOptions:
      - hard
      - nfsvers=4.1
      - timeo=600
      - retrans=2
    nfs:
      server: {{ .Values.alertmanager.persistentVolume.fs_mounts.server }}
      path: {{ .Values.alertmanager.persistentVolume.fs_mounts.path }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}

和在alertmanager-pvc中:

{{- if not .Values.alertmanager.statefulSet.enabled -}}
{{- if and .Values.alertmanager.enabled .Values.alertmanager.persistentVolume.enabled -}}
{{- if not .Values.alertmanager.persistentVolume.existingClaim -}}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
  name: prometheus-alertmanager
spec:
  accessModes:
{{ toYaml .Values.alertmanager.persistentVolume.accessModes | indent 4 }}
{{- if (eq "aws" .Values.alertmanager.persistentVolume.storageClass) }}
  storageClassName: "gp2"
  resources:
    requests:
      storage: {{ .Values.alertmanager.persistentVolume.size }}
{{- if (eq "nfs" .Values.alertmanager.persistentVolume.storageClass) }}
  storageClassName: "nfs"
  resources:
    requests:
      storage: {{ .Values.alertmanager.persistentVolume.size }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}

1 个答案:

答案 0 :(得分:0)

问题出在nfs if语句中,标识错误。