This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.13.8.2. Kubernetes 资源
与 DeploymentConfig 和 BuildConfigs 不同,它包括作为 API 定义一组字段来控制触发器的字段,Kubernetes 资源没有用于触发的字段。OpenShift Container Platform 使用注解来允许用户请求触发器。该注解定义如下:
当 OpenShift Container Platform 看到包含 pod 模板的核心 Kubernetes 资源之一时(即,只有 CronJob、Deployment、StatefulSets、DaemonSets、Job、ReplicaSet、ReplicaSets、ReplicationController 和 Pod)以及此注解,它会尝试使用当前与触发器引用的 ImageStreamTag 关联的镜像更新对象。更新针对指定的 fieldPath
进行。
在以下示例中,当 example:latest
镜像流标签被更新时,触发器会触发。触发后,web
容器的 pod 模板镜像引用会使用新的镜像值更新。如果 pod 模板是 Deployment 定义的一部分,则对 pod 模板的更改会自动触发部署,从而有效地推出新镜像。
image.openshift.io/triggers=[{"from":{"kind":"ImageStreamTag","name":"example:latest"},"fieldPath":"spec.template.spec.containers[?(@.name='web')].image"}]
image.openshift.io/triggers=[{"from":{"kind":"ImageStreamTag","name":"example:latest"},"fieldPath":"spec.template.spec.containers[?(@.name='web')].image"}]
在 Deployment 中添加镜像触发器时,也可以使用 oc set triggers
命令。例如,以下命令将镜像更改触发器添加到名为 example
的 Deployment 中,以便在更新 example:latest
镜像流标签时,部署中的 web
容器使用新镜像值更新:
oc set triggers deploy/example --from-image=example:latest -c web
$ oc set triggers deploy/example --from-image=example:latest -c web
除非 Deployment 已暂停,否则此 pod 模板更新会自动导致使用新镜像值进行部署。