Configure fleets to auto-register MicroShift clusters

If you have fleets of devices that are running an operating system image that includes MicroShift, you can configure your fleets to auto-register MicroShift clusters with Red Hat Advanced Cluster Management.

About this task

Configuring your device template

To enable auto-registration in a fleet, add configuration to its device template.

If you have not already created the HTTP Repository named acm-registration for the Red Hat Advanced Cluster Management agent registration API (including validationSuffix and httpConfig), create it by following the repository steps in Configuring your device in Managing devices.

Complete the following steps:

Procedure

  1. Add the acm-crd resource configuration, which includes the filePath for your crd.yaml file, your repository, and suffix to your Fleet resource. See the following example:
    apiVersion: flightctl.io/v1beta1
    kind: Fleet
    metadata:
      name: fleet-acm
    spec:
      selector:
        matchLabels:
          fleet: acm
      template:
        spec:
          os:
            image: <your_os_image>
          config:
            - name: acm-crd
              httpRef:
                filePath: /var/local/acm-import/crd.yaml
                repository: acm-registration
                suffix: /agent-registration/crds/v1
  2. Add the acm-import resource configuration with the filePath, repository, and suffix, as shown in the following example:
          config:
            - name: acm-import
              httpRef:
                filePath: /var/local/acm-import/import.yaml
                repository: acm-registration
                suffix: /agent-registration/manifests/{{.metadata.name}}
  3. MicroShift must authenticate to the container registries that host the Red Hat Advanced Cluster Management images. If the device already has a suitable pull secret for those registries (for example, at /etc/crio/openshift-pull-secret), you do not need to add another one here. Otherwise, add the pull-secret resource, as you see in the following addition to the template:
          config:
            - name: pull-secret
              inline:
                - path: "/etc/crio/openshift-pull-secret"
                  content: "{\"auths\":{...}}"
  4. Add the apply-acm-manifests resource. The following hook waits until the kubeadmin kubeconfig file exists and MicroShift pods are ready, then runs kubectl apply on your crd.yaml and import.yaml files when those files are created. The afterupdating hook fires both when a device first joins the fleet and receives its initial configuration, and on subsequent updates.

    Include the wait steps because MicroShift might not be running when the hook runs. For example, you might apply an operating system image update and this registration configuration together in a single device update. See the following example:

          config:
            - name: apply-acm-manifests
              inline:
                - path: "/etc/flightctl/hooks.d/afterupdating/50-acm-registration.yaml"
                  content: |
                    - run: /usr/bin/bash -c "until [ -f $KUBECONFIG ]; do sleep 1; done"
                      timeout: 5m
                      envVars:
                        KUBECONFIG: /var/lib/microshift/resources/kubeadmin/kubeconfig
                    - run: kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=300s
                      timeout: 5m
                      envVars:
                        KUBECONFIG: /var/lib/microshift/resources/kubeadmin/kubeconfig
                    - if:
                      - path: /var/local/acm-import/crd.yaml
                        op: [created]
                      run: kubectl apply -f /var/local/acm-import/crd.yaml
                      envVars:
                        KUBECONFIG: /var/lib/microshift/resources/kubeadmin/kubeconfig
                    - if:
                      - path: /var/local/acm-import/import.yaml
                        op: [created]
                      run: kubectl apply -f /var/local/acm-import/import.yaml
                      envVars:
                        KUBECONFIG: /var/lib/microshift/resources/kubeadmin/kubeconfig

    Auto-registration uses the Red Hat Advanced Cluster Management agent registration API: devices fetch the Kubernetes manifests for the klusterlet agent and apply them to MicroShift. The resources under spec.template.spec.config in your fleet template do the following:

    • acm-crd uses the HTTP configuration provider to query the agent registration server for manifests that contain the custom resource definition for the Red Hat Advanced Cluster Management klusterlet agent. The Red Hat Edge Manager agent writes those manifests to /var/local/acm-import/crd.yaml on each device.
    • acm-import queries the server for import manifests for a cluster whose name matches the device. The {{.metadata.name}} template variable supplies the device name. The agent writes the returned manifests to /var/local/acm-import/import.yaml.
    • pull-secret adds registry credentials on the device so that MicroShift can pull the Red Hat Advanced Cluster Management agent images. Skip this item if you already provide a suitable pull secret by another method, for example by embedding it in the operating system image or by using another configuration provider.
    • apply-acm-manifests adds an afterupdating lifecycle hook rule file under /etc/flightctl/hooks.d/afterupdating/. The hook runs after the configuration is applied and the crd.yaml and import.yaml files exist; it applies those manifests to MicroShift by using kubectl. For more information, see Device lifecycle hooks.
  5. In the console, label the device fleet:acm and click Approve, which automatically selects the fleet-acm fleet. For more information about labels on devices, see Labels and label selectors.