<p>I'm trying to deploy mongodb with the kubernetes operator on AWS EKS with EFS for the storage class. Just following the documentation examples here:</p>
<p><a href="https://github.com/mongodb/mongodb-kubernetes-operator" rel="nofollow noreferrer">https://github.com/mongodb/mongodb-kubernetes-operator</a></p>
<p>I don't understand how to define the PVC naming properly. I've looked through the Github issues and Stack Overflow. Just not finding the example to resolve what seems to be a simple issue.</p>
<hr />
<pre><code>apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
  name: mongodb
spec:
  members: 1
  type: ReplicaSet
  version: &quot;4.2.6&quot;
  security:
    authentication:
      modes: [&quot;SCRAM&quot;]
  users:
    - name: my-user
      db: admin
      passwordSecretRef: # a reference to the secret that will be used to generate the user's password
        name: my-user-password
      roles:
        - name: clusterAdmin
          db: admin
        - name: userAdminAnyDatabase
          db: admin
      scramCredentialsSecretName: my-scram
  statefulSet:
    spec:
     volumeClaimTemplates:
       - metadata:
         name: data-volume
         spec:
          accessModes: [ &quot;ReadWriteOnce&quot; ]
          resources:
            requests:
              storage: 1Gi
            storageClassName: &quot;efs-sc&quot;
</code></pre>
<p>Events:</p>
<pre><code>create Pod mongodb-0 in StatefulSet mongodb failed error: failed to create PVC -mongodb-0: PersistentVolumeClaim &quot;-mongodb-0&quot; is invalid: metadata.name: Invalid value: &quot;-mongodb-0&quot;: a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*') 
</code></pre>

miqueltango
<p>I replicated this error and I found an error in your yaml file. There is a missing indentation in the <code>voluemClaimTemplates</code> name.</p>
<p>This is your yaml file:</p>
<pre class="lang-yaml prettyprint-override"><code>     volumeClaimTemplates:
       - metadata:
    👉   name: data-volume
         spec:
          accessModes: [ &quot;ReadWriteOnce&quot; ]
          resources:
            requests:
              storage: 1Gi
            storageClassName: &quot;efs-sc&quot;
</code></pre>
<p>And this is the correct part with fixed indentation:</p>
<pre class="lang-yaml prettyprint-override"><code>     volumeClaimTemplates:
       - metadata:
    👉     name: data-volume
         spec:
          accessModes: [ &quot;ReadWriteOnce&quot; ]
          resources:
            requests:
              storage: 1Gi
            storageClassName: &quot;efs-sc&quot;
</code></pre>
<p>It appears that because of this error the operator could not get the name correctly and he was trying to create volumes with its default template. You can verify that yourself with <code>kubectl get sts mongodb -o yaml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>  volumeClaimTemplates:
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      volumeMode: Filesystem
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: data-volume
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10G
      volumeMode: Filesystem

</code></pre>
