1

我找不到描述这些错误的好信息:

[sarah@localhost helm] helm install statefulset --name statefulset --debug
[debug] Created tunnel using local port: '33172'

[debug] SERVER: "localhost:33172"

[debug] Original chart version: ""
[debug] CHART PATH: /home/helm/statefulset/

Error: error validating "": error validating data: [field spec.template for v1beta1.StatefulSetSpec is required, field spec.serviceName for v1beta1.StatefulSetSpec is required, found invalid field containers for v1beta1.StatefulSetSpec]

我还是 Helm 的新手;我已经构建了两个与此模板相似的工作图表并且没有这些错误,即使代码没有太大不同。我在想可能存在某种我没有注意到的格式错误。要么是那个,要么是由于不同的类型(其他的是 Pod,这是 StatefulSet)。

它引用的 YAML 文件在这里:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: "{{.Values.PrimaryName}}"
  labels:
    name: "{{.Values.PrimaryName}}"
    app: "{{.Values.PrimaryName}}"
    chart: "{{.Chart.Name}}-{{.Chart.Version}}"
  annotations:
    "helm.sh/created": {{.Release.Time.Seconds | quote }}
spec:
  #serviceAccount: "{{.Values.PrimaryName}}-sa"
  containers:
  - name: {{.Values.ContainerName}}
    image: "{{.Values.PostgresImage}}"
    ports:
    - containerPort: 5432
      protocol: TCP
      name: postgres
    resources:
      requests:
        cpu: {{default "100m" .Values.Cpu}}
        memory: {{default "100M" .Values.Memory}}
    env:
    - name: PGHOST
      value: /tmp
    - name: PG_PRIMARY_USER
      value: primaryuser
    - name: PG_MODE
      value: set
    - name: PG_PRIMARY_PORT
      value: "5432"
    - name: PG_PRIMARY_PASSWORD
      value: "{{.Values.PrimaryPassword}}"
    - name: PG_USER
      value: testuser
    - name: PG_PASSWORD
      value: "{{.Values.UserPassword}}"
    - name: PG_DATABASE
      value: userdb
    - name: PG_ROOT_PASSWORD
      value: "{{.Values.RootPassword}}"
    volumeMounts:
    - name: pgdata
      mountPath: "/pgdata"
      readOnly: false
    volumes:
    - name: pgdata
      persistentVolumeClaim:
       claimName: {{.Values.PVCName}}

是否有人能够 a) 指出正确的方向,以了解如何实现 spec.template 和 spec.serviceName 必填字段,b) 了解为什么字段“容器”无效,和/或 c) 提及任何可以帮助调试 Helm 图表的工具?我尝试了 'helm lint' 和 '--debug' 标志,但 'helm lint' 没有显示错误,并且标志输出显示了上面的错误。

错误是否也可能来自不同的文件?

4

1 回答 1

2

StatefulSets对象的结构与 Pod 不同。您需要稍微修改一下您的 yaml 文件:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: "{{.Values.PrimaryName}}"
  labels:
    name: "{{.Values.PrimaryName}}"
    app: "{{.Values.PrimaryName}}"
    chart: "{{.Chart.Name}}-{{.Chart.Version}}"
  annotations:
    "helm.sh/created": {{.Release.Time.Seconds | quote }}
spec:
  selector:
    matchLabels:
      app: "" # has to match .spec.template.metadata.labels
  serviceName: "" # put your serviceName here
  replicas: 1 # by default is 1
  template:
    metadata:
      labels:
        app: "" # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: {{.Values.ContainerName}}
        image: "{{.Values.PostgresImage}}"
        ports: 
        - containerPort: 5432
          protocol: TCP
          name: postgres
        resources:
          requests:  
            cpu: {{default "100m" .Values.Cpu}}
            memory: {{default "100M" .Values.Memory}}
        env:
        - name: PGHOST
          value: /tmp
        - name: PG_PRIMARY_USER
          value: primaryuser
        - name: PG_MODE
          value: set
        - name: PG_PRIMARY_PORT
          value: "5432"
        - name: PG_PRIMARY_PASSWORD
          value: "{{.Values.PrimaryPassword}}"
        - name: PG_USER
          value: testuser
        - name: PG_PASSWORD
          value: "{{.Values.UserPassword}}
        - name: PG_DATABASE
          value: userdb
        - name: PG_ROOT_PASSWORD
          value: "{{.Values.RootPassword}}"
        volumeMounts:
        - name: pgdata
          mountPath: "/pgdata"
          readOnly: false
      volumes:
      - name: pgdata
        persistentVolumeClaim:
          claimName: {{.Values.PVCName}}
于 2017-11-02T14:32:05.597 回答