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 using Kubernetes labels. A namespace-scoped configuration can reference the selector to deploy the same object to multiple matching namespaces. section 11.2.1 section 11.3.1

NamespaceSelectors are primarily useful in unstructured repositories. In a hierarchy repository, a selector adds a restriction to inheritance: a namespace must both be below the folder containing the object and match the selector. section 11.2.1 section 11.2.2

Select production namespaces

Define a selector named production that matches the label env: production. A namespace-scoped Role can then reference that selector through the configmanagement.gke.io/namespace-selector annotation, applying one configuration to matching namespaces. In an unstructured repository, each namespace-scoped object must either specify metadata.namespace directly or use a NamespaceSelector. section 11.3.1

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

The production NamespaceSelector defines its label match. 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"]

The production Role references the selector by annotation. section 11.3.1

Selection depends on namespace labels being present and valid. Policy Controller constraints can require labels such as environment and team and restrict their allowed values. A selector can also target a namespace normally expected to be unique, avoiding massive changes to team configurations when a new project is created. section 11.3.1

How Google Anthos in Action covers it

How deep it goes
Defines label-based selection, shows selector and annotation configurations, and explains the additional hierarchy restriction.
Examples
Uses a production Role, a Config Connector StorageBucket, and a required-label constraint to illustrate selection and label governance.
What you can do after
Apply it via Anthos Config Management by defining a selector and annotating namespace-scoped configurations.
How it connects
Connects Kubernetes label selectors with repository inheritance, RBAC, Config Connector, 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.