<p>I'm working on attaching Amazon EKS (NFS) to Kubernetes pod using terraform.</p>
<p>Everything runs without an error and is created:</p>
<ul>
<li>Pod victoriametrics</li>
<li>Storage Classes</li>
<li>Persistent Volumes</li>
<li>Persistent Volume Claims</li>
</ul>
<p>However, the volume <code>victoriametrics-data</code> doesn't attach to the pod. Anyway, I can't see one in the pod's shell.
Could someone be so kind to help me understand where I'm wrong, please?</p>
<p>I have cut some unimportant code for the question to get code shorted.</p>
<pre class="lang-golang prettyprint-override"><code>resource &quot;kubernetes_deployment&quot; &quot;victoriametrics&quot; {
...
      spec {
        container {
          image = var.image
          name  = var.name
          ...
          volume_mount {
              mount_path        = &quot;/data&quot;
              mount_propagation = &quot;None&quot;
              name              = &quot;victoriametrics-data&quot;
              read_only         = false
            }
        }

        volume {
            name = &quot;victoriametrics-data&quot;
        }

      }
    }
...

}
</code></pre>
<pre class="lang-golang prettyprint-override"><code>resource &quot;kubernetes_csi_driver&quot; &quot;efs&quot; {
  metadata {
    name = &quot;${local.cluster_name}-${local.namespace}&quot;
    annotations = {
      name = &quot;For store data of ${local.namespace}.&quot;
    }
  }
  spec {
    attach_required        = true
    pod_info_on_mount      = true
    volume_lifecycle_modes = [&quot;Persistent&quot;]
  }
}
</code></pre>
<pre class="lang-golang prettyprint-override"><code>resource &quot;kubernetes_storage_class&quot; &quot;efs&quot; {
  metadata {
    name = &quot;efs-sc&quot;
  }
  storage_provisioner = kubernetes_csi_driver.efs.id
  reclaim_policy      = &quot;Retain&quot;
  mount_options       = [&quot;file_mode=0700&quot;, &quot;dir_mode=0777&quot;, &quot;mfsymlinks&quot;, &quot;uid=1000&quot;, &quot;gid=1000&quot;, &quot;nobrl&quot;, &quot;cache=none&quot;]
}
</code></pre>
<pre class="lang-golang prettyprint-override"><code>resource &quot;kubernetes_persistent_volume&quot; &quot;victoriametrics&quot; {
  metadata {
    name = &quot;${local.cluster_name}-${local.namespace}&quot;
  }
  spec {
    storage_class_name               = &quot;efs-sc&quot;
    persistent_volume_reclaim_policy = &quot;Retain&quot;
    volume_mode                      = &quot;Filesystem&quot;
    access_modes                     = [&quot;ReadWriteMany&quot;]
    capacity = {
      storage = var.size_of_persistent_volume_claim
    }
    persistent_volume_source {
      nfs {
        path   = &quot;/&quot;
        server = local.eks_iput_target
      }
    }
  }
}
</code></pre>
<pre class="lang-golang prettyprint-override"><code>resource &quot;kubernetes_persistent_volume_claim&quot; &quot;victoriametrics&quot; {
  metadata {
    name      = local.name_persistent_volume_claim
    namespace = local.namespace
  }
  spec {
    access_modes       = [&quot;ReadWriteMany&quot;]
    storage_class_name = &quot;efs-sc&quot;
    resources {
      requests = {
        storage = var.size_of_persistent_volume_claim
      }
    }
    volume_name = kubernetes_persistent_volume.victoriametrics.metadata.0.name
  }
}
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: victoriametrics
  namespace: victoriametrics
  labels:
    k8s-app: victoriametrics
    purpose: victoriametrics
  annotations:
    deployment.kubernetes.io/revision: '1'
    name: &gt;-
      VictoriaMetrics - The High Performance Open Source Time Series Database &amp;
      Monitoring Solution.
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: victoriametrics
      purpose: victoriametrics
  template:
    metadata:
      name: victoriametrics
      creationTimestamp: null
      labels:
        k8s-app: victoriametrics
        purpose: victoriametrics
      annotations:
        name: &gt;-
          VictoriaMetrics - The High Performance Open Source Time Series
          Database &amp; Monitoring Solution.
    spec:
      containers:
        - name: victoriametrics
          image: 714154805721.dkr.ecr.us-east-1.amazonaws.com/victoriametrics:v1.68.0
          ports:
            - containerPort: 8428
              protocol: TCP
            - containerPort: 2003
              protocol: TCP
            - containerPort: 2003
              protocol: UDP
          volumeMounts:
            - mountPath: /data
              name: victoriametrics-data
            - mountPath: /var/log
              name: varlog
          env:
            - name: Name
              value: victoriametrics
          resources:
            limits:
              cpu: '1'
              memory: 1Gi
            requests:
              cpu: 500m
              memory: 1Gi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      volumes:
      - name: victoriametrics-data
        emptyDir: {}
      - name: varlog
        emptyDir: {}    
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      automountServiceAccountToken: true
      shareProcessNamespace: false
      securityContext: {}
      schedulerName: default-scheduler
      tolerations:
        - key: k8s-app
          operator: Equal
          value: victoriametrics
          effect: NoSchedule
      enableServiceLinks: true
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  minReadySeconds: 15
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 300
</code></pre>

Rostyslav Malenko
<p>You need to use the persistent volume claim that you have created instead of <code>emptyDir</code> in your deployment:</p>
<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: victoriametrics
...
  volumes:
  - name: victoriametrics-data
      persistentVolumeClaim:
        claimName: &lt;value of local.name_persistent_volume_claim&gt;
</code></pre>
