cloud-native-toolkit / multi-tenancy-gitops

Provides our opinionated point of view on how GitOps can be used to manage the infrastructure, services and application layers of K8s based systems
https://cloudnativetoolkit.dev/adopting/use-cases/gitops/gitops-ibm-cloud-paks/
Apache License 2.0
113 stars 728 forks source link
argocd cloudpaks gitops gitops-toolkit kubernetes openshift

Cloud Native Toolkit - GitOps Production Deployment Guide

The GitOps concept originated from Weaveworks back in 2017 and the goal was to automate the operations of a Kubernetes (K8s) system using a model external to the system as the source of truth (History of GitOps).

This repository provides our opinionated point of view on how GitOps can be used to manage the infrastructure, services and application layers of K8s based systems. It takes into account the various personas interacting with the system and accounts for separation of duties. The instructions and examples are focused around the Red Hat OpenShift platform and IBM Cloud Paks.

The reference architecture for this GitOps workflow can be found here.

Table of contents

Pre-requisites

Red Hat OpenShift cluster

CLI tools

IBM Entitlement Key

Setup git repositories

Tasks:

  1. Create a new GitHub Organization using instructions from this GitHub documentation.
  2. From each template repository, click the Use this template button and create a copy of the repository in your new GitHub Organization. Create repository from a template
  3. Clone the repositories locally.
    mkdir -p gitops-repos
    cd gitops-repos
    # Clone using SSH
    git clone git@github.com:<GIT_ORG>/multi-tenancy-gitops.git
    git clone git@github.com:<GIT_ORG>/multi-tenancy-gitops-infra.git
    git clone git@github.com:<GIT_ORG>/multi-tenancy-gitops-services.git
  4. Update the default Git URl and branch references in your multi-tenancy-gitops repository by running the provided script ./scripts/set-git-source.sh script.
    cd multi-tenancy-gitops
    GIT_ORG=<GIT_ORG> GIT_BRANCH=master ./scripts/set-git-source.sh
    git commit -m "Update Git URl and branch references"
    git push origin master

Install and configure OpenShift GitOps

Tasks:

  1. Install the OpenShift GitOps Operator, create a ClusterRole and deploy a default instance of ArgoCD.
    oc apply -f setup/ocp47/
    while ! oc wait crd applications.argoproj.io --timeout=-1s --for=condition=Established  2>/dev/null; do sleep 30; done
    while ! oc wait pod --timeout=-1s --for=condition=Ready -l '!job-name' -n openshift-gitops > /dev/null; do sleep 30; done
  2. Delete the default ArgoCD instance
    oc delete gitopsservice cluster -n openshift-gitops || true
    oc delete argocd openshift-gitops -n openshift-gitops || true
  3. Create a custom ArgoCD instance with custom checks
    oc apply -f setup/ocp47/argocd-instance/ -n openshift-gitops
    while ! oc wait pod --timeout=-1s --for=condition=ContainersReady -l app.kubernetes.io/name=openshift-gitops-cntk-server -n openshift-gitops > /dev/null; do sleep 30; done

Bootstrap the OpenShift cluster

Tasks:

  1. Select a profile and delete the others from the 0-bootstrap directory. If this is your first usage of the gitops workflow, use the single-cluster profile and deploy the ArgoCD Bootstrap Application.
    GITOPS_PROFILE="0-bootstrap/single-cluster"
    oc apply -f ${GITOPS_PROFILE}/bootstrap.yaml
  2. Retrieve the ArgoCD/GitOps URL and admin password:
    oc get route -n openshift-gitops openshift-gitops-cntk-server -o template --template='https://{{.spec.host}}'
    oc extract secrets/openshift-gitops-cntk-cluster --keys=admin.password -n openshift-gitops --to=-

Select resources to deploy

Tasks:

  1. Select a profile and delete the others from the 0-bootstrap directory. If this is your first usage of the gitops workflow, Use the single-cluster profile.
    GITOPS_PROFILE="0-bootstrap/single-cluster"
  2. Review the Infrastructure layer kustomization.yaml and un-comment the resources to deploy.
  3. Review the Services layer kustomization.yaml and un-comment the resources to deploy.
  4. Commit and push changes to your git repository
    git add .
    git commit -m "initial bootstrap setup"
    git push origin
  5. Validate the recipe was deployed correctly following the Validation section in the recipe.