Skip to content

Commit dc59b24

Browse files
author
Jonathan S. Katz
committed
Update Quickstart
This reflects the easier installation methodology available (i.e. that default storage classes do work, and they're glorious), and expands on some of the other things that people want to get started, i.e. being able to connect to a database.
1 parent 8f454a6 commit dc59b24

File tree

2 files changed

+184
-63
lines changed

2 files changed

+184
-63
lines changed

docs/content/quickstart/_index.md

Lines changed: 184 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,72 +16,30 @@ There are two paths to quickly get you up and running with the PostgreSQL Operat
1616
- Installation via [Operator Lifecycle Manager]({{< relref "/installation/other/operator-hub.md" >}})
1717
- Installation via [Google Cloud Marketplace]({{< relref "/installation/other/google-cloud-marketplace.md" >}})
1818

19-
Marketplaces can help you get more quickly started in your environment as they provide a mostly automated process, but there are a few steps you will need to take to ensure you can fully utilize your PostgreSQL Operator environment.
19+
Marketplaces can help you get more quickly started in your environment as they provide a mostly automated process, but there are a few steps you will need to take to ensure you can fully utilize your PostgreSQL Operator environment. You can find out more information about how to get started with one of those installers in the [Installation]({{< relref "/installation/_index.md" >}}) section.
2020

2121
# PostgreSQL Operator Installer
2222

2323
Below will guide you through the steps for installing and using the PostgreSQL Operator using an installer that works with Ansible.
2424

25-
## The Very, VERY Quickstart
25+
## Installation
2626

27-
If your environment is set up to use hostpath storage (found in things like [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) or [OpenShift Code Ready Containers](https://developers.redhat.com/products/codeready-containers/overview), the following command could work for you:
27+
### Install the PostgreSQL Operator
28+
29+
On environments that have a [default storage class](https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class/) set up (which is most modern Kubernetes environments), the below command should work:
2830

2931
```
3032
kubectl create namespace pgo
3133
kubectl apply -f https://raw.githubusercontent.com/CrunchyData/postgres-operator/v{{< param operatorVersion >}}/installers/kubectl/postgres-operator.yml
3234
```
3335

34-
If not, please read onward: you can still get up and running fairly quickly with just a little bit of configuration.
35-
36-
## Step 1: Configuration
37-
38-
### Get the PostgreSQL Operator Installer Manifest
39-
40-
You will need to download the PostgreSQL Operator Installer manifest to your environment, which you can do with the following command:
41-
42-
```
43-
curl https://raw.githubusercontent.com/CrunchyData/postgres-operator/v{{< param operatorVersion >}}/installers/kubectl/postgres-operator.yml > postgres-operator.yml
44-
```
45-
46-
If you wish to download a specific version of the installer, you can substitute `master` with the version of the tag, i.e.
47-
48-
```
49-
curl https://raw.githubusercontent.com/CrunchyData/postgres-operator/v{{< param operatorVersion >}}/installers/kubectl/postgres-operator.yml > postgres-operator.yml
50-
```
51-
52-
### Configure the PostgreSQL Operator Installer
53-
54-
There are many [configuration parameters]({{< relref "/installation/configuration.md">}}) to help you fine tune your installation, but there are a few that you may want to change to get the PostgreSQL Operator to run in your environment. Open up the `postgres-operator.yml` file and edit a few variables.
55-
56-
Find the `pgo_admin_password` variable. This is the password you will use with the [`pgo` client]({{< relref "/installation/pgo-client" >}}) to manage your PostgreSQL clusters. The default is `password`, but you can change it to something like `hippo-elephant`.
57-
58-
You will also need to set the storage default storage classes that you would like the PostgreSQL Operator to use. These variables are called `primary_storage`, `replica_storage`, `backup_storage`, and `backrest_storage`. There are several storage configurations listed out in the configuration file under the heading `storage[1-9]_name`. Find the one that you want to use, and set it to that value.
59-
60-
For example, if your Kubernetes environment is using NFS storage, you would set these variables to the following:
61-
62-
```
63-
backrest_storage: "nfsstorage"
64-
backup_storage: "nfsstorage"
65-
primary_storage: "nfsstorage"
66-
replica_storage: "nfsstorage"
67-
```
36+
This will launch the `pgo-deployer` container that will run the various setup and installation jobs. This can take a few minutes to complete depending on your Kubernetes cluster.
6837

69-
If you are using either Openshift or CodeReady Containers, you will need to set `disable_fsgroup` to 'true' in order to deploy the PostgreSQL Operator in OpenShift environments that have the typical restricted Security Context Constraints.
38+
If your install is unsuccessful, you may need to modify your configuration. Please read the ["Troubleshooting"](#troubleshooting) section. You can still get up and running fairly quickly with just a little bit of configuration.
7039

71-
For a full list of available storage types that can be used with this installation method, please review the [configuration parameters]({{< relref "/installation/configuration.md">}}).
40+
### Install the `pgo` Client
7241

73-
## Step 2: Installation
74-
75-
Installation is as easy as executing:
76-
77-
```
78-
kubectl create namespace pgo
79-
kubectl apply -f postgres-operator.yml
80-
```
81-
82-
This will launch the `pgo-deployer` container that will run the various setup and installation jobs. This can take a few minutes to complete depending on your Kubernetes cluster.
83-
84-
While the installation is occurring, download the `pgo` client set up script. This will help set up your local environment for using the PostgreSQL Operator:
42+
During or after the installation of the PostgreSQL Operator, download the `pgo` client set up script. This will help set up your local environment for using the PostgreSQL Operator:
8543

8644
```
8745
curl https://raw.githubusercontent.com/CrunchyData/postgres-operator/v{{< param operatorVersion >}}/installers/kubectl/client-setup.sh > client-setup.sh
@@ -123,13 +81,13 @@ source ~/.bashrc
12381

12482
**NOTE**: For macOS users, you must use `~/.bash_profile` instead of `~/.bashrc`
12583

126-
## Step 3: Verification
84+
### Post-Installation Setup
12785

12886
Below are a few steps to check if the PostgreSQL Operator is up and running.
12987

130-
By default, the PostgreSQL Operator installs into a namespace called `pgo`. First, see that the the Kubernetes Deployment of the Operator exists and is healthy:
88+
By default, the PostgreSQL Operator installs into a namespace called `pgo`. First, see that the Kubernetes Deployment of the Operator exists and is healthy:
13189

132-
```shell
90+
```
13391
kubectl -n pgo get deployments
13492
```
13593

@@ -142,7 +100,7 @@ postgres-operator 1/1 1 1 16h
142100

143101
Next, see if the Pods that run the PostgreSQL Operator are up and running:
144102

145-
```shell
103+
```
146104
kubectl -n pgo get pods
147105
```
148106

@@ -157,13 +115,13 @@ Finally, let's see if we can connect to the PostgreSQL Operator from the `pgo` c
157115

158116
In a new console window, run the following command to set up a port forward:
159117

160-
```shell
118+
```
161119
kubectl -n pgo port-forward svc/postgres-operator 8443:8443
162120
```
163121

164122
Back to your original console window, you can verify that you can connect to the PostgreSQL Operator using the following command:
165123

166-
```shell
124+
```
167125
pgo version
168126
```
169127

@@ -174,17 +132,17 @@ pgo client version {{< param operatorVersion >}}
174132
pgo-apiserver version {{< param operatorVersion >}}
175133
```
176134

177-
## Step 4: Have Some Fun - Create a PostgreSQL Cluster
135+
## Create a PostgreSQL Cluster
178136

179137
The quickstart installation method creates a namespace called `pgo` where the PostgreSQL Operator manages PostgreSQL clusters. Try creating a PostgreSQL cluster called `hippo`:
180138

181-
```shell
139+
```
182140
pgo create cluster -n pgo hippo
183141
```
184142

185-
Alternatively, because we set the [`PGO_NAMESPACE`](/pgo-client/#general-notes-on-using-the-pgo-client) environmental variable in our `.bashrc` file, we could omit the `-n` flag from the [`pgo create cluster`](/pgo-client/reference/pgo_create_cluster/) command and just run this:
143+
Alternatively, because we set the [`PGO_NAMESPACE`]({{< relref "pgo-client/reference/pgo_create_cluster.md" >}}#general-notes-on-using-the-pgo-client) environmental variable in our `.bashrc` file, we could omit the `-n` flag from the [`pgo create cluster`]({{< relref "pgo-client/reference/pgo_create_cluster.md" >}}) command and just run this:
186144

187-
```shell
145+
```
188146
pgo create cluster hippo
189147
```
190148

@@ -197,9 +155,9 @@ created Pgcluster hippo
197155
workflow id 1cd0d225-7cd4-4044-b269-aa7bedae219b
198156
```
199157

200-
This will create a PostgreSQL cluster named `hippo`. It may take a few moments for the cluster to be provisioned. You can see the status of this cluster using the `pgo test` command:
158+
This will create a PostgreSQL cluster named `hippo`. It may take a few moments for the cluster to be provisioned. You can see the status of this cluster using the [`pgo test`]({{< relref "pgo-client/reference/pgo_test.md" >}}) command:
201159

202-
```shell
160+
```
203161
pgo test -n pgo hippo
204162
```
205163

@@ -215,3 +173,166 @@ cluster : hippo
215173

216174
The `pgo test` command provides you the basic information you need to connect to your PostgreSQL cluster from within your Kubernetes environment. For more detailed information, you can use `pgo show cluster -n pgo hippo`.
217175

176+
## Connect to a PostgreSQL Cluster
177+
178+
By default, the PostgreSQL Operator creates a database inside the cluster with the same name of the cluster, in this case, `hippo`. Below demonstrates how we can connect to `hippo`.
179+
180+
### How Users Work
181+
182+
You can get information about the users in your cluster with the [`pgo show user`]({{< relref "pgo-client/reference/pgo_show_user.md" >}}) command:
183+
184+
```
185+
pgo show user -n pgo hippo
186+
```
187+
188+
This will give you all the unprivileged, non-system PostgreSQL users for the `hippo` PostgreSQL cluster, for example:
189+
190+
```
191+
CLUSTER USERNAME PASSWORD EXPIRES STATUS ERROR
192+
------- -------- ------------------------ ------- ------ -----
193+
hippo testuser datalake never ok
194+
```
195+
196+
To get the information about all PostgreSQL users that the PostgreSQL Operator is managing, you will need to use the `--show-system-accounts` flag:
197+
198+
```
199+
pgo show user -n pgo hippo --show-system-accounts
200+
```
201+
202+
which returns something similar to:
203+
204+
```
205+
CLUSTER USERNAME PASSWORD EXPIRES STATUS ERROR
206+
------- -------------- ------------------------ ------- ------ -----
207+
hippo postgres <REDACTED> never ok
208+
hippo primaryuser <REDACTED> never ok
209+
hippo testuser datalake never ok
210+
```
211+
212+
The `postgres` user represents the [database superuser](https://www.postgresql.org/docs/current/role-attributes.html) and has every privilege granted to it. The PostgreSQL Operator securely interfaces through the `postgres` account to perform certain actions, such as managing users.
213+
214+
The `primaryuser` is the used for replication and [high availability]({{< relref "architecture/high-availability/_index.md" >}}). You should never need to interface with this user account.
215+
216+
### Connecting via `psql`
217+
218+
Let's see how we can connect to `hippo` using [`psql`](https://www.postgresql.org/docs/current/app-psql.html), the command-line tool for accessing PostgreSQL. Ensure you have [installed the `psql` client](https://www.crunchydata.com/developers/download-postgres/binaries/postgresql12).
219+
220+
The PostgreSQL Operator creates a service with the same name as the cluster. See for yourself! Get a list of all of the Services available in the `pgo` namespace:
221+
222+
```
223+
kubectl -n pgo get svc
224+
225+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
226+
hippo ClusterIP 10.96.218.63 <none> 2022/TCP,5432/TCP 59m
227+
hippo-backrest-shared-repo ClusterIP 10.96.75.175 <none> 2022/TCP 59m
228+
postgres-operator ClusterIP 10.96.121.246 <none> 8443/TCP,4171/TCP,4150/TCP 71m
229+
```
230+
231+
Let's connect the `hippo` cluster. First, in a different console window, set up a port forward to the `hippo` service:
232+
233+
```
234+
kubectl -n pgo port-forward svc/hippo 5432:5432
235+
```
236+
237+
You can connect to the database with the following command, substituting `datalake` for your actual password:
238+
239+
```
240+
PGPASSWORD=datalake psql -h localhost -p 5432 -U testuser hippo
241+
```
242+
243+
You should then be greeted with the PostgreSQL prompt:
244+
245+
```
246+
psql (12.4)
247+
Type "help" for help.
248+
249+
hippo=>
250+
```
251+
252+
### Connecting via [pgAdmin 4]({{< relref "architecture/pgadmin4.md" >}})
253+
254+
[pgAdmin 4]({{< relref "architecture/pgadmin4.md" >}}) is a graphical tool that can be used to manage and query a PostgreSQL database from a web browser. The PostgreSQL Operator provides a convenient integration with pgAdmin 4 for managing how users can log into the database.
255+
256+
To add pgAdmin 4 to `hippo`, you can execute the following command:
257+
258+
```
259+
pgo create pgadmin -n pgo hippo
260+
```
261+
262+
It will take a few moments to create the pgAdmin 4 instance. The PostgreSQL Operator also creates a pgAdmin 4 service. See for yourself! Get a list of all of the Services available in the `pgo` namespace:
263+
264+
```
265+
kubectl -n pgo get svc
266+
267+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
268+
hippo ClusterIP 10.96.218.63 <none> 2022/TCP,5432/TCP 59m
269+
hippo-backrest-shared-repo ClusterIP 10.96.75.175 <none> 2022/TCP 59m
270+
hippo-pgadmin ClusterIP 10.96.165.27 <none> 5050/TCP 5m1s
271+
postgres-operator ClusterIP 10.96.121.246 <none> 8443/TCP,4171/TCP,4150/TCP 71m
272+
```
273+
274+
Let's connect to our `hippo` cluster via pgAdmin 4! In a different terminal, set up a port forward to pgAdmin 4:
275+
276+
```
277+
kubectl -n pgo port-forward svc/hippo-pgadmin 5050:5050
278+
```
279+
280+
Navigate your browser to http://localhost:5050 and use your database username (`testuser`) and password (e.g. `datalake`) to log in. Though the prompt says “email address”, using your PostgreSQL username will work:
281+
282+
![pgAdmin 4 Login Page](/images/pgadmin4-login2.png)
283+
284+
(There are occasions where the initial credentials do not properly get set in pgAdmin 4. If you have trouble logging in, try running the command `pgo update user -n pgo hippo --username=testuser --password=datalake`).
285+
286+
Once logged into pgAdmin 4, you will be automatically connected to your database. Explore pgAdmin 4 and run some queries!
287+
288+
For more information, please see the section on [pgAdmin 4]({{< relref "architecture/pgadmin4.md" >}}).
289+
290+
## Troubleshooting
291+
292+
### Installation Failures
293+
294+
Some Kubernetes environments may require you to customize the configuration for the PostgreSQL Operator installer. The below provides a guide on the common parameters that require modification, though this may vary based on your installation. For a full reference, please visit the [Installation]({{< relref "/installation/_index.md" >}}) section.
295+
296+
If you already attempted to install the PostgreSQL Operator and that failed, the easiest way to clean up that installation is to delete the [Namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) that you attempted to install the PostgreSQL Operator into. **Note: This deletes all of the other objects in the Namespace, so please be sure this is OK!**
297+
298+
To delete the namespace, you can run the following command:
299+
300+
```
301+
kubectl delete namespace pgo
302+
```
303+
304+
#### Get the PostgreSQL Operator Installer Manifest
305+
306+
You will need to download the PostgreSQL Operator Installer manifest to your environment, which you can do with the following command:
307+
308+
```
309+
curl https://raw.githubusercontent.com/CrunchyData/postgres-operator/v{{< param operatorVersion >}}/installers/kubectl/postgres-operator.yml > postgres-operator.yml
310+
```
311+
312+
#### Configure the PostgreSQL Operator Installer
313+
314+
There are many [configuration parameters]({{< relref "/installation/configuration.md">}}) to help you fine tune your installation, but there are a few that you may want to change to get the PostgreSQL Operator to run in your environment. Open up the `postgres-operator.yml` file and edit a few variables.
315+
316+
Find the `pgo_admin_password` variable. This is the password you will use with the [`pgo` client]({{< relref "/installation/pgo-client" >}}) to manage your PostgreSQL clusters. The default is `password`, but you can change it to something like `hippo-elephant`.
317+
318+
You may also need to set the storage default storage classes that you would like the PostgreSQL Operator to use. These variables are called `primary_storage`, `replica_storage`, `backup_storage`, and `backrest_storage`. There are several storage configurations listed out in the configuration file under the heading `storage[1-9]_name`. Find the one that you want to use, and set it to that value.
319+
320+
For example, if your Kubernetes environment is using NFS storage, you would set these variables to the following:
321+
322+
```
323+
backrest_storage: "nfsstorage"
324+
backup_storage: "nfsstorage"
325+
primary_storage: "nfsstorage"
326+
replica_storage: "nfsstorage"
327+
```
328+
329+
If you are using either Openshift or CodeReady Containers and you have a `restricted` Security Context Constraint, you will need to set `disable_fsgroup` to `true` in order to deploy the PostgreSQL Operator.
330+
331+
For a full list of available storage types that can be used with this installation method, please review the [configuration parameters]({{< relref "/installation/configuration.md">}}).
332+
333+
When you are done editing the file, you can install the PostgreSQL Operator by running the following commands:
334+
335+
```
336+
kubectl create namespace pgo
337+
kubectl apply -f postgres-operator.yml
338+
```
71.7 KB
Loading

0 commit comments

Comments
 (0)