在kubernetes中复制docker-compose卷的行为 [英] Replicate docker-compose volume behavior in kubernetes

查看:124
本文介绍了在kubernetes中复制docker-compose卷的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将tomcat + postgres应用程序的docker-compose文件迁移到kubernetes。我的测试环境是启用了Kubernetes的Windows Dockers。

I am migrating a docker-compose file for a tomcat + postgres application to kubernetes. My test environment is Dockers for Windows with Kubernetes enabled.

如果我将emptyDir卷用于postgres,则可以成功测试我的应用程序,但无法持久postgres数据。

If I use an emptyDir volume for postgres, I am able to test my application successfully, but I am unable to persist postgres data.

      volumes:
      - name: "pgdata-vol"
        emptyDir: {}

在MacOS上,我能够使用hostPath卷保留postgres数据。

On MacOS, I am able to persist postgres data using a hostPath volume.

  volumes:
  - name: "pgdata-vol"
    hostPath:
      path: /tmp/vols/pgdata

不幸的是,如果我在Windows上尝试相同的解决方案,则会遇到权限错误。在上一个问题中对此进行了讨论。请参见用于Postgres的Kubernetes(在Windows Docker中)卷配置

Unfortunately, if I try the same solution on Windows, I encounter a permission error. This was discussed in a previous question. See Kubernetes (in Docker for Windows) Volume Configuration for Postgres.

我不需要通过主机文件系统访问卷。我只是希望我的音量可以从一次运行一直保持到下一次。运行 docker-compose ... up docker-compose ... down 时,我能够实现此行为使用以下卷定义。

I do not need to access my volumes through the host file system. I simply want my volume to persist from one run to the next. I am able to achieve this behavior when running docker-compose ... up and docker-compose ... down using the following volume definition.

volumes:
  pgdata:

卷参考

    environment:
      - PGDATA=/pgdata
    volumes:
      - pgdata:/pgdata

用来形容这类体积的好名字吗?有没有办法将这种类型的卷转换为kubernetes?

Is there a good name to use to describe this type of volume? Is there a way to translate this type of volume into kubernetes?

推荐答案

空目录确实用于临时数据。
如果您需要持久性数据,则可以选择使用类似Docker的主机路径,但是如果您有多个节点,则为另一个节点安排了一个容器,数据将丢失。

Empty dir is indeed for temporary data. If you need persistent data you have the choice between using a host path like in Docker, but if you have multiple nodes an a pod is scheduled for a different node the data will be missing.

因此,更好的解决方案是使用持久卷。这必须由您的基础结构提供,因此特定于您的环境。

A better solution is therefore to use a persistent volume. This must be provided by your infrastructure and is therefore specific to your environment.

有关详细信息,请参见:> https://kubernetes.io/docs/concepts/storage/volumes/

See for details: https://kubernetes.io/docs/concepts/storage/volumes/

对于Windows的Docker上的许可问题,您可能需要考虑使用minikube。

For the permission problem on Docker for Windows you might want to consider to use minikube instead.

这篇关于在kubernetes中复制docker-compose卷的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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