liveBook · Manning

Namespace selector

As explained in Google Anthos in Action

A NamespaceSelector is an Anthos Config Management object that selects namespaces by matching their Kubernetes labels.

A NamespaceSelector is an Anthos Config Management (ACM) object that selects namespaces by their Kubernetes labels. A namespace-scoped configuration can reference the selector instead of naming one namespace, allowing a Role, ConfigMap, or other object to apply to the matching namespaces. section 11.2.2

Selectors are primarily useful in unstructured policy repositories. There, every namespace-scoped object must specify either metadata.namespace or a NamespaceSelector annotation. In a hierarchy repository, a selector further restricts inheritance: a namespace must both match the selector and be a child of the folder containing the object. section 11.2.1 section 11.3.1

kind: NamespaceSelector
apiVersion: configmanagement.gke.io/v1
metadata:
 name: production
spec:
 selector:
   matchLabels:
     env: production

This definition names a selector production and matches namespaces labeled env: production. section 11.3.1

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
 name: prod-developer
 annotations:
   configmanagement.gke.io/namespace-selector: production
rules:
- apiGroups: [""]
 resources: ["pods", "configmaps"]
 verbs: ["get", "watch", "list"]
- apiGroups: ["apps", "extensions"]
 resources: ["deployments", "replicasets"]
 verbs: ["get", "watch", "list"]
- apiGroups: [""]
 resources: ["secrets"]
 verbs: ["list"]

This Role uses the configmanagement.gke.io/namespace-selector annotation to reference production, so one role configuration targets matching namespaces. section 11.3.1

Namespace labels therefore determine where selector-targeted objects land. If a policy depends on labels such as env and team, validate those labels and their permitted values; a required-labels constraint is one way to enforce that convention. section 11.3.1

How Google Anthos in Action covers it

How deep it goes
Shows selector YAML, annotation-based use, and repository-mode restrictions; does not explain selector reconciliation internals.
Examples
Uses a production-label selector and annotated developer Role, plus a selector targeting a Config Connector project namespace.
What it assumes
Assumes familiarity with Kubernetes labels and namespace-scoped objects while showing the ACM-specific selector and annotation syntax.
What you can do after
Operate/configure it: define a label-matching selector and reference it from namespace-scoped objects while accounting for repository mode.
How it connects
Connects Kubernetes label selectors to namespace labels, ACM policy repositories, hierarchical inheritance, RBAC Roles, and Policy Controller constraints.

Also explained in

Compare how 2 books explain namespace selector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Google Anthos in Action. The section links point to the parts of the book it draws on.