<p>i have a question to ask you about kubernates. I need to configure a Horizontal Load Balancer on a service with Kubernates. Specifically in my yaml file I used the following kind: HorizontalPodAutoscaler; the problem arises on the logic of uploading files to the volume: in a nutshell, when a pod is released, the data inside is overwritten, so with a new pod the volume is emptied. Am I wrong in configurations?
Specifically, I set the volume in the Dockerfile to build the corresponding image of the service launched with Kubernates.</p>

Danilo Giovannico
<p>it's not good idea to store data in Dockerimage however still what you can do is,</p>
<ul>
<li>Copy data to docker image</li>
<li>Inside the Kubernetes POD create the PVC volume</li>
<li>Attach POD to PVC and use the volume mount</li>
<li>Use the <strong>init container</strong> to copy data from the docker path to the volume mount file path</li>
</ul>
<p><strong>Dockerfile</strong></p>
<pre><code>FROM python:latest
COPY data.csv ./tmp/
</code></pre>
<p><strong>Kubernetes YAML</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: POD-name
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      initContainers:
      - name: copy
        image: busybox:1.28
        command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;cp /tmp/data.csv /data/data.csv&quot;]
        volumeMounts:
        - name: pvc
          mountPath: /data/
      containers:
      - name: test
        image: image:tag
        ports:
        - containerPort: 8080
        env:
        - name: PORT
          value: &quot;8080&quot;
        volumeMounts:
        - mountPath: &quot;/data/&quot;
          name: pvc
      volumes:
      - name: pvc
        persistentVolumeClaim:
          claimName: pvc-claim
</code></pre>
