@@ -31,8 +31,8 @@ You can set one of these scopes:
3131
3232.. _ns-scope-same-ns:
3333
34- Operator Uses Same Namespace as Resources
35- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+ Operator Uses the Same Single Namespace as Resources
35+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3636
3737You can set the scope for the |k8s-op-short| to use the same |k8s-ns| as
3838resources. In this case, the |k8s-op-short| watches |onprem| and
@@ -43,32 +43,71 @@ uses the default namespace.
4343
4444.. _ns-scope-different-ns:
4545
46- Operator Uses Different Namespace than Resources
47- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+ Operator Uses a Subset of Namespaces
47+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4848
49- You can set the scope for the |k8s-op-short| to use a different |k8s-ns|
50- than its resources. In this case, the |k8s-op-short| watches |onprem|
51- and |k8s-mdbrscs| in a |k8s-ns| that you specify.
49+ You can set the scope for the |k8s-op-short| to use one or more |k8s-nss|
50+ that differ from the namespace used by the |k8s-op-short| resources.
51+ In this case, the |k8s-op-short| watches |onprem| and |k8s-mdbrscs|
52+ in a subset of |k8s-nss| that you specify.
53+
54+ To install the |k8s-op-short| instances with this
55+ scope, use ``helm`` with the :ref:`helm-watch-namespace` parameter.
56+
57+ .. include:: /includes/admonitions/fact-subset-of-namespaces.rst
5258
53- You can use ``helm`` to install the |k8s-op-short| with this scope.
5459Follow the relevant :ref:`installation instructions
55- <install-k8s-operator>` for ``helm``, but use the following command to
56- set the namespace for the |k8s-op-short| to watch:
60+ <install-k8s-operator>` for ``helm``, but specify one or more namespaces
61+ in the :ref:`helm-watch-namespace` parameter for the |k8s-op-short| to
62+ watch:
63+
64+ .. include:: /includes/code-examples/yaml-files/example-watch-one-namespace-helm.yaml
65+
66+ .. include:: /includes/code-examples/yaml-files/example-watch-two-namespaces-helm.yaml
67+
68+ .. include:: /includes/code-examples/yaml-files/example-watch-namespaces-env-helm.yaml
69+
70+ .. include:: /includes/code-examples/yaml-files/example-watch-namespaces-staging-only-helm.yaml
71+
72+ When installing the |k8s-op-short| to watch resources in one or more
73+ namespaces other than the namespace in which the |k8s-op-short| is
74+ deployed:
75+
76+ 1. Create the following resources:
77+
78+ - A |k8s-cr| with access to multiple resources. For the full resource
79+ definition, see the
80+ :github:`operator-roles.yaml </mongodb/mongodb-enterprise-kubernetes/blob/master/helm_chart/templates/operator-roles.yaml>`
81+ example. This is a cluster-scoped resource.
82+
83+ - A |k8s-crb| on each namespace to watch. This ``clusterRoleBinding``
84+ will bind the ``clusterRole`` you created with the ServiceAccount
85+ the |k8s-op-short| is using on the namespace where you install it.
86+
87+ 2. Include the ``clusterRole`` and ``clusterRoleBinding``
88+ in the default configuration files that you apply during the
89+ installation.
90+
91+ The following example illustrates how ``clusterRoles`` and
92+ ``clusterRoleBindings`` work together in the cluster.
5793
58- .. code-block:: sh
94+ Suppose you create a ServiceAccount in the ``mongodb`` namespace, and
95+ then install the |k8s-op-short| in this namespace. The |k8s-op-short|
96+ uses this ServiceAccount.
5997
60- helm install <chart-name> helm_chart \
61- --set operator.watchNamespace=<namespace> \
98+ To set the |k8s-op-short| scope to watch namespaces ``ns1`` and ``ns2``:
6299
63- Setting the namespace ensures that:
100+ 1. Obtain :k8sdocs:`cluster-admin privileges </reference/access-authn-authz/rbac/#user-facing-roles>`.
101+ 2. Using these privileges, create a cluster-wide, non-namespaced |k8s-cr|.
102+ 3. Create a |k8s-crb| in three namespaces: ``mongodb``, ``ns1``
103+ and ``ns2``. This ``clusterRoleBinding`` will bind the
104+ ``clusterRole`` to the ServiceAccount in the ``mongodb`` namespace.
105+ The ``clusterRoleBinding`` will allow the |k8s-op-short| deployed in
106+ the ``mongodb`` namespace to access the resources described in the
107+ ``clusterRole`` of the target namespace, that is, in ``mongodb``,
108+ ``ns1`` and ``ns2``.
64109
65- - The namespace you want the |k8s-op-short| to watch has the correct
66- |k8s-cr| and |k8s-crb|. The ``clusterRole`` and ``clusterRoleBinding``
67- are included in the default configuration files that you apply during
68- the installation. To create the ``clusterRole`` and
69- ``clusterRoleBinding``, you must have
70- :k8sdocs:`cluster-admin privileges </reference/access-authn-authz/rbac/#user-facing-roles>`.
71- - The |k8s-op-short| can watch and create resources in this namespace.
110+ See also :ref:`helm-watch-namespace`.
72111
73112.. _cluster-wide-scope:
74113
0 commit comments