roc*_*sta 2 postgresql docker kubernetes
我开始使用 Kubernates,但在使用 Kubernetes 和 GCE Persistent 磁盘安装 Postgres 时遇到问题。我可以使用 Kubernates 演练和以下指南成功安装 Mysql: http
但是,当我尝试用 postgres 实现类似的事情时,在附加到磁盘或使用磁盘时似乎失败了。我已经创建了一个基于上面帖子中的 mysql 的 pod yaml,但替换了 postgres docker 图像:
apiVersion: v1beta1
id: postgres
desiredState:
manifest:
version: v1beta1
id: postgres
containers:
- name: postgres
image: postgres
env:
- name: DB_PASS
value: password
cpu: 100
ports:
- containerPort: 5432
volumeMounts:
# name must match the volume name below
- name: persistent-storage
# mount path within the container
mountPath: /var/lib/postgresql/data
volumes:
- name: persistent-storage
source:
persistentDisk:
# This GCE PD must already exist and be formatted ext4
pdName: postgres-disk
fsType: ext4
labels:
name: postgres
kind: Pod
Run Code Online (Sandbox Code Playgroud)
但是当我创建
$ kubectl create -f postgres.yaml
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
$ kubectl logs postgres
$ postgres cannot access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
Run Code Online (Sandbox Code Playgroud)
我可以看到 postgres-disk 连接到一个 minion 服务器,所以我想知道它是否与我正在使用的 docker 映像中的卷有关,或者我是否需要 postgresql.conf 文件的单独安装路径。
现在,如果我更改挂载路径(例如 mountPath:/var/lib/postgresql),pod 将正常启动,但它似乎没有使用持久数据。检查 minion 上 docker 容器中的卷给了我:
"Volumes": {
"/dev/termination-log": "/var/lib/kubelet/pods/52177db4-149c-11e5-a64b-42010af06968/containers/postgres/91ecf33c939588b4165865f46b646677bf964fab81ea7ec08b598568513d4644",
"/var/lib/postgresql": "/var/lib/kubelet/pods/52177db4-149c-11e5-a64b-42010af06968/volumes/kubernetes.io~gce-pd/pgdata",
"/var/lib/postgresql/data": "/var/lib/docker/vfs/dir/c3ecda11de6a598d99842c06bee22097f1cb63a6e467cbe7af874d003140a4af",
"/var/run/secrets/kubernetes.io/serviceaccount": "/var/lib/kubelet/pods/52177db4-149c-11e5-a64b-42010af06968/volumes/kubernetes.io~secret/default-token-b6s28"
},
Run Code Online (Sandbox Code Playgroud)
我也尝试使用带有 v1beta3 的 json 文件,结果类似:
{
"kind": "Pod",
"apiVersion": "v1beta3",
"metadata": {
"name": "postgres"
},
"spec": {
"volumes": [{
"name": "pgdata",
"gcePersistentDisk": {
"pdName": "postgres-disk",
"fsType": "ext4"
}
}],
"containers": [
{
"name": "postgres",
"image": "postgres",
"ports": [
{
"name": "postgres-ports",
"hostPort": 5432,
"containerPort": 5432
}
],
"env": [
{
"name": "DB_USER",
"value": "postgres"
},
{
"name": "DB_PASS",
"value": "password"
}
],
"volumeMounts": [
{
"name": "pgdata",
"readOnly": false,
"mountPath": "/var/lib/postgresql/data"
}
]
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我很可能只是在 doco 中遗漏了一些东西,但是对此有任何帮助将不胜感激!
| 归档时间: |
|
| 查看次数: |
5455 次 |
| 最近记录: |