k8s PodSecurityPolicy的头盔模板

时间:2020-04-24 11:18:52

标签: kubernetes kubernetes-helm

我的头盔图表中有一个PodSecurityPolicy,并且想动态更改rule上的runAsUser

启用{{- if .Values.global.psp.enabled }}并且相应的values.yaml包含以下内容:

runAsUnprivilegedUser: true 

我希望模板能够像这样呈现:

runAsUser:
    # Require the container to run without root privileges.
    rule: 'MustRunAsNonRoot'

另外为默认的非root用户提供UID1000。

另一方面,如果将runAsUnprivilegedUser设置为false,我想拥有

runAsUser:
    rule: 'RunAsAny'

受雇。

1 个答案:

答案 0 :(得分:2)

我认为您可以使用条件语句来做到这一点

kind: PodSecurityPolicy
apiVersion: policy/v1beta1
metadata:
  name: allow-flex-volumes
spec:
  runAsUser:
    # Require the container to run without root privileges.
    {{- if and .Values.global.psp .Values.podSecurityContext}}
    rule: 'MustRunAsNonRoot'
    {{else }}
    rule: 'RunAsAny'
    {{end}}