非root用户运行容器

设置运行的用户及用户组
不允许越权
这样不以root用户运行容器 安全一些

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: "myapp"
  5. spec:
  6. securityContext:
  7. runAsUser: 1000
  8. runAsGroup: 1000
  9. fsGroup: 2000
  10. volumes:
  11. - name: security
  12. emptyDir: {}
  13. containers:
  14. - name: myapp
  15. image: busybox
  16. command: ['sh','-c','sleep 1h']
  17. resources:
  18. limits:
  19. cpu: 200m
  20. memory: 500Mi
  21. requests:
  22. cpu: 100m
  23. memory: 200Mi
  24. volumeMounts:
  25. - name: security
  26. mountPath: /data/demo
  27. securityContext:
  28. allowPrivilegeEscalation: false

将此pod跑起来之后就可以看到用户的变化
image.png