Chapter 6. Automating application management with the GitOps controller


GitOps with Argo CD for MicroShift is a lightweight, optional add-on controller derived from the Red Hat OpenShift GitOps Operator. GitOps for MicroShift uses the command-line interface (CLI) of Argo CD to interact with the GitOps controller that acts as the declarative GitOps engine. You can consistently configure and deploy Kubernetes-based infrastructure and applications across clusters and development lifecycles.

6.1. What you can do with the GitOps agent

By using the GitOps with Argo CD agent with MicroShift, you can utilize the following principles:

  • Implement application lifecycle management.

    • Create and manage your clusters and application configuration files using the core principles of developing and maintaining software in a Git repository.
    • You can update the single repository and GitOps automates the deployment of new applications or updates to existing ones.
    • For example, if you have 1,000 edge devices, each using MicroShift and a local GitOps agent, you can easily add or update an application on all 1,000 devices with just one change in your central Git repository.
  • The Git repository contains a declarative description of the infrastructure you need in your specified environment and contains an automated process to make your environment match the described state.
  • You can also use the Git repository as an audit trail of changes so that you can create processes based on Git flows such as review and approval for merging pull requests that implement configuration changes.

6.2. Creating GitOps applications on MicroShift

You can create a custom YAML configuration to deploy and manage applications in your MicroShift service. To install the necessary packages to run GitOps applications, follow the documentation in "Installing the GitOps Argo CD manifests from an RPM package".

Prerequisites

  • You installed the microshift-gitops packages.
  • The Argo CD pods are running in the openshift-gitops namespace.

Procedure

  1. Create a YAML file and add your customized configurations for the application:

    Example YAML for a spring-petclinic application

    kind: AppProject
    apiVersion: argoproj.io/v1alpha1
    metadata:
      name: default
      namespace: openshift-gitops
    spec:
      clusterResourceWhitelist:
      - group: '*'
        kind: '*'
      destinations:
      - namespace: '*'
        server: '*'
      sourceRepos:
      - '*'
    ---
    kind: Application
    apiVersion: argoproj.io/v1alpha1
    metadata:
      name: spring-petclinic
      namespace: openshift-gitops
    spec:
      destination:
        namespace: spring-petclinic
        server: https://kubernetes.default.svc
      project: default
      source:
        directory:
          recurse: true
        path: app
        repoURL: https://github.com/siamaksade/openshift-gitops-getting-started
      syncPolicy:
        automated: {}
        syncOptions:
        - CreateNamespace=true
        - ServerSideApply=true

  2. To deploy the applications defined in the YAML file, run the following command:

    $ oc apply -f <my_app.yaml> 1
    1
    Replace <my_app.yaml> with the name of your application YAML.

Verification

  • To verify your application is deployed and synced, run the following command:

    $ oc get applications -A

    It might take a few minutes for the application to show the Healthy status.

    Example output

    NAMESPACE          NAME               SYNC STATUS   HEALTH STATUS
    openshift-gitops   spring-petclinic   Synced        Healthy

6.3. Limitations of using the GitOps agent with MicroShift

GitOps with Argo CD for MicroShift has the following differences from the Red Hat OpenShift GitOps Operator:

  • The gitops-operator component is not used with MicroShift.
  • To maintain the small resource use of MicroShift, the Argo CD web console is not available. You can use the Argo CD CLI.
  • Because MicroShift is single-node, there is no multi-cluster support. Each instance of MicroShift is paired with a local GitOps agent.
  • The oc adm must-gather command is not available in MicroShift.

6.4. Troubleshooting GitOps

If you have problems with your GitOps controller, you can use the OpenShift CLI (oc) tool.

6.4.1. Debugging GitOps with oc adm inspect

You can debug GitOps by using the OpenShift CLI (oc).

Prerequisites

  • The oc command line tool is installed.

Procedure

  1. Run the oc adm inspect command when in the GitOps namespace:

    $ oc adm inspect ns/openshift-gitops

    Example output

    Gathering data for ns/openshift-gitops...
    W0501 20:34:35.978508 57625 util.go:118] the server doesn't have a resource type egressfirewalls, skipping the inspection
    W0501 20:34:35.980881 57625 util.go:118] the server doesn't have a resource type egressqoses, skipping the inspection
    W0501 20:34:36.040664 57625 util.go:118] the server doesn't have a resource type servicemonitors, skipping the inspection
    Wrote inspect data to inspect.local.2673575938140296280.

Next steps

  • If oc adm inspect did not provide the information you need, you can run an sos report.

6.5. Additional resources

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.