add the forked kong subcharts to avoid helm update
[it/dep.git] / ric-platform / 50-RIC-Platform / helm / kong / charts / kong / charts / postgresql / README.md
1 # PostgreSQL
2
3 [PostgreSQL](https://www.postgresql.org/) is an object-relational database management system (ORDBMS) with an emphasis on extensibility and on standards-compliance.
4
5 ## TL;DR;
6
7 ```console
8 $ helm install stable/postgresql
9 ```
10
11 ## Introduction
12
13 This chart bootstraps a [PostgreSQL](https://github.com/bitnami/bitnami-docker-postgresql) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
14
15 Bitnami charts can be used with [Kubeapps](https://kubeapps.com/) for deployment and management of Helm Charts in clusters.
16
17 ## Prerequisites
18
19 - Kubernetes 1.10+
20 - PV provisioner support in the underlying infrastructure
21
22 ## Installing the Chart
23
24 To install the chart with the release name `my-release`:
25
26 ```console
27 $ helm install --name my-release stable/postgresql
28 ```
29
30 The command deploys PostgreSQL on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.
31
32 > **Tip**: List all releases using `helm list`
33
34 ## Uninstalling the Chart
35
36 To uninstall/delete the `my-release` deployment:
37
38 ```console
39 $ helm delete my-release
40 ```
41
42 The command removes all the Kubernetes components associated with the chart and deletes the release.
43
44 ## Configuration
45
46 The following tables lists the configurable parameters of the PostgreSQL chart and their default values.
47
48 | Parameter                                     | Description                                                                                                            | Default                                                  |
49 |-----------------------------------------------|------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
50 | `global.imageRegistry`                        | Global Docker Image registry                                                                                           | `nil`                                                    |
51 | `image.registry`                              | PostgreSQL Image registry                                                                                              | `docker.io`                                              |
52 | `image.repository`                            | PostgreSQL Image name                                                                                                  | `bitnami/postgresql`                                     |
53 | `image.tag`                                   | PostgreSQL Image tag                                                                                                   | `{VERSION}`                                              |
54 | `image.pullPolicy`                            | PostgreSQL Image pull policy                                                                                           | `Always`                                                 |
55 | `image.pullSecrets`                           | Specify Image pull secrets                                                                                             | `nil` (does not add image pull secrets to deployed pods) |
56 | `image.debug`                                 | Specify if debug values should be set                                                                                  | `false`                                                  |
57 | `volumePermissions.image.registry`            | Init container volume-permissions image registry                                                                       | `docker.io`                                              |
58 | `volumePermissions.image.repository`          | Init container volume-permissions image name                                                                           | `bitnami/minideb`                                        |
59 | `volumePermissions.image.tag`                 | Init container volume-permissions image tag                                                                            | `latest`                                                 |
60 | `volumePermissions.image.pullPolicy`          | Init container volume-permissions image pull policy                                                                    | `Always`                                                 |
61 | `volumePermissions.securityContext.runAsUser` | User ID for the init container                                                                                         | `0`                                                      |
62 | `usePasswordFile`                             | Have the secrets mounted as a file instead of env vars                                                                 | `false`                                                  |
63 | `replication.enabled`                         | Would you like to enable replication                                                                                   | `false`                                                  |
64 | `replication.user`                            | Replication user                                                                                                       | `repl_user`                                              |
65 | `replication.password`                        | Replication user password                                                                                              | `repl_password`                                          |
66 | `replication.slaveReplicas`                   | Number of slaves replicas                                                                                              | `1`                                                      |
67 | `replication.synchronousCommit`                   | Set synchronous commit mode. Allowed values: `on`, `remote_apply`, `remote_write`, `local` and `off`                                                                                              | `off`                                                      |
68 | `replication.numSynchronousReplicas`                   | Number of replicas that will have synchronous replication. Note: Cannot be greater than `replication.slaveReplicas`.                                                                                              | `0`                                                      |
69 | `replication.applicationName`                   | Cluster application name. Useful for advanced replication settings                                                                                              | `my_application`                                                      |
70 | `existingSecret`                              | Name of existing secret to use for PostgreSQL passwords                                                                | `nil`                                                    |
71 | `postgresqlUsername`                          | PostgreSQL admin user                                                                                                  | `postgres`                                               |
72 | `postgresqlPassword`                          | PostgreSQL admin password                                                                                              | _random 10 character alphanumeric string_                |
73 | `postgresqlDatabase`                          | PostgreSQL database                                                                                                    | `nil`                                                    |
74 | `postgresqlConfiguration`                     | Runtime Config Parameters                                                                                              | `nil`                                                    |
75 | `postgresqlExtendedConf`                      | Extended Runtime Config Parameters (appended to main or default configuration)                                         | `nil`                                                    |
76 | `pgHbaConfiguration`                          | Content of pg\_hba.conf                                                                                                | `nil (do not create pg_hba.conf)`                        |
77 | `configurationConfigMap`                      | ConfigMap with the PostgreSQL configuration files (Note: Overrides `postgresqlConfiguration` and `pgHbaConfiguration`) | `nil`                                                    |
78 | `extendedConfConfigMap`                       | ConfigMap with the extended PostgreSQL configuration files                                                             | `nil`                                                    |
79 | `initdbScripts`                               | List of initdb scripts                                                                                                 | `nil`                                                    |
80 | `initdbScriptsConfigMap`                      | ConfigMap with the initdb scripts (Note: Overrides `initdbScripts`)                                                    | `nil`                                                    |
81 | `service.type`                                | Kubernetes Service type                                                                                                | `ClusterIP`                                              |
82 | `service.port`                                | PostgreSQL port                                                                                                        | `5432`                                                   |
83 | `service.nodePort`                            | Kubernetes Service nodePort                                                                                            | `nil`                                                    |
84 | `service.annotations`                         | Annotations for PostgreSQL service                                                                                     | {}                                                       |
85 | `service.loadBalancerIP`                      | loadBalancerIP if service type is `LoadBalancer`                                                                       | `nil`                                                    |
86 | `persistence.enabled`                         | Enable persistence using PVC                                                                                           | `true`                                                   |
87 | `persistence.existingClaim`                   | Provide an existing `PersistentVolumeClaim`                                                                            | `nil`                                                    |
88 | `persistence.mountPath`                       | Path to mount the volume at                                                                                            | `/bitnami/postgresql`                                    |
89 | `persistence.storageClass`                    | PVC Storage Class for PostgreSQL volume                                                                                | `nil`                                                    |
90 | `persistence.accessMode`                      | PVC Access Mode for PostgreSQL volume                                                                                  | `ReadWriteOnce`                                          |
91 | `persistence.size`                            | PVC Storage Request for PostgreSQL volume                                                                              | `8Gi`                                                    |
92 | `persistence.annotations`                     | Annotations for the PVC                                                                                                | `{}`                                                     |
93 | `master.nodeSelector`                         | Node labels for pod assignment (postgresql master)                                                                     | `{}`                                                     |
94 | `master.affinity`                             | Affinity labels for pod assignment (postgresql master)                                                                 | `{}`                                                     |
95 | `master.tolerations`                          | Toleration labels for pod assignment (postgresql master)                                                               | `[]`                                                     |
96 | `slave.nodeSelector`                          | Node labels for pod assignment (postgresql slave)                                                                      | `{}`                                                     |
97 | `slave.affinity`                              | Affinity labels for pod assignment (postgresql slave)                                                                  | `{}`                                                     |
98 | `slave.tolerations`                           | Toleration labels for pod assignment (postgresql slave)                                                                | `[]`                                                     |
99 | `terminationGracePeriodSeconds`               | Seconds the pod needs to terminate gracefully                                                                          | `nil`                                                    |
100 | `resources`                                   | CPU/Memory resource requests/limits                                                                                    | Memory: `256Mi`, CPU: `250m`                             |
101 | `securityContext.enabled`                     | Enable security context                                                                                                | `true`                                                   |
102 | `securityContext.fsGroup`                     | Group ID for the container                                                                                             | `1001`                                                   |
103 | `securityContext.runAsUser`                   | User ID for the container                                                                                              | `1001`                                                   |
104 | `livenessProbe.enabled`                       | Would you like a livessProbed to be enabled                                                                            | `true`                                                   |
105 | `networkPolicy.enabled`                       | Enable NetworkPolicy                                                                                                   | `false`                                                  |
106 | `networkPolicy.allowExternal`                 | Don't require client label for connections                                                                             | `true`                                                   |
107 | `livenessProbe.initialDelaySeconds`           | Delay before liveness probe is initiated                                                                               | 30                                                       |
108 | `livenessProbe.periodSeconds`                 | How often to perform the probe                                                                                         | 10                                                       |
109 | `livenessProbe.timeoutSeconds`                | When the probe times out                                                                                               | 5                                                        |
110 | `livenessProbe.failureThreshold`              | Minimum consecutive failures for the probe to be considered failed after having succeeded.                             | 6                                                        |
111 | `livenessProbe.successThreshold`              | Minimum consecutive successes for the probe to be considered successful after having failed                            | 1                                                        |
112 | `readinessProbe.enabled`                      | would you like a readinessProbe to be enabled                                                                          | `true`                                                   |
113 | `readinessProbe.initialDelaySeconds`          | Delay before liveness probe is initiated                                                                               | 5                                                        |
114 | `readinessProbe.periodSeconds`                | How often to perform the probe                                                                                         | 10                                                       |
115 | `readinessProbe.timeoutSeconds`               | When the probe times out                                                                                               | 5                                                        |
116 | `readinessProbe.failureThreshold`             | Minimum consecutive failures for the probe to be considered failed after having succeeded.                             | 6                                                        |
117 | `readinessProbe.successThreshold`             | Minimum consecutive successes for the probe to be considered successful after having failed                            | 1                                                        |
118 | `metrics.enabled`                             | Start a prometheus exporter                                                                                            | `false`                                                  |
119 | `metrics.service.type`                        | Kubernetes Service type                                                                                                | `ClusterIP`                                              |
120 | `service.clusterIP`                           | Static clusterIP or None for headless services                                                                         | `nil`                                                     |
121 | `metrics.service.annotations`                 | Additional annotations for metrics exporter pod                                                                        | `{}`                                                     |
122 | `metrics.service.loadBalancerIP`              | loadBalancerIP if redis metrics service type is `LoadBalancer`                                                         | `nil`                                                    |
123 | `metrics.image.registry`                      | PostgreSQL Image registry                                                                                              | `docker.io`                                              |
124 | `metrics.image.repository`                    | PostgreSQL Image name                                                                                                  | `wrouesnel/postgres_exporter`                            |
125 | `metrics.image.tag`                           | PostgreSQL Image tag                                                                                                   | `{VERSION}`                                              |
126 | `metrics.image.pullPolicy`                    | PostgreSQL Image pull policy                                                                                           | `IfNotPresent`                                           |
127 | `metrics.image.pullSecrets`                   | Specify Image pull secrets                                                                                             | `nil` (does not add image pull secrets to deployed pods) |
128 | `extraEnv`                                    | Any extra environment variables you would like to pass on to the pod                                                   | `{}`                                                     |
129 | `updateStrategy`                              | Update strategy policy                                                                                                 | `{type: "onDelete"}`                                     |
130
131 Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
132
133 ```console
134 $ helm install --name my-release \
135   --set postgresqlPassword=secretpassword,postgresqlDatabase=my-database \
136     stable/postgresql
137 ```
138
139 The above command sets the PostgreSQL `postgres` account password to `secretpassword`. Additionally it creates a database named `my-database`.
140
141 Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,
142
143 ```console
144 $ helm install --name my-release -f values.yaml stable/postgresql
145 ```
146
147 > **Tip**: You can use the default [values.yaml](values.yaml)
148
149 ### postgresql.conf / pg_hba.conf files as configMap
150
151 This helm chart also supports to customize the whole configuration file.
152
153 Add your custom file to "files/postgresql.conf" in your working directory. This file will be mounted as configMap to the containers and it will be used for configuring the PostgreSQL server.
154
155 Alternatively, you can specify PostgreSQL configuration parameters using the `postgresqlConfiguration` parameter as a dict, using camelCase, e.g. {"sharedBuffers": "500MB"}.
156
157 In addition to these options, you can also set an external ConfigMap with all the configuration files. This is done by setting the `configurationConfigMap` parameter. Note that this will override the two previous options.
158
159 ### Allow settings to be loaded from files other than the default `postgresql.conf`
160
161 If you don't want to provide the whole PostgreSQL configuration file and only specify certain parameters, you can add your extended `.conf` files to "files/conf.d/" in your working directory.
162 Those files will be mounted as configMap to the containers adding/overwriting the default configuration using the `include_dir` directive that allows settings to be loaded from files other than the default `postgresql.conf`.
163
164 Alternatively, you can also set an external ConfigMap with all the extra configuration files. This is done by setting the `extendedConfConfigMap` parameter. Note that this will override the previous option.
165
166 ## Initialize a fresh instance
167
168 The [Bitnami PostgreSQL](https://github.com/bitnami/bitnami-docker-postgresql) image allows you to use your custom scripts to initialize a fresh instance. In order to execute the scripts, they must be located inside the chart folder `files/docker-entrypoint-initdb.d` so they can be consumed as a ConfigMap.
169
170 Alternatively, you can specify custom scripts using the `initdbScripts` parameter as dict.
171
172 In addition to these options, you can also set an external ConfigMap with all the initialization scripts. This is done by setting the `initdbScriptsConfigMap` parameter. Note that this will override the two previous options.
173
174 The allowed extensions are `.sh`, `.sql` and `.sql.gz`.
175
176 ## Production and horizontal scaling
177
178 The following repo contains the recommended production settings for PostgreSQL server in an alternative [values file](values-production.yaml). Please read carefully the comments in the values-production.yaml file to set up your environment
179
180 To horizontally scale this chart, first download the [values-production.yaml](values-production.yaml) file to your local folder, then:
181
182 ```console
183 $ helm install --name my-release -f ./values-production.yaml stable/postgresql
184 $ kubectl scale statefulset my-postgresql-slave --replicas=3
185 ```
186
187 ## Persistence
188
189 The [Bitnami PostgreSQL](https://github.com/bitnami/bitnami-docker-postgresql) image stores the PostgreSQL data and configurations at the `/bitnami/postgresql` path of the container.
190
191 Persistent Volume Claims are used to keep the data across deployments. This is known to work in GCE, AWS, and minikube.
192 See the [Configuration](#configuration) section to configure the PVC or to disable persistence.
193
194 ## Metrics
195
196 The chart optionally can start a metrics exporter for [prometheus](https://prometheus.io). The metrics endpoint (port 9187) is not exposed and it is expected that the metrics are collected from inside the k8s cluster using something similar as the described in the [example Prometheus scrape configuration](https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml).
197
198 The exporter allows to create custom metrics from additional SQL queries. See the Chart's `values.yaml` for an example and consult the [exporters documentation](https://github.com/wrouesnel/postgres_exporter#adding-new-metrics-via-a-config-file) for more details.
199
200 ## NetworkPolicy
201
202 To enable network policy for PostgreSQL, install [a networking plugin that implements the Kubernetes NetworkPolicy spec](https://kubernetes.io/docs/tasks/administer-cluster/declare-network-policy#before-you-begin), and set `networkPolicy.enabled` to `true`.
203
204 For Kubernetes v1.5 & v1.6, you must also turn on NetworkPolicy by setting the DefaultDeny namespace annotation. Note: this will enforce policy for _all_ pods in the namespace:
205
206 ```console
207 $ kubectl annotate namespace default "net.beta.kubernetes.io/network-policy={\"ingress\":{\"isolation\":\"DefaultDeny\"}}"
208 ```
209
210 With NetworkPolicy enabled, traffic will be limited to just port 5432.
211
212 For more precise policy, set `networkPolicy.allowExternal=false`. This will only allow pods with the generated client label to connect to PostgreSQL.
213 This label will be displayed in the output of a successful install.
214
215 ## Upgrade
216
217 ### 3.0.0
218
219 This releases make it possible to specify different nodeSelector, affinity and tolerations for master and slave pods.
220 It also fixes an issue with `postgresql.master.fullname` helper template not obeying fullnameOverride.
221
222 #### Breaking changes
223
224 - `affinty` has been renamed to `master.affinity` and `slave.affinity`.
225 - `tolerations` has been renamed to `master.tolerations` and `slave.tolerations`.
226 - `nodeSelector` has been renamed to `master.nodeSelector` and `slave.nodeSelector`.
227
228 ### 2.0.0
229
230 In order to upgrade from the `0.X.X` branch to `1.X.X`, you should follow the below steps:
231
232  - Obtain the service name (`SERVICE_NAME`) and password (`OLD_PASSWORD`) of the existing postgresql chart. You can find the instructions to obtain the password in the NOTES.txt, the service name can be obtained by running
233
234  ```console
235 $ kubectl get svc
236  ```
237
238 - Install (not upgrade) the new version
239
240 ```console
241 $ helm repo update
242 $ helm install --name my-release stable/postgresql
243 ```
244
245 - Connect to the new pod (you can obtain the name by running `kubectl get pods`):
246
247 ```console
248 $ kubectl exec -it NAME bash
249 ```
250
251 - Once logged in, create a dump file from the previous database using `pg_dump`, for that we should connect to the previous postgresql chart:
252
253 ```console
254 $ pg_dump -h SERVICE_NAME -U postgres DATABASE_NAME > /tmp/backup.sql
255 ```
256
257 After run above command you should be prompted for a password, this password is the previous chart password (`OLD_PASSWORD`).
258 This operation could take some time depending on the database size.
259
260 - Once you have the backup file, you can restore it with a command like the one below:
261
262 ```console
263 $ psql -U postgres DATABASE_NAME < /tmp/backup.sql
264 ```
265
266 In this case, you are accessing to the local postgresql, so the password should be the new one (you can find it in NOTES.txt).
267
268 If you want to restore the database and the database schema does not exist, it is necessary to first follow the steps described below.
269
270 ```console
271 $ psql -U postgres
272 postgres=# drop database DATABASE_NAME;
273 postgres=# create database DATABASE_NAME;
274 postgres=# create user USER_NAME;
275 postgres=# alter role USER_NAME with password 'BITNAMI_USER_PASSWORD';
276 postgres=# grant all privileges on database DATABASE_NAME to USER_NAME;
277 postgres=# alter database DATABASE_NAME owner to USER_NAME;
278 ```