Mik*_*ski 31 amazon-web-services docker kubernetes persistent-volume-claims
我正在使用kops在AWS上运行Kubernetes集群.我已经将一个EBS卷安装到一个容器上,它可以从我的应用程序中看到,但它是只读的,因为我的应用程序不是以root身份运行的.如何PersistentVolumeClaim
以root用户身份登录?在VolumeMount
似乎不具有任何选项来控制所安装的路径的用户,组或文件权限.
这是我的部署yaml文件:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: notebook-1
spec:
replicas: 1
template:
metadata:
labels:
app: notebook-1
spec:
volumes:
- name: notebook-1
persistentVolumeClaim:
claimName: notebook-1
containers:
- name: notebook-1
image: jupyter/base-notebook
ports:
- containerPort: 8888
volumeMounts:
- mountPath: "/home/jovyan/work"
name: notebook-1
Run Code Online (Sandbox Code Playgroud)
Ale*_*and 28
Pod安全上下文支持设置a fsGroup
,允许您设置拥有卷的组ID,从而设置可以写入的组ID.文档中的示例:
apiVersion: v1
kind: Pod
metadata:
name: hello-world
spec:
containers:
# specification of the pod's containers
# ...
securityContext:
fsGroup: 1234
Run Code Online (Sandbox Code Playgroud)
更多信息请访问:https://kubernetes.io/docs/concepts/policy/security-context/
小智 24
当您必须以非 root 用户身份在容器内运行进程时,这是 Kubernetes Deployments/StatefulSets 面临的挑战之一。但是,当您将卷挂载到 pod 时,它总是在root:root
.
因此,非 root 用户必须有权访问要读取和写入数据的文件夹。
请按照以下步骤操作。
在 podspec
上下文中的 Deployment/StatefulSet 中添加以下行。
spec:
securityContext:
runAsUser: 1099
runAsGroup: 1099
fsGroup: 1099
Run Code Online (Sandbox Code Playgroud)以用户身份运行
指定对于 Pod 中的任何容器,所有进程都以用户 ID 1099 运行。
运行组
为 Pod 的任何容器内的所有进程指定主组 ID 1099。
如果省略此字段,则容器的主要组 ID 将为root(0)
。
创建的任何文件也将在runAsGroup
指定时归用户 1099 和组 1099 所有。
组
指定连接的任何卷的所有者将是组 ID 1099 的所有者。
在它下创建的任何文件都将具有nonrootgroup:nonrootgroup
.
ssh*_*how 20
我最终使用initContainer
与主容器相同的volumeMount来设置适当的权限,在我的情况下,为自定义Grafana图像.
initContainers:
- name: take-data-dir-ownership
image: alpine:3.6
# Give `grafana` user (id 472) permissions a mounted volume
# https://github.com/grafana/grafana-docker/blob/master/Dockerfile
command:
- chown
- -R
- 472:472
- /var/lib/grafana
volumeMounts:
- name: data
mountPath: /var/lib/grafana
Run Code Online (Sandbox Code Playgroud)
当pod中的主映像作为非root用户运行并且需要对已装入卷执行写入权限时,这是必需的.
小智 8
对于k8s版本1.10+,runAsGroup
已添加,它类似于fsGroup
但工作方式不同。
可以在此处跟踪实现:https : //github.com/kubernetes/features/issues/213
小智 5
请参考这个问题:https ://github.com/kubernetes/kubernetes/issues/2630
如果是emptydir
,则可以使用securityContext
中的 :spec
spec:
securityContext:
runAsUser: 1000
fsGroup: 1000
containers: ...
Run Code Online (Sandbox Code Playgroud)
如果卷是 a hostpath
,则 aninitContainer
可用于chown
卷中的路径:
initContainers:
- name: example-c
image: busybox:latest
command: ["sh","-c","mkdir -p /vol-path && chown -R 1000:1000 /vol-path"]
resources:
limits:
cpu: "1"
memory: 1Gi
volumeMounts:
- name: vol-example
mountPath: /vol-path
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24778 次 |
最近记录: |