项目作者: open-cluster-management

项目描述 :
Deploy Development Builds of Open Cluster Management (OCM) on RedHat Openshift Container Platform
高级语言: Shell
项目地址: git://github.com/open-cluster-management/deploy.git
创建时间: 2020-03-09T15:59:21Z
项目社区:https://github.com/open-cluster-management/deploy

开源协议:Apache License 2.0

下载


Deploy the open-cluster-management project

Welcome!

You might be asking yourself, “What is Open Cluster Management?”, well it is the open-cluster-management project. View the open-cluster-management architecture diagram:

Architecture diagram

The GitHub org and project are currently distinct from the SaaS offering named “Red Hat OpenShift Cluster Manager” but will ultimately co-exist/share technology as needed. Core technology, such as Hive is already shared between the two offerings.

Kubernetes provides a platform to deploy and manage containers in a standard, consistent control plane. However, as application workloads move from development to production, they often require multiple fit-for-purpose Kubernetes clusters to support DevOps pipelines. Users such as administrators and site reliability engineers (SREs), face challenges as they work across a range of environments, including multiple data centers, private clouds, and public clouds that run Kubernetes clusters. The open-cluster-management project provides the tools and capabilities to address these common challenges.

open-cluster-management provides end-to-end visibility and control to manage your Kubernetes environment. Take control of your application modernization program with management capabilities for cluster creation, application lifecycle, and provide security and compliance for all of them across data centers and hybrid cloud environments. Clusters and applications are all visible and managed from a single console with built-in security policies. Run your operations where Red Hat OpenShift runs, and manage any Kubernetes cluster in your fleet.

With the open-cluster-management project, you can complete the following functionality tasks:

  • Work across a range of environments, including multiple data centers, private clouds and public clouds that run Kubernetes clusters.
  • Easily create Kubernetes clusters and offer cluster lifecycle management in a single console.
  • Enforce policies at the target clusters using Kubernetes-supported custom resource definitions.
  • Deploy and maintain day-two operations of business applications distributed across your cluster landscape.

Our code is open! To reach us in the open source community please head to https://open-cluster-management.io, and you can also find us on Kubernetes Slack workspace: https://kubernetes.slack.com/archives/C01GE7YSUUF

If you’re looking for RHACM, the Red Hat multicluster management product that runs on OpenShift, your Red Hat account team rep should be able to help you get an evaluation of ACM so that you can use the actual product bits in a supported way. There is also a self-supported evaluation if you prefer that, and you can get started right away at: https://www.redhat.com/en/technologies/management/advanced-cluster-management
-> click the “Try It” button.

Let’s get started…

You can find our work-in-progress documentation here. Please read through the docs to find out how you can use the open-cluster-management project. Oh, and please submit an issue for any problems you may find, or clarifications you might suggest.

You can find information on how to contribute to this project and our docs project in our CONTRIBUTING.md doc.

Prereqs

You must meet the following requirements to install the open-cluster-management project:

  • An OpenShift Container Platform (OCP) 4.3+ cluster available
    • You must have a default storage class defined
  • oc (ver. 4.3+) & kubectl (ver. 1.16+) configured to connect to your OCP cluster
  • oc is connected with adequate permissions to create new namespaces in your OCP cluster.
  • The following utilities required:
    • sed
      • On macOS install using: brew install gnu-sed
    • jq
      • On macOS install using: brew install jq
    • yq (v4.12+)
      • On macOS install using: brew install yq
  • The following utilities are optional:
    • watch
      • On macOS install using: brew install watch

Repo Structure and Organization

This repo contains the 3 directories:

  • prereqs - YAML definitions for prerequisite objects (namespaces and pull-secrets)
  • acm-operator - YAML definitions for setting up a CatalogSource for our operator
  • multiclusterhub - YAML definitions for creating an instance of MultiClusterHub

Each of the three directories contains a kustomization.yaml file that will apply the YAML definitions to your OCP instance with the following command: kubectl apply -k.

There are helper scripts in the root of this repo:

  • start.sh - takes the edge off having to manually edit YAML files
  • uninstall.sh - we’re not perfect yet; includes additional scripting to ensure we clean up our mess on your OCP cluster.

You have multiple choices of installation:

  • the easy way - using the provided start.sh script which will assist you through the process.
  • the hard way - instructions to deploy open-cluster-management with only oc commands.
  • downstream images v2.0+ - instructions to deploy downstream images, i.e. for QE

