To apply a custom layered image to your cluster by using the on-cluster build process, make a MachineOSConfig
custom resource (CR) that specifies the following parameters:
-
the Containerfile to build
-
the machine config pool to associate the build
-
where the final image should be pushed and pulled from
-
the push and pull secrets to use
When you create the object, the Machine Config Operator (MCO) creates a MachineOSBuild
object and a machine-os-builder
pod. The build process also creates transient objects, such as config maps, which are cleaned up after the build is complete.
When the build is complete, the MCO pushes the new custom layered image to your repository for use when deploying new nodes. You can see the digested image pull spec for the new custom layered image in the MachineOSBuild
object and machine-os-builder
pod.
You should not need to interact with these new objects or the machine-os-builder
pod. However, you can use all of these resources for troubleshooting, if necessary.
You need a separate MachineOSConfig
CR for each machine config pool where you want to use a custom layered image.
|
On-cluster image layering is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
|
Prerequisites
-
You have enabled the TechPreviewNoUpgrade
feature set by using the feature gates. For more information, see "Enabling features using feature gates".
-
You have a copy of the global pull secret in the openshift-machine-config-operator
namespace that the MCO needs in order to pull the base operating system image.
-
You have a copy of the etc-pki-entitlement
secret in the openshift-machine-api
namespace.
-
You have the push secret that the MCO needs in order to push the new custom layered image to your registry.
-
You have a pull secret that your nodes need to pull the new custom layered image from your registry. This should be a different secret than the one used to push the image to the repository.
-
You are familiar with how to configure a Containerfile. Instructions on how to create a Containerfile are beyond the scope of this documentation.
-
Optional: You have a separate machine config pool for the nodes where you want to apply the custom layered image.
Procedure
-
Create a machineOSconfig
object:
-
Create a YAML file similar to the following:
apiVersion: machineconfiguration.openshift.io/v1alpha1
kind: MachineOSConfig
metadata:
name: layered
spec:
machineConfigPool:
name: <mcp_name> (1)
buildInputs:
containerFile: (2)
- containerfileArch: noarch (3)
content: |-
FROM configs AS final (4)
RUN dnf install -y cowsay && \
dnf clean all && \
ostree container commit
imageBuilder: (5)
imageBuilderType: PodImageBuilder
baseImagePullSecret: (6)
name: global-pull-secret-copy
renderedImagePushspec: image-registry.openshift-image-registry.svc:5000/openshift/os-image:latest (7)
renderedImagePushSecret: (8)
name: builder-dockercfg-7lzwl
buildOutputs: (9)
currentImagePullSecret:
name: builder-dockercfg-7lzwl
1 |
Specifies the machine config pool to deploy the custom layered image. |
2 |
Specifies the Containerfile to configure the custom layered image. You can specify multiple build stages in the Containerfile. |
3 |
Specifies the architecture of the image to be built. You must set this parameter to noarch . |
4 |
Specifies the build stage as final. This field is required and applies to the last image in the build. |
5 |
Specifies the name of the image builder to use. You must set this parameter to PodImageBuilder . |
6 |
Specifies the name of the pull secret that the MCO needs in order to pull the base operating system image from the registry. |
7 |
Specifies the image registry to push the newly-built custom layered image to. This can be any registry that your cluster has access to. This example uses the internal OpenShift Container Platform registry. |
8 |
Specifies the name of the push secret that the MCO needs in order to push the newly-built custom layered image to the registry. |
9 |
Specifies the secret required by the image registry that the nodes need in order to pull the newly-built custom layered image. This should be a different secret than the one used to push the image to your repository. |
-
Create the MachineOSConfig
object:
$ oc create -f <file_name>.yaml
-
If necessary, when the MachineOSBuild
object has been created and is in the READY
state, modify the node spec for the nodes where you want to use the new custom layered image:
-
Check that the MachineOSBuild
object is READY
. When the SUCCEEDED
value is True
, the build is complete.
Example output showing that the MachineOSBuild
object is ready
NAME PREPARED BUILDING SUCCEEDED INTERRUPTED FAILED
layered-rendered-layered-ad5a3cad36303c363cf458ab0524e7c0-builder False False True False False
-
Edit the nodes where you want to deploy the custom layered image by adding a label for the machine config pool you specified in the MachineOSConfig
object:
$ oc label node <node_name> 'node-role.kubernetes.io/<mcp_name>='
- node-role.kubernetes.io/<mcp_name>=
-
Specifies a node selector that identifies the nodes to deploy the custom layered image.
When you save the changes, the MCO drains, cordons, and reboots the nodes. After the reboot, the node will be using the new custom layered image.
Verification
-
Verify that the new pods are ready by running the following command:
$ oc get pods -n openshift-machine-config-operator
Example output
NAME READY STATUS RESTARTS AGE
build-rendered-layered-ad5a3cad36303c363cf458ab0524e7c0 2/2 Running 0 2m40s (1)
# ...
machine-os-builder-6fb66cfb99-zcpvq 1/1 Running 0 2m42s (2)
1 |
This is the build pod where the custom layered image is building. |
2 |
This pod can be used for troubleshooting. |
-
Verify the current stage of your layered build by running the following command:
Example output
NAME PREPARED BUILDING SUCCEEDED INTERRUPTED FAILED
layered-rendered-layered-ef6460613affe503b530047a11b28710-builder False True False False False
-
Verify that the MachineOSBuild
object contains a reference to the new custom layered image by running the following command:
$ oc describe machineosbuild <object_name>
Example output
apiVersion: machineconfiguration.openshift.io/v1alpha1
kind: MachineOSBuild
metadata:
name: layered-rendered-layered-ad5a3cad36303c363cf458ab0524e7c0-builder
spec:
desiredConfig:
name: rendered-layered-ad5a3cad36303c363cf458ab0524e7c0
machineOSConfig:
name: layered
renderedImagePushspec: image-registry.openshift-image-registry.svc:5000/openshift-machine-config-operator/os-image:latest
# ...
status:
conditions:
- lastTransitionTime: "2024-05-21T20:25:06Z"
message: Build Ready
reason: Ready
status: "True"
type: Succeeded
finalImagePullspec: image-registry.openshift-image-registry.svc:5000/openshift-machine-config-operator/os-image@sha256:f636fa5b504e92e6faa22ecd71a60b089dab72200f3d130c68dfec07148d11cd (1)
1 |
Digested image pull spec for the new custom layered image. |
-
Verify that the appropriate nodes are using the new custom layered image:
-
Start a debug session as root for a control plane node:
$ oc debug node/<node_name>
-
Set /host
as the root directory within the debug shell:
-
Run the rpm-ostree status
command to view that the custom layered image is in use:
sh-5.1# rpm-ostree status
Example output
# ...
Deployments:
* ostree-unverified-registry:quay.io/openshift-release-dev/os-image@sha256:f636fa5b504e92e6faa22ecd71a60b089dab72200f3d130c68dfec07148d11cd (1)
Digest: sha256:bcea2546295b2a55e0a9bf6dd4789433a9867e378661093b6fdee0031ed1e8a4
Version: 416.94.202405141654-0 (2024-05-14T16:58:43Z)
1 |
Digested image pull spec for the new custom layered image. |