How to bootstrap FluxCD for Azure DevOps

FluxCD DevOps
FluxCD DevOps

Introduction

FluxCD is a continuous delivery (CD) tool designed for Kubernetes. It automates application deployment within Kubernetes clusters by monitoring version-controlled configuration files. In this article, I will show you how to set up and install FluxCD for your Azure DevOps Services.

Prerequisites

  • Access to a k8s cluster.
  • Flux CLI installed.
  • Basic knowledge of kubernetes.

Step-by-step Guide

  1. Create the DevOps repo with the following files:

    mkdir -p clusters/my-cluster/flux-system
    touch clusters/my-cluster/flux-system/gotk-components.yaml
    touch clusters/my-cluster/flux-system/gotk-sync.yaml \
    touch clusters/my-cluster/flux-system/kustomization.yaml
    
  2. Update the kustomization.yaml file with the following content:

    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    resources:
      - gotk-components.yaml
      - gotk-sync.yaml
    patches:
      - patch: |
          - op: add
            path: /spec/template/spec/containers/0/args/-
            value: --ssh-hostkey-algos=rsa-sha2-512,rsa-sha2-256
        target:
          kind: Deployment
          name: (source-controller|image-automation-controller)
    
  3. Commit and push the changes:

    git add -A && git commit -m "feat: init flux" && git push
    
  4. Next, generate an SSH key pair that is compatible with Azure DevOps:

    ssh-keygen -t rsa-sha2-512
    
  5. Upload the SSH public key to Azure DevOps.

  6. Finally, bootstrap the FluxCD:

    flux bootstrap git \
      --components-extra=image-reflector-controller,image-automation-controller \
      --url=ssh://[email protected]/v3/<org>/<project>/<repository> \
      --branch=<your-branch> \
      --ssh-hostkey-algos=rsa-sha2-512,rsa-sha2-256 \
      --private-key-file=<path/to/your/ssh/private.key> \
      --password=<key-passphrase-if-any> \
      --path=./clusters/my-cluster
    

Conclusion

Now that FluxCD has been bootstrapped for your DevOps, you can commit your applications (yaml files) to /clusters/my-cluster, and FluxCD will deploy them to your K8s cluster automatically.

References

Comments