Man*_*tro 6 kubernetes kubernetes-security kubernetes-deployment kubernetes-pod
我在部署中使用了 nfs 挂载卷。我需要给它 fsGroup 如下所示:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
Run Code Online (Sandbox Code Playgroud)
有没有办法在部署清单上做到这一点?正如我在文档中看到的,我只能在 pod yaml 中设置安全上下文。
Cro*_*rou 11
您可以像使用 inside 一样使用securityContextin 。DeploymentPod
就像已经建议将它放在下面一样template.spec:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
labels:
app: test
spec:
replicas: 3
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
securityContext:
runAsUser: 2000
runAsGroup: 3000
fsGroup: 2000
containers:
- name: test
image: busybox
ports:
- containerPort: 80
command: [ "sh", "-c", "sleep 1h" ]
Run Code Online (Sandbox Code Playgroud)
你可以测试它:
$ kubectl exec -it test-deployment-54d954d7f-2b582 sh
/ $ ps
PID USER TIME COMMAND
1 2000 0:00 sleep 1h
6 2000 0:00 sh
11 2000 0:00 ps
/ $ whoami
whoami: unknown uid 200
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6100 次 |
| 最近记录: |