<p>I am trying to add a file to a pod's disk during initialization of the pod but without luck. Below is my deployment file which I use to deploy the pod. The file gets downloaded to the persistent volume, but the pod doesn't get into ready state. After a few seconds, the pods fail and get rebuilt. Which kicks off the whole process again.</p>

<p>Any help would be appreciated.</p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: mapserver
spec:
  selector:
    matchLabels:
      app: mapserver
  template:
    metadata:
      labels:
        app: mapserver
    spec:
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: mapserver-pv-claim
      containers:
      - name: maptiles
        image: klokantech/tileserver-gl
        command: ["/bin/sh"]
        args:
        - -c
        - |
           echo "[INFO] Startingcontainer"; if [ $(DOWNLOAD_MBTILES) = "true" ]; then
             echo "[INFO] Download MBTILES_PLANET_URL";
             rm /data/*
             cd /data/
             curl -k -sSL -X GET -u user:ww $(MBTILES_PLANET_URL) -O
             echo "[INFO] Download finished";
           fi;
         env:
         - name: MBTILES_PLANET_URL
           value: 'https://abc-dev/nexus/repository/xyz-raw/2017-07-03_europe_netherlands.mbtiles'
         - name: DOWNLOAD_MBTILES
           value: 'true'
        livenessProbe:
          failureThreshold: 120
          httpGet:
            path: /health
            port: 80
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 30
          successThreshold: 1
          timeoutSeconds: 5
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        readinessProbe:
          failureThreshold: 120
          httpGet:
            path: /health
            port: 80
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 30
          successThreshold: 1
          timeoutSeconds: 5
        resources:
          limits:
            cpu: 300m
            memory: 3Gi
          requests:
            cpu: 100m
            memory: 1Gi
        volumeMounts:
        - mountPath: "/data"
          name: storage
</code></pre>

<blockquote>
  <p>am trying to add a file to a pod's disk during initialization of the pod but without luck.</p>
</blockquote>

<p>In that case you might want to use <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer"><code>InitContainers</code></a> instead.</p>

<p>Judging from your manifest, your main command gets executed (copies the file and then exits) terminating the container (and accompanying pod) in the process. Deployment then restarts the exited pod and cycle repeats. If you use <code>InitContainers</code> instead (with the same definition and same PV as you are doing now for main container) you should then prepopulate data using <code>InitContaienrs</code> that runs to completion and then continue to use it in your normal container (that should have non-exiting main process as its command/entry point).</p>

<p>Note: if you don't want to use <code>InitContainers</code> or just as a quick test, you could append a regular non-exiting command after your copy statement, and also, check if you need to start container with tty, depending on your use case and ways to keep container up and running.</p>
