Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 1. Configuring an OpenShift cluster by deploying an application with cluster configurations
With Red Hat OpenShift GitOps, you can configure Argo CD to recursively sync the content of a Git directory with an application that contains custom configurations for your cluster.
1.1. Prerequisites Copier lienLien copié sur presse-papiers!
- You have logged in to the OpenShift Container Platform cluster as an administrator.
- You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
1.2. Using an Argo CD instance to manage cluster-scoped resources Copier lienLien copié sur presse-papiers!
Do not elevate the permissions of Argo CD instances to be cluster-scoped unless you have a distinct use case that requires it. Only users with cluster-admin privileges should manage the instances you elevate. Anyone with access to the namespace of a cluster-scoped instance can elevate their privileges on the cluster to become a cluster administrator themselves.
To manage cluster-scoped resources, update the existing Subscription object for the Red Hat OpenShift GitOps Operator and add the namespace of the Argo CD instance to the ARGOCD_CLUSTER_CONFIG_NAMESPACES environment variable in the spec section.
Procedure
-
In the Administrator perspective of the web console, navigate to Operators
Installed Operators Red Hat OpenShift GitOps Subscription. - Click the Actions list and then click Edit Subscription.
On the openshift-gitops-operator Subscription details page, under the YAML tab, edit the
SubscriptionYAML file by adding the namespace of the Argo CD instance to theARGOCD_CLUSTER_CONFIG_NAMESPACESenvironment variable in thespecsection:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Save and Reload.
To verify that the Argo CD instance is configured with a cluster role to manage cluster-scoped resources, perform the following steps:
-
Navigate to User Management
Roles and from the Filter list select Cluster-wide Roles. Search for the
argocd-application-controllerby using the Search by name field.The Roles page displays the created cluster role.
TipAlternatively, in the OpenShift CLI, run the following command:
oc auth can-i create oauth -n openshift-gitops --as system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controller
oc auth can-i create oauth -n openshift-gitops --as system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controllerCopy to Clipboard Copied! Toggle word wrap Toggle overflow The output
yesverifies that the Argo instance is configured with a cluster role to manage cluster-scoped resources. Else, check your configurations and take necessary steps as required.
-
Navigate to User Management
1.3. Default permissions of an Argo CD instance Copier lienLien copié sur presse-papiers!
By default Argo CD instance has the following permissions:
-
Argo CD instance has the
adminprivileges to manage resources only in the namespace where it is deployed. For instance, an Argo CD instance deployed in the foo namespace has theadminprivileges to manage resources only for that namespace. Argo CD has the following cluster-scoped permissions because Argo CD requires cluster-wide
readprivileges on resources to function appropriately:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
You can edit the cluster roles used by the
argocd-serverandargocd-application-controllercomponents where Argo CD is running such that thewriteprivileges are limited to only the namespaces and resources that you wish Argo CD to manage.oc edit clusterrole argocd-server oc edit clusterrole argocd-application-controller
$ oc edit clusterrole argocd-server $ oc edit clusterrole argocd-application-controllerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.4. Running the Argo CD instance at the cluster-level Copier lienLien copié sur presse-papiers!
The default Argo CD instance and the accompanying controllers, installed by the Red Hat OpenShift GitOps Operator, can now run on the infrastructure nodes of the cluster by setting a simple configuration toggle.
Procedure
Label the existing nodes:
oc label node <node-name> node-role.kubernetes.io/infra=""
$ oc label node <node-name> node-role.kubernetes.io/infra=""Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: If required, you can also apply taints and isolate the workloads on infrastructure nodes and prevent other workloads from scheduling on these nodes:
oc adm taint nodes -l node-role.kubernetes.io/infra \ infra=reserved:NoSchedule infra=reserved:NoExecute
$ oc adm taint nodes -l node-role.kubernetes.io/infra \ infra=reserved:NoSchedule infra=reserved:NoExecuteCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the
runOnInfratoggle in theGitOpsServicecustom resource:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: If taints have been added to the nodes, then add
tolerationsto theGitOpsServicecustom resource.Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Verify that the workloads in the
openshift-gitopsnamespace are now scheduled on the infrastructure nodes by viewing PodsPod details for any pod in the console UI.
Any nodeSelectors and tolerations manually added to the default Argo CD custom resource are overwritten by the toggle and tolerations in the GitOpsService custom resource.
1.5. Creating an application by using the Argo CD dashboard Copier lienLien copié sur presse-papiers!
Argo CD provides a dashboard which allows you to create applications.
This sample workflow walks you through the process of configuring Argo CD to recursively sync the content of the cluster directory to the cluster-configs application. The directory defines the OpenShift Container Platform web console cluster configurations that add a link to the Red Hat Developer Blog - Kubernetes under the
menu in the web console, and defines a namespace spring-petclinic on the cluster.
Prerequisites
- You have logged in to the OpenShift Container Platform cluster as an administrator.
- You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
- You have logged in to Argo CD instance.
Procedure
- In the Argo CD dashboard, click NEW APP to add a new Argo CD application.
For this workflow, create a cluster-configs application with the following configurations:
- Application Name
-
cluster-configs - Project
-
default - Sync Policy
-
Manual - Repository URL
-
https://github.com/redhat-developer/openshift-gitops-getting-started - Revision
-
HEAD - Path
-
cluster - Destination
-
https://kubernetes.default.svc - Namespace
-
spring-petclinic - Directory Recurse
-
checked
- Click CREATE to create your application.
-
Open the Administrator perspective of the web console and expand Administration
Namespaces. -
Search for and select the namespace, then enter
argocd.argoproj.io/managed-by=openshift-gitopsin the Label field so that the Argo CD instance in theopenshift-gitopsnamespace can manage your namespace.
1.6. Creating an application by using the oc tool Copier lienLien copié sur presse-papiers!
You can create Argo CD applications in your terminal by using the oc tool.
Prerequisites
- You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
- You have logged in to an Argo CD instance.
Procedure
Download the sample application:
git clone git@github.com:redhat-developer/openshift-gitops-getting-started.git
$ git clone git@github.com:redhat-developer/openshift-gitops-getting-started.gitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the application:
oc create -f openshift-gitops-getting-started/argo/app.yaml
$ oc create -f openshift-gitops-getting-started/argo/app.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
oc getcommand to review the created application:oc get application -n openshift-gitops
$ oc get application -n openshift-gitopsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add a label to the namespace your application is deployed in so that the Argo CD instance in the
openshift-gitopsnamespace can manage it:oc label namespace spring-petclinic argocd.argoproj.io/managed-by=openshift-gitops
$ oc label namespace spring-petclinic argocd.argoproj.io/managed-by=openshift-gitopsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.7. Creating an application in the default mode by using the GitOps CLI Copier lienLien copié sur presse-papiers!
You can create applications in the default mode by using the GitOps argocd CLI.
This sample workflow walks you through the process of configuring Argo CD to recursively sync the content of the cluster directory to the cluster-configs application. The directory defines the OpenShift Container Platform cluster configurations and the spring-petclinic namespace on the cluster.
Prerequisites
- You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
-
You have installed the OpenShift CLI (
oc). -
You have installed the Red Hat OpenShift GitOps
argocdCLI. - You have logged in to Argo CD instance.
Procedure
Get the
adminaccount password for the Argo CD server:ADMIN_PASSWD=$(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)$ ADMIN_PASSWD=$(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the Argo CD server URL:
SERVER_URL=$(oc get routes openshift-gitops-server -n openshift-gitops -o jsonpath='{.status.ingress[0].host}')$ SERVER_URL=$(oc get routes openshift-gitops-server -n openshift-gitops -o jsonpath='{.status.ingress[0].host}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Log in to the Argo CD server by using the
adminaccount password and enclosing it in single quotes:ImportantEnclosing the password in single quotes ensures that special characters, such as
$, are not misinterpreted by the shell. Always use single quotes to enclose the literal value of the password.argocd login --username admin --password ${ADMIN_PASSWD} ${SERVER_URL}$ argocd login --username admin --password ${ADMIN_PASSWD} ${SERVER_URL}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
argocd login --username admin --password '<password>' openshift-gitops.openshift-gitops.apps-crc.testing
$ argocd login --username admin --password '<password>' openshift-gitops.openshift-gitops.apps-crc.testingCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that you are able to run
argocdcommands in the default mode by listing all applications:argocd app list
$ argocd app listCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the configuration is correct, then existing applications will be listed with the following header:
Sample output
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGETCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create an application in the default mode:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Label the
spring-petclinicdestination namespace to be managed by theopenshif-gitopsArgo CD instance:oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"
$ oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the available applications to confirm that the application is created successfully:
argocd app list
$ argocd app listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Even though the
cluster-configsArgo CD application has theHealthystatus, it is not automatically synced due to itsnonesync policy, causing it to remain in theOutOfSyncstatus.
1.8. Creating an application in core mode by using the GitOps CLI Copier lienLien copié sur presse-papiers!
You can create applications in core mode by using the GitOps argocd CLI.
This sample workflow walks you through the process of configuring Argo CD to recursively sync the content of the cluster directory to the cluster-configs application. The directory defines the OpenShift Container Platform cluster configurations and the spring-petclinic namespace on the cluster.
Prerequisites
- You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
-
You have installed the OpenShift CLI (
oc). -
You have installed the Red Hat OpenShift GitOps
argocdCLI.
Procedure
Log in to the OpenShift Container Platform cluster by using the
ocCLI tool:oc login -u <username> -p <password> <server_url>
$ oc login -u <username> -p <password> <server_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443
$ oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check whether the context is set correctly in the
kubeconfigfile:oc config current-context
$ oc config current-contextCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the default namespace of the current context to
openshift-gitops:oc config set-context --current --namespace openshift-gitops
$ oc config set-context --current --namespace openshift-gitopsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the following environment variable to override the Argo CD component names:
export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-server
$ export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that you are able to run
argocdcommands incoremode by listing all applications:argocd app list --core
$ argocd app list --coreCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the configuration is correct, then existing applications will be listed with the following header:
Sample output
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGETCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create an application in
coremode:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Label the
spring-petclinicdestination namespace to be managed by theopenshif-gitopsArgo CD instance:oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"
$ oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the available applications to confirm that the application is created successfully:
argocd app list --core
$ argocd app list --coreCopy to Clipboard Copied! Toggle word wrap Toggle overflow Even though the
cluster-configsArgo CD application has theHealthystatus, it is not automatically synced due to itsnonesync policy, causing it to remain in theOutOfSyncstatus.
1.9. Synchronizing your application with your Git repository Copier lienLien copié sur presse-papiers!
You can synchronize your application with your Git repository by modifying the synchronization policy for Argo CD. The policy modification automatically applies the changes in your cluster configurations from your Git repository to the cluster.
Procedure
- In the Argo CD dashboard, notice that the cluster-configs Argo CD application has the statuses Missing and OutOfSync. Because the application was configured with a manual sync policy, Argo CD does not sync it automatically.
- Click SYNC on the cluster-configs tile, review the changes, and then click SYNCHRONIZE. Argo CD will detect any changes in the Git repository automatically. If the configurations are changed, Argo CD will change the status of the cluster-configs to OutOfSync. You can modify the synchronization policy for Argo CD to automatically apply changes from your Git repository to the cluster.
- Notice that the cluster-configs Argo CD application now has the statuses Healthy and Synced. Click the cluster-configs tile to check the details of the synchronized resources and their status on the cluster.
-
Navigate to the OpenShift Container Platform web console and click
to verify that a link to the Red Hat Developer Blog - Kubernetes is now present there.
Navigate to the Project page and search for the
spring-petclinicnamespace to verify that it has been added to the cluster.Your cluster configurations have been successfully synchronized to the cluster.
1.10. Synchronizing an application in the default mode by using the GitOps CLI Copier lienLien copié sur presse-papiers!
You can synchronize applications in the default mode by using the GitOps argocd CLI.
This sample workflow walks you through the process of configuring Argo CD to recursively sync the content of the cluster directory to the cluster-configs application. The directory defines the OpenShift Container Platform cluster configurations and the spring-petclinic namespace on the cluster.
Prerequisites
- You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
- You have logged in to Argo CD instance.
-
You have installed the OpenShift CLI (
oc). -
You have installed the Red Hat OpenShift GitOps
argocdCLI.
Procedure
Get the
adminaccount password for the Argo CD server:ADMIN_PASSWD=$(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)$ ADMIN_PASSWD=$(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the Argo CD server URL:
SERVER_URL=$(oc get routes openshift-gitops-server -n openshift-gitops -o jsonpath='{.status.ingress[0].host}')$ SERVER_URL=$(oc get routes openshift-gitops-server -n openshift-gitops -o jsonpath='{.status.ingress[0].host}')Copy to Clipboard Copied! Toggle word wrap Toggle overflow Log in to the Argo CD server by using the
adminaccount password and enclosing it in single quotes:ImportantEnclosing the password in single quotes ensures that special characters, such as
$, are not misinterpreted by the shell. Always use single quotes to enclose the literal value of the password.argocd login --username admin --password ${ADMIN_PASSWD} ${SERVER_URL}$ argocd login --username admin --password ${ADMIN_PASSWD} ${SERVER_URL}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
argocd login --username admin --password '<password>' openshift-gitops.openshift-gitops.apps-crc.testing
$ argocd login --username admin --password '<password>' openshift-gitops.openshift-gitops.apps-crc.testingCopy to Clipboard Copied! Toggle word wrap Toggle overflow Because the application is configured with the
nonesync policy, you must manually trigger the sync operation:argocd app sync openshift-gitops/app-cluster-configs
$ argocd app sync openshift-gitops/app-cluster-configsCopy to Clipboard Copied! Toggle word wrap Toggle overflow List the application to confirm that the application has the
HealthyandSyncedstatuses:argocd app list
$ argocd app listCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.11. Synchronizing an application in core mode by using the GitOps CLI Copier lienLien copié sur presse-papiers!
You can synchronize applications in core mode by using the GitOps argocd CLI.
This sample workflow walks you through the process of configuring Argo CD to recursively sync the content of the cluster directory to the cluster-configs application. The directory defines the OpenShift Container Platform cluster configurations and the spring-petclinic namespace on the cluster.
Prerequisites
- You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
-
You have installed the OpenShift CLI (
oc). -
You have installed the Red Hat OpenShift GitOps
argocdCLI.
Procedure
Log in to the OpenShift Container Platform cluster by using the
ocCLI tool:oc login -u <username> -p <password> <server_url>
$ oc login -u <username> -p <password> <server_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443
$ oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check whether the context is set correctly in the
kubeconfigfile:oc config current-context
$ oc config current-contextCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the default namespace of the current context to
openshift-gitops:oc config set-context --current --namespace openshift-gitops
$ oc config set-context --current --namespace openshift-gitopsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the following environment variable to override the Argo CD component names:
export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-server
$ export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow Because the application is configured with the
nonesync policy, you must manually trigger the sync operation:argocd app sync --core openshift-gitops/app-cluster-configs
$ argocd app sync --core openshift-gitops/app-cluster-configsCopy to Clipboard Copied! Toggle word wrap Toggle overflow List the application to confirm that the application has the
HealthyandSyncedstatuses:argocd app list --core
$ argocd app list --coreCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.12. In-built permissions for cluster configuration Copier lienLien copié sur presse-papiers!
By default, the Argo CD instance has permissions to manage specific cluster-scoped resources such as cluster Operators, optional OLM Operators and user management.
-
Argo CD does not have
cluster-adminpermissions. - You can extend the permissions bound to any Argo CD instances managed by the GitOps Operator. However, you must not modify the permission resources, such as roles or cluster roles created by the GitOps Operator, because the Operator might reconcile them back to their initial state. Instead, create dedicated role and cluster role objects and bind them to the appropriate service account that the application controller uses.
Permissions for the Argo CD instance:
| Resources | Descriptions |
|---|---|
| Resource Groups | Configure the user or administrator |
|
| Optional Operators managed by OLM |
|
| Groups, Users and their permissions |
|
| Control plane Operators managed by CVO used to configure cluster-wide build configuration, registry configuration and scheduler policies |
|
| Storage |
|
| Console customization |
1.13. Adding permissions for cluster configuration Copier lienLien copié sur presse-papiers!
You can grant permissions for an Argo CD instance to manage cluster configuration. Create a cluster role with additional permissions and then create a new cluster role binding to associate the cluster role with a service account.
Prerequisites
-
You have access to an OpenShift Container Platform cluster with
cluster-adminprivileges and are logged in to the web console. - You have installed the Red Hat OpenShift GitOps Operator on your OpenShift Container Platform cluster.
Procedure
In the web console, select User Management
Roles Create Role. Use the following ClusterRoleYAML template to add rules to specify the additional permissions.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Create to add the cluster role.
-
To create the cluster role binding, select User Management
Role Bindings Create Binding. - Select All Projects from the Project list.
- Click Create binding.
- Select Binding type as Cluster-wide role binding (ClusterRoleBinding).
- Enter a unique value for the RoleBinding name.
- Select the newly created cluster role or an existing cluster role from the drop-down list.
Select the Subject as ServiceAccount and the provide the Subject namespace and name.
-
Subject namespace:
openshift-gitops Subject name:
openshift-gitops-argocd-application-controllerNoteThe value of Subject name depends on the GitOps control plane components for which you create the cluster roles and cluster role bindings.
-
Subject namespace:
Click Create. The YAML file for the
ClusterRoleBindingobject is as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.14. Installing OLM Operators using Red Hat OpenShift GitOps Copier lienLien copié sur presse-papiers!
Red Hat OpenShift GitOps with cluster configurations manages specific cluster-scoped resources and takes care of installing cluster Operators or any namespace-scoped OLM Operators.
Consider a case where as a cluster administrator, you have to install an OLM Operator such as Tekton. You use the OpenShift Container Platform web console to manually install a Tekton Operator or the OpenShift CLI to manually install a Tekton subscription and Tekton Operator group on your cluster.
Red Hat OpenShift GitOps places your Kubernetes resources in your Git repository. As a cluster administrator, use Red Hat OpenShift GitOps to manage and automate the installation of other OLM Operators without any manual procedures. For example, after you place the Tekton subscription in your Git repository by using Red Hat OpenShift GitOps, the Red Hat OpenShift GitOps automatically takes this Tekton subscription from your Git repository and installs the Tekton Operator on your cluster.
1.14.1. Installing cluster-scoped Operators Copier lienLien copié sur presse-papiers!
Operator Lifecycle Manager (OLM) uses a default global-operators Operator group in the openshift-operators namespace for cluster-scoped Operators. Hence you do not have to manage the OperatorGroup resource in your Gitops repository. However, for namespace-scoped Operators, you must manage the OperatorGroup resource in that namespace.
To install cluster-scoped Operators, create and place the Subscription resource of the required Operator in your Git repository.
Example: Grafana Operator subscription
1.14.2. Installing namepace-scoped Operators Copier lienLien copié sur presse-papiers!
To install namespace-scoped Operators, create and place the Subscription and OperatorGroup resources of the required Operator in your Git repository.
Example: Ansible Automation Platform Resource Operator
When deploying multiple Operators using Red Hat OpenShift GitOps, you must create only a single Operator group in the corresponding namespace. If more than one Operator group exists in a single namespace, any CSV created in that namespace transition to a failure state with the TooManyOperatorGroups reason. After the number of Operator groups in their corresponding namespaces reaches one, all the previous failure state CSVs transition to pending state. You must manually approve the pending install plan to complete the Operator installation.