7.3.6. ImagePolicy 准入插件
准入插件截获对 API 的请求,并根据配置的规则执行检查,并根据这些规则允许或拒绝某些操作。OpenShift Container Platform 可以使用 ImagePolicy
准入插件限制环境中运行的镜像:
- 镜像源:可以用于拉取镜像的 registry
- 镜像解析:强制 pod 使用不可变摘要运行,以确保因为重新标记而不会改变镜像
- 容器镜像标签限制:强制镜像具有或没有特定标签
- 镜像注解限制:强制集成容器 registry 中的镜像具有或没有特定注解
警告
ImagePolicy
准入插件目前被视为 beta。
流程
如果启用了
ImagePolicy
插件,则需要修改它,以允许在每个 master 节点上修改/etc/origin/master/master-config.yaml
文件来允许使用外部 registry:admissionConfig: pluginConfig: openshift.io/ImagePolicy: configuration: kind: ImagePolicyConfig apiVersion: v1 executionRules: - name: allow-images-from-other-registries onResources: - resource: pods - resource: builds matchRegistries: - docker.io - <my.registry.example.com> - registry.redhat.io
注意启用
ImagePolicy
要求用户在部署应用程序时指定 registry,如oc new-app docker.io/kubernetes/guestbook
替代oc new-app kubernetes/guestbook
,否则会失败。要在安装时启用准入插件,
openshift_master_admission_plugin_config
变量可用于json
格式的字符串,包括所有pluginConfig
配置:openshift_master_admission_plugin_config={"openshift.io/ImagePolicy":{"configuration":{"kind":"ImagePolicyConfig","apiVersion":"v1","executionRules":[{"name":"allow-images-from-other-registries","onResources":[{"resource":"pods"},{"resource":"builds"}],"matchRegistries":["docker.io","*my.registry.example.com*","registry.redhat.io"]}]}}}