Skip to content

Deploying your Application with OpenShift GitOps#

  1. From the OpenShift Console Administrator view click through HOME -> Operators -> Operator Hub, search for "openshift gitops" and hit Install. Accept all defaults.

    OpenShift Web Console - OpenShift GitOps in OperatorHub

  2. Create a new project

    oc new-project bgd
    
  3. Deploy ArgoCD into your project

    cat <<EOF | oc apply -f -
    apiVersion: argoproj.io/v1alpha1
    kind: ArgoCD
    metadata:
      name: argocd
    spec:
      sso:
        dex:
          openShiftOAuth: true
          resources:
            limits:
              cpu: 500m
              memory: 256Mi
            requests:
              cpu: 250m
              memory: 128Mi
        provider: dex
      rbac:
        defaultPolicy: "role:readonly"
        policy: "g, system:authenticated, role:admin"
        scopes: "[groups]"
      server:
        insecure: true
        route:
          enabled: true
          tls:
            insecureEdgeTerminationPolicy: Redirect
            termination: edge
    EOF
    
  4. Wait for ArgoCD to be ready

    oc rollout status deploy/argocd-server
    
  5. Apply the gitops configuration

    cat <<EOF | oc apply -f -
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: bgd-app
      namespace: bgd
    spec:
      destination:
        namespace: bgd
        server: https://kubernetes.default.svc
      project: default
      source:
        path: apps/bgd/base
        repoURL: https://github.com/rh-mobb/gitops-bgd-app
        targetRevision: main
      syncPolicy:
        automated:
          prune: true
          selfHeal: false
        syncOptions:
        - CreateNamespace=false
    EOF
    
  6. Find the URL for your Argo CD dashboard and log in using your OpenShift credentials

    oc get route argocd-server -n bgd -o jsonpath='{.spec.host}{"\n"}'
    

  7. Click on the Application to show its topology

  8. Verify that OpenShift sees the Deployment as rolled out

    oc rollout status deploy/bgd
    
  9. Get the route and browse to it in your browser

    oc get route bgd -n bgd -o jsonpath='{.spec.host}{"\n"}'
    
  10. You should see a green box in the website like so

  11. Patch the OpenShift resource to force it to be out of sync with git

    oc patch deploy/bgd --type='json' \
      -p='[{"op": "replace", "path":
      "/spec/template/spec/containers/0/env/0/value", "value":"blue"}]'
    
  12. Refresh Your browser and you should see a blue box in the website like so

  13. Meanwhile check ArgoCD it should show the application as out of sync. Click the Sync button to have it revert the change you made in OpenShift

  14. Check again, you should see a green box in the website like so