Updating a cluster in a disconnected environment by using the CLI

Use the following procedures to update a cluster in a disconnected environment without access to the OpenShift Update Service.

Prerequisites

  • You must have the oc command-line interface (CLI) tool installed.

  • You must provision a local container image registry with the container images for your update, as described in Mirroring OKD images.

  • You must have access to the cluster as a user with admin privileges. See Using RBAC to define and apply permissions.

  • You must have a recent etcd backup in case your update fails and you must restore your cluster to a previous state.

  • You must ensure that all machine config pools (MCPs) are running and not paused. Nodes associated with a paused MCP are skipped during the update process. You can pause the MCPs if you are performing a canary rollout update strategy.

  • If your cluster uses manually maintained credentials, update the cloud provider resources for the new release. For more information, including how to determine if this is a requirement for your cluster, see Preparing to update a cluster with manually maintained credentials.

  • If you run an Operator or you have configured any application with the pod disruption budget, you might experience an interruption during the update process. If minAvailable is set to 1 in PodDisruptionBudget, the nodes are drained to apply pending machine configs which might block the eviction process. If several nodes are rebooted, all the pods might run on only one node, and the PodDisruptionBudget field can prevent the node drain.

If you run an Operator or you have configured any application with the pod disruption budget, you might experience an interruption during the update process. If minAvailable is set to 1 in PodDisruptionBudget, the nodes are drained to apply pending machine configs which might block the eviction process. If several nodes are rebooted, all the pods might run on only one node, and the PodDisruptionBudget field can prevent the node drain.

Pausing a MachineHealthCheck resource

During the update process, nodes in the cluster might become temporarily unavailable. In the case of worker nodes, the machine health check might identify such nodes as unhealthy and reboot them. To avoid rebooting such nodes, pause all the MachineHealthCheck resources before updating the cluster.

Prerequisites

  • Install the OpenShift CLI (oc).

Procedure

  1. To list all the available MachineHealthCheck resources that you want to pause, run the following command:

    1. $ oc get machinehealthcheck -n openshift-machine-api
  2. To pause the machine health checks, add the cluster.x-k8s.io/paused="" annotation to the MachineHealthCheck resource. Run the following command:

    1. $ oc -n openshift-machine-api annotate mhc <mhc-name> cluster.x-k8s.io/paused=""

    The annotated MachineHealthCheck resource resembles the following YAML file:

    1. apiVersion: machine.openshift.io/v1beta1
    2. kind: MachineHealthCheck
    3. metadata:
    4. name: example
    5. namespace: openshift-machine-api
    6. annotations:
    7. cluster.x-k8s.io/paused: ""
    8. spec:
    9. selector:
    10. matchLabels:
    11. role: worker
    12. unhealthyConditions:
    13. - type: "Ready"
    14. status: "Unknown"
    15. timeout: "300s"
    16. - type: "Ready"
    17. status: "False"
    18. timeout: "300s"
    19. maxUnhealthy: "40%"
    20. status:
    21. currentHealthy: 5
    22. expectedMachines: 5

    Resume the machine health checks after updating the cluster. To resume the check, remove the pause annotation from the MachineHealthCheck resource by running the following command:

    1. $ oc -n openshift-machine-api annotate mhc <mhc-name> cluster.x-k8s.io/paused-

Retrieving a release image digest

In order to update a cluster in a disconnected environment using the oc adm upgrade command with the --to-image option, you must reference the sha256 digest that corresponds to your targeted release image.

Procedure

  1. Run the following command on a device that is connected to the internet:

    1. $ oc adm release info -o 'jsonpath={.digest}{"\n"}' quay.io/openshift-release-dev/ocp-release:${OCP_RELEASE_VERSION}-${ARCHITECTURE}

    For {OCP_RELEASE_VERSION}, specify the version of OKD to which you want to update, such as 4.10.16.

    For {ARCHITECTURE}, specify the architecture of the cluster, such as x86_64, aarch64, s390x, or ppc64le.

    Example output

    1. sha256:a8bfba3b6dddd1a2fbbead7dac65fe4fb8335089e4e7cae327f3bad334add31d
  2. Copy the sha256 digest for use when updating your cluster.

Updating the disconnected cluster

Update the disconnected cluster to the OKD version that you downloaded the release images for.

If you have a local OpenShift Update Service, you can update by using the connected web console or CLI instructions instead of this procedure.

