Bookmark this page

Lab: Manage Kubernetes Operators

Install an operator and verify that it is healthy.

Outcomes

  • Install the Compliance operator on the command line.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command ensures that the cluster API is reachable and that the operator that is used in this exercise is not present.

[student@workstation ~]$ lab start operators-review

Instructions

In this exercise, you install the Compliance operator. For more information, refer to the Compliance Operator chapter in the Red Hat OpenShift Container Platform 4.14 Security and Compliance documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/security_and_compliance/index#compliance-operator.

  1. Log in to your OpenShift cluster as the admin user with the redhatocp password.

    1. Log in to the cluster as the admin user.

      [student@workstation ~]$ oc login -u admin -p redhatocp \
          https://api.ocp4.example.com:6443
      Login successful.
      
      ...output omitted...
  2. Examine the package manifest for the Compliance operator to discover the operator name, catalog name, suggested namespace, and channel.

    1. Use the oc command to list the package manifest resources.

      [student@workstation ~]$ oc get packagemanifest
      NAME                      CATALOG                     AGE
      lvms-operator             do280 Operator Catalog Cs   2d5h
      file-integrity-operator   do280 Operator Catalog Cs   2d5h
      metallb-operator          do280 Operator Catalog Cs   2d5h
      compliance-operator       do280 Operator Catalog Cs   2d5h
      kubevirt-hyperconverged   do280 Operator Catalog Cs   2d5h
    2. Examine the compliance-operator package manifest.

      [student@workstation ~]$ oc get packagemanifest compliance-operator -o yaml
      apiVersion: packages.operators.coreos.com/v1
      kind: PackageManifest
      metadata:
        creationTimestamp: "2024-01-24T14:05:27Z"
        labels:
          catalog: do280-catalog-cs
          catalog-namespace: openshift-marketplace
      ...output omitted...
        name: compliance-operator
        namespace: default
      spec: {}
      status:
      ...output omitted...
        channels:
        - currentCSV: compliance-operator.v1.4.0
          currentCSVDesc:
            annotations:
              alm-examples: |-
      ...output omitted...
              operatorframework.io/suggested-namespace: openshift-compliance
      ...output omitted...
            version: 1.4.0
          name: stable
        defaultChannel: stable
        packageName: compliance-operator
      ...output omitted...

      The package manifest contains the following information:

      FieldValue
      catalog do280-catalog-cs
      catalog-namespace openshift-marketplace
      suggested-namespace openshift-compliance
      defaultChannel stable
      packageName compliance-operator
  3. Create the recommended openshift-compliance namespace.

    1. Use the oc command to create the namespace.

      [student@workstation ~]$ oc create namespace openshift-compliance
      namespace/openshift-compliance created
  4. Create an operator group with the compliance-operator name in the openshift-compliance namespace. The target namespace of the operator group is the openshift-compliance namespace. You can use the ~/DO280/labs/operators-review/operator-group.yaml file as a template.

    1. Create an operator-group.yaml file with the following content:

      apiVersion: operators.coreos.com/v1
      kind: OperatorGroup
      metadata:
        name: compliance-operator
        namespace: openshift-compliance
      spec:
        targetNamespaces:
        - openshift-compliance
    2. Use the oc command to create the operator group:

      [student@workstation ~]$ oc create -f operator-group.yaml
      operatorgroup.operators.coreos.com/compliance-operator created
  5. Create a compliance-operator subscription in the openshift-compliance namespace. The subscription has the following parameters:

    FieldValue
    channel stable
    spec.name compliance-operator
    source do280-catalog-cs
    sourceNamespace openshift-marketplace

    You can use the ~/DO280/labs/operators-review/subscription.yaml file as a template.

    You can configure automatic install plan approvals.

    1. Create a subscription.yaml file with the following content:

      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: compliance-operator
        namespace: openshift-compliance
      spec:
        channel: stable
        installPlanApproval: Automatic
        name: compliance-operator
        source: do280-catalog-cs
        sourceNamespace: openshift-marketplace
    2. Use the oc command to create the operator group:

      [student@workstation ~]$ oc create -f subscription.yaml
      subscription.operators.coreos.com/compliance-operator created
  6. Wait until the operator is installed.

    The Operator Lifecycle Manager creates a cluster service version in the openshift-compliance namespace. Wait until the cluster service version resource (CSV) is in the Succeeded phase.

    Although the CSV defines a single compliance-operator deployment, the operator has two additional deployments. Wait until the compliance-operator, ocp4-openshift-compliance-pp, and rhcos4-openshift-compliance-pp deployments are ready.

    1. Select the openshift-compliance project.

      [student@workstation ~]$ oc project openshift-compliance
      Now using project "openshift-compliance" on server "https://api.ocp4.example.com:6443".
    2. Wait until the CSV is in the Succeeded phase.

      [student@workstation ~]$ oc get csv
      NAME                        DISPLAY               VERSION   ...  PHASE
      compliance-operator.v1.4.0  Compliance Operator   1.4.0     ...  Succeeded
      ...output omitted...

      The available CSV version in the lab might change. Commands in the following steps require you to replace the available version in the lab.

    3. Inspect the CSV to view the operator deployment. Replace the version that you obtained in a previous step. The .spec.install.spec.deployments JSONPath expression describes the location of the operator deployments in the CSV resource. Optionally, use the jq command to indent the output.

      [student@workstation ~]$ oc get csv compliance-operator.v1.4.0 \
        -o jsonpath={.spec.install.spec.deployments} | jq
      [
        {
          "name": "compliance-operator",
          "spec": {
      ...output omitted...

      The Compliance operator describes a single deployment with the compliance-operator name.

    4. Use the oc command to list the workloads in the operator namespace.

      [student@workstation ~]$ oc get all
      NAME                                    ...
      pod/compliance-operator-...             ...
      pod/ocp4-openshift-compliance-pp-...    ...
      pod/rhcos4-openshift-compliance-pp-...  ...
      
      ...output omitted...
      
      NAME                                             READY  ...
      deployment.apps/compliance-operator              1/1    ...
      deployment.apps/ocp4-openshift-compliance-pp     1/1    ...
      deployment.apps/rhcos4-openshift-compliance-pp   1/1    ...
      
      ...output omitted...

      Besides the compliance-operator deployment, the Compliance operator creates two other deployments.

      Wait until all deployments are ready.

  7. Verify that the operator works correctly.

    This operator watches custom resources of the ScanSettingBinding type and runs file integrity checks on cluster nodes. The operator reports results with custom resources of the ComplianceSuite type.

    Create a scan setting binding in the openshift-compliance namespace. You can use the ~/DO280/labs/operators-review/scan-setting-binding.yaml file as a template.

    You can also use the web console to create the scan setting binding. The YAML editor in the web console provides the same scan setting binding resource as an example.

    Wait until a resource of the ComplianceSuite type in the DONE phase is present in the openshift-compliance namespace.

    1. Examine the alm-examples annotation in the CSV. Replace the version that you obtained in a previous step.

      [student@workstation ~]$ oc get csv compliance-operator.v1.4.0 \
        -o jsonpath={.metadata.annotations.alm-examples} | jq
      [
      ...output omitted...
        {
          "apiVersion": "compliance.openshift.io/v1alpha1",
          "kind": "ScanSettingBinding",
          "metadata": {
            "name": "nist-moderate"
          },
          "profiles": [
            {
              "apiGroup": "compliance.openshift.io/v1alpha1",
              "kind": "Profile",
              "name": "rhcos4-moderate"
            }
          ],
          "settingsRef": {
            "apiGroup": "compliance.openshift.io/v1alpha1",
            "kind": "ScanSetting",
            "name": "default"
          }
        },
      ...output omitted...
      ]

      The annotation contains an example scan setting binding that you can use. The example is in JSON format. When creating a scan setting binding in the web console, the YAML editor loads the same example.

      You can also use the oc explain command to describe the scan setting binding resource.

    2. Create the scan setting binding resource by using the example file in the ~/DO280/labs/operators-review/scan-setting-binding.yaml path.

      [student@workstation ~]$ oc create \
        -f ~/DO280/labs/operators-review/scan-setting-binding.yaml
      scansettingbinding.compliance.openshift.io/nist-moderate created
    3. Use the oc command to list compliance suite and pod resources. Execute the command repeatedly until the compliance suite resource is in the DONE phase.

      [student@workstation ~]$ oc get compliancesuite,pod
      NAME                                                    PHASE   RESULT
      compliancesuite.compliance.openshift.io/nist-moderate   DONE    NON-COMPLIANT
      
      NAME                                    ...
      pod/compliance-operator-...             ...
      pod/ocp4-openshift-compliance-pp-...    ...
      pod/rhcos4-openshift-compliance-pp-...  ...

      To execute the scan, the compliance operator creates extra pods. The pods disappear when the scan completes.

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade operators-review

Finish

As the student user on the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish operators-review

Revision: do280-4.14-08d11e1