Mount host dir for Postgres on Minikube - permissions issue












0














I'm trying to setup PostgreSQL on Minikube with data path being my host folder mounted on Minikube (I'd like to keep my data on host).



With the kubernetes object created (below) I get permission error, the same one as here How to solve permission trouble when running Postgresql from minikube? although the question mentioned doesn't answer the issue. It advises to mount minikube's VM dir instead.



---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
volumes:
- name: storage
hostPath:
path: /data/postgres


Is there any other way to do that other than building own image on top of Postgres and playing with the permissions somehow? I'm on macOS with Minikube 0.30.0 and I'm experiencing that with both Virtualbox and hyperkit drivers for Minikube.










share|improve this question






















  • Have you tried to change the owner of /var/lib/postgresql/data via initContainer in the same way as described here?
    – mk_sta
    Nov 20 '18 at 13:12
















0














I'm trying to setup PostgreSQL on Minikube with data path being my host folder mounted on Minikube (I'd like to keep my data on host).



With the kubernetes object created (below) I get permission error, the same one as here How to solve permission trouble when running Postgresql from minikube? although the question mentioned doesn't answer the issue. It advises to mount minikube's VM dir instead.



---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
volumes:
- name: storage
hostPath:
path: /data/postgres


Is there any other way to do that other than building own image on top of Postgres and playing with the permissions somehow? I'm on macOS with Minikube 0.30.0 and I'm experiencing that with both Virtualbox and hyperkit drivers for Minikube.










share|improve this question






















  • Have you tried to change the owner of /var/lib/postgresql/data via initContainer in the same way as described here?
    – mk_sta
    Nov 20 '18 at 13:12














0












0








0







I'm trying to setup PostgreSQL on Minikube with data path being my host folder mounted on Minikube (I'd like to keep my data on host).



With the kubernetes object created (below) I get permission error, the same one as here How to solve permission trouble when running Postgresql from minikube? although the question mentioned doesn't answer the issue. It advises to mount minikube's VM dir instead.



---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
volumes:
- name: storage
hostPath:
path: /data/postgres


Is there any other way to do that other than building own image on top of Postgres and playing with the permissions somehow? I'm on macOS with Minikube 0.30.0 and I'm experiencing that with both Virtualbox and hyperkit drivers for Minikube.










share|improve this question













I'm trying to setup PostgreSQL on Minikube with data path being my host folder mounted on Minikube (I'd like to keep my data on host).



With the kubernetes object created (below) I get permission error, the same one as here How to solve permission trouble when running Postgresql from minikube? although the question mentioned doesn't answer the issue. It advises to mount minikube's VM dir instead.



---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
volumes:
- name: storage
hostPath:
path: /data/postgres


Is there any other way to do that other than building own image on top of Postgres and playing with the permissions somehow? I'm on macOS with Minikube 0.30.0 and I'm experiencing that with both Virtualbox and hyperkit drivers for Minikube.







postgresql docker kubernetes minikube






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 16:20









Michal Ostruszka

1,10421319




1,10421319












  • Have you tried to change the owner of /var/lib/postgresql/data via initContainer in the same way as described here?
    – mk_sta
    Nov 20 '18 at 13:12


















  • Have you tried to change the owner of /var/lib/postgresql/data via initContainer in the same way as described here?
    – mk_sta
    Nov 20 '18 at 13:12
















Have you tried to change the owner of /var/lib/postgresql/data via initContainer in the same way as described here?
– mk_sta
Nov 20 '18 at 13:12




Have you tried to change the owner of /var/lib/postgresql/data via initContainer in the same way as described here?
– mk_sta
Nov 20 '18 at 13:12












1 Answer
1






active

oldest

votes


















0














Look at these lines from here : hostPath




the files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a privileged Container or modify the file permissions on the host to be able to write to a hostPath volume




So, either you have to run as root or you have to change the file permission of /data/postgres directory.



However, you can run your Postgres container as root without rebuilding docker image.



You have to add following to your container:



securityContext:
runAsUser: 0


Your yaml should look like this:



apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
securityContext:
runAsUser: 0
volumes:
- name: storage
hostPath:
path: /data/postgres





share|improve this answer





















  • Using securityContext doesn't help. Getting chown: changing ownership of '/var/lib/postgresql/data': Input/output error. In minikube I see host dir being mounted with uid=501 and gid=20 which is totally crazy (taken from host) and moreover it cannot be changed even as root (getting permission denied)
    – Michal Ostruszka
    Nov 19 '18 at 20:36










  • This thread might help: github.com/docker-library/postgres/issues/116
    – Emruz Hossain
    Nov 20 '18 at 4:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378779%2fmount-host-dir-for-postgres-on-minikube-permissions-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Look at these lines from here : hostPath




the files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a privileged Container or modify the file permissions on the host to be able to write to a hostPath volume




So, either you have to run as root or you have to change the file permission of /data/postgres directory.



