Kubernetes kubefed使用Cluster Selector

Using Cluster Selector

In addition to specifying an explicit list of clusters that a resource should be propagated to via the spec.placement.clusters field of a federated resource, it is possible to use the spec.placement.clusterSelector field to provide a label selector that determines a list of clusters at runtime.

If the goal is to select a subset of member clusters, make sure that the KubeFedCluster binaries from pre-reqs [now covered by Helm installation] resources that are intended to be selected have the appropriate labels applied.

The following command is an example to label a KubeFedCluster:

kubectl label kubefedclusters -n kube-federation-system cluster1 foo=bar

Please refer to Kubernetes label command for more information on how kubectl label works.

The following sections detail how spec.placement.clusters and spec.placement.clusterSelector are used in determining the clusters that a federated resource should be propagated to.

Neither spec.placement.clusters nor spec.placement.clusterSelector is provided

spec:
  placement: {}

In this case, you can either set spec: {} as above or remove spec field from your placement policy. The resource will not be propagated to member clusters.

在这种情况下,可以如上所述设置spec:{},也可以从放置策略中删除spec字段。资源将不会传播到成员群集。

Both spec.placement.clusters and spec.placement.clusterSelector are provided

spec:
  placement:
    clusters:
      - name: cluster2
      - name: cluster1
    clusterSelector:
      matchLabels:
        foo: bar

For this case, spec.placement.clusterSelector will be ignored as spec.placement.clusters is provided. This ensures that the results of runtime scheduling have priority over manual definition of a cluster selector.

spec.placement.clusterSelector will also be ignored if spec.placement.clusters is provided but empty. In the following example, no clusters will be selected:

spec:
  placement:
    clusters: []
    clusterSelector:
      matchLabels:
        foo: bar

只要提供了spec.placement.clusters字段(即使其值为空),spec.placement.clusterSelector配置也会被忽略。

spec.placement.clusters is not provided, spec.placement.clusterSelector is provided but empty

spec:
  placement:
    clusterSelector: {}

In this case, the resource will be propagated to all member clusters.

在这种情况下,资源将传播到所有成员集群。

spec.placement.clusters is not provided, spec.placement.clusterSelector is provided and not empty

spec:
  placement:
    clusterSelector:
      matchLabels:
        foo: bar

In this case, the resource will only be propagated to member clusters that are labeled with foo: bar.

在这种情况下,资源将只传播到标有foo:bar的成员集群。

摘自:https://github.com/kubernetes-sigs/kubefed/blob/master/docs/userguide.md#using-cluster-selector

posted @ 2021-10-25 14:19  人艰不拆_zmc  阅读(108)  评论(0编辑  收藏  举报