Fleet, the GitOps tool embedded in Rancher
Posted on October 29, 2021 by Adrian Wyssmann ‐ 5 min read
There are a lot of different GitOps solution out in the field. But when you are using Rancher, you already have one at hand. As a Rancher user, I had a look what it is and how it works
What is fleet?
Fleet is integrated into Rancher and allows you to create so called GitRepo’s which in essence points to a git repo, where fleet scans a list of paths for resources, which are then applied to a target (cluster, cluster group). I supports raw Kubernetes YAML, Helm charts and Kustomize. Actually everything is dynamically turned into a helm chart, where it is then deployed using helm.
How does it work?
The architecture of fleet looks like this:
There is the Fleet Manager, the centralized component that orchestrates the deployments of Kubernetes assets from git. The Fleet Manager is accessed via Rancher UI and actually lives in the local Rancher cluster. On the local cluster also runs the Fleet Controller, which does the orchestration. Then, on every managed downstream cluster, a Fleet agent is running, which communicates with the Fleet Manager.
Fleet watches git repositories which you define in a resource called GitRepo, which have to be added to the Fleet manager. Where exactly, depends on whether you manage a single cluster or a multi-cluster
Let’s start
As we use a multi-cluster. first we have a repo-cluster-tooling-nop-local.yaml
which looks like this
So this GitRepo watches folder fleet
of the main
-branch in the rancher
git repo. I add this to the local custer:
That this will work, we need to add a secret gitrepo-auth
so fleet can authenticate against the git repo. The secret should be in the fleet-local
namespace.
In case you have a private helm repo, you also have to create the helm secret for fleet following the [instructions][helm repo]:
The fleet-local
namespace is a special namespace used for the single cluster use case or to bootstrap the configuration of the Fleet manager.
So GitRepo fleet-bootstrap
watches fleet
, which contains definitions of other GitRepos. The [GitRepo
definitions in fleet
will manage workloads of downstream cluster. This setup allows me to add additional GitRepos, which are then automatically added to the Fleet Manager. So for instance we have one file per cluster repo-cluster-tooling-${context}.yaml
with the a content like this:
As you can see this one will be applied into the fleet-default
namespace. I scans various folders for resources and applies them. Most of them contain simple manifest files, except metallb/dev
which is helm chart deployment.
This folder contains a fleet.yaml
which tell fleet to install metallb helm chart from our internal helm chart repo
Once I add the repo-cluster-tooling-${context}.yaml
to the fleet
-folder in my git repo, and then merge the changes to main
-branch, the new GitRepo is added:
Each GitRepo shows a detailed list of the resources applied, and it’s state. Here, we see that all is fine and active
- see Cluster and Bundle state for more details:
For each of the GitRepos, fleet crates one or more fleet bundles, an internal unit used for the orchestration of resources from git. The content of a Bundle, may be a manifest, a helm chart or a Kustomize configuration.
Conclusion
One problem I have with fleet is, that if something does not work, you may not have enough info in the Fleet ui itself. It may be necessary that you dig into the logs of the controller or the agents to understand why a deployment actually fails. This may be an issue if developers of your organization do have limited access to Rancher.
Fleet is at your hand when your are using Rancher and definitively worth a look, as it is quite easy to get started with. The above is just a very simple example and there are much more possibilities on how you can structure your setup. For example instead of having multiple GitRepo definitions you can use “Target customization”, which allows you to define in the same GitRepo definition, how resources should be modified per target.