从minikube运行Postgresql时如何解决权限问题? [英] How to solve permission trouble when running Postgresql from minikube?
问题描述
我正在尝试使用具有持久卷声明的minikube运行Postgresql数据库.这些是yaml规范:
I am trying to run a Postgresql database using minikube with a persistent volume claim. These are the yaml specifications:
minikube-persistent-volume.yaml:
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv0001
labels:
type: hostpath
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/Users/jonathan/data"
postgres-persistent-volume-claim.yaml:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-postgres
spec:
accessModes: [ "ReadWriteMany" ]
resources:
requests:
storage: 2Gi
postgres-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
template:
metadata:
labels:
app: postgres
spec:
containers:
- image: postgres:9.5
name: postgres
ports:
- containerPort: 5432
name: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-disk
env:
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: POSTGRES_USER
value: keycloak
- name: POSTGRES_DATABASE
value: keycloak
- name: POSTGRES_PASSWORD
value: key
- name: POSTGRES_ROOT_PASSWORD
value: masterkey
volumes:
- name: postgres-disk
persistentVolumeClaim:
claimName: pv-postgres
当我开始执行此操作时,会在部署的日志中得到以下信息:
when I start this I get the following in the logs from the deployment:
[...]
fixing permissions on existing directory
/var/lib/postgresql/data/pgdata ... ok
initdb: could not create directory "/var/lib/postgresql/data/pgdata/pg_xlog": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data/pgdata"
为什么会出现此拒绝权限"错误,我该怎么办?
Why do I get this Permission denied error and what can I do about it?
推荐答案
也许VirtualBox挂载那些主机文件夹时存在写权限问题.
相反,使用/data/postgres
作为路径,一切正常.
Maybe you're having a write permission issue with Virtualbox mounting those host folders.
Instead, use /data/postgres
as a path and things will work.
Minikube自动保留以下目录,因此即使重新引导/重新创建您的VM,它们也将被保留:
Minikube automatically persists the following directories so they will be preserved even if your VM is rebooted/recreated:
-
/data
-
/var/lib/localkube
-
/var/lib/docker
/data
/var/lib/localkube
/var/lib/docker
阅读这些部分以获取更多详细信息:
Read these sections for more details:
- https://github.com/kubernetes/minikube#persistent-volumes
- https://github.com/kubernetes/minikube# Mounted-host-folders
- https://github.com/kubernetes/minikube#persistent-volumes
- https://github.com/kubernetes/minikube#mounted-host-folders
这篇关于从minikube运行Postgresql时如何解决权限问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!