kubernetes - Kubernetes(在 Docker for Windows 中)Postgres 的卷配置
问题描述
我有一个用 docker-compose 测试的 tomcat + postgres 应用程序。我正在尝试将应用程序打包在 kubernetes 配置文件中。
目前,我正在使用我的 Docker Desktop for Windows 安装运行 kubernetes(和 kubectl)。最终,我想部署到其他环境。
我目前正在尝试在以下配置文件中复制 docker-compose 中的一些卷功能。
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 启动时,我看到以下错误。
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)。
解决方案
我找到了这个问题的部分解决方案。
有趣的是,如果我指定一个 linux 风格的路径作为我的主机路径(在 Windows 上),那么我的 pgdata-vol 会一直存在,直到重新启动 Docker Desktop。
而不是安装到真正的 Windows 位置
volumes:
- name: "pgdata-vol"
hostPath:
path: /c/temp/vols/pgdata
我使用“linux”位置作为我的 Windows hostPath
volumes:
- name: "pgdata-vol"
hostPath:
path: /tmp/vols/pgdata
奇怪的是,我实际上无法从 Windows 中找到这条路径。我认为这个 /tmp 对于我的 Docker 桌面实例是本地的。
该解决方案不能提供真正的持久性,但它帮助我解决了影响测试的障碍。
推荐阅读
- ruby-on-rails - Authlogic gem:在会话级别而不是在用户级别使用 last_request_at 列
- sql-server - 使用 mod_proxy 通过反向代理连接到 SQL Server 的正确连接字符串是什么(
)]? - splunk - 如何在 splunk 中获取一个字段值的每小时总和
- typo3 - TYPO3 流体:从页面获取所有内容 ID
- multithreading - 为什么多线程时间不等于 gunicorn 的单个处理时间?
- javascript - 十进制转换错误 - 16 个字符后返回错误答案
- vue.js - Vuetify 路由:更改页面内容难题
- c# - ClaimTypes.NameIdentifier 总是返回 null
- python - 如何将所选图像添加到 opencv2 中的 imread() 函数中
- javascript - 想要为电子邮件查询创建 SQL 查询生成器