Using image streams with Kubernetes resources

Image streams, being OKD native resources, work out of the box with all the rest of native resources available in OKD, such as builds or deployments. It is also possible to make them work with native Kubernetes resources, such as jobs, replication controllers, replica sets or Kubernetes deployments.

Enabling image streams with Kubernetes resources

When using image streams with Kubernetes resources, you can only reference image streams that reside in the same project as the resource. The image stream reference must consist of a single segment value, for example ruby:2.5, where ruby is the name of an image stream that has a tag named 2.5 and resides in the same project as the resource making the reference.

This feature can not be used in the default namespace, nor in any openshift- or kube- namespace.

There are two ways to enable image streams with Kubernetes resources:

  • Enabling image stream resolution on a specific resource. This allows only this resource to use the image stream name in the image field.

  • Enabling image stream resolution on an image stream. This allows all resources pointing to this image stream to use it in the image field.

Procedure

You can use oc set image-lookup to enable image stream resolution on a specific resource or image stream resolution on an image stream.

  1. To allow all resources to reference the image stream named mysql, enter the following command:

    1. $ oc set image-lookup mysql

    This sets the Imagestream.spec.lookupPolicy.local field to true.

    Imagestream with image lookup enabled

    1. apiVersion: v1
    2. kind: ImageStream
    3. metadata:
    4. annotations:
    5. openshift.io/display-name: mysql
    6. name: mysql
    7. namespace: myproject
    8. spec:
    9. lookupPolicy:
    10. local: true

    When enabled, the behavior is enabled for all tags within the image stream.

  2. Then you can query the image streams and see if the option is set:

    1. $ oc set image-lookup imagestream --list

You can enable image lookup on a specific resource.

  • To allow the Kubernetes deployment named mysql to use image streams, run the following command:

    1. $ oc set image-lookup deploy/mysql

    This sets the alpha.image.policy.openshift.io/resolve-names annotation on the deployment.

    Deployment with image lookup enabled

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: mysql
    5. namespace: myproject
    6. spec:
    7. replicas: 1
    8. template:
    9. metadata:
    10. annotations:
    11. alpha.image.policy.openshift.io/resolve-names: '*'
    12. spec:
    13. containers:
    14. - image: mysql:latest
    15. imagePullPolicy: Always
    16. name: mysql

You can disable image lookup.

  • To disable image lookup, pass --enabled=false:

    1. $ oc set image-lookup deploy/mysql --enabled=false