Coder Social home page Coder Social logo

fluxcd's Introduction

fluxCD

This is a demonstration of GitOps on kubernetes cluster using Flux with AWS. If you want GCP or Azure, please view gcp, Azure

1. Prerequisites

2. Let's start

1. Initialize cluster

aws cloudformation deploy --stack-name flux --template-file ./cloudformation-resources/k8s.yaml --capabilities CAPABILITY_IAM

2. get kubeconfig

List clusters:

aws eks list-clusters

Get kubeconfig file:

aws eks update-kubeconfig --name EKSCluster

Test cluster:

kubectl get nodes

3. Bootstrap flux

Configure environment variable:

export GITHUB_TOKEN=
export GITHUB_USER=

eg: manager-flux

export GITHUB_REPO=

eg: main

export BRANCH=

eg: ./clusters/dev

export PATH=
flux bootstrap github --owner $GITHUB_USER --repository $GITHUB_REPO --branch $BRANCH --path $PATH --personal

4. Worker repo

Create github repo with the name worker-flux with content in k8s-resources folder

* deployment.yaml
* kustomization.yaml

You can replace it with your desire resources

5. Manager repo

Example structure:

* ./clusters
  * staging
    * flux-system
      * gotk-components.yaml
      * gotk-sync.yaml
      * kustomization.yaml
    * nginx-source.yaml
    * nginx-kustomization.yaml
  * production
    * flux-system
      * gotk-components.yaml
      * gotk-sync.yaml
      * kustomization.yaml

Clone manager repo

git clone [email protected]:$GITHUB_USER/$GITHUB_REPO.git $HOME/$GITHUB_REPO
cd $HOME/$GITHUB_REPO

Create resources that point to worker repo

cat << EOF | sudo tee -a $PATH/ngin-source.yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
  name: nginx
  namespace: flux-system
spec:
  interval: 1m
  ref:
    branch: $BRANCH
  url: https://github.com/$GITHUB_USER/worker-flux
EOF
git add -A && git commit -m "Add nginx GitRepository"
git push

Create resources that point to gitrepo was created:

cat << EOF | sudo tee -a $PATH/ngin-kustomization.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: nginx
  namespace: flux-system
spec:
  interval: 30m0s
  path: ./
  prune: true
  retryInterval: 2m0s
  sourceRef:
    kind: GitRepository
    name: nginx
  targetNamespace: default
  timeout: 3m0s
  wait: true
git add -A && git commit -m "Add nginx Kustomization`
git push

6. Check

View kustomization resources:

flux get kustomizations --watch

View deployment resources:

kubectl -n default get deployments

Update worker repo:

  • Eg: replica
  • Commit > push

View kustomization resources again:

flux get kustomizations --watch

View deployment resources again:

kubectl -n default get deployments

7. Destroy cluster

aws cloudformation delete-stack --stack-name flux

fluxcd's People

Contributors

haquocdat543 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.