kubernetes - 在 Kubernetes 部署中设置 securityContext
问题描述
我在我的部署中使用 nfs 挂载卷。我需要给它 fsGroup 如下所示:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
有没有办法在部署清单上做到这一点?正如我在文档中看到的那样,我只能在 pod yaml 中设置 securitycontext。
解决方案
您可以像使用securityContext
inDeployment
一样使用 in Pod
。
就像已经建议将它放在下面一样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" ]
你可以测试它:
$ 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
推荐阅读
- java - 运行时子类的超类方法和子方法
- javascript - Javascript 对象 - Svelte 中的压缩和计数
- r - R:基于给定时间范围的数据帧的子集行
- reactjs - 如何在反应中将观察者附加到主题?
- r - 如何使用 R 制作多个 for 循环以执行不同的功能
- ios - 无法在IOS上使用firebase运行flutter应用程序,因为它给出了错误
- python - 如何用 for 循环做到这一点?
- blazor - 单个 Blazor 项目是否可以同时包含 WebAssembly 部分和服务器端部分?
- python - 有没有办法在 Jupyter 中自动切换 matplotlib 后端?
- php - textarea 上的表情符号不保存帖子