Overview
FluxCD’s Flux2 is a GitOps tool for managing Kubernetes clusters. It provides a seamless way to deploy, update, and manage applications using Git repositories as the source of truth. In this documentation, we will focus on using Git with Flux2.
Description
The git
package is a Node.js library for interacting with Git repositories, which is used extensively by Flux2 for managing Git repositories within Kubernetes environments. Flux2 integrates tightly with Git APIs and SDKs, allowing it to provide the best possible Git support for GitOps.
Prerequisites
Before getting started, ensure you have a good understanding of the following:
Usage
To use Git with Flux2, follow these steps:
- Install Flux2: Install Flux2 in your Kubernetes cluster using the official documentation: Install Flux
- Create a GitRepository resource: Use the
flux create source git
command to create or update a GitRepository resource. For example:
flux create source git my-repo \
--url=https://github.com/myusername/my-repo \
--branch=main
This command generates a GitRepository resource and waits for it to sync. For Git over SSH, host and SSH keys are automatically generated and stored in a Kubernetes secret. For private Git repositories, basic authentication credentials are stored in a Kubernetes secret.
Best Practices
- Use a dedicated Git branch for deployments: Create a separate Git branch for deployments, such as
k8s
,prod
, orstaging
. This helps maintain a clear separation between your development and production environments. - Ignore unnecessary files: Use the
ignore
attribute in the GitRepository resource to ignore unnecessary files, such as logs or build artifacts. This helps reduce the amount of data transferred between the Git repository and the Kubernetes cluster.
License
The git
package used by Flux2 is licensed under the Apache License, Version 2.0. For more information, visit Apache License.