Either way you choose to go, you are going to need a pull-secret in order to gain access to our built images residing in our private Quay environment. Please follow the instructions Prepare to deploy Open Cluster Management Instance to get your pull-secret setup.

Prepare to deploy Open Cluster Management Instance (only do once)

  1. Clone this repo locally

    1. git clone https://github.com/stolostron/deploy.git
  2. Generate your pull-secret:

    • ensure you have access to the quay org (stolostron)
    • to request access to stolostron in quay.io, for external (non Red Hat) users, you can please contact the ACM BU via email at contact@redhat.com"">acm-contact@redhat.com. Or, if you have access to Red Hat Slack you can contact us on our Slack Channel #forum-hypbld) and indicate if you want upstream (stolostron) or downstream (acm-d) repos (or both). We’ll need your quay ID. Once the team indicates they’ve granted you access, open your Notifications at quay.io and accept the invitation(s) waiting for you.
    • you will also need a bot and token generated for each of the repositories you wish to use.
    • acm-d (stolostron images are public)
    • :exclamation: save secret file in the prereqs directory as pull-secret.yaml
    • :exclamation: edit pull-secret.yaml file and change the name to multiclusterhub-operator-pull-secret
      1. apiVersion: v1
      2. kind: Secret
      3. metadata:
      4. name: multiclusterhub-operator-pull-secret
      5. ...

Deploy using the ./start.sh script (the easy way)

We’ve added a very simple start.sh script to make your life easier. To deploy downstream images please refer to “Deploying downstream builds” section below.

First, you need to export KUBECONFIG=/path/to/some/cluster/kubeconfig (or do an oc login that will set it for you).
deploy installs ACM to the cluster configured in your KUBECONFIG env variable.

Optionally export DEBUG=true for additional debugging output for 2.1+ releases. export USE_STARTING_CSV=true to use an explicit STARTING_CSV variable.

Running start.sh

  1. Run the start.sh script. You have the following options when you run the command:

    1. -t modify the YAML but exit before apply the resources
    2. --silent, skip all prompting, uses the previous configuration
    3. --watch, will monitor the main Red Hat ACM pod deployments for up to 10min
    4. --search, will activate search as part of the deployment.
    5. $ ./start.sh --watch --search
  2. When prompted for the SNAPSHOT tag, either press Enter to use the previous tag, or provide a new SNAPSHOT tag.

  3. Depending on your script option choice, open-cluster-management will be deployed or deploying.

    For version 2.1+, you can monitor the status fields of the multiclusterhub object created in the open-cluster-management namespace (namespace will differ if TARGET_NAMESPACE is set).

    For version 2.0 and below, use watch oc -n open-cluster-management get pods to view the progress.

  4. The script provides you with the Open Cluster Management URL.

Note: This script can be run multiple times and will attempt to continue where it left off. It is also good practice to run the uninstall.sh script if you have a failure and have installed multiple times.

Deploying Downstream Builds SNAPSHOTS for Product Quality Engineering (only 2.0+)

Requirements

Required Access

To deploy downstream builds, you need access to pull the related images from the downstream mirror respository, quay.io/acm-d. Access is internal to Red Hat only for Dev/Test/QE use. Contact us in Slack Channel #forum-hypbld on Red Hat Slack for access.

Configuration

