|
| 1 | += PostgreSQL Operator Build Instructions |
| 2 | +:toc: |
| 3 | +v2.6, {docdate} |
| 4 | + |
| 5 | +== Overview |
| 6 | + |
| 7 | +This document describes how to build from source code the |
| 8 | +Postgres Operator, mostly this is for developers or people |
| 9 | +wanting to hack on the operator. |
| 10 | + |
| 11 | +This document assumes you have already followed the Install instructions and have a working Kube environment. |
| 12 | + |
| 13 | +== Requirements |
| 14 | + |
| 15 | +The operator is developed with the Golang versions great than or equal to version 1.8 See |
| 16 | +link:https://golang.org/dl/[Golang website] for details on installing golang. |
| 17 | + |
| 18 | +The Operator project builds and operates with the following containers: |
| 19 | + |
| 20 | +* link:https://hub.docker.com/r/crunchydata/pgo-lspvc/[PVC Listing Container] |
| 21 | +* link:https://hub.docker.com/r/crunchydata/pgo-rmdata/[Remove Data Container] |
| 22 | +* link:https://hub.docker.com/r/crunchydata/postgres-operator/[postgres-operator Container] |
| 23 | +* link:https://hub.docker.com/r/crunchydata/pgo-apiserver/[apiserver Container] |
| 24 | +* link:https://hub.docker.com/r/crunchydata/pgo-load/[file load Container] |
| 25 | + |
| 26 | +This Operator is developed and tested on the following operating systems but is known to run on other operating systems: |
| 27 | + |
| 28 | +* *CentOS 7* |
| 29 | +* *RHEL 7* |
| 30 | + |
| 31 | +=== Kubernetes Environment |
| 32 | + |
| 33 | +To test the *postgres-operator*, it is required to have a Kubernetes cluster |
| 34 | +environment. The Operator is tested on Kubeadm Kubernetes installed clusters. Other Kubernetes installation methods have been known to work as well. |
| 35 | + |
| 36 | +link:https://kubernetes.io/docs/setup/independent/install-kubeadm/[Installing kubeadm - Official Kubernetes Documentation] |
| 37 | + |
| 38 | + |
| 39 | +== Build from Source |
| 40 | + |
| 41 | +Install a golang compiler, this can be done with either your package manager or by following directions from https://golang.org/dl/. The operator is currently built using golang version 1.8.X but also runs using golang version 1.9.X |
| 42 | + |
| 43 | +Then install the project library dependencies, the godep dependency manager is used as follows: |
| 44 | +.... |
| 45 | +cd $COROOT |
| 46 | +make setup |
| 47 | +.... |
| 48 | + |
| 49 | +==== Compiling the PostgreSQL Operator |
| 50 | +.... |
| 51 | +cd $COROOT |
| 52 | +make all |
| 53 | +which pgo |
| 54 | +.... |
| 55 | + |
| 56 | +=== Create Namespace |
| 57 | + |
| 58 | +This example is based on a kubeadm installation with the admin |
| 59 | +user being already created. The example below assumes the cluster name is *kubernetes* and the cluster default user is *kubernetes-admin*. |
| 60 | +.... |
| 61 | +kubectl create -f $COROOT/examples/demo-namespace.json |
| 62 | +kubectl get namespaces |
| 63 | +.... |
| 64 | + |
| 65 | +then set your context to the new demo namespace |
| 66 | +.... |
| 67 | +sudo chmod o+w /etc/kubernetes |
| 68 | +sudo chmod o+w /etc/kubernetes/admin.conf |
| 69 | +kubectl config set-context demo --namespace=demo --cluster=kubernetes --user=kubernetes-admin |
| 70 | +kubectl config use-context demo |
| 71 | +kubectl config current-context |
| 72 | +.... |
| 73 | + |
| 74 | +Permissions are granted to the Operator by means of a Service Account called *postgres-operator*. That service account is added to the Operator deployment. |
| 75 | + |
| 76 | +The postgres-operator service account is granted cluster-admin priviledges using a cluster role binding *postgres-operator-cluster-role-binding*. |
| 77 | + |
| 78 | +See link:https://kubernetes.io/docs/admin/authorization/rbac/[here] for more details on how to enable RBAC roles and modify the scope of the permissions to suit your needs. |
| 79 | + |
| 80 | +The sample service account and cluster role bindings specify the *demo* namespace. Edit the yaml definitions of these to match the namespace you are deploying the operator into. |
| 81 | + |
| 82 | +If you are not using the *demo* namespace, you will edit the following: |
| 83 | + |
| 84 | + * $COROOT/deploy/service-account.yaml |
| 85 | + * $COROOT/deploy/cluster-role-binding.yaml |
| 86 | + |
| 87 | +=== Deploy the PostgreSQL Operator |
| 88 | +*NOTE*: This will create and use */data* on your |
| 89 | +local system as the persistent store for the operator to use |
| 90 | +for its persistent volume. |
| 91 | +.... |
| 92 | +cd $COROOT |
| 93 | +make deployoperator |
| 94 | +kubectl get pod -l 'name=postgres-operator' |
| 95 | +.... |
| 96 | + |
| 97 | +You should see output similar to: |
| 98 | +.... |
| 99 | +NAME READY STATUS RESTARTS AGE |
| 100 | +postgres-operator-7f8db87c7b-4tk52 2/2 Running 0 8s |
| 101 | +.... |
| 102 | + |
| 103 | +This output shows that both the *apiserver* and *postgres-operator* containers |
| 104 | +are in ready state and the pod is running. |
| 105 | + |
| 106 | +You can find the operator service IP address as follows: |
| 107 | +.... |
| 108 | +kubectl get service postgres-operator |
| 109 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 110 | +postgres-operator ClusterIP 10.105.56.167 <none> 8080/TCP,8443/TCP 1m |
| 111 | +.... |
| 112 | + |
| 113 | +In this example, the *apiserver* is reachable at *https://10.105.56.167:8443*. |
| 114 | + |
| 115 | + |
| 116 | +When you first run the operator, it will create the required |
| 117 | +CustomResourceDefinitions. You can view these as follows: |
| 118 | + |
| 119 | +.... |
| 120 | +kubectl get crd |
| 121 | +.... |
| 122 | + |
| 123 | +Instead of using the bash script you can also deploy the operator using the provided Helm chart: |
| 124 | +.... |
| 125 | +cd $COROOT/chart |
| 126 | +helm install ./postgres-operator |
| 127 | +helm ls |
| 128 | +.... |
| 129 | + |
| 130 | +=== Verify Installation |
| 131 | + |
| 132 | +When you first run the operator, it will look for the presence of the |
| 133 | +predefined custom resource definitions, and create them if not found. |
| 134 | +The best way to verify a successful deployment of the Operator is by |
| 135 | +viewing these custom resource definitions: |
| 136 | + |
| 137 | +.... |
| 138 | +kubectl get crd |
| 139 | +kubectl get pgclusters |
| 140 | +kubectl get pgreplicas |
| 141 | +kubectl get pgbackups |
| 142 | +kubectl get pgupgrades |
| 143 | +kubectl get pgpolicies |
| 144 | +kubectl get pgingests |
| 145 | +kubectl get pgtasks |
| 146 | +.... |
| 147 | + |
| 148 | +At this point, you should be ready to start using the *pgo* client! Be |
| 149 | +sure to set the environment variable *CO_APISERVER_URL* to the DNS |
| 150 | +name of the *postgres-operator* service or to the IP address of the |
| 151 | +*postgres-operator* service IP address. For example: |
| 152 | + |
| 153 | +.... |
| 154 | +export CO_APISERVER_URL=https://10.105.56.167:8443 |
| 155 | +.... |
| 156 | + |
| 157 | +Or if you have DNS configured on your client host: |
| 158 | +.... |
| 159 | +export CO_APISERVER_URL=https://postgres-operator.demo.svc.cluster.local:8443 |
| 160 | +.... |
| 161 | + |
| 162 | +== Makefile Targets |
| 163 | + |
| 164 | +The following table describes the Makefile targets: |
| 165 | +.Makefile Targets |
| 166 | +[width="80%",frame="topbot",options="header,footer"] |
| 167 | +|====================== |
| 168 | +|Target | Description |
| 169 | +|all | compile all binaries and build all images |
| 170 | +|setup | fetch the dependent packages required to build with |
| 171 | +|deployoperator | deploy the Operator (apiserver and postgers-operator) to Kubernetes |
| 172 | +|main | compile the postgres-operator |
| 173 | +|runmain | locally execute the postgres-operator |
| 174 | +|pgo | build the pgo binary |
| 175 | +|runpgo | run the pgo binary |
| 176 | +|runapiserver | run the apiserver binary outside of Kube |
| 177 | +|clean | remove binaries and compiled packages, restore dependencies |
| 178 | +|operatorimage | compile and build the postgres-operator Docker image |
| 179 | +|apiserverimage | compile and build the apiserver Docker image |
| 180 | +|lsimage | build the lspvc Docker image |
| 181 | +|loadimage | build the file load Docker image |
| 182 | +|rmdataimage | build the data deletion Docker image |
| 183 | +|release | build the postgres-operator release |
| 184 | +|====================== |
| 185 | + |
| 186 | + |
0 commit comments