解决Kubernetes以root用户mount volumn导致无写权限的问题
source link: https://www.pkslow.com/archives/kubernetes-mount-volumn-as-none-root
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
一年春又尽,倚杖对斜晖。
1 问题描述
我们在使用StatefulSet
来使用PVC
或直接使用PVC
时,发现运行的时候无法写所mount
的volume
,查看日志是没有足够的权限,只能读不能写。
2 问题分析
首先,因为安全问题,我们所运行的容器是不可以为root
用户,否则会被kill
掉。通过ls
命令查看,所mount
的目录却是属于root
用户的,而且其它用户并没有可写权限。
因此,解决方案就简单了,不通过root用户来mount就行了。
3 解决方案
可以通过配置Pod
的securityContext
解决:
apiVersion: v1
kind: Pod
metadata:
name: pkslow-app
spec:
containers:
# specification of the pod's containers
# ...
securityContext:
fsGroup: 319
这个319是所运行的非root用户的,可以通过命令id
查看。
$ id
uid=319(larry) gid=319(staff) groups=319(staff)
要注意这个所配的securityContext
是属于Pod
Level,而不是container Level
。因为容器也有自己的securityContext
,不要配错了。
参考:Kubernetes: how to set VolumeMount user group and file permissions
欢迎关注微信公众号<南瓜慢说>,将持续为你更新...
推荐阅读:
如何制定切实可行的计划并好好执行
容器技术(Docker-Kubernetes)
SpringBoot-Cloud相关
Https专题
- 本文作者: 南瓜慢说
- 本文链接: https://www.pkslow.com/archives/kubernetes-mount-volumn-as-none-root
- 版权声明: 本博客所有文章除特别声明外,不可转载!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK