Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

13.9.2. Kubernetes 리소스

API 정의의 일부로 를 포함하는 DeploymentConfigs 및 BuildConfigs와 달리 트리거 제어를 위한 필드 집합을 포함하는 Kubernetes 리소스에 트리거를 위한 필드가 없습니다. 대신 OpenShift Container Platform에서는 주석을 사용하여 사용자가 트리거를 요청할 수 있습니다. 주석은 다음과 같이 정의됩니다.

Key: image.openshift.io/triggers
Value: array of triggers, where each item has the schema:
[
 {
   "from" :{
     "kind": "ImageStreamTag", // required, the resource to trigger from, must be ImageStreamTag
     "name": "example:latest", // required, the name of an ImageStreamTag
     "namespace": "myapp",     // optional, defaults to the namespace of the object
   },
   // required, JSON path to change
   // Note that this field is limited today, and only accepts a very specific set
   // of inputs (a JSON path expression that precisely matches a container by ID or index).
   // For pods this would be "spec.containers[?(@.name='web')].image".
   "fieldPath": "spec.template.spec.containers[?(@.name='web')].image",
   // optional, set to true to temporarily disable this trigger.
   "paused": "false"
 },
 ...
]

OpenShift Container Platform에서 Pod 템플릿(예: CronJobs, Deployments, StatefulSets, StatefulSets, DaemonSets, Jobs, ReplicaSets, ReplicationControllers, Pod) 및 이 주석을 모두 포함하는 핵심 Kubernetes 리소스 중 하나를 확인하고 트리거에서 참조하는 ImageStreamTag와 현재 연결된 이미지를 사용하여 오브젝트를 업데이트 시도합니다. 업데이트는 지정된 fieldPath에 대해 수행됩니다.

다음 예에서 example:latest 이미지 스트림 태그가 업데이트되면 트리거가 실행됩니다. 실행 시 컨테이너에 대한 오브젝트의 Pod 템플릿 이미지 참조가 새 이미지 값으로 업데이트됩니다. pod 템플릿이 Deployment 정의에 속하는 경우 pod 템플릿에 대한 변경으로 배포가 자동으로 트리거되어 새 이미지를 효과적으로 롤아웃합니다.

image.openshift.io/triggers=[{"from":{"kind":"ImageStreamTag","name":"example:latest"},"fieldPath":"spec.template.spec.containers[?(@.name='web')].image"}]

배포에 이미지 트리거를 추가할 때 oc set triggers 명령을 사용할 수도 있습니다. 예를 들어 다음 명령은 example:latest 이미지 스트림 태그가 업데이트되면 배포 내의 컨테이너가 새 이미지 값으로 업데이트되도록 이미지 변경 트리거를 예제라는 배포에 추가합니다.

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

배포가 일시 중지되지 않으면 이 pod 템플릿 업데이트로 인해 새 이미지 값으로 배포가 자동으로 수행됩니다.