Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ShadowArc147/gitops-setup

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Red Hat Openshift GitOps Demo

1. Introduction

GitOps is an increasingly popular set of practices for managing the complexities of running hybrid multicluster Kubernetes infrastructure. GitOps centers on treating Git repositories as the single source of truth and applying Git workflows that have been consistently used for application development to infrastructure and application operators.

This repository provides a starting point to deploy many different operator and applications, such as GitOps, ArgoCD, Nexus, as well as your first application.

2. Installing ArgoCD and Openshift GitOps

Red Hat OpenShift GitOps Red Hat OpenShift GitOps uses Argo CD to manage specific cluster-scoped resources, including platform operators, optional Operator Lifecycle Manager (OLM) operators, and user management. Argo CD is a popular Cloud Native Computing Foundation (CNCF) open source GitOps Kubernetes Operator for declarative configuration on Kubernetes clusters.

Now, we are going to install the Red Hat OpenShift GitOps Operator to an OpenShift Container Platform cluster and logging in to the Argo CD instance.

oc process -f templates/gitops-01-operator.yaml | oc apply -f -

After the installation is completed, the operator pods will be running in the openshift-operators project.

By default, the GitOps operator deploys an ArgoCD instance in the openshift-gitops project. To avoid that and have full control of the installation location, the following configuration has been set in the previous OCP template.

    spec:
      config:
        env:
          - name: DISABLE_DEFAULT_ARGOCD_INSTANCE
            value: "true"

Now, we are going to deploy our ArgoCD instance manually using the following template:

oc process -f templates/gitops-02-argocd.yaml | oc apply -f -

This command will create a namespace gitops, a default Application Project and an ArgoCD cluster. The configuration used is the default Operator configuration with some small improvements: Delegating authentication on the OpenShift integrated login, or implementing basic RBAC policies.

Access the installed ArgoCD cluster using the following route:

oc get routes argocd-cluster-server -n gitops --template="https://{{.spec.host}}"

2.1. Configuring Authentication

ArgoCD provides several ways of authenticating users. Here we will talk about the two easier to configure: The default admin user and the integration with Openshift login.

2.1.1. Using the OpenShift integrated login

Enabling OpenShift integrated login is quite simple, but might not be perfectly documented as of today. It is already configured in the templates deployed in the section above. This is just for documentation purposes.

This feature implies changes at several levels:

  1. Set an environment variable at the operator level. This will tell the operator to enable Dex server for external authentication. GH Issue, Blog post.

        spec:
          config:
            env:
              - name: DISABLE_DEX
                value: "false"
  2. Configure the ArgoCD object to use the DEX Openshift login integration.

        spec:
          dex:
            openShiftOAuth: true
  3. Configure the ArgoCD object with the desired RBAC policies. For example, the simples option:

        spec:
          rbac:
            defaultPolicy: 'role:readonly'
            policy: |
              g, system:cluster-admins, role:admin
            scopes: '[groups]'

2.1.2. Using the default admin user

Apart from using the Openshift integrated login, it is possible to use the built-in admin user. This user has been disabled in the ArgoCD template template/gitops-02-argocd.yaml configuring .spec.disableAdmin to true. Set it to false if you want to use it.

Then, you will be able to login using ArgoCD user / password. Use user admin and obtain the password with the following command:

oc extract secret/argocd-cluster-cluster -n gitops  --to=-

2.2. Configuring authorization

🔥
Authorization in ArgoCD is a combination of configuring permissions at different levels. Here we present all three levels that you have to take care of in order to set proper authorization configuration. Please, read the three following sections carefully.

2.2.1. Using ArgoCD managed namespaces

The current version of Openshift GitOps supports deploying several clusters of ArgoCD in the same Openshift cluster. This feature is essential for organizations that want to implement multi-tenancy at the OCP level. With this feature available, now we have to distribute each namespace among the ArgoCD clusters. This is done using the managed-by label.

Add a label to the namespace where your application is deployed in so that the Argo CD instance in the gitops namespace can manage it:

oc label namespace spring-petclinic argocd.argoproj.io/managed-by=gitops

If you don’t do so, the error message that you will see in the web console when you try to synchronize an application is:

Namespace "<namespace>" for <resource> "<resource-name>" is not managed.

Link to the documentation.

2.2.2. Using namespace Isolation at cluster level (Service Account)

The ArgoCD instance have only privileges in its namespace which is gitops. For creating/updating/listing resources in other namespaces, it’s mandatory to update the RBAC for its Service Account.

This section can be as complex as the security requirements that your organization demands for the ArgoCD deployment. The easiest solution for non-productive environments would be to grant cluster-admin rights to the service account that interacts with the k8s API.

