Kubernetes(在Windows的Docker中)Postgres的卷配置 [英] Kubernetes (in Docker for Windows) Volume Configuration for Postgres

查看:127
本文介绍了Kubernetes(在Windows的Docker中)Postgres的卷配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用docker-compose测试的tomcat + postgres应用程序.我正在尝试将应用程序打包到kubernetes配置文件中.

I have a tomcat + postgres application that I test with docker-compose. I am trying to package the application in a kubernetes config file.

就目前而言,我正在使用适用于Windows的Docker桌面运行kubernetes(和kubectl).最终,我想部署到其他环境.

For now, I am running kubernetes (and kubectl) using my Docker Desktop for Windows installation. Eventually, I want to deploy to other environments.

我目前正在尝试在以下配置文件中复制docker-compose中的某些卷功能.

I am currently trying to replicate some of the volume functionality in docker-compose within the following config file.

apiVersion: v1
kind: Pod
metadata:
  name: pg-pod
spec:
  volumes:
  - name: "pgdata-vol"
    #emptyDir: {}
    hostPath:
      path: /c/temp/vols/pgdata
  containers:
  - image: postgres
    name: db
    ports:
    - containerPort: 5432
      name: http
      protocol: TCP
    volumeMounts:
    - mountPath: "/pgdata"
      name: "pgdata-vol"
    env:
    - name: PGDATA
      value: /pgdata

postgres启动时,出现以下错误.

When postgres launches, I get see the following error.

fixing permissions on existing directory /pgdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers ... 400kB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
2019-07-26 20:43:41.844 UTC [78] FATAL:  data directory "/pgdata" has wrong ownership
2019-07-26 20:43:41.844 UTC [78] HINT:  The server must be started by the user that owns the data directory.
child process exited with exit code 1
initdb: removing contents of data directory "/pgdata"
running bootstrap script ...

我假设我需要为卷定义提供一些其他参数,或者需要尝试其他类型的卷配置( local hostPath ). /p>

I presume that I either need to provide some additional parameters to my volume definition or I need to try a different type of volume config (local vs hostPath).

推荐答案

我找到了解决此问题的部分方法.

I found a partial solution to this issue.

有趣的是,如果我将linux风格的路径分配为主机路径(在Windows上),那么我的pgdata-vol会一直存在,直到重新启动Docker Desktop.

Interestingly, if I assign a linux-style path as my host-path (on Windows), then my pgdata-vol persists until Docker Desktop is restarted.

不是安装到真实的Windows位置

Instead of mounting to a real windows location

  volumes:
  - name: "pgdata-vol"
    hostPath:
      path: /c/temp/vols/pgdata

我使用"linux"位置作为Windows hostPath

I use a "linux" location as my Windows hostPath

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

奇怪的是,我实际上无法从Windows找到此路径.我认为这个/tmp对我的Docker Desktop实例是本地的.

Curiously, I cannot actually find this path from Windows. I presume this /tmp is local to my Docker Desktop instance.

此解决方案无法提供真正的持久性,但它帮助我解决了影响测试的障碍.

This solution does not offer true persistence, but it has helped me to work around a roadblock that was impacting testing.

这篇关于Kubernetes(在Windows的Docker中)Postgres的卷配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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