Ready to automate your Kubernetes deployments? GitOps is the way to go, and FluxCD is a fantastic tool to make it happen. This guide walks you through the initial setup: installing Flux on your cluster and connecting it to your GitHub repository. Let's get started!
What's GitOps, Anyway?
In simple terms, GitOps means using a Git repository as the single source of truth for your desired infrastructure and application state. Flux is the operator that runs in your Kubernetes cluster, constantly comparing the cluster's live state to the state defined in your Git repo. If they differ, Flux automatically makes changes to the cluster to match the repo. Magic!
Prerequisites
Before we begin, make sure you have:
- A Kubernetes Cluster: Any cluster will do (like
k3son a Raspberry Pi,minikube, or a cloud provider's offering). Ensurekubectlis configured to access it. - A GitHub Account: We'll use GitHub to host our configuration repository.
- A GitHub Personal Access Token (PAT): Flux needs this to create deploy keys and potentially commit manifests back to your repository during the bootstrap process.
1. Create a GitHub Personal Access Token (PAT)
Flux needs permissions to interact with your repository.
- Go to your GitHub Settings.
- Navigate to Developer settings (usually near the bottom left).
- Click on Personal access tokens -> Tokens (classic).
- Click Generate new token -> Generate new token (classic).
- Give it a descriptive Note (e.g., "flux-bootstrap").
- Set an Expiration (e.g., 90 days - remember to rotate it!).
- Select the
reposcope. This grants permissions needed for Flux to manage repository configuration. - Click Generate token.
- Immediately copy the generated token! You won't see it again.
-
Store the Token Securely (Temporarily in ENV): For the bootstrap command, export it as an environment variable in your terminal. Never commit this token to Git!
export GITHUB_TOKEN="<paste-your-token-here>" -
Export Your GitHub Username: Flux also needs your username.
export GITHUB_USER="<your-github-username>"
2. Install the Flux CLI
You'll need the flux command-line tool to interact with Flux. Installation methods vary by OS:
-
macOS (Homebrew):
brew install fluxcd/tap/flux -
Linux/Other (Curl):
curl -s [https://fluxcd.io/install.sh](https://fluxcd.io/install.sh) | sudo bash (Check the official Flux documentation for other methods)
Verify the installation:
bash
which flux
flux --version
Top comments (0)