Mapping to Downstream Clusters

Mapping to Downstream Clusters - 图1info

Multi-cluster Only: This approach only applies if you are running Fleet in a multi-cluster style

When deploying GitRepos to downstream clusters the clusters must be mapped to a target.

Defining targets

The deployment targets of GitRepo is done using the spec.targets field to match clusters or cluster groups. The YAML specification is as below.

  1. kind: GitRepo
  2. apiVersion: fleet.cattle.io/v1alpha1
  3. metadata:
  4. name: myrepo
  5. namespace: clusters
  6. spec:
  7. repo: https://github.com/rancher/fleet-examples
  8. paths:
  9. - simple
  10. # Targets are evaluated in order and the first one to match is used. If
  11. # no targets match then the evaluated cluster will not be deployed to.
  12. targets:
  13. # The name of target. This value is largely for display and logging.
  14. # If not specified a default name of the format "target000" will be used
  15. - name: prod
  16. # A selector used to match clusters. The structure is the standard
  17. # metav1.LabelSelector format. If clusterGroupSelector or clusterGroup is specified,
  18. # clusterSelector will be used only to further refine the selection after
  19. # clusterGroupSelector and clusterGroup is evaluated.
  20. clusterSelector:
  21. matchLabels:
  22. env: prod
  23. # A selector used to match cluster groups.
  24. clusterGroupSelector:
  25. matchLabels:
  26. region: us-east
  27. # A specific clusterGroup by name that will be selected
  28. clusterGroup: group1

Target Matching

All clusters and cluster groups in the same namespace as the GitRepo will be evaluated against all targets. If any of the targets match the cluster then the GitRepo will be deployed to the downstream cluster. If no match is made, then the GitRepo will not be deployed to that cluster.

There are three approaches to matching clusters. One can use cluster selectors, cluster group selectors, or an explicit cluster group name. All criteria is additive so the final match is evaluated as “clusterSelector && clusterGroupSelector && clusterGroup”. If any of the three have the default value it is dropped from the criteria. The default value is either null or “”. It is important to realize that the value {} for a selector means “match everything.”

  1. # Match everything
  2. clusterSelector: {}
  3. # Selector ignored
  4. clusterSelector: null

Default target

If no target is set for the GitRepo then the default targets value is applied. The default targets value is as below.

  1. targets:
  2. - name: default
  3. clusterGroup: default

This means if you wish to setup a default location non-configured GitRepos will go to, then just create a cluster group called default and add clusters to it.