To deploy a downstream build from quay.io/acm-d ensure that your OCP cluster meets the following requirements:

  1. The cluster must have an ImageContentSourcePolicy (Caution: if you modify this on a running cluster, it will cause a rolling restart of all nodes).
    To create the ImageContentSourcePolicy run:

    1. echo "
    2. apiVersion: operator.openshift.io/v1alpha1
    3. kind: ImageContentSourcePolicy
    4. metadata:
    5. name: rhacm-repo
    6. spec:
    7. repositoryDigestMirrors:
    8. - mirrors:
    9. - quay.io:443/acm-d
    10. source: registry.redhat.io/rhacm2
    11. - mirrors:
    12. - quay.io:443/acm-d
    13. source: registry.redhat.io/multicluster-engine
    14. - mirrors:
    15. - registry.redhat.io/openshift4/ose-oauth-proxy
    16. source: registry.access.redhat.com/openshift4/ose-oauth-proxy" | kubectl apply -f -
  2. Add the pull-secrets for the quay.io:443 registry with access to the quay.io/acm-d repository in your OpenShift
    main pull-secret. (Caution: if you apply this on a pre-existing cluster, it will cause a rolling restart of all nodes).

    1. # Replace <USER> and <PASSWORD> with your credentials
    2. oc get secret/pull-secret -n openshift-config --template='{{index .data ".dockerconfigjson" | base64decode}}' >pull_secret.yaml
    3. oc registry login --registry="quay.io:443" --auth-basic="<USER>:<PASSWORD>" --to=pull_secret.yaml
    4. oc set data secret/pull-secret -n openshift-config --from-file=.dockerconfigjson=pull_secret.yaml
    5. rm pull_secret.yaml

    You can also set the pull secrets in the OpenShift console or using the bootstrap repo at cluster create time.

    Your OpenShift main pull secret should contain an entry with quay.io:443.

    1. {
    2. "auths": {
    3. "cloud.openshift.com": {
    4. "auth": "ENCODED SECRET",
    5. "email": "email@address.com"
    6. },
    7. "quay.io:443": {
    8. "auth": "ENCODED SECRET",
    9. "email": ""
    10. }
    11. }
    12. }
  3. Set the QUAY_TOKEN environment variable

    In order to get a QUAY_TOKEN, go to your quay.io “Account Settings” page by selecting your username/icon in the top right corner of the page, then “Generate Encrypted Password”.
    Choose “Kubernetes Secret” and copy just secret text that follows .dockerconfigjson:, export DOCKER_CONFIG= this value.

    If you copy the value of .dockerconfigjson, you can simplify setting the QUAY_TOKEN as follows:

    1. export DOCKER_CONFIG=<The value after .dockerconfigjson from the quay.io>
    2. export QUAY_TOKEN=$(echo $DOCKER_CONFIG | base64 -d | sed "s/quay\.io/quay\.io:443/g" | base64)

    (On Linux, use export QUAY_TOKEN=$(echo $DOCKER_CONFIG | base64 -d | sed "s/quay\.io/quay\.io:443/g" | base64 -w 0) to ensure that there are no line breaks in the base64 encoded token)

Deploy the downstream image

NOTE: You should only use a downstream build if you’re doing QE on the final product builds.

  1. export COMPOSITE_BUNDLE=true
  2. export DOWNSTREAM=true
  3. export CUSTOM_REGISTRY_REPO="quay.io:443/acm-d"
  4. export QUAY_TOKEN=<a quay token with quay.io:443 as the auth domain>
  5. ./start.sh --watch

Enable search later

Use the following command to enable search

  1. oc set env deploy search-operator DEPLOY_REDISGRAPH="true" -n INSTALL_NAMESPACE

Deploy a managed cluster with downstream images

Run on the hub cluster:

  1. # Create a namespace managed cluster namespace on the hub cluster
  2. export CLUSTER_NAME=managed-cluster1
  3. oc new-project "${CLUSTER_NAME}"
  4. oc label namespace "${CLUSTER_NAME}" cluster.open-cluster-management.io/managedCluster="${CLUSTER_NAME}"
  5. # Create the managed cluster
  6. echo "
  7. apiVersion: cluster.open-cluster-management.io/v1
  8. kind: ManagedCluster
  9. metadata:
  10. name: ${CLUSTER_NAME}
  11. spec:
  12. hubAcceptsClient: true" | kubectl apply -f -
  13. # Create the KlusterletAddonConfig
  14. echo "
  15. apiVersion: agent.open-cluster-management.io/v1
  16. kind: KlusterletAddonConfig
  17. metadata:
  18. name: ${CLUSTER_NAME}
  19. namespace: ${CLUSTER_NAME}
  20. spec:
  21. clusterName: ${CLUSTER_NAME}
  22. clusterNamespace: ${CLUSTER_NAME}
  23. applicationManager:
  24. enabled: true
  25. certPolicyController:
  26. enabled: true
  27. clusterLabels:
  28. cloud: auto-detect
  29. vendor: auto-detect
  30. iamPolicyController:
  31. enabled: true
  32. policyController:
  33. enabled: true
  34. searchCollector:
  35. enabled: true
  36. version: 2.2.0" | kubectl apply -f -
  37. oc get secret "${CLUSTER_NAME}"-import -n "${CLUSTER_NAME}" -o jsonpath={.data.crds\\.yaml} | base64 --decode > klusterlet-crd.yaml
  38. oc get secret "${CLUSTER_NAME}"-import -n "${CLUSTER_NAME}" -o jsonpath={.data.import\\.yaml} | base64 --decode > import.yaml

