0

helm install geared-marsupi ./buildachart/ 错误:Deployment.apps “geared-marsupi-buildachart”无效:spec.template.spec.containers[1].volumeMounts[0].name:未找到:“postgres_sql”

它看起来更像是一个缩进问题,但不知何故它不起作用并且失败了。我有两个容器,一个是不需要任何卷的drupal,第二个是我添加了卷的postgresql。




apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "buildachart.fullname" . }}
  labels:
    {{- include "buildachart.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
{{- end }}
  selector:
    matchLabels:
      {{- include "buildachart.selectorLabels" . | nindent 6 }}
  template:
    metadata:
    {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      labels:
        {{- include "buildachart.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "buildachart.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag  }}" #| default .Chart.AppVersion
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
        - name: postgres #{{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: postgres #"{{ .Values.image.repository1 }}:{{ .Values.image.tag }}" #| default .Chart.AppVersion
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
          - name: POSTGRES_USER
            value: "{{ .Values.user }}" #"user"
          - name: POSTGRES_PASSWORD
            value: "{{ .Values.password }}" #"password"
          - name: POSTGRES_DB
            value: "{{ .Values.db }}" #"test"
          volumeMounts:
          - name: postgres_sql
            mountPath: /var/lib/postgresql/data
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      volumes:
      - name: postgres_sql
        hostPath:
          path: /data/postgresdb_path
          type: Directory
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

我尝试将卷直接放在容器选项卡下,然后放在第二个 postgre 容器的名称选项卡下,但结果相同。

工作 Yaml 文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal
spec:
  selector:
    matchLabels:
      app: drupal
  template:
    metadata:
      labels:
        app: drupal
    spec:
      containers:
      - name: drupal
        image: drupal
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
      - name: postgres
        image: postgres
        env:
        - name: POSTGRES_USER
          value: test
        - name: POSTGRES_PASSWORD
          value: passwd
        volumeMounts:
        - name: postgres_vol
          mountPath: /var/lib/postgresql/data
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
      volumes: 
      - name: test-volume
        hostPath:
        - path: /data
          type: Directory
4

0 回答 0