Skip to content

Commit 7796591

Browse files
Jonathan S. Katzjkatz
authored andcommitted
Update documentation on namespaces
This ensures the updated information on namespaces is presently available and updates diagrams.
1 parent 803506e commit 7796591

File tree

9 files changed

+75
-106
lines changed

9 files changed

+75
-106
lines changed

docs/content/architecture/namespace.md

Lines changed: 75 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,102 +5,25 @@ draft: false
55
weight: 400
66
---
77

8-
## Operator Namespaces
8+
# Kubernetes Namespaces and the PostgreSQL Operator
99

10-
The Operator itself knows which namespace it is running
11-
within by referencing the PGO_OPERATOR_NAMESPACE environment variable
12-
at startup time from within its Deployment definition.
10+
The PostgreSQL Operator leverages Kubernetes Namespaces to react to actions
11+
taken within a Namespace to keep its PostgreSQL clusters deployed as requested.
12+
Early on, the PostgreSQL Operator was scoped to a single namespace and would
13+
only watch PostgreSQL clusters in that Namspace, but since version 4.0, it has
14+
been expanded to be able to manage PostgreSQL clusters across multiple
15+
namespaces.
1316

14-
The PGO_OPERATOR_NAMESPACE environment variable a user sets in their
15-
.bashrc file is used to determine what namespace the Operator
16-
is deployed into. The PGO_OPERATOR_NAMESPACE variable is referenced
17-
by the Operator during deployment.
18-
19-
The .bashrc NAMESPACE environment variable a user sets determines
20-
which namespaces the Operator will watch.
21-
22-
## Namespace Watching
23-
24-
The Operator at startup time determines which namespaces it will
25-
service based on what it finds in the NAMESPACE environment variable
26-
that is passed into the Operator containers within the deployment.json file.
27-
28-
The NAMESPACE variable can hold different values which determine
29-
the namespaces which will be *watched* by the Operator. If NAMESPACE is
30-
empty, then the Operator will simply default to watching the namespace in
31-
which it is deployed.
32-
33-
### OwnNamespace Example
34-
35-
Prior to version 4.0, the Operator was deployed into
36-
a single namespace and Postgres Clusters created by it were
37-
created in that same namespace.
38-
39-
To achieve that same deployment model you would use
40-
variable settings as follows:
41-
42-
export PGO_OPERATOR_NAMESPACE=pgo
43-
44-
![Reference](/Namespace-Single.png)
45-
46-
### SingleNamespace Example
47-
48-
To have the Operator deployed into its own namespace but
49-
create Postgres Clusters into a different namespace the
50-
variables would be as follows:
51-
52-
export PGO_OPERATOR_NAMESPACE=pgo
53-
export NAMESPACE=pgouser1
54-
55-
![Reference](/Namespace-Single-Single.png)
56-
57-
### MultiNamespace Example
58-
59-
To have the Operator deployed into its own namespace but
60-
create Postgres Clusters into more than one namespace the
61-
variables would be as follows:
62-
63-
export PGO_OPERATOR_NAMESPACE=pgo
64-
export NAMESPACE=pgouser1,pgouser2
65-
66-
![Reference](/Namespace-Single-Multiple.png)
67-
68-
### RBAC
69-
70-
To support multiple namespace watching, each namespace that the PostgreSQL
71-
Operator watches requires its own copy of the following resources:
72-
73-
- `role/pgo-pg-role`
74-
- `role/pgo-backrest-role`
75-
- `role/pgo-target-role`
76-
- `rolebinding/pgo-pg-role-binding`
77-
- `rolebinding/pgo-backrest-role-binding`
78-
- `rolebinding/pgo-target-role-binding`
79-
- `serviceaccount/pgo-pg`
80-
- `serviceaccount/pgo-backrest`
81-
- `serviceaccount/pgo-target`
82-
83-
When you run the `install-rbac.sh` script, it iterates through the
84-
list of namespaces to be watched and creates these resources into
85-
each of those namespaces.
86-
87-
If you need to add a new namespace that the Operator will watch
88-
after an initial execution of `install-rbac.sh`, you will need to run
89-
the following for each new namespace:
90-
91-
add-targeted-namespace.sh YOURNEWNAMESPACE
92-
93-
The example deployment creates the following RBAC structure
94-
on your Kubernetes system after running the install scripts:
95-
96-
![Reference](/Operator-RBAC-Diagram.png)
17+
The following provides more information about how the PostgreSQL Operator works
18+
with namespaces, and presents several deployment patterns that can be used to
19+
deploy the PostgreSQL Operator.
9720

9821
## Namespace Operating Modes
9922

10023
The PostgreSQL Operator can be run with various Namespace Operating Modes, with each mode
10124
determining whether or not certain namespaces capabilities are enabled for the Operator
102-
installation. When the PosgreSQL Operator is run, the Kubernetes environment is inspected to
103-
determine what cluster roles are currently assigned to the `pgo-operator` `ServiceAccount`
25+
installation. When the PostgreSQL Operator is run, the Kubernetes environment is inspected to
26+
determine what cluster roles are currently assigned to the `pgo-operator` `ServiceAccount`
10427
(i.e. the `ServiceAccount` running the Pod the PostgreSQL Operator is deployed within). Based
10528
on the `ClusterRoles` identified, one of the namespace operating modes described below will be
10629
enabled for the Operator installation. Please consult the installation guides for the various
@@ -110,15 +33,15 @@ required for each mode.
11033
### `dynamic`
11134