Next apply the saved YAML manifests to your managed cluster:

  1. # Change kubconfig to the managed cluster
  2. # Add quay credentials to the managed cluster too
  3. # Replace <USER> and <PASSWORD> with your credentials
  4. oc get secret/pull-secret -n openshift-config --template='{{index .data ".dockerconfigjson" | base64decode}}' >pull_secret.yaml
  5. oc registry login --registry="quay.io:443" --auth-basic="<USER>:<PASSWORD>" --to=pull_secret.yaml
  6. oc set data secret/pull-secret -n openshift-config --from-file=.dockerconfigjson=pull_secret.yaml
  7. rm pull_secret.yaml
  8. # Apply klusterlet-crd
  9. kubectl apply -f klusterlet-crd.yaml
  10. # replace the registry in import.yaml "registry.redhat.io/rhacm2" to "quay.io:443/acm-d"
  11. sed 's/registry.redhat.io\/rhacm2/quay.io:443\/acm-d/g' import.yaml > import.yaml
  12. # Apply the import.yaml
  13. kubectl apply -f import.yaml
  14. # Validate the pod status on the managed cluster
  15. kubectl get pod -n open-cluster-management-agent

Validate the imported cluster’s status in the hub cluster:

  1. kubectl get managedcluster ${CLUSTER_NAME}
  2. kubectl get pod -n open-cluster-management-agent-addon

Test if it works by applying creating a ManifestWork in the hub cluster:

  1. echo "apiVersion: work.open-cluster-management.io/v1
  2. kind: ManifestWork
  3. metadata:
  4. name: mw-01
  5. namespace: ${CLUSTER_NAME}
  6. spec:
  7. workload:
  8. manifests:
  9. - apiVersion: v1
  10. kind: Pod
  11. metadata:
  12. name: hello
  13. namespace: default
  14. spec:
  15. containers:
  16. - name: hello
  17. image: busybox
  18. command: ["sh", "-c", 'echo "Hello, Kubernetes!" && sleep 3600']
  19. restartPolicy: OnFailure" | kubectl apply -f -

On the managed cluster validate that the hello pod is running:

  1. $ kubectl get pods -n default
  2. NAME READY STATUS RESTARTS AGE
  3. hello 1/1 Running 0 3m23s

To Delete a MultiClusterHub Instance (the easy way)

  1. Run the uninstall.sh script in the root of this repo.

To Delete the multiclusterhub-operator (the easy way)

  1. Run the clean-clusters.sh script, and enter DESTROY to delete any Hive deployments and detach all imported clusters.
  2. Run the uninstall.sh script in the root of this repo.

Troubleshooting

  1. If uninstall hangs on the helmRelease delete, you can run this command to move it along. This is distructive and can result in orphaned objects.
    1. for helmrelease in $(oc get helmreleases.apps.open-cluster-management.io | tail -n +2 | cut -f 1 -d ' '); do oc patch helmreleases.apps.open-cluster-management.io $helmrelease --type json -p '[{ "op": "remove", "path": "/metadata/finalizers" }]'; done
  2. If you need to get the build snapshot from your hub, the snapshot comes from image tagging CICD does to group components into builds. This snapshot is set in the catalogsource when deploying from acm-d. So to get what version was deployed you would read the image of the ACM catalogsource. An example of how to do this is oc get catalogsource acm-custom-registry -n openshift-marketplace -o jsonpath='{.spec.image}', which returns quay.io/stolostron/acm-custom-registry:2.5.0-SNAPSHOT-2022-05-26-19-51-06.

the hard way

Click if you dare



## Manually deploy using kubectl commands

1. Create the prereq objects by applying the yaml definitions contained in the prereqs dir:
bash kubectl apply --openapi-patch=true -k prereqs/

2. Update the kustomization.yaml file in the acm-operator dir to set newTag
You can find a snapshot tag by viewing the list of tags available here Use a tag that has the word SNAPSHOT in it.
For downstream deploys, make sure to set newName differently, usually to acm-d.
bash namespace: open-cluster-management images: - name: acm-custom-registry newName: quay.io/stolostron/acm-custom-registry newTag: 1.0.0-SNAPSHOT-2020-05-04-17-43-49

3. Create the multiclusterhub-operator objects by applying the yaml definitions contained in the acm-operator dir:
bash kubectl apply -k acm-operator/

4. Wait for subscription to be healthy:
bash oc get subscription.operators.coreos.com acm-operator-subscription --namespace open-cluster-management -o yaml ... status: catalogHealth: - catalogSourceRef: apiVersion: operators.coreos.com/v1alpha1 kind: CatalogSource name: acm-operator-subscription namespace: open-cluster-management resourceVersion: "1123089" uid: f6da232b-e7c1-4fc6-958a-6fb1777e728c healthy: true ...

