Skip to content

Latest commit

 

History

History
152 lines (132 loc) · 7.75 KB

api-custom-image-creating.adoc

File metadata and controls

152 lines (132 loc) · 7.75 KB

Creating a custom image by using the ImageStream CRD

You can create a custom image by using the ImageStream Custom Resource Definition (CRD).

In the following procedure, you configure an ImageStream CRD and use it to create the ImageStream Custom Resource (CR) that defines the custom image. The ImageStream CR provides a URL for the custom image, which you need when you want to use the custom image to configure a workbench.

Note: The custom image that you create also becomes available in the {productname-short} dashboard so that your data scientist users can select it when they create a workbench.

Prerequisites
  • You have cluster administrator privileges for your {openshift-platform} cluster.

  • You have installed the OpenShift command-line interface (CLI). See Installing the OpenShift CLI.

Procedure
  1. In a terminal window, if you are not already logged in to your {openshift-platform} cluster as a cluster administrator, log in as shown in the following example:

    oc login <openshift_cluster_url> -u <admin_username> -p <password>
  2. Define the ImageStream CRD.

    1. Create a YAML manifest file named notebook-image-stream.yaml.

    2. Copy the following configuration and paste it in the notebook-image-stream.yaml file:

      Example ImageStream
      kind: ImageStream
      apiVersion: image.openshift.io/v1
      metadata:
        annotations:
          opendatahub.io/notebook-image-desc: A custom Jupyter Notebook image # (1)
          opendatahub.io/notebook-image-name: My Custom Notebook # (2)
        name: my-custom-notebook
        namespace: redhat-ods-applications # (3)
        labels: # (4)
          app.kubernetes.io/created-by: byon
          opendatahub.io/dashboard: 'true'
          opendatahub.io/notebook-image: 'true'
          opendatahub.io/component: 'true'
          platform.opendatahub.io/part-of: 'workbenches'
          app.kubernetes.io/part-of: 'workbenches'
      spec:
        lookupPolicy:
          local: true
        tags:
          - name: '1.0' # (5)
            annotations: # (6)
              opendatahub.io/notebook-python-dependencies: '[{"name":"PyTorch","version":"2.2"}]' # (7)
              opendatahub.io/notebook-software: '[{"name":"Python","version":"v3.11"}]' # (8)
              opendatahub.io/workbench-image-recommended: 'true' # (9)
            from:
              kind: DockerImage
              name: 'image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/my-custom-workbench:latest' # (10)
            importPolicy:
            importPolicy:
              importMode: Legacy
            referencePolicy:
              type: Source

      The example YAML file includes the following information:

      1. A description of the image.

      2. The image name that is displayed in the drop down menu when a user creates a workbench in the {productname-short} dashboard.

      3. The redhat-ods-applications namespace is the default namespace in which the ImageStream CR is created.

      4. The labels that are required if you want the image to appear in the {productname-short} dashboard. The app.kubernetes.io/created-by: byon label identifies the origination of the image object.

      5. Annotations that are required if you want to make the image available in the {productname-short} dashboard.

      6. The version for the image. You can configure multiple versions for the same image. For this example, the version is 1.0.

      7. An annotation that gives the user information about the Python packages and versions that are pre-installed in the image.

      8. An annotation that specifies information such as the Python version, Jupyter version, or CUDA version.

      9. An annotation that specifies whether the ImageStream version is the default version of the image. Set this field to 'true' if the ImageStream version is the default. Otherwise, set it to 'false'. You must specify the opendatahub.io/workbench-image-recommended annotation field if there are multiple versions of the image with different configurations. If you have only one version of the image, set the field to 'true'.

      10. The image registry URL to store the image stream. Store the image stream in an image registry outside of the cluster where {productname-short} is installed.

  3. To create the ImageStream CR, run the following command, where the ImageStream CRD YAML manifest file name is notebook-image-stream.yaml:

    oc create -f notebook-image-stream.yaml
Verification
  1. To verify that the ImageStream was successfully created, run the following command, where the name of the ImageStream is my-custom-notebook:

    oc describe imagestream my-custom-notebook -n redhat-ods-applications

    You should see output similar to the following example:

    Example output
    Name:                   my-custom-notebook
    Namespace:              redhat-ods-applications
    Created:                6 minutes ago
    Labels:                 app.kubernetes.io/created-by=byon
                            opendatahub.io/dashboard=true
                            opendatahub.io/notebook-image=true
    Annotations:            kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"image.openshift.io/v1","kind":"ImageStream","metadata":{"annotations":{"opendatahub.io/notebook-image-desc":"A custom Jupyter Notebook image","opendatahub.io/notebook-image-name":"My Custom Notebook"},"labels":{"app.kubernetes.io/created-by":"byon","opendatahub.io/dashboard":"true","opendatahub.io/notebook-image":"true"},"name":"my-custom-notebook","namespace":"redhat-ods-applications"},"spec":{"lookupPolicy":{"local":true},"tags":[{"annotations":{"opendatahub.io/notebook-python-dependencies":"[{\"name\":\"PyTorch\",\"version\":\"2.2\"}]","opendatahub.io/notebook-software":"[{\"name\":\"Python\",\"version\":\"v3.11\"}]","opendatahub.io/workbench-image-recommended":"true"},"from":{"kind":"DockerImage","name":"quay.io/modh/rocm-notebooks@sha256:199367d2946fc8....8279b10150020af22db"},"importPolicy":{"importMode":"Legacy"},"name":"1.0","referencePolicy":{"type":"Source"}}]}}
    
                            opendatahub.io/notebook-image-desc=A custom Jupyter Notebook image
                            opendatahub.io/notebook-image-name=My Custom Notebook
                            openshift.io/image.dockerRepositoryCheck=2025-03-10T11:02:44Z
    Image Repository:       image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/my-custom-notebook
    Image Lookup:           local=true
    Unique Images:          1
    Tags:                   1
    
    1.0
      tagged from quay.io/modh/rocm-notebooks@sha256:199367d2946..b411433ffbb5f0988279b10150020af22db
    
      * quay.io/modh/rocm-notebooks@sha256:199367d2946fc8427....1433ffbb5f0988279b10150020af22db
          6 minutes ago
  2. To determine the URL for your custom image so that you can reference it when you create a workbench:

    1. Make a note of the values for the Image Repository and the Tags fields from the ImageStream output.

      In the following example, the Image Repository value is image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/my-custom-notebook and the Tags value is 1.0:

      Example output
      ....
      Image Repository:       image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/my-custom-notebook
      Image Lookup:           local=true
      Unique Images:          1
      Tags:                   1
      1.0
        tagged from quay.io/modh/rocm-notebooks@sha256:199367d2946..b411433ffbb5f0988279b10150020af22db
      ....
    2. Create a fully-formed image URL by combining the values for the Image Repository and the Tags fields, as shown in the following example:

      image-registry.openshift-image-registry.svc:5000/redhat-ods-applications/my-custom-notebook:1.0