11235
Enables full dynamic namespace capabilities, in which the Operator can create, delete and update
113-
any namespaces within the Kubernetes cluster, while then also having the ability to create the
36+
any namespaces within the Kubernetes cluster, while then also having the ability to create the
11437
`Roles`, `RoleBindings` and `ServiceAccounts` within those namespaces as required for the Operator
115-
to create PostgreSQL clusters. Additionally, while in this mode the Operator can listen for
116-
namespace events (e.g. namespace additions, updates and deletions), and then create or remove
117-
controllers for various namespaces as those namespaces are added or removed from the Kubernetes
38+
to create PostgreSQL clusters. Additionally, while in this mode the Operator can listen for
39+
namespace events (e.g. namespace additions, updates and deletions), and then create or remove
40+
controllers for various namespaces as those namespaces are added or removed from the Kubernetes
11841
cluster and/or Operator install. The mode therefore allows the Operator to dynamically respond
11942
to namespace events in the cluster, and then interact with those namespaces as required to manage
12043
PostgreSQL clusters within them.
121-
44+
12245
The following represents the `ClusterRole` required for the `dynamic` mode to be enabled:
12346

12447
```yaml
@@ -169,7 +92,7 @@ rules:
16992
17093
### `readonly`
17194

172-
In this mode the PostgreSQL Operator is still able to listen for namespace events within the
95+
In this mode the PostgreSQL Operator is still able to listen for namespace events within the
17396
Kubernetetes cluster, and then create and run and/or remove controllers as namespaces are added,
17497
updated and deleted. However, while in this mode the Operator is unable to create, delete or
17598
update namespaces itself, nor can it create the RBAC it requires in any of those namespaces to
@@ -197,9 +120,9 @@ rules:
197120
### `disabled`
198121

199122
Disables namespace capabilities within the Operator altogether. While in this mode the Operator
200-
will simply attempt to work with the target namespaces specified during installation. If no
123+
will simply attempt to work with the target namespaces specified during installation. If no
201124
target namespaces are specified, then the Operator will be configured to work within the namespace
202-
in which it is deployed. As with `readonly`, while in this mode namespaces must be pre-configured
125+
in which it is deployed. As with `readonly`, while in this mode namespaces must be pre-configured
203126
with the proper RBAC, since the Operator cannot create the RBAC itself. Additionally, in the event
204127
that target namespaces are deleted or the required RBAC within those namespaces are modified, the
205128
Operator will need to be re-deployed to ensure it no longer attempts to listen for events in those
@@ -209,15 +132,61 @@ and/or removed).
209132

210133
Mode `disabled` is enabled when no `ClusterRoles` have been installed.
211134

212-
## pgo Clients and Namespaces
213135

214-
The *pgo* CLI now is required to identify which namespace it
215-
wants to use when issuing commands to the Operator.
136+
## Namespace Deployment Patterns
137+
138+
There are several different ways the PostgreSQL Operator can be deployed in
139+
Kubernetes clusters with respect to Namespaces.
140+
141+
### One Namespace: PostgreSQL Operator + PostgreSQL Clusters
142+
143+
![PostgreSQL Operator Own Namespace Deployment](/images/namespace-own.png)
144+
145+
This patterns is great for testing out the PostgreSQL Operator in development
146+
environments, and can also be used to keep your entire PostgreSQL workload
147+
within a single Kubernetes Namespace.
148+
149+
This can be set up with the `disabled` Namespace mode.
150+
151+
### Single Tenant: PostgreSQL Operator Separate from PostgreSQL Clusters
152+
153+
![PostgreSQL Operator Single Namespace Deployment](/images/namespace-single.png)
154+
155+
The PostgreSQL Operator can be deployed into its own namespace and manage
156+
PostgreSQL clusters in a separate namespace.
157+
158+
This can be set up with either the `readonly` or `dynamic` Namespace modes.
159+
160+
### Multi Tenant: PostgreSQL Operator Managing PostgreSQL Clusters in Multiple Namespaces
216161

217-
Users of *pgo* can either create a PGO_NAMESPACE environment
218-
variable to set the namespace in a persistent manner or they
219-
can specify it on the *pgo* command line using the *--namespace*
220-
flag.
162+
![PostgreSQL Operator Multi Namespace Deployment](/images/namespace-multi.png)
221163

222-
If a pgo request doe not contain a valid namespace the request
223-
will be rejected.
164+
The PostgreSQL Operator can manage PostgreSQL clusters across multiple
165+
namespaces which allows for multi-tenancy.
166+
167+
This can be set up with either the `readonly` or `dynamic` Namespace modes.
168+
169+
## [`pgo` client]({{< relref "/pgo-client/_index.md" >}}) and Namespaces
170+
171+
The [`pgo` client]({{< relref "/pgo-client/_index.md" >}}) needs to be aware of
172+
the Kubernetes Namespaces it is issuing commands to. This can be accomplish with
173+
the `-n` flag that is available on most PostgreSQL Operator commands. For
174+
example, to create a PostgreSQL cluster called `hippo` in the `pgo` namespace,
175+
you would execute the following command:
176+
177+
```
178+
pgo create cluster -n pgo hippo
179+
```
180+
181+
For convenience, you can set the `PGO_NAMESPACE` environmental variable to
182+
automatically use the desired namespace with the commands.
183+
184+
For example, to create a cluster named `hippo` in the `pgo` namespace, you could
185+
do the following
186+
187+
```
188+
# this export only needs to be run once per session
189+
export PGO_NAMESPACE=pgo
190+
191+
pgo create cluster hippo
192+
```
-28.1 KB
Binary file not shown.
-29.1 KB
Binary file not shown.
-26.3 KB
Binary file not shown.

docs/static/Namespace-Single.png

-20.3 KB
Binary file not shown.
-117 KB
Binary file not shown.
151 KB
Loading
93.2 KB
Loading
98.4 KB
Loading

0 commit comments

Comments
 (0)