Prerequisites

  • You mirrored the images for the new release to your registry.

  • You applied the release image signature ConfigMap for the new release to your cluster.

    The release image signature config map allows the Cluster Version Operator (CVO) to ensure the integrity of release images by verifying that the actual image signatures match the expected signatures.

  • You obtained the sha256 digest for your targeted release image.

  • You installed the OpenShift CLI (oc).

  • You paused all MachineHealthCheck resources.

Procedure

  • Update the cluster:

    1. $ oc adm upgrade --allow-explicit-upgrade --to-image <defined_registry>/<defined_repository>@<digest>

    Where:

    <defined_registry>

    Specifies the name of the mirror registry you mirrored your images to.

    <defined_repository>

    Specifies the name of the image repository you want to use on the mirror registry.

    <digest>

    Specifies the sha256 digest for the targeted release image, for example, sha256:81154f5c03294534e1eaf0319bef7a601134f891689ccede5d705ef659aa8c92.

    • See “Mirroring OKD images” to review how your mirror registry and repository names are defined.

    • If you used an ImageContentSourcePolicy or ImageDigestMirrorSet, you can use the canonical registry and repository names instead of the names you defined. The canonical registry name is quay.io and the canonical repository name is openshift-release-dev/ocp-release.

    • You can only configure global pull secrets for clusters that have an ImageContentSourcePolicy object. You cannot add a pull secret to a project.

Additional resources

Configuring image registry repository mirroring

Setting up container registry repository mirroring enables you to perform the following tasks:

  • Configure your OKD cluster to redirect requests to pull images from a repository on a source image registry and have it resolved by a repository on a mirrored image registry.

  • Identify multiple mirrored repositories for each target repository, to make sure that if one mirror is down, another can be used.

Repository mirroring in OKD includes the following attributes:

  • Image pulls are resilient to registry downtimes.

  • Clusters in disconnected environments can pull images from critical locations, such as quay.io, and have registries behind a company firewall provide the requested images.

  • A particular order of registries is tried when an image pull request is made, with the permanent registry typically being the last one tried.

  • The mirror information you enter is added to the /etc/containers/registries.conf file on every node in the OKD cluster.

  • When a node makes a request for an image from the source repository, it tries each mirrored repository in turn until it finds the requested content. If all mirrors fail, the cluster tries the source repository. If successful, the image is pulled to the node.

Setting up repository mirroring can be done in the following ways:

  • At OKD installation:

    By pulling container images needed by OKD and then bringing those images behind your company’s firewall, you can install OKD into a datacenter that is in a disconnected environment.

  • After OKD installation:

    If you did not configure mirroring during OKD installation, you can do so postinstallation by using one of the following custom resource (CR) objects:

    • ImageDigestMirrorSet. This CR allows you to pull images from a mirrored registry by using digest specifications.

    • ImageTagMirrorSet. This CR allows you to pull images from a mirrored registry by using image tags.

    Using an ImageContentSourcePolicy (ICSP) object to configure repository mirroring is a deprecated feature. Deprecated functionality is still included in OKD and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments. If you have existing YAML files that you used to create ImageContentSourcePolicy objects, you can use the oc adm migrate icsp command to convert those files to an ImageDigestMirrorSet YAML file. For more information, see “Converting ImageContentSourcePolicy (ICSP) files for image registry repository mirroring” in the following section.

Both of these custom resource objects identify the following information:

  • The source of the container image repository you want to mirror.

  • A separate entry for each mirror repository you want to offer the content requested from the source repository.

If your cluster uses an ImageDigestMirrorSet or ImageTagMirrorSet object to configure repository mirroring, you can use only global pull secrets for mirrored registries. You cannot add a pull secret to a project.

The following procedure creates a postinstallation mirror configuration, where you create an ImageDigestMirrorSet object.

Prerequisites

  • Access to the cluster as a user with the cluster-admin role.

  • Ensure that there are no ImageContentSourcePolicy objects on your cluster. For example, you can use the following command:

    1. $ oc get ImageContentSourcePolicy

    Example output

    1. No resources found

