|
| 1 | +--- |
| 2 | +title: "OperatorHub.io" |
| 3 | +date: |
| 4 | +draft: false |
| 5 | +weight: 200 |
| 6 | +--- |
| 7 | + |
| 8 | +If your Kubernetes cluster is already running the [Operator Lifecycle Manager][OLM], |
| 9 | +the PostgreSQL Operator can be installed as part of [Crunchy PostgreSQL for Kubernetes][hub-listing] |
| 10 | +that is available in OperatorHub.io. |
| 11 | + |
| 12 | +[hub-listing]: https://operatorhub.io/operator/postgresql |
| 13 | +[OLM]: https://olm.operatorframework.io/ |
| 14 | + |
| 15 | + |
| 16 | +## Before You Begin |
| 17 | + |
| 18 | +There are a few manual steps that the cluster administrator must perform prior to installing the PostgreSQL Operator. |
| 19 | +At the very least, it must be provided with an initial configuration. |
| 20 | + |
| 21 | +First, make sure OLM and the OperatorHub.io catalog are installed by running |
| 22 | +`kubectl get CatalogSources --all-namespaces`. You should see something similar to the following: |
| 23 | + |
| 24 | +``` |
| 25 | +NAMESPACE NAME DISPLAY TYPE PUBLISHER |
| 26 | +olm operatorhubio-catalog Community Operators grpc OperatorHub.io |
| 27 | +``` |
| 28 | + |
| 29 | +Take note of the name and namespace above, you will need them later on. |
| 30 | + |
| 31 | +Next, select a namespace in which to install the PostgreSQL Operator. PostgreSQL clusters will also be deployed here. |
| 32 | +If it does not exist, create it now. |
| 33 | + |
| 34 | +``` |
| 35 | +export PGO_OPERATOR_NAMESPACE=pgo |
| 36 | +kubectl create namespace "$PGO_OPERATOR_NAMESPACE" |
| 37 | +``` |
| 38 | + |
| 39 | +Next, clone the PostgreSQL Operator repository locally. |
| 40 | + |
| 41 | +``` |
| 42 | +git clone -b v{{< param operatorVersion >}} https://github.com/CrunchyData/postgres-operator.git |
| 43 | +cd postgres-operator |
| 44 | +``` |
| 45 | + |
| 46 | +### PostgreSQL Operator Configuration |
| 47 | + |
| 48 | +Edit `conf/postgres-operator/pgo.yaml` to configure the deployment. Look over all of the options and make any |
| 49 | +changes necessary for your environment. A full description of each option is available in the |
| 50 | +[`pgo.yaml` configuration guide]({{< relref "configuration/pgo-yaml-configuration.md" >}}). |
| 51 | + |
| 52 | +When the file is ready, upload the entire directory to the `pgo-config` ConfigMap. |
| 53 | + |
| 54 | +``` |
| 55 | +kubectl -n "$PGO_OPERATOR_NAMESPACE" create configmap pgo-config \ |
| 56 | + --from-file=./conf/postgres-operator |
| 57 | +``` |
| 58 | + |
| 59 | +### Secrets |
| 60 | + |
| 61 | +Configure pgBackRest for your environment. If you do not plan to use AWS S3 to store backups, you can omit |
| 62 | +the `aws-s3` keys below. |
| 63 | + |
| 64 | +``` |
| 65 | +kubectl -n "$PGO_OPERATOR_NAMESPACE" create secret generic pgo-backrest-repo-config \ |
| 66 | + --from-file=./installers/ansible/roles/pgo-operator/files/pgo-backrest-repo/config \ |
| 67 | + --from-file=./installers/ansible/roles/pgo-operator/files/pgo-backrest-repo/sshd_config \ |
| 68 | + --from-file=./installers/ansible/roles/pgo-operator/files/pgo-backrest-repo/aws-s3-ca.crt \ |
| 69 | + --from-literal=aws-s3-key="<your-aws-s3-key>" \ |
| 70 | + --from-literal=aws-s3-key-secret="<your-aws-s3-key-secret>" |
| 71 | +``` |
| 72 | + |
| 73 | +### Certificates (optional) |
| 74 | + |
| 75 | +The PostgreSQL Operator has an API that uses TLS to communicate securely with clients. If you have |
| 76 | +a certificate bundle validated by your organization, you can install it now. If not, the API will |
| 77 | +automatically generate and use a self-signed certificate. |
| 78 | + |
| 79 | +``` |
| 80 | +kubectl -n "$PGO_OPERATOR_NAMESPACE" create secret tls pgo.tls \ |
| 81 | + --cert=/path/to/server.crt \ |
| 82 | + --key=/path/to/server.key |
| 83 | +``` |
| 84 | + |
| 85 | +Once these resources are in place, the PostgreSQL Operator can be installed into the cluster. |
| 86 | + |
| 87 | + |
| 88 | +## Installation |
| 89 | + |
| 90 | +Create an `OperatorGroup` and a `Subscription` in your chosen namespace. |
| 91 | +Make sure the `source` and `sourceNamespace` match the CatalogSource from earlier. |
| 92 | + |
| 93 | +``` |
| 94 | +kubectl -n "$PGO_OPERATOR_NAMESPACE" create -f- <<YAML |
| 95 | +--- |
| 96 | +apiVersion: operators.coreos.com/v1 |
| 97 | +kind: OperatorGroup |
| 98 | +metadata: |
| 99 | + name: postgresql |
| 100 | +spec: |
| 101 | + targetNamespaces: ["$PGO_OPERATOR_NAMESPACE"] |
| 102 | +
|
| 103 | +--- |
| 104 | +apiVersion: operators.coreos.com/v1alpha1 |
| 105 | +kind: Subscription |
| 106 | +metadata: |
| 107 | + name: postgresql |
| 108 | +spec: |
| 109 | + name: postgresql |
| 110 | + channel: stable |
| 111 | + source: operatorhubio-catalog |
| 112 | + sourceNamespace: olm |
| 113 | + startingCSV: postgresoperator.v{{< param operatorVersion >}} |
| 114 | +YAML |
| 115 | +``` |
| 116 | + |
| 117 | + |
| 118 | +## After You Install |
| 119 | + |
| 120 | +Once the PostgreSQL Operator is installed in your Kubernetes cluster, you will need to do a few things |
| 121 | +to use the [PostgreSQL Operator Client]({{< relref "/pgo-client/_index.md" >}}). |
| 122 | + |
| 123 | +Install the first set of client credentials and download the `pgo` binary and client certificates. |
| 124 | + |
| 125 | +``` |
| 126 | +PGO_CMD=kubectl ./deploy/install-bootstrap-creds.sh |
| 127 | +PGO_CMD=kubectl ./installers/kubectl/client-setup.sh |
| 128 | +``` |
| 129 | + |
| 130 | +The client needs to be able to reach the PostgreSQL Operator API from outside the Kubernetes cluster. |
| 131 | +Create an external service or forward a port locally. |
| 132 | + |
| 133 | +``` |
| 134 | +kubectl -n "$PGO_OPERATOR_NAMESPACE" expose deployment postgres-operator --type=LoadBalancer |
| 135 | +
|
| 136 | +export PGO_APISERVER_URL="https://$( |
| 137 | + kubectl -n "$PGO_OPERATOR_NAMESPACE" get service postgres-operator \ |
| 138 | + -o jsonpath="{.status.loadBalancer.ingress[*]['ip','hostname']}" |
| 139 | +):8443" |
| 140 | +``` |
| 141 | +_or_ |
| 142 | +``` |
| 143 | +kubectl -n "$PGO_OPERATOR_NAMESPACE" port-forward deployment/postgres-operator 8443 |
| 144 | +
|
| 145 | +export PGO_APISERVER_URL="https://127.0.0.1:8443" |
| 146 | +``` |
| 147 | + |
| 148 | +Verify connectivity using the `pgo` command. |
| 149 | + |
| 150 | +``` |
| 151 | +pgo version |
| 152 | +# pgo client version {{< param operatorVersion >}} |
| 153 | +# pgo-apiserver version {{< param operatorVersion >}} |
| 154 | +``` |
| 155 | + |
0 commit comments