Building, Installing, and Setting up Flux
This document outlines the steps required to build, install, and set up Flux.
Development Environment
To build and run Flux from source, you’ll need a Go development environment.
Install Go:
- Download and install the latest Go version from the official website: https://go.dev/
Set up Environment Variables:
- Set the
GOPATH
environment variable to the desired location for your Go workspace. - Add the
bin
directory within yourGOPATH
to your system’sPATH
.
- Set the
Building Flux
Clone the repository:
git clone https://github.com/fluxcd/flux2.git cd flux2
Install dependencies:
make install-envtest
Build the project:
make build
This will create a binary file in the
_output/bin
directory.
Installing Flux
To install Flux on your system, you can use the provided binary file or install it via Homebrew.
Install from binary:
- Copy the binary file from the
_output/bin
directory to a location in your system’sPATH
.
- Copy the binary file from the
Install via Homebrew:
- Add the Flux tap to your Homebrew configuration:
brew tap fluxcd/tap
- Install Flux using Homebrew:
brew install flux
- Add the Flux tap to your Homebrew configuration:
Setting Up Flux
Initialize Flux:
- Run the following command to initialize Flux:
flux --target-namespace=flux-system init
- Run the following command to initialize Flux:
Configure Flux:
- Create a Kubernetes secret containing your Git provider credentials:
apiVersion: v1 kind: Secret metadata: name: flux-system-git-credentials type: Opaque data: username: <your-username> password: <your-password>
- Apply the secret to your cluster:
kubectl apply -f secret.yaml
- Configure Flux using the
flux
command:flux --target-namespace=flux-system bootstrap \ --git-url=https://github.com/your-org/your-repo \ --git-branch=main \ --git-sync-interval=1m \ --git-secret-name=flux-system-git-credentials \ --image-automation.policy=auto
- Create a Kubernetes secret containing your Git provider credentials:
Running Flux
Once Flux is set up, it will automatically monitor your Git repository and deploy changes to your cluster.
Running Tests
Run unit tests:
make test
Run end-to-end tests:
make e2e
Building for Development
Build for development:
make build-dev
This will build a development version of Flux with debugging symbols.
Installing for Development
Install for development:
make install-dev
This will install the development version of Flux in your system’s
PATH
.
Using Docker
Build a Docker image:
docker build -t fluxcd/flux:latest .
Run the Docker image:
docker run -it fluxcd/flux:latest
Cleaning Up
- Remove build artifacts:
make tidy
Example Usage
Deploy a Kubernetes manifest:
flux --target-namespace=flux-system deploy \ --manifest=path/to/your/manifest.yaml
Create a new Helm release:
flux --target-namespace=flux-system helm-release create \ --name=my-release \ --namespace=my-namespace \ --chart=path/to/your/chart \ --version=1.2.3
Update an existing Helm release:
flux --target-namespace=flux-system helm-release update \ --name=my-release \ --namespace=my-namespace \ --chart=path/to/your/chart \ --version=1.2.4
Additional Resources
Top-Level Directory Explanations
manifests/ - This directory contains Kubernetes manifests used by Flux. It includes various subdirectories for different types of manifests, such as bases/
for base manifests, crds/
for Custom Resource Definitions, and policies/
for policy manifests.
pkg/ - This directory contains the Go packages for Flux. It includes various subdirectories for different packages, such as bootstrap/
for bootstrapping, log/
for logging, manifestgen/
for manifest generation, and printers/
for printing manifests.