华为云UCS
华为云UCS
- 最新动态
- 服务公告
- 产品介绍
- 计费说明
- 快速入门
-
用户指南
- UCS集群
- 容器舰队
- 集群联邦
- 镜像仓库
- 权限管理
-
策略中心
- 策略中心概述
- 策略定义与策略实例的基本概念
- 启用策略中心
- 创建和管理策略实例
- 示例:使用策略中心实现Kubernetes资源合规性治理
-
使用策略定义库
- 策略定义库概述
- k8spspvolumetypes
- k8spspallowedusers
- k8spspselinuxv2
- k8spspseccomp
- k8spspreadonlyrootfilesystem
- k8spspprocmount
- k8spspprivilegedcontainer
- k8spsphostnetworkingports
- k8spsphostnamespace
- k8spsphostfilesystem
- k8spspfsgroup
- k8spspforbiddensysctls
- k8spspflexvolumes
- k8spspcapabilities
- k8spspapparmor
- k8spspallowprivilegeescalationcontainer
- k8srequiredprobes
- k8srequiredlabels
- k8srequiredannotations
- k8sreplicalimits
- noupdateserviceaccount
- k8simagedigests
- k8sexternalips
- k8sdisallowedtags
- k8sdisallowanonymous
- k8srequiredresources
- k8scontainerratios
- k8scontainerrequests
- k8scontainerlimits
- k8sblockwildcardingress
- k8sblocknodeport
- k8sblockloadbalancer
- k8sblockendpointeditdefaultrole
- k8spspautomountserviceaccounttokenpod
- k8sallowedrepos
- 配置管理
- 服务网格
- 流量分发
- 可观测性
- 云原生服务中心
- 容器迁移
- 流水线
- 错误码
- 最佳实践
- API参考
- 常见问题
- 文档下载
- 通用参考
本文导读
链接复制成功!
k8srequiredannotations
基本信息
- 策略类型:合规
- 推荐级别:L1
- 生效资源类型:*
- 参数:
annotations: 键值对数组,key/ allowedRegex key: a8r.io/owner # Matches email address or github user allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$
作用
要求资源包含指定的annotations,其值与提供的正则表达式匹配。
策略实例示例
以下策略实例展示了策略定义生效的资源类型,parameters中指定了提示信息message以及annotations的约束定义。
apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sRequiredAnnotations metadata: name: all-must-have-certain-set-of-annotations spec: match: kinds: - apiGroups: [""] kinds: ["Service"] parameters: message: "All services must have a `a8r.io/owner` and `a8r.io/runbook` annotations." annotations: - key: a8r.io/owner # Matches email address or github user allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$ - key: a8r.io/runbook # Matches urls including or not http/https allowedRegex: ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$
符合策略实例的资源定义
示例中的annotations符合策略实例。
apiVersion: v1 kind: Service metadata: name: allowed-service annotations: a8r.io/owner: "dev-team-alfa@contoso.com" a8r.io/runbook: "https://confluence.contoso.com/dev-team-alfa/runbooks" spec: ports: - name: http port: 80 targetPort: 8080 selector: app: foo
不符合策略实例的资源定义
示例中的annotations没有配置值,不符合策略实例。
apiVersion: v1 kind: Service metadata: name: disallowed-service spec: ports: - name: http port: 80 targetPort: 8080 selector: app: foo
父主题: 使用策略定义库