GitOps Research
Published: 2023-12-01 02:24:02

## Kubernetes Deployments

* [Pods, Replica Sets, & Deployments in 5 Minutes](https://www.youtube.com/watch?v=iC-WxZGhFqs&list=PLehXSATXjcQHdGTNwl0f_JZqQT_tkA0ca&index=3) - Sai Vennam (5 minutes)

* Observe

* Diff

* Act

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wh1f60c3o6br2fqtnxgz.png)

## GitOps vs DevOps

* [What is GitOps? | GitOps vs DevOps](https://www.youtube.com/watch?v=lI03nh0EmaQ) - Sai Vennam (6 Minutes)

* Declarative

* Version-Controlled

* Auto-Reconciled

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfzts0jq7jeo97k9pjtq.png)

## Flux Overview

* Extends K8s with Custom Resources known as Controllers that watch Source Repositories and Auto-Reconcile

* Provides GitOps for both Apps and Infra

* Has CLI to:

  * Bootstrap cluster & repository

  * Add Git Sources

  * Configure Build and Apply

* As [K8's custom resource](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/), it's fully declaratively configured using YAML encoded manifests, most of which are generated with the CLI.

### Bootstrap a Cluster

* Deploys FLux to Cluster

* Creates and Configures Infrastructure Github Repo

* Commits Flux-System K8s Manifests

* [Use a CLI to bootstrap a cluster](https://youtu.be/N6UCKF7JD7k?si=NLGlT9IRWHeoKdMM&t=918) - Geert Baeke - (6 minutes starting at Minute 15)

* [Get Started with Flux](https://fluxcd.io/flux/get-started/) - Tutorial on Fluxcd.io

* [Bootstrap for Github Organization](https://fluxcd.io/flux/installation/bootstrap/github/#github-organization) - Note for how to handle Repos in a Github Org.

```bash
brew install fluxcd/tap/flux
flux check --pre
export GITHUB_TOKEN=
export GITHUB_USER=
flux bootstrap github \
  --owner=$GITHUB_USER \
  --repository=my-infra \
  --branch=main \
  --path=app-cluster \
  --personal
```

### Add Source

* Generates GitRepository Manifiest that you commit and push to the infrastructure repo created during bootstrap.

* [Use CLI to add GitRepository](https://fluxcd.io/flux/get-started/#add-podinfo-repository-to-flux) - Generates Manifest which you commit

### Configure Build and Apply

* Generates Kustomization Manifest that you commit and push to the infrastructure repo created during bootstrap.

* [Use CLI to configure build and apply](https://fluxcd.io/flux/get-started/#deploy-podinfo-application)

### Run Migrations with Pre-Deployment Jobs

Kustomization Manifests which are reconciled by Flux can be configured to depend on each other.  This makes running pre-deployment jobs like a migration possible.

* [Configure Pre-Deployment Jobs](https://fluxcd.io/flux/use-cases/running-jobs/)

### Connect to CI

* Image Automation Controller

* Image Reflector Controller

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exqa4tbst53loxpdi19m.png)

## GitOps for Infrastructure outside K8s

* Terraform Controller

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cy1fewrkzpfefsoyukn.png)

* Free and Open Source 

Videos

* [How to achieve (actual) GitOps with Terraform and Kubernetes](https://youtu.be/MlsbC9v8fxY?feature=shared&t=592) - Roberth Strand

* [How to Achieve (Actual) GitOps with Terraform and Flux](https://youtu.be/EXp2xAbII_k?si=TRMR_JtAtuDjoZ4q&t=665) - Priyanka Ravi

Resources

* [Getting Started with Terraform Controller](https://docs.gitops.weave.works/docs/terraform/get-started/) - Official Docs

* [Blog Post - Flux Tutorial](https://anaisurl.com/full-tutorial-getting-started-with-flux-cd/) - Anais Urlichs