oc adm policy add-cluster-role-to-user admin system:serviceaccount:gitops:argocd-cluster-argocd-application-controller

If you prefer to have a per-project tunning, you can use the configuration set in the template template/gitops-03-application-app.yaml, where we provide project admin rights to the same service account. This is also oriented to get a proper multi-tenancy configuration, like in the previous section. Check the template mentioned or use the following command:

oc adm policy add-role-to-user admin system:serviceaccount:gitops:argocd-cluster-argocd-application-controller -n spring-petclinic

Obviously, you can even set a finer tunning by creating a custom Role and RoleBinding to specify the resources that each ArgoCD will be allowed to manage per namespace. This KCS gives you an example of how to configure one of these RoleBindings.

Extra documentation:

2.2.3. Using advanced RBAC configuration (SSO users)

The RBAC feature enables restriction of access to Argo CD resources. Argo CD does not have its own user management system and has only one built-in user admin.

The RBAC configuration can be customized using the `ArgoCD.spec.rbac.policy `

/ / TO DO

oc adm groups new spring-petclinic-developer oc adm groups new spring-petclinic-admin oc adm groups add-users spring-petclinic-admin alopezme oc adm groups add-users spring-petclinic-developer svidalur

3. Creating your first application

⚠️

This section expects you to create the namespace for the demo application manually. In the following section you will see how to automate it with GitOps, too.

Execute the following command:

oc new-project spring-petclinic --display-name="Pet Clinic app" --description="This project holds all the resources of the Pet Clinic application"

Create an Application resource using the following template:

oc process -f templates/gitops-03-application-app.yaml | oc apply -f -

4. Managing your infra with Openshift GitOps

⚠️

This section explains how to automate the management of Openshift infra resources like projects. Please, delete the project created manually in the previous section.

Execute the following command:

oc delete project spring-petclinic

6. Annex: Installing Nexus

TL;DR: Execute the following script to auto-install a Nexus instance in your cluster: ./auto-install.nexus.sh

Nexus Repository OSS is an open source repository that supports many artifact formats, including Docker, Java™, and npm. With the Nexus tool integration, pipelines in your toolchain can publish and retrieve versioned apps and their dependencies by using central repositories that are accessible from other environments.

If you are planning to deploy your applications using Helm charts, most of the architectures you will need a Helm repository to host to packaged Helm charts. Install a Nexus repository manager using the following commands:

# Define common variables
OPERATOR_NAMESPACE="nexus"

# Deploy operator
oc process -f templates/nexus-01-operator.yaml -p OPERATOR_NAMESPACE=$OPERATOR_NAMESPACE | oc apply -f -

# Workaround for issue: https://github.com/sonatype/operator-nxrm3/issues/8
oc adm policy add-scc-to-user privileged -z default -n $OPERATOR_NAMESPACE

# Deploy application instance
oc process -f templates/nexus-02-server.yaml -p OPERATOR_NAMESPACE=$OPERATOR_NAMESPACE -p SERVER_NAME="nexus-server" | oc apply -f -

6.1. Creating a Helm repository

Create a Helm repository with the following steps:

  • Access the Nexus route: oc get routes nexus-server --template="https://{{.spec.host}}".

  • Log in using the admin credentials: admin / admin123.

  • Server Administration > Repositories > Create Repositories > "Helm(hosted)"

    • name: helm-charts.

    • DeploymentPolicy: Allow redeploy.

  • Click on Create repository.

If you don’t want to use the console, you can use CURL command to create this repository on the auto-install-nexus script.

7. Openshift GitOps support and deployed versions

OpenShift GitOps is shipped inclusive as part of the OpenShift Container Platform subscription and supported per the Red Hat production terms of support.

Check the following table with GitOps versions and its equivalent to ArgoCD:

GitOps version OCP version ArgoCD version Release date

1.0 (TP)

4.6

1.8

Feb 12, 2021

1.1

4.7

X

April 15, 2021

1.2

4.8

2.0

July 29, 2021

1.3 (Not GA yet)

4.9

2.1

October, 2021?

Note that only the ArgoCD CRD is supported, the rest are Tech Preview in the latest version of Openshift GitOps:

Feature Support in GitOps 1.2

Argo CD

GA

Argo CD ApplicationSet

TP

Red Hat OpenShift GitOps Application Manager (kam)

TP

Red Hat OpenShift GitOps Service

TP

For more information check the Openshift GitOps release notes.

About

This repository showcases how to deploy a basic Red Hat Git Ops environment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Shell 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.