You Can Use OpenShift’s ImageStreams With Deployments…Here’s How

Photo by Markus Winkler on Unsplash

I recently ran into problems trying to reference an ImageStream from my Deployment on OpenShift. I had just built a new image and pushed it to an ImageStream, but when I tried to refer to it from my Deployment, I got ErrImagePull errors. However, when I tried to deploy using a DeploymentConfig with an ImageChange trigger, I didn’t have any problems.

Why was I unable to refer to my new ImageStream from my Deployment? In this post, I’ll talk about the minor change I made to fix the ErrImagePull error.

The change has to do with changing the ImageStream’s lookup policy.

Updating the ImageStream’s Lookup Policy

An ImageStream’s lookup policy, if set to local, changes Docker short name references (like my-image:latest) to the full image reference saved in the ImageStream’s metadata. This lookup policy defaults to false. For tags set under your ImageStream’s spec.tags, I found that this is actually not an issue. But images that you build and push directly to an ImageStream don’t create new tags under spec.tags. Instead, they create them under status.tags, which I found to not work with the default lookup policy.

So, if you are running into ErrImagePull errors, try setting the ImageStream’s lookup policy to match below:

apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
  name: my-image
spec:
  lookupPolicy:
    local: true
. . .

Then, in your Deployment, you can refer to the ImageStream using a short name like this:

apiVersion: apps/v1
kind: Deployment
. . .
spec:
  template:
    spec:
      containers:
        - name: my-image
          image: my-image:latest

Making this quick change to your ImageStream’s lookup policy should fix the ErrImagePull errors you’re getting when trying to refer to it from a Deployment!

Implementing Image Change Triggers in Deployments

A lesser-known fact about Deployments in OpenShift is that you can implement Image Change triggers using the image.openshift.io/triggers Deployment annotation. Here’s an example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ubi8
  annotations:
    image.openshift.io/triggers: |-
      [
        {
          "from": {
            "kind": "ImageStreamTag",
            "name": "my-image:latest"
          },
          "fieldPath": "spec.template.spec.containers[0].image"
        }
      ]
spec:
. . .

In this example, whenever you push a new image to my-image:latest, it’ll trigger a new rollout.

For more information on this annotation, check out the OpenShift documentation.

Thanks For Reading

Although the configuration is slightly different, you can refer to ImageStreams and configure Image Change triggers in Deployments just like you can with DeploymentConfigs! Hopefully, if you were running into the same ErrImagePull issues like me, this article helps you get past those errors. And, if you wanted to implement Image Change triggers in your Deployment, hopefully, you now have a clear way forward.

Austin Dewey

Austin Dewey is a DevOps engineer focused on delivering a streamlined developer experience on cloud and container technologies. Austin started his career with Red Hat’s consulting organization, where he helped drive success at many different Fortune 500 companies by automating deployments on Red Hat’s Kubernetes-based PaaS, OpenShift Container Platform. Currently, Austin works at fintech startup Prime Trust, building automation to scale financial infrastructure and support developers on Kubernetes and AWS. Austin is the author of "Learn Helm", a book focused on packaging and delivering applications to Kubernetes, and he enjoys writing about open source technologies at his blog in his free time, austindewey.com.

Leave a Reply