OpenShift Use Image Registry Recipe

  1. Ensure you're logged in with oc
  2. By default, a registry does not have an external route; if this is required, the registry must be exposed:
    1. Follow the instructions to expose the registry for your cluster version.
    2. Then, allow a user to push to the registry
      oc policy add-role-to-user registry-editor $(oc whoami | sed 's/://g')
    3. Finally, allow a user to pull from the registry:
      oc policy add-role-to-user registry-viewer $(oc whoami | sed 's/://g')
  3. Get the registry route and save to a variable:
    REGISTRY=$(oc get route default-route -n openshift-image-registry --template='{{ .spec.host }}')
  4. Make sure it looks okay:
    echo ${REGISTRY}
  5. Log into the registry:
    podman login -u $(oc whoami | sed 's/://g') -p $(oc whoami -t) ${REGISTRY}
    • For self-signed certificates, add --tls-verify=false to podman login
  6. After you've built some local container, list that image:
    $ podman images
    REPOSITORY                            TAG         IMAGE ID      CREATED            SIZE
    localhost/perfcontainer               latest      b967130f1c6c  About an hour ago  630 MB
  7. Tag the image for pushing to your registry (replace $IMAGEID, $PROJECT, and $IMAGE)
    podman tag $IMAGEID $REGISTRY/$PROJECT/$IMAGE
  8. Push the image to your registry:
    podman push $REGISTRY/$PROJECT/$IMAGE
  9. List the image stream within the cluster (an image stream is an indirect pointer to an image that allows updating the pointer without re-building):
    oc get imagestreams $IMAGE -n $PROJECT
  10. The image may now be referenced internally with image-registry.openshift-image-registry.svc:5000/$PROJECT/$IMAGE

Common issues

  1. Registry does not get exposed: oc get route default-route -n openshift-image-registry is returning Error from server (NotFound): routes.route.openshift.io "default-route" not found
    1. Check if oc get configs.imageregistry.operator.openshift.io/cluster -o jsonpath='{.spec.managementState}' is set to Removed and if so, set it to Managed:
      oc patch configs.imageregistry.operator.openshift.io/cluster --patch '{"spec":{"managementState":"Managed"}}' --type=merge
    2. If oc get configs.imageregistry.operator.openshift.io/cluster -o yaml shows Error: storage backend not configured, then configure some storage (e.g. PVC), or, for testing:
      oc patch configs.imageregistry.operator.openshift.io/cluster --patch '{"spec":{"storage":{"emptyDir":{}}}}' --type=merge
    3. Example command combining all the common issues:
      oc patch configs.imageregistry.operator.openshift.io/cluster --patch '{"spec":{"defaultRoute":true,"managementState":"Managed","storage":{"emptyDir":{}}}}' --type=merge