我正在使用minikube在本地运行kubernetes。我的本地k8有两个Pod,其中一个是PostgreSQL,另一个是我自己的应用程序。我已经安装了PersistentVolume
和PersistentVolumeClaim
以便为PostgreSQL创建有状态的容器:
kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/psql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
这是PostgreSQL部署yaml文件:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
template:
metadata:
labels:
name: postgres
spec:
containers:
- name: postgres
imagePullPolicy: Never
image: postgres:9.6
ports:
- name: postgres
containerPort: 5432
volumeMounts:
- mountPath: /var/lib/postgresql
name: postgres-persistent-storage
volumes:
- name: postgres-persistent-storage
persistentVolumeClaim:
claimName: postgres-pv-claim
问题是PostgreSQL服务无法启动,并且当我运行其pod时会发生此错误:
Error: /var/lib/postgresql/9.6/main is not accessible; please fix the directory permissions (/var/lib/postgresql/9.6/ should be world readable)
No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning).
我检查了PostgreSQL pod的内部,发现/var/lib/postgresql
是空的,就像minikube主机中的/data/psql
一样。
有人可以帮忙吗?