What are the essential Flux CLI commands that every engineer should know?
Quick Answer
The essential Flux CLI commands include flux check for validation, flux get for status inspection, flux reconcile for triggering immediate syncs, flux create for resource creation, flux logs for debugging, and flux export for extracting resource definitions. These commands cover the full lifecycle of managing Flux resources.
Detailed Answer
Think of the Flux CLI as a remote control for your GitOps system. Just like a TV remote has buttons for power, volume, channel, and settings, the Flux CLI has commands for checking health, viewing status, triggering actions, and debugging problems. You could walk to the TV and press buttons manually (edit YAML and kubectl apply), but the remote makes everything faster and less error-prone.
The Flux CLI is the primary interface for interacting with Flux controllers running in a Kubernetes cluster. The most fundamental command is flux check, which validates both the client (CLI version) and the server (controllers running in the cluster). Running flux check --pre before bootstrap verifies that the cluster meets prerequisites, while running flux check after installation confirms all controllers are healthy. This should be the first command you run when troubleshooting any Flux issue, as it immediately reveals version mismatches, missing controllers, or unhealthy pods.
For day-to-day operations, flux get is the workhorse command. It displays the status of Flux resources with their reconciliation state, last applied revision, and any error messages. You can scope it to specific resource types: flux get sources git shows all GitRepository sources, flux get kustomizations shows all Kustomizations, and flux get helmreleases shows all Helm releases. The -A flag shows resources across all namespaces. When you need to see everything at once, flux get all -A provides a comprehensive overview of every Flux-managed resource in the cluster, which is invaluable for getting a quick health snapshot.
The flux reconcile command triggers an immediate reconciliation cycle instead of waiting for the next scheduled interval. This is essential during development and debugging. For example, after pushing a commit, you can run flux reconcile source git payments-api to force the source-controller to fetch immediately, followed by flux reconcile kustomization payments-api to apply the new manifests without waiting. The reconciliation cascades downstream: reconciling a source automatically triggers reconciliation of all Kustomizations and HelmReleases that depend on it, so typically you only need to reconcile the source.
The flux create command generates Flux resources either imperatively (applying directly to the cluster) or declaratively (exporting YAML). Adding the --export flag to any create command outputs the YAML definition without applying it, which is the recommended approach for production. This lets you review the manifest, commit it to Git, and let Flux apply it through the normal GitOps flow. Conversely, flux export extracts existing Flux resources as clean YAML, stripping away status fields and metadata annotations. This is useful when you initially created resources imperatively and want to move them into version control.
For troubleshooting, flux logs is indispensable. It streams logs from all Flux controllers, filtered by resource type and name. Running flux logs --kind=Kustomization --name=payments-api shows only logs related to that specific Kustomization's reconciliation, cutting through the noise of a busy cluster. Combined with flux events, which shows Kubernetes events generated by Flux controllers, these commands provide complete visibility into what Flux is doing and why a particular reconciliation might be failing.