Chapter 8. Caching images for faster workspace start

To improve the start time performance of CodeReady Workspaces workspaces, use the Image Puller. The Image Puller is an additional OpenShift deployment. It creates a DaemonSet downloading and running the relevant container images on each node. These images are already available when a CodeReady Workspaces workspace starts.

The Image Puller provides the following parameters for configuration.

Table 8.1. Image Puller parameters

ParameterUsageDefault

CACHING_INTERVAL_HOURS

DaemonSets health checks interval in hours

"1"

CACHING_MEMORY_REQUEST

The memory request for each cached image when the puller is running. See Section 8.2, “Defining the memory parameters for the Image Puller”.

10Mi

CACHING_MEMORY_LIMIT

The memory limit for each cached image when the puller is running. See Section 8.2, “Defining the memory parameters for the Image Puller”.

20Mi

CACHING_CPU_REQUEST

The processor request for each cached image when the puller is running

.05 or 50 millicores

CACHING_CPU_LIMIT

The processor limit for each cached image when the puller is running

.2 or 200 millicores

DAEMONSET_NAME

Name of DaemonSet to create

kubernetes-image-puller

DEPLOYMENT_NAME

Name of the Deployment to create

kubernetes-image-puller

NAMESPACE

OpenShift project containing DaemonSet to create

k8s-image-puller

IMAGES

Semicolon separated list of images to pull, in the format <name1>=<image1>;<name2>=<image2> See Section 8.1, “Defining the list of images to pull”.

 

NODE_SELECTOR

Node selector to apply to the Pods created by the DaemonSet

'{}'

8.1. Defining the list of images to pull

Prerequisites

Procedure

  1. Get the list of relevant container images.

    Example 8.1. Getting the list of all relevant images for CodeReady Workspaces

  2. Exclude from the list the container images not containing the sleep command.

    Example 8.2. Images incompatibles with {image-puller-short}, missing the sleep command

    • FROM scratch images.
    • che-machine-exec
  3. Exclude from the list the container images mounting volumes in Dockerfile.

Additional resources

8.2. Defining the memory parameters for the Image Puller

Define the memory requests and limits parameters to ensure pulled containers and the platform have enough memory to run.

Procedure

  1. To define the minimal value for CACHING_MEMORY_REQUEST or CACHING_MEMORY_LIMIT, consider the necessary amount of memory required to run each of the container images to pull.
  2. To define the maximal value for CACHING_MEMORY_REQUEST or CACHING_MEMORY_LIMIT, consider the total memory allocated to the DaemonSet Pods in the cluster:

    (memory limit) * (number of images) * (number of nodes in the cluster)

    Pulling 5 images on 20 nodes, with a container memory limit of 20Mi requires 2000Mi of memory.

8.3. Installing Image Puller using the CodeReady Workspaces Operator

This section describes how to use the CodeReady Workspaces Operator to install the Image Puller. This is a Community-supported technology preview feature.

Prerequisites

Procedure

  1. Edit the CheCluster Custom Resource and set .spec.imagePuller.enable to true

    Example 8.3. Enabling Image Puller in the CheCluster Custom Resource

    apiVersion: org.eclipse.che/v1
    kind: CheCluster
    metadata:
      name: codeready-workspaces
    spec:
      # ...
      imagePuller:
        enable: true
    Uninstalling Image Puller using CodeReady Workspaces Operator
    • Edit the CheCluster Custom Resource and set .spec.imagePuller.enable to false.
  2. Edit the CheCluster Custom Resource and set the .spec.imagePuller.spec to configure the optional Image Puller parameters for the CodeReady Workspaces Operator.

    Example 8.4. Configuring Image Puller in the CheCluster Custom Resource

    apiVersion: org.eclipse.che/v1
    kind: CheCluster
    metadata:
      name: codeready-workspaces
    spec:
      ...
      imagePuller:
        enable: true
        spec:
            configMapName: <kubernetes-image-puller>
            daemonsetName: <kubernetes-image-puller>
            deploymentName: <kubernetes-image-puller>
            images: <{image-puller-images}>

Verification steps

  1. OpenShift creates a {image-puller-operator-id} Subscription.
  2. The eclipse-che namespace contains a community supported Kubernetes Image Puller Operator ClusterServiceVersion:

    $ oc get clusterserviceversions
  3. The eclipse-che namespace contains these deployments: kubernetes-image-puller and {image-puller-deployment-id}.

    $ oc get deployments
  4. The community supported Kubernetes Image Puller Operator creates a KubernetesImagePuller Custom Resource:

    $ oc get kubernetesimagepullers

