<p>I'm trying to create a new Kubernetes deployment that will allow me to persist a pod's state when it is restarted or shutdown. Just for some background, the Kubernetes instance is a managed Amazon EKS Cluster, and I am trying to incorporate an Amazon EFS-backed Persistent Volume that is mounted to the pod. </p>

<p>Unfortunately as I have it now, the PV mounts to <code>/etc/</code> as desired, but the contents are nearly empty, except for some files that were modified during boot.</p>

<p>The deployment yaml looks as below:</p>

<pre><code>kind: Deployment
apiVersion: apps/v1

spec:
  replicas: 1
  selector:
    matchLabels:
      app: testpod
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: testpod
    spec:
      volumes:
        - name: efs
          persistentVolumeClaim:
            claimName: efs
      containers:
        - name: testpod
          image: 'xxxxxxxxxxxx.dkr.ecr.us-east-2.amazonaws.com/testpod:latest'
          args:
            - /bin/init
          ports:
            - containerPort: 443
              protocol: TCP
          resources: {}
          volumeMounts:
            - name: efs
              mountPath: /etc
              subPath: etc
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
          securityContext:
            capabilities:
              add:
                - ALL
      restartPolicy: Always
      terminationGracePeriodSeconds: 60
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
</code></pre>

<p>Any ideas of what could be going wrong? I would expect /etc/ to be populated with the contents of the image.</p>

<p>Edit:</p>

<p>This seems to be working fine in Docker by using the same image, creating a volume with <code>docker volume create &lt;name&gt;</code> and then mounting it as <code>-v &lt;name&gt;:/etc</code>.</p>

ChrisDevWard
<p>Kubernetes does not have the Docker feature that populates volumes based on the contents of the image.  If you create a new volume (whether an <code>emptyDir</code> volume or something based on cloud storage like AWS EBS or EFS) it will start off empty, and hide whatever was in the container.</p>

<p>As such, you can’t mount a volume over large parts of the container; it won’t work to mount a volume over your application’s source tree, or over <code>/etc</code> as you show.  For files in <code>/etc</code> in particular, a better approach would be to use a Kubernetes <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume" rel="noreferrer">ConfigMap</a> to hold specific files you want to add to that directory.  (Store your config files in source control and add them as part of the deployment sequence; don’t try to persist untracked modifications to deployed files.)</p>
