OpenShift中外置Docker Registry镜像更新未触发自动部署问题咨询
Absolutely, you can set up OpenShift to automatically trigger a deployment when your external Docker registry's image is updated. Let's walk through fixing your current configuration based on the template you shared.
What's Missing in Your Current Setup
The core issue is that your ImageStream isn't configured to regularly check for updates from the external registry. By default, OpenShift only imports the external image once when the ImageStream is created—after that, it won't automatically pull new versions unless you set up scheduled imports.
Step 1: Update the ImageStream for Scheduled Imports
Modify your ImageStream's importPolicy to enable scheduled polling of the external registry. This tells OpenShift to periodically check if the external image has been updated, and if so, sync it to the ImageStream.
Here's the adjusted ImageStream section with the necessary changes:
{ "kind": "ImageStream", "apiVersion": "image.openshift.io/v1", "metadata": { "name": "test-100", "creationTimestamp": null, "labels": {"app": "test-100"}, "annotations": {"openshift.io/generated-by": "OpenShiftNewApp"} }, "spec": { "lookupPolicy": {"local": false}, "tags": [ { "name": "latest", "annotations": {"openshift.io/imported-from": "artifactory.company.com/docker-dev-local/test/dev/test:latest"}, "from": {"kind": "DockerImage", "name": "artifactory.company.com/docker-dev-local/test/dev/test:latest"}, "generation": null, "importPolicy": { "scheduled": true, "interval": "10m" # Optional: Customize polling interval (default is 15m) }, "referencePolicy": {"type": "Local"} # Optional: Copies image to OpenShift's internal registry for better reliability } ] } }
scheduled: trueenables periodic checks for external image updates.intervallets you set how often OpenShift polls the registry (e.g.,10mfor 10 minutes; omit to use the default 15-minute interval).referencePolicy: {"type": "Local"}(optional) copies the external image to OpenShift's internal registry, which can improve deployment speed and reduce dependency on the external registry's availability.
Step 2: Refine the DeploymentConfig's Container Image Reference
In your DeploymentConfig's pod template, you're directly referencing the external registry image. While the ImageChange trigger might still work, it's better to reference the ImageStreamTag instead to ensure full alignment with the trigger:
"containers": [ { "name": "test-100", "image": "test-100:latest", # Use ImageStreamTag instead of external URL "ports": [ {"containerPort": 8080, "protocol": "TCP"}, {"containerPort": 8443, "protocol": "TCP"}, {"containerPort": 8778, "protocol": "TCP"} ], "resources": {} } ]
Your existing ImageChange trigger is correctly configured (automatic: true and pointing to test-100:latest), so once the ImageStream updates, this trigger will automatically kick off a new deployment.
Step 3: Test the Setup Manually (Optional)
To verify everything works without waiting for the scheduled interval, you can manually trigger an image import:
oc import-image test-100:latest
If the external image has been updated, this command will sync the new version to the ImageStream, which should immediately trigger a new deployment via the ImageChange trigger.
How It All Works Together
- OpenShift periodically polls the external registry (per your
intervalsetting) for updates to the image. - When a new image version is detected, it updates the
test-100:latestImageStreamTag. - The DeploymentConfig's ImageChange trigger detects the updated ImageStreamTag and automatically starts a new deployment with the latest image.
内容的提问来源于stack exchange,提问作者niklodeon

