5.3. 配置 Gatekeeper operator


从 Operator Lifecycle Manager 目录安装 Gatekeeper Operator,以便在集群中安装 Gatekeeper。在 Red Hat Advanced Cluster Management 中,您可以使用策略来使用监管框架安装 Gatekeeper operator。安装 Gatekeeper operator 后,配置 Gatekeeper operator 自定义资源来安装 Gatekeeper。

5.3.1. 先决条件

  • 需要的访问权限 : 集群管理员。
  • 了解如何通过完成将 Operator 添加到集群以及 OpenShift Container Platform 文档中的 附加资源部分 来使用 Operator Lifecycle Manager (OLM)和 OperatorHub。

5.3.2. Gatekeeper 自定义资源示例

Gatekeeper operator 自定义资源告诉 Gatekeeper Operator 在集群中启动 Gatekeeper 安装。要安装 Gatekeeper,请使用以下示例 YAML,其中包括示例和默认值:

apiVersion: operator.gatekeeper.sh/v1alpha1
kind: Gatekeeper
metadata:
  name: gatekeeper
spec:
  audit:
    replicas: 1
    auditEventsInvolvedNamespace: Enabled 
1

    logLevel: DEBUG
    auditInterval: 10s
    constraintViolationLimit: 55
    auditFromCache: Enabled
    auditChunkSize: 66
    emitAuditEvents: Enabled
    containerArguments: 
2

    - name: ""
      value: ""
    resources:
      limits:
        cpu: 500m
        memory: 150Mi
      requests:
        cpu: 500m
        memory: 130Mi
  validatingWebhook: Enabled
  mutatingWebhook: Enabled
  webhook:
    replicas: 3
    emitAdmissionEvents: Enabled
    admissionEventsInvolvedNamespace: Enabled 
3

    disabledBuiltins:
     - http.send
    operations: 
4

     - "CREATE"
     - "UPDATE"
     - "CONNECT"
    failurePolicy: Fail
    containerArguments: 
5

    - name: ""
      value: ""
    resources:
      limits:
        cpu: 480m
        memory: 140Mi
      requests:
        cpu: 400m
        memory: 120Mi
  nodeSelector:
    region: "EMEA"
  affinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchLabels:
              auditKey: "auditValue"
          topologyKey: topology.kubernetes.io/zone
  tolerations:
    - key: "Example"
      operator: "Exists"
      effect: "NoSchedule"
  podAnnotations:
    some-annotation: "this is a test"
    other-annotation: "another test"
Copy to Clipboard Toggle word wrap
1
对于版本 3.14 及之后的版本,启用 auditEventsInvolvedNamespace 参数来管理您要创建的命名空间审计事件。启用此参数时,Gatekeeper 控制器部署使用以下参数运行 :--audit-events-involved-namespace=true
3
对于版本 3.14 及之后的版本,启用 admissionEventsInvolvedNamespace 参数来管理您要创建的命名空间准入事件。当启用此参数时,Gatekeeper 控制器部署使用以下参数运行 :--admission-events-involved-namespace=true
4
对于版本 3.14 及更高版本,要管理 webhook 操作,请为 operations 参数使用以下值:" CREATE", "UPDATE" , "CONNECT", 和 "DELETE"
2 5
对于版本 3.17 及更高版本,请通过提供要传递给容器的参数名称和值列表来指定 containerArguments。从参数名称中省略前导短划线。省略的值被视为 true。如果之前由 operator 或来自其他字段的配置设置了参数,则您提供的参数将被忽略。请参阅以下拒绝列表且当前不支持的标记:
  • port
  • prometheus-port
  • health-addr
  • validating-webhook-configuration-name
  • mutating-webhook-configuration-name
  • disable-cert-rotation
  • client-cert-name
  • tls-min-version

5.3.3. 为同步详情配置 auditFromCache

对于版本 3.14 或更高版本,Gatekeeper operator 使用 auditFromCache 参数为审计配置公开 Gatekeeper operator 自定义资源中的设置,该参数默认是禁用的。配置 auditFromCache 参数,以从约束中收集资源。

当您将 auditFromCache 参数设置为 Automatic 时,Gatekeeper operator 会从约束中收集资源,并将这些资源插入到 Gatekeeper Config 资源中。如果资源不存在,则 Gatekeeper operator 会创建 Config 资源。

如果将 auditFromCache 参数设置为 Enabled,则需要使用对象手动将 Gatekeeper Config 资源设置为同步到缓存。如需更多信息,请参阅 Gatekeeper 文档中的配置审计

要为来自约束的资源集合配置 auditFromCache 参数,请完成以下步骤:

  1. Gatekeeper 资源中将 auditFromCache 设置为 Automatic。请参见以下示例:

    apiVersion: operator.gatekeeper.sh/v1alpha1
    kind: Gatekeeper
    metadata:
      name: gatekeeper
    spec:
      audit:
        replicas: 2
        logLevel: DEBUG
        auditFromCache: Automatic
    Copy to Clipboard Toggle word wrap
  2. 要验证资源是否已添加到您的 Config 资源中,请查看 syncOnly 参数部分是否已添加。运行以下命令:

    oc get configs.config.gatekeeper.sh config -n openshift-gatekeeper-system
    Copy to Clipboard Toggle word wrap

    您的 Config 资源可能类似以下示例:

    apiVersion: config.gatekeeper.sh/v1alpha1
    kind: Config
    metadata:
     name: config
     namespace: "openshift-gatekeeper-system"
    spec:
     sync:
       syncOnly:
       - group: ""
         version: "v1"
         kind: "Namespace"
       - group: ""
         version: "v1"
         kind: "Pod"
    Copy to Clipboard Toggle word wrap

可选: 您可以运行以下命令来查看 Gatekeeper operator 自定义资源的描述信息:

oc explain gatekeeper.spec.audit.auditFromCache
Copy to Clipboard Toggle word wrap

5.3.4. 其他资源

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat