我无法在kubernetes卷中保留数据 [英] i can't presist data in kubernetes volumes

查看:50
本文介绍了我无法在kubernetes卷中保留数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以记录实时流量并重播的应用程序.

i have an application that record live traffic and replay them.

https://github.com/buger/goreplay

这是一个易于使用的应用程序,但是当我尝试将其与kubernetes结合使用时,在将数据持久存储在卷中时会遇到问题.

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.

我想这样做:

  • 在第一个Pod中,我使用goreplay容器和其他只有一个简单python服务器的容器...工作是goreplay将侦听来自外部到服务器的请求并将其保存到文件中,这是部署文件:
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:
          - "--input-raw"
          - ":3000"
          - "--output-file=requests_docker.gor"
        volumeMounts:
          - name: data
            mountPath: /var/lib/goreplay
      - name: myserver
        image: feiznouri/python-server:1.1
        args:
          - "3000"
        ports:
        - name: server-port
          containerPort: 3000
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: goreplay-claim

通常,这将创建文件.

问题是,当我删除部署并创建一个部署时,其工作是读取文件并将保存请求转发到服务器,它找不到该文件,显然我使用的是错误的卷,这是第二个部署,它查找并读取文件:

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 :

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:
          - "--input-file"
          - "requests_docker_0.gor"
          - "--output-http=http://localhost:3000"
        volumeMounts:
          - name: data
            mountPath: /var/lib/goreplay
      - name: myserver
        image: feiznouri/python-server:1.1
        args:
          - "3000"
        ports:
        - name: server-port
          containerPort: 3000
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: goreplay-claim

PS:这是永久卷的yaml文件:

PS: this is the yaml file for the persistent volume :

apiVersion: v1
kind: PersistentVolume
metadata:
  name: goreplay-volume
  labels:
    type: local
spec:
  storageClassName: custum
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt/data"

这是存储类的文件:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: custom
provisioner: k8s.io/minikube-hostpath
reclaimPolicy: Retain
volumeBindingMode: Immediate

这是针对永久性批量声明:

and this for the persistent volume claim :

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: goreplay-claim
spec:
  storageClassName: custum
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Mi

我该如何进行这项工作,以及查找和使用我在第二个Pod中创建的第一个文件!

how can i make this work and find and use the first file that i created in the second pod !

先谢谢您

推荐答案

我复制了它,看起来好像很好.

I replicated it and it looks like the volumes are fine.

不好的是如何将文件路径传递到goreplay.

What is not fine, is how you pass file paths to goreplay.

这是我所做的:

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 -> /home/goreplay

让我解释一下您在这里看到的内容.我执行了goreplay容器并检查了goreplay进程的PID(PID = 1).接下来,我通过检查/proc/1/cwd 符号链接来检查该进程的当前工作目录.如您所见,它与/home/goreplay 链接.

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 /proc/1/cwd symlink. As you see it's symlinked to /home/goreplay.

它告诉我们什么?

它告诉我们-output-file = requests_docker.gor 正在使goreplay将文件保存在/home/goreplay/requests_docker.gor 中(因为您是指定相对于进程当前工作目录的路径,而不是使用指向卷的绝对路径).它应该设置为:

It tells us that --output-file=requests_docker.gor is making goreplay to save the file in /home/goreplay/requests_docker.gor (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:

--output-file=/var/lib/gorepath/requests_docker.gor

因为它是安装卷的目录.

since it's the directory where the volume is mounted.

相同适用于第二个部署.您应该指定:

Same applies to the second deployment. You should specify:

--input-file=/var/lib/goreplay/requests_docker_0.gor`

,以便它从卷而不是Pod的主目录(/home/goreplay )中读取.

so that it reads from the volume and not from the pod's home directory (/home/goreplay).

更改它,它应该可以工作.

Change it and it should work.

这篇关于我无法在kubernetes卷中保留数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