8.4. Installing Image Puller on OpenShift 4 using OperatorHub

This procedure describes how to install the community supported Kubernetes Image Puller Operator on OpenShift 4 using the Operator.

Procedure

  1. To create an OpenShift project <kubernetes-image-puller> to host the Image Puller, open the OpenShift web console, navigate to the HomeProjects section and click Create Project.
  2. Specify the project details:

    • Name: <kubernetes-image-puller>
    • Display Name: <Image Puller>
    • Description: <Kubernetes Image Puller>
  3. Navigate to OperatorsOperatorHub.
  4. Use the Filter by keyword box to search for community supported Kubernetes Image Puller Operator. Click the community supported Kubernetes Image Puller Operator.
  5. Read the description of the Operator. Click ContinueInstall.
  6. Select A specific project on the cluster for the Installation Mode. In the drop-down find the OpenShift project <kubernetes-image-puller>. Click Subscribe.
  7. Wait for the community supported Kubernetes Image Puller Operator to install. Click the KubernetesImagePullerCreate instance.
  8. In a redirected window with a YAML editor, make modifications to the KubernetesImagePuller Custom Resource and click Create.
  9. Navigate to the Workloads and Pods menu in the <kubernetes-image-puller> OpenShift project. Verify that the Image Puller is available.

8.5. Installing Image Puller on OpenShift using OpenShift templates

This procedure describes how to install the Kubernetes Image Puller on OpenShift using OpenShift templates.

Procedure

  1. Clone the Image Puller repository and get in the directory containing the OpenShift templates:

    $ git clone https://github.com/che-incubator/kubernetes-image-puller
    $ cd kubernetes-image-puller/deploy/openshift
  2. Configure the app.yaml, configmap.yaml and serviceaccount.yaml OpenShift templates using following parameters:

    Table 8.2. Image Puller OpenShift templates parameters in app.yaml

    ValueUsageDefault

    DEPLOYMENT_NAME

    The value of DEPLOYMENT_NAME in the ConfigMap

    kubernetes-image-puller

    IMAGE

    Image used for the kubernetes-image-puller deployment

    registry.redhat.io/codeready-workspaces/imagepuller-rhel8:2.8

    IMAGE_TAG

    The image tag to pull

    latest

    SERVICEACCOUNT_NAME

    The name of the ServiceAccount created and used by the deployment

    {image-puller-serviceaccount-name}

    Table 8.3. Image Puller OpenShift templates parameters in configmap.yaml

    ValueUsageDefault

    CACHING_CPU_LIMIT

    The value of CACHING_CPU_LIMIT in the ConfigMap

    .2

    CACHING_CPU_REQUEST

    The value of CACHING_CPU_REQUEST in the ConfigMap

    .05

    CACHING_INTERVAL_HOURS

    The value of CACHING_INTERVAL_HOURS in the ConfigMap

    "1"

    CACHING_MEMORY_LIMIT

    The value of CACHING_MEMORY_LIMIT in the ConfigMap

    "20Mi"`

    CACHING_MEMORY_REQUEST

    The value of CACHING_MEMORY_REQUEST in the ConfigMap

    "10Mi"

    DAEMONSET_NAME

    The value of DAEMONSET_NAME in the ConfigMap

    kubernetes-image-puller

    DEPLOYMENT_NAME

    The value of DEPLOYMENT_NAME in the ConfigMap

    kubernetes-image-puller

    IMAGES

    The value of IMAGES in the ConfigMap

    {image-puller-images}

    NODE_SELECTOR

    The value of NODE_SELECTOR in the ConfigMap

    "{}"

    Table 8.4. Image Puller OpenShift templates parameters in serviceaccount.yaml

    ValueUsageDefault

    SERVICEACCOUNT_NAME

    The name of the ServiceAccount created and used by the deployment

    {image-puller-serviceaccount-name}

  3. Create an OpenShift project to host the Image Puller:

    $ oc new-project <kubernetes-image-puller>
  4. Process and apply the templates to install the puller:

    $ oc process -f serviceaccount.yaml | oc apply -f -
    $ oc process -f configmap.yaml | oc apply -f -
    $ oc process -f app.yaml | oc apply -f -

Verification steps

  1. Verify the existence of a <kubernetes-image-puller> deployment and a <kubernetes-image-puller> DaemonSet. The DaemonSet needs to have a Pod for each node in the cluster:

    $ oc get deployment,daemonset,pod --namespace <kubernetes-image-puller>
  2. Verify the values of the <kubernetes-image-puller> ConfigMap.

    $ oc get configmap <kubernetes-image-puller> --output yaml