VolumeMount Name not found

3/6/2019

I have below StatefulSet postgres for EKS. When I run it I am getting below error.

Events:
  Type     Reason        Age               From                    Message
  ----     ------        ----              ----                    -------
   Warning  FailedCreate  7s (x17 over 1m)  statefulset-controller  create Pod postgres-0 in StatefulSet postgres failed error: Pod "postgres-0" is invalid: spec.containers[0].volumeMounts[0].name: Not found: "postgredb" 

StatefulSet:

  apiVersion: apps/v1
  kind: StatefulSet
  metadata:
    name: postgres
  spec:
    selector:
      matchLabels:
        app: postgres # has to match .spec.template.metadata.labels
    serviceName: "postgres"
    replicas: 1
    template:
      metadata:
        labels:
          app: postgres
      spec:
        terminationGracePeriodSeconds: 10
        containers:
          - name: postgres
            image: postgres:10.4
            imagePullPolicy: "IfNotPresent"
            ports:
              - containerPort: 5432
            volumeMounts:
              - name: postgredb
                mountPath: /var/lib/postgresql/data
    volumeClaimTemplates:
      - metadata:
          name: postgresdb
          annotations:
            volume.beta.kubernetes.io/storage-class: "aws-efs"
        spec:
          accessModes: [ "ReadWriteOnce" ]
          resources:
            requests:
              storage: 1Gi

I have StorageClass configured as well. What am I doing wrong here?

-- Pat
amazon-eks
eks
kubernetes

1 Answer

3/7/2019

Just a typo.

volumeMounts:
  - name: postgredb

It should be name:postgresdb, not name:postgredb.

-- ccshih
Source: StackOverflow