5. Once the open-cluster-management CatalogSource is healthy you can deploy the example-multiclusterhub-cr.yaml
bash apiVersion: operator.open-cluster-management.io/v1 kind: MultiClusterHub metadata: name: multiclusterhub namespace: open-cluster-management spec: imagePullSecret: multiclusterhub-operator-pull-secret

6. Create the example-multiclusterhub objects by applying the yaml definitions contained in the multiclusterhub dir:
bash kubectl apply -k multiclusterhub/
## To Delete a MultiClusterHub Instance

1. Delete the example-multiclusterhub objects by deleting the yaml definitions contained in the multiclusterhub dir:
bash kubectl delete -k multiclusterhub/

2. Not all objects are currently being cleaned up by the multiclusterhub-operator upon deletion of a multiclusterhub instance… you can ensure all objects are cleaned up by executing the uninstall.sh script in the multiclusterhub dir:
bash ./multiclusterhub/uninstall.sh

After completing the steps above you can redeploy the multiclusterhub instance by simply running:
bash kubectl apply -k multiclusterhub/

## To Delete the multiclusterhub-operator

1. Delete the multiclusterhub-operator objects by deleting the yaml definitions contained in the acm-operator dir:
bash kubectl delete -k acm-operator/

2. Not all objects are currently being cleaned up by the multiclusterhub-operator upon deletion. You can ensure all objects are cleaned up by executing the uninstall.sh script in the acm-operator dir:
bash ./acm-operator/uninstall.sh

After completing the steps above you can redeploy the multiclusterhub-operator by simply running:
bash kubectl apply -k acm-operator/


Upgrade for Downstream

You can test the upgrade process with downstream builds only, using this repo. To test upgrade follow the instructions below:

  1. Export environment variables needed for downstream deployment:
    1. export CUSTOM_REGISTRY_REPO=quay.io/acm-d
    2. export DOWNSTREAM=true
    3. export COMPOSITE_BUNDLE=true
  2. Apply ImageContentSourcePolicy to redirect registry.redhat.io/rhacm2 to quay.io:443/acm-d
    1. oc apply -k addons/downstream
  3. In order to perform an upgrade you need to install a previously GA’d version of ACM. To do that you will need to set the following variables:
    1. export MODE=Manual # MODE is set to Manual so that we can specify a previous version to install
    2. export STARTING_VERSION=2.x.x # Where 2.x.x is a previously GA'd version of ACM i.e. `STARTING_VERSION=2.0.4`
  4. Run the start.sh script
    1. ./start.sh --watch

Once the installation is complete you can then attempt to upgrade the ACM instance by running the upgrade.sh script. You will need to set additional variables in your environment to tell the upgrade script what you want it to do:

  1. Export environment variables needed by the upgrade.sh script
    1. export NEXT_VERSION=2.x.x # Where 2.x.x is some value greater than the version you previously defined in the STARTING_VERSION=2.x.x
    2. export NEXT_SNAPSHOT=2.X.X-DOWNSTREAM-YYYY-MM-DD-HH-MM-SS #This variable will specify the registry pod and wait for completion
  2. Now run the upgrade process:
    1. ./upgrade.sh

Upgrades for snapshots

This approach mostly works, but we do not test or intend to have snapshot to snapshot upgrades.

  1. Connect to the Red Hat Advanced Cluster Management for Kubernetes OpenShift cluster
  2. Run the upgrade-snapshot.sh script
    1. ./upgrade-snapshot.sh [--watch] [--debug]
  3. It will ask you to provide a snapshot to upgrade to. It does not validate the value, so if you put an older snapshot or an invalid one, the ugprade will get stuck. Press ctrl-c and try again.
  4. It takes about 5min to complete, and the final --watch output should look like this:

    1. Upgrade started
    2. =---------{ Upgrade takes <10min }---------=
    3. Elapsed : 300s
    4. 1. Multiclusterhub CSV : Succeeded
    5. 2. Multiclusterengine CSV : Succeeded
    6. 3. Multiclusterengine operator: Available
    7. 4. Multiclusterhub operator : Running
    8. DONE!

MultiCluster Engine

For detailed instructions to install and manage the MultiCluster Engine, see the following README.

Override MultiCluster Engine Catalogsource

The default MultiClusterEngine catalogsource can be overriden by defining the MCE_SNAPSHOT_CHOICE environment variable with the proper tag before calling ./start.sh script.

Example -

  1. MCE_SNAPSHOT_CHOICE=2.0.0-BACKPLANE-2021-12-02-18-35-02 ./start.sh