However, you can run your Postgres container as root without rebuilding docker image.



You have to add following to your container:



securityContext:
runAsUser: 0


Your yaml should look like this:



apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
securityContext:
runAsUser: 0
volumes:
- name: storage
hostPath:
path: /data/postgres





share|improve this answer





















  • Using securityContext doesn't help. Getting chown: changing ownership of '/var/lib/postgresql/data': Input/output error. In minikube I see host dir being mounted with uid=501 and gid=20 which is totally crazy (taken from host) and moreover it cannot be changed even as root (getting permission denied)
    – Michal Ostruszka
    Nov 19 '18 at 20:36










  • This thread might help: github.com/docker-library/postgres/issues/116
    – Emruz Hossain
    Nov 20 '18 at 4:19
















0














Look at these lines from here : hostPath




the files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a privileged Container or modify the file permissions on the host to be able to write to a hostPath volume




So, either you have to run as root or you have to change the file permission of /data/postgres directory.



However, you can run your Postgres container as root without rebuilding docker image.



You have to add following to your container:



securityContext:
runAsUser: 0


Your yaml should look like this:



apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
securityContext:
runAsUser: 0
volumes:
- name: storage
hostPath:
path: /data/postgres





share|improve this answer





















  • Using securityContext doesn't help. Getting chown: changing ownership of '/var/lib/postgresql/data': Input/output error. In minikube I see host dir being mounted with uid=501 and gid=20 which is totally crazy (taken from host) and moreover it cannot be changed even as root (getting permission denied)
    – Michal Ostruszka
    Nov 19 '18 at 20:36










  • This thread might help: github.com/docker-library/postgres/issues/116
    – Emruz Hossain
    Nov 20 '18 at 4:19














0












0








0






Look at these lines from here : hostPath




the files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a privileged Container or modify the file permissions on the host to be able to write to a hostPath volume




So, either you have to run as root or you have to change the file permission of /data/postgres directory.



However, you can run your Postgres container as root without rebuilding docker image.



You have to add following to your container:



securityContext:
runAsUser: 0


Your yaml should look like this:



apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
securityContext:
runAsUser: 0
volumes:
- name: storage
hostPath:
path: /data/postgres





share|improve this answer












Look at these lines from here : hostPath




the files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a privileged Container or modify the file permissions on the host to be able to write to a hostPath volume




So, either you have to run as root or you have to change the file permission of /data/postgres directory.



However, you can run your Postgres container as root without rebuilding docker image.



You have to add following to your container:



securityContext:
runAsUser: 0


Your yaml should look like this:



apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: storage
env:
- name: POSTGRES_PASSWORD
value: user
- name: POSTGRES_USER
value: pass
- name: POSTGRES_DB
value: k8s
securityContext:
runAsUser: 0
volumes:
- name: storage
hostPath:
path: /data/postgres






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 17:02









Emruz Hossain

1,084210




1,084210












  • Using securityContext doesn't help. Getting chown: changing ownership of '/var/lib/postgresql/data': Input/output error. In minikube I see host dir being mounted with uid=501 and gid=20 which is totally crazy (taken from host) and moreover it cannot be changed even as root (getting permission denied)
    – Michal Ostruszka
    Nov 19 '18 at 20:36










  • This thread might help: github.com/docker-library/postgres/issues/116
    – Emruz Hossain
    Nov 20 '18 at 4:19


















  • Using securityContext doesn't help. Getting chown: changing ownership of '/var/lib/postgresql/data': Input/output error. In minikube I see host dir being mounted with uid=501 and gid=20 which is totally crazy (taken from host) and moreover it cannot be changed even as root (getting permission denied)
    – Michal Ostruszka
    Nov 19 '18 at 20:36










  • This thread might help: github.com/docker-library/postgres/issues/116
    – Emruz Hossain
    Nov 20 '18 at 4:19
















Using securityContext doesn't help. Getting chown: changing ownership of '/var/lib/postgresql/data': Input/output error. In minikube I see host dir being mounted with uid=501 and gid=20 which is totally crazy (taken from host) and moreover it cannot be changed even as root (getting permission denied)
– Michal Ostruszka
Nov 19 '18 at 20:36




Using securityContext doesn't help. Getting chown: changing ownership of '/var/lib/postgresql/data': Input/output error. In minikube I see host dir being mounted with uid=501 and gid=20 which is totally crazy (taken from host) and moreover it cannot be changed even as root (getting permission denied)
– Michal Ostruszka
Nov 19 '18 at 20:36












This thread might help: github.com/docker-library/postgres/issues/116
– Emruz Hossain
Nov 20 '18 at 4:19




This thread might help: github.com/docker-library/postgres/issues/116
– Emruz Hossain
Nov 20 '18 at 4:19


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378779%2fmount-host-dir-for-postgres-on-minikube-permissions-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory