이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 8. Triggering updates on image stream changes


When an image stream tag is updated to point to a new image, OpenShift Container Platform can automatically take action to roll the new image out to resources that were using the old image. You configure this behavior in different ways depending on the type of resource that references the image stream tag.

8.1. OpenShift Container Platform resources

OpenShift Container Platform deployment configurations and build configurations can be automatically triggered by changes to image stream tags. The triggered action can be run using the new value of the image referenced by the updated image stream tag.

8.2. Triggering Kubernetes resources

Kubernetes resources do not have fields for triggering, unlike deployment and build configurations, which include as part of their API definition a set of fields for controlling triggers. Instead, you can use annotations in OpenShift Container Platform to request triggering.

The annotation is defined as follows:

apiVersion: v1
kind: Pod
metadata:
  annotations:
    image.openshift.io/triggers:
      [
       {
         "from": {
           "kind": "ImageStreamTag", 1
           "name": "example:latest", 2
           "namespace": "myapp" 3
         },
         "fieldPath": "spec.template.spec.containers[?(@.name==\"web\")].image", 4
         "paused": false 5
       },
      # ...
      ]
# ...
1
Required: kind is the resource to trigger from must be ImageStreamTag.
2
Required: name must be the name of an image stream tag.
3
Optional: namespace defaults to the namespace of the object.
4
Required: fieldPath is the JSON path to change. This field is limited and accepts only a JSON path expression that precisely matches a container by ID or index. For pods, the JSON path is spec.containers[?(@.name='web')].image.
5
Optional: paused is whether or not the trigger is paused, and the default value is false. Set paused to true to temporarily disable this trigger.

When one of the core Kubernetes resources contains both a pod template and this annotation, OpenShift Container Platform attempts to update the object by using the image currently associated with the image stream tag that is referenced by trigger. The update is performed against the fieldPath specified.

Examples of core Kubernetes resources that can contain both a pod template and annotation include:

  • CronJobs
  • Deployments
  • StatefulSets
  • DaemonSets
  • Jobs
  • ReplicationControllers
  • Pods

8.3. Setting the image trigger on Kubernetes resources

When adding an image trigger to deployments, you can use the oc set triggers command. For example, the sample command in this procedure adds an image change trigger to the deployment named example so that when the example:latest image stream tag is updated, the web container inside the deployment updates with the new image value. This command sets the correct image.openshift.io/triggers annotation on the deployment resource.

Procedure

  • Trigger Kubernetes resources by entering the oc set triggers command:

    $ oc set triggers deploy/example --from-image=example:latest -c web

    Example deployment with trigger annotation

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        image.openshift.io/triggers: '[{"from":{"kind":"ImageStreamTag","name":"example:latest"},"fieldPath":"spec.template.spec.containers[?(@.name==\"container\")].image"}]'
    # ...

    Unless the deployment is paused, this pod template update automatically causes a deployment to occur with the new image value.

Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.