<p>i have an application that record live traffic and replay them.</p>
<p><a href="https://github.com/buger/goreplay" rel="nofollow noreferrer">https://github.com/buger/goreplay</a></p>
<p>it is a simple app to use, but when i tried to use it with kubernetes i get a problem with persisting data in volumes.</p>
<p>i want to do this :</p>
<ul>
<li>in pod number one i use the goreplay container and other container that just have a simple python server... the job is the goreplay will listen to the requests coming from outside to the server and save them to a file , this is the deployment file :</li>
</ul>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: goreplay-deployment
  labels:
        app: goreplay-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: goreplay-app
  template:
    metadata:
      labels:
        app: goreplay-app
    spec:
      containers:
      - name: goreplay
        image: feiznouri/goreplay:2.0
        args:
          - &quot;--input-raw&quot;
          - &quot;:3000&quot;
          - &quot;--output-file=requests_docker.gor&quot;
        volumeMounts:
          - name: data
            mountPath: /var/lib/goreplay
      - name: myserver
        image: feiznouri/python-server:1.1
        args:
          - &quot;3000&quot;
        ports:
        - name: server-port
          containerPort: 3000
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: goreplay-claim
</code></pre>
<p>normally this will create the file.</p>
<p>the prblem is that when i delete the deployment, and create one that it's job is to read the file and forward the saving request to a server, it can't find the file , clearly i am using the volumes wrong , this is the second deployment that suppose to find and read the file :</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: goreplay-deployment
  labels:
        app: goreplay-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: goreplay-app
  template:
    metadata:
      labels:
        app: goreplay-app
    spec:
      containers:
      - name: goreplay
        image: feiznouri/goreplay:2.0
        args:
          - &quot;--input-file&quot;
          - &quot;requests_docker_0.gor&quot;
          - &quot;--output-http=http://localhost:3000&quot;
        volumeMounts:
          - name: data
            mountPath: /var/lib/goreplay
      - name: myserver
        image: feiznouri/python-server:1.1
        args:
          - &quot;3000&quot;
        ports:
        - name: server-port
          containerPort: 3000
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: goreplay-claim
</code></pre>
<p>PS: this is the yaml file for the persistent volume :</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: goreplay-volume
  labels:
    type: local
spec:
  storageClassName: custum
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: &quot;/mnt/data&quot;
</code></pre>
<p>and this the file for the storage class :</p>
<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: custom
provisioner: k8s.io/minikube-hostpath
reclaimPolicy: Retain
volumeBindingMode: Immediate
</code></pre>
<p>and this for the persistent volume claim :</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: goreplay-claim
spec:
  storageClassName: custum
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Mi
</code></pre>
<p>how can i make this work and find and use the first file that i created in the second pod !</p>
<p>thank you in advance.</p>

feiz
<p>I replicated it and it looks like the volumes are fine.</p>
<p>What is not fine, is how you pass file paths to goreplay.</p>
<p>Here is what I did:</p>
<pre><code>kubectl exec -it goreplay-deployment-899c49f95-7qdh4 -c goreplay sh
/home/goreplay # ps auxwf
PID   USER     TIME  COMMAND
    1 root      0:00 ./gor --input-raw :3000 --output-file=requests_docker.gor
   36 root      0:00 sh
   42 root      0:00 ps auxwf
/home/goreplay # ls /proc/1/cwd -l
lrwxrwxrwx    1 root     root             0 Feb 19 09:44 /proc/1/cwd -&gt; /home/goreplay
</code></pre>
<p>Let me explain what you see here. I execed into goreplay container and checked the PID of goreplay process (PID=1). Next, I checked what is this process's current working directory by checking the <code>/proc/1/cwd</code> symlink. As you see it's symlinked to <code>/home/goreplay</code>.</p>
<p>What does it tell us?</p>
<p>It tells us that <code>--output-file=requests_docker.gor</code> is making goreplay to save the file in <code>/home/goreplay/requests_docker.gor</code> (since you are specifying path relative to process's current working dir instead of using absolute path pointing to volume). It should be set to:</p>
<pre><code>--output-file=/var/lib/gorepath/requests_docker.gor
</code></pre>
<p>since it's the directory where the volume is mounted.</p>
<hr />
<p>Same applies to the second deployment. You should specify:</p>
<pre><code>--input-file=/var/lib/goreplay/requests_docker_0.gor`
</code></pre>
<p>so that it reads from the volume and not from the pod's home directory (<code>/home/goreplay</code>).</p>
<hr />
<p>Change it and it should work.</p>
