Postgres与Kubernetes和persistentDisk

我正在开始使用Kubernates,并且在使用Kubernetes和GCE持久性磁盘的情况下安装Postgres时遇到问题。 我可以使用Kubernates演练和以下指南成功安装Mysql: http ://amygdala.github.io/kubernetes/2015/01/13/k8s1.html

然而,当我试图用postgres实现类似的事情时,它似乎失败时,附加到磁盘或使用磁盘。 我创build了一个基于上面的post中的mysql的pod yaml,但是用postgres docker image代替了:

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 

但是,当我创build

 $ kubectl create -f postgres.yaml 

我得到以下错误:

 $ kubectl logs postgres $ postgres cannot access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory 

我可以看到postgres-disk连接到一个minion服务器,所以我想知道它是否与我正在使用的docker映像中的卷相关,或者如果我需要单独的postgresql.conf文件的装载path。

现在,如果我更改装载path(例如,mountPath:/ var / lib / postgresql),则该容器将开始正常工作,但是它似乎没有使用持久性数据。 检查仆人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" }, 

我也尝试使用与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" } ] } ] } } 

我很可能错过了doco中的一些东西,但任何帮助,将不胜感激!

请检查卷的文档https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/volumes.md#gcepersistentdisk

在您使用带有吊舱的GCE PD之前,您需要创build它。

 gcloud compute disks create --size=500GB --zone=us-central1-a pg-data-disk 

这将是你的configuration,介意gcePersistentDisk

 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: gcePersistentDisk: # This GCE PD must already exist and be formatted ext4 pdName: pg-data-disk fsType: ext4 labels: name: postgres kind: Pod 

我也遇到同样的问题 – 这是由于db初始化脚本错误地假定非空卷目录意味着它已经被初始化。

不幸的是,新的GCE持久性磁盘包含lost+found目录。

我已经在这里提交了一个修复docker的图片。

你的yaml有“persistentDisk”,它应该有“gcePersistentDisk”。 使用kubectl create -f <file> --validate来捕获这样的错误。 虽然你的json看起来是正确的。

是否有可能postgres需要configuration文件已经存在?