Procedure

  1. Configure mirrored repositories, by either:

    • Setting up a mirrored repository with Red Hat Quay, as described in Red Hat Quay Repository Mirroring. Using Red Hat Quay allows you to copy images from one repository to another and also automatically sync those repositories repeatedly over time.

    • Using a tool such as skopeo to copy images manually from the source directory to the mirrored repository.

      For example, after installing the skopeo RPM package on a Red Hat Enterprise Linux (RHEL) 7 or RHEL 8 system, use the skopeo command as shown in this example:

      1. $ skopeo copy \
      2. docker://registry.access.redhat.com/ubi9/ubi-minimal:latest@sha256:5cf... \
      3. docker://example.io/example/ubi-minimal

      In this example, you have a container image registry that is named example.io with an image repository named example to which you want to copy the ubi9/ubi-minimal image from registry.access.redhat.com. After you create the registry, you can configure your OKD cluster to redirect requests made of the source repository to the mirrored repository.

  2. Log in to your OKD cluster.

  3. Create an ImageDigestMirrorSet or ImageTagMirrorSet CR, as needed, replacing the source and mirrors with your own registry and repository pairs and images:

    1. apiVersion: config.openshift.io/v1 (1)
    2. kind: ImageDigestMirrorSet (2)
    3. metadata:
    4. name: ubi9repo
    5. spec:
    6. imageDigestMirrors: (3)
    7. - mirrors:
    8. - example.io/example/ubi-minimal (4)
    9. - example.com/example/ubi-minimal (5)
    10. source: registry.access.redhat.com/ubi9/ubi-minimal (6)
    11. mirrorSourcePolicy: AllowContactingSource (7)
    12. - mirrors:
    13. - mirror.example.com/redhat
    14. source: registry.redhat.io/openshift4 (8)
    15. mirrorSourcePolicy: AllowContactingSource
    16. - mirrors:
    17. - mirror.example.com
    18. source: registry.redhat.io (9)
    19. mirrorSourcePolicy: AllowContactingSource
    20. - mirrors:
    21. - mirror.example.net/image
    22. source: registry.example.com/example/myimage (10)
    23. mirrorSourcePolicy: AllowContactingSource
    24. - mirrors:
    25. - mirror.example.net
    26. source: registry.example.com/example (11)
    27. mirrorSourcePolicy: AllowContactingSource
    28. - mirrors:
    29. - mirror.example.net/registry-example-com
    30. source: registry.example.com (12)
    31. mirrorSourcePolicy: AllowContactingSource
    1Indicates the API to use with this CR. This must be config.openshift.io/v1.
    2Indicates the kind of object according to the pull type:
    • ImageDigestMirrorSet: Pulls a digest reference image.

    • ImageTagMirrorSet: Pulls a tag reference image.

    3Indicates the type of image pull method, either:
    • imageDigestMirrors: Use for an ImageDigestMirrorSet CR.

    • imageTagMirrors: Use for an ImageTagMirrorSet CR.

    4Indicates the name of the mirrored image registry and repository.
    5Optional: Indicates a secondary mirror repository for each target repository. If one mirror is down, the target repository can use another mirror.
    6Indicates the registry and repository source, which is the repository that is referred to in image pull specifications.
    7Optional: Indicates the fallback policy if the image pull fails:
    • AllowContactingSource: Allows continued attempts to pull the image from the source repository. This is the default.

    • NeverContactSource: Prevents continued attempts to pull the image from the source repository.

    8Optional: Indicates a namespace inside a registry, which allows you to use any image in that namespace. If you use a registry domain as a source, the object is applied to all repositories from the registry.
    9Optional: Indicates a registry, which allows you to use any image in that registry. If you specify a registry name, the object is applied to all repositories from a source registry to a mirror registry.
    10Pulls the image registry.example.com/example/myimage@sha256:…​ from the mirror mirror.example.net/image@sha256:...
    11Pulls the image registry.example.com/example/image@sha256:…​ in the source registry namespace from the mirror mirror.example.net/image@sha256:…​.
    12Pulls the image registry.example.com/myimage@sha256 from the mirror registry example.net/registry-example-com/myimage@sha256:…​. The ImageContentSourcePolicy resource is applied to all repositories from a source registry to a mirror registry mirror.example.net/registry-example-com.
  4. Create the new object:

    1. $ oc create -f registryrepomirror.yaml

    After the object is created, the Machine Config Operator (MCO) cordons the nodes as the new settings are deployed to each node. The MCO restarts the nodes for an ImageTagMirrorSet object only. The MCO does not restart the nodes for ImageDigestMirrorSet objects. When the nodes are uncordoned, the cluster starts using the mirrored repository for requests to the source repository.

  5. To check that the mirrored configuration settings are applied, do the following on one of the nodes.

    1. List your nodes:

      1. $ oc get node

      Example output

      1. NAME STATUS ROLES AGE VERSION
      2. ip-10-0-137-44.ec2.internal Ready worker 7m v1.28.5
      3. ip-10-0-138-148.ec2.internal Ready master 11m v1.28.5
      4. ip-10-0-139-122.ec2.internal Ready master 11m v1.28.5
      5. ip-10-0-147-35.ec2.internal Ready worker 7m v1.28.5
      6. ip-10-0-153-12.ec2.internal Ready worker 7m v1.28.5
      7. ip-10-0-154-10.ec2.internal Ready master 11m v1.28.5
    2. Start the debugging process to access the node:

      1. $ oc debug node/ip-10-0-147-35.ec2.internal

      Example output

      1. Starting pod/ip-10-0-147-35ec2internal-debug ...
      2. To use host binaries, run `chroot /host`
    3. Change your root directory to /host:

      1. sh-4.2# chroot /host
    4. Check the /etc/containers/registries.conf file to make sure the changes were made:

      1. sh-4.2# cat /etc/containers/registries.conf

      The following output represents a registries.conf file where an ImageDigestMirrorSet object and an ImageTagMirrorSet object were applied. The final two entries are marked digest-only and tag-only respectively.

      Example output

      1. unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
      2. short-name-mode = ""
      3. [[registry]]
      4. prefix = ""
      5. location = "registry.access.redhat.com/ubi9/ubi-minimal" (1)
      6. [[registry.mirror]]
      7. location = "example.io/example/ubi-minimal" (2)
      8. pull-from-mirror = "digest-only" (3)
      9. [[registry.mirror]]
      10. location = "example.com/example/ubi-minimal"
      11. pull-from-mirror = "digest-only"
      12. [[registry]]
      13. prefix = ""
      14. location = "registry.example.com"
      15. [[registry.mirror]]
      16. location = "mirror.example.net/registry-example-com"
      17. pull-from-mirror = "digest-only"
      18. [[registry]]
      19. prefix = ""
      20. location = "registry.example.com/example"
      21. [[registry.mirror]]
      22. location = "mirror.example.net"
      23. pull-from-mirror = "digest-only"
      24. [[registry]]
      25. prefix = ""
      26. location = "registry.example.com/example/myimage"
      27. [[registry.mirror]]
      28. location = "mirror.example.net/image"
      29. pull-from-mirror = "digest-only"
      30. [[registry]]
      31. prefix = ""
      32. location = "registry.redhat.io"
      33. [[registry.mirror]]
      34. location = "mirror.example.com"
      35. pull-from-mirror = "digest-only"
      36. [[registry]]
      37. prefix = ""
      38. location = "registry.redhat.io/openshift4"
      39. [[registry.mirror]]
      40. location = "mirror.example.com/redhat"
      41. pull-from-mirror = "digest-only"
      42. [[registry]]
      43. prefix = ""
      44. location = "registry.access.redhat.com/ubi9/ubi-minimal"
      45. blocked = true (4)
      46. [[registry.mirror]]
      47. location = "example.io/example/ubi-minimal-tag"
      48. pull-from-mirror = "tag-only" (5)
      1Indicates the repository that is referred to in a pull spec.
      2Indicates the mirror for that repository.
      3Indicates that the image pull from the mirror is a digest reference image.
      4Indicates that the NeverContactSource parameter is set for this repository.
      5Indicates that the image pull from the mirror is a tag reference image.
    5. Pull an image to the node from the source and check if it is resolved by the mirror.

      1. sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi9/ubi-minimal@sha256:5cf...

Troubleshooting repository mirroring

If the repository mirroring procedure does not work as described, use the following information about how repository mirroring works to help troubleshoot the problem.

  • The first working mirror is used to supply the pulled image.

  • The main registry is only used if no other mirror works.

  • From the system context, the Insecure flags are used as fallback.

  • The format of the /etc/containers/registries.conf file has changed recently. It is now version 2 and in TOML format.

  • You cannot add the same repository to both an ImageDigestMirrorSet and an ImageTagMirrorSet object.

Converting ImageContentSourcePolicy (ICSP) files for image registry repository mirroring

Using an ImageContentSourcePolicy (ICSP) object to configure repository mirroring is a deprecated feature. This functionality is still included in OKD and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.

ICSP objects are being replaced by ImageDigestMirrorSet and ImageTagMirrorSet objects to configure repository mirroring. If you have existing YAML files that you used to create ImageContentSourcePolicy objects, you can use the oc adm migrate icsp command to convert those files to an ImageDigestMirrorSet YAML file. The command updates the API to the current version, changes the kind value to ImageDigestMirrorSet, and changes spec.repositoryDigestMirrors to spec.imageDigestMirrors. The rest of the file is not changed.

For more information about ImageDigestMirrorSet or ImageTagMirrorSet objects, see “Configuring image registry repository mirroring” in the previous section.

Prerequisites

  • Access to the cluster as a user with the cluster-admin role.

  • Ensure that you have ImageContentSourcePolicy objects on your cluster.

Procedure

  1. Use the following command to convert one or more ImageContentSourcePolicy YAML files to an ImageDigestMirrorSet YAML file:

    1. $ oc adm migrate icsp <file_name>.yaml <file_name>.yaml <file_name>.yaml --dest-dir <path_to_the_directory>

    where:

    <file_name>

    Specifies the name of the source ImageContentSourcePolicy YAML. You can list multiple file names.

    --dest-dir

    Optional: Specifies a directory for the output ImageDigestMirrorSet YAML. If unset, the file is written to the current directory.

    For example, the following command converts the icsp.yaml and icsp-2.yaml file and saves the new YAML files to the idms-files directory.

    1. $ oc adm migrate icsp icsp.yaml icsp-2.yaml --dest-dir idms-files

    Example output

    1. wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi8repo.5911620242173376087.yaml
    2. wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi9repo.6456931852378115011.yaml
  2. Create the CR object by running the following command:

    1. $ oc create -f <path_to_the_directory>/<file-name>.yaml

    where:

    <path_to_the_directory>

    Specifies the path to the directory, if you used the --dest-dir flag.

    <file_name>

    Specifies the name of the ImageDigestMirrorSet YAML.

Widening the scope of the mirror image catalog to reduce the frequency of cluster node reboots

You can scope the mirrored image catalog at the repository level or the wider registry level. A widely scoped ImageContentSourcePolicy resource reduces the number of times the nodes need to reboot in response to changes to the resource.

To widen the scope of the mirror image catalog in the ImageContentSourcePolicy resource, perform the following procedure.

Prerequisites

  • Install the OKD CLI oc.

  • Log in as a user with cluster-admin privileges.

  • Configure a mirrored image catalog for use in your disconnected cluster.

Procedure

  1. Run the following command, specifying values for <local_registry>, <pull_spec>, and <pull_secret_file>:

    1. $ oc adm catalog mirror <local_registry>/<pull_spec> <local_registry> -a <pull_secret_file> --icsp-scope=registry

    where:

    <local_registry>

    is the local registry you have configured for your disconnected cluster, for example, local.registry:5000.

    <pull_spec>

    is the pull specification as configured in your disconnected registry, for example, redhat/redhat-operator-index:v4

    <pull_secret_file>

    is the registry.redhat.io pull secret in .json file format. You can download the pull secret from the Red Hat OpenShift Cluster Manager.

    The oc adm catalog mirror command creates a /redhat-operator-index-manifests directory and generates imageContentSourcePolicy.yaml, catalogSource.yaml, and mapping.txt files.

  2. Apply the new ImageContentSourcePolicy resource to the cluster:

    1. $ oc apply -f imageContentSourcePolicy.yaml

Verification

  • Verify that oc apply successfully applied the change to ImageContentSourcePolicy:

    1. $ oc get ImageContentSourcePolicy -o yaml

    Example output

    1. apiVersion: v1
    2. items:
    3. - apiVersion: operator.openshift.io/v1alpha1
    4. kind: ImageContentSourcePolicy
    5. metadata:
    6. annotations:
    7. kubectl.kubernetes.io/last-applied-configuration: |
    8. {"apiVersion":"operator.openshift.io/v1alpha1","kind":"ImageContentSourcePolicy","metadata":{"annotations":{},"name":"redhat-operator-index"},"spec":{"repositoryDigestMirrors":[{"mirrors":["local.registry:5000"],"source":"registry.redhat.io"}]}}
    9. ...

After you update the ImageContentSourcePolicy resource, OKD deploys the new settings to each node and the cluster starts using the mirrored repository for requests to the source repository.

Additional resources