From f6ee2a9d9d268b0323bfcf888e4d7f95a546a3fa Mon Sep 17 00:00:00 2001 From: "Roberto C. Morano" Date: Sun, 1 Nov 2020 15:40:10 +0100 Subject: [PATCH] initial commit --- .gitignore | 1 + LICENSE | 188 ++++ README.md | 35 + .../cardano-db-sync-deployment.yaml | 89 ++ base/cardano-db-sync/kustomization.yaml | 3 + .../cardano-explorer-api-deployment.yaml | 70 ++ .../cardano-explorer-api-service.yaml | 15 + base/cardano-explorer-api/kustomization.yaml | 4 + .../cardano-graphql-deployment.yaml | 88 ++ .../cardano-graphql-service.yaml | 15 + base/cardano-graphql/configmap.yaml | 16 + base/cardano-graphql/kustomization.yaml | 6 + base/cardano-graphql/pvc.yaml | 10 + base/cardano-hasura/hasura-deployment.yaml | 75 ++ .../hasura-service-exposed.yaml | 17 + base/cardano-hasura/hasura-service.yaml | 38 + base/cardano-hasura/kustomization.yaml | 4 + base/cardano-node/cardano-node-service.yaml | 35 + .../cardano-node-statefulset.yaml | 84 ++ base/cardano-node/kustomization.yaml | 4 + .../cardano-submit-api-deployment.yaml | 47 + .../cardano-submit-api-service.yaml | 19 + base/cardano-submit-api/kustomization.yaml | 4 + base/common-env.yaml | 10 + base/helm-charts/postgresql-ha/.helmignore | 21 + base/helm-charts/postgresql-ha/Chart.yaml | 26 + base/helm-charts/postgresql-ha/README.md | 470 ++++++++++ .../postgresql-ha/ci/ct-values.yaml | 1 + .../ci/values-production-with-pdb.yaml | 20 + .../helm-charts/postgresql-ha/files/README.md | 1 + .../postgresql-ha/files/conf.d/README.md | 4 + .../docker-entrypoint-initdb.d/README.md | 3 + .../pgpool-entrypoint-initdb.d/README.md | 3 + .../postgresql-ha/templates/NOTES.txt | 53 ++ .../postgresql-ha/templates/_helpers.tpl | 817 ++++++++++++++++++ .../postgresql-ha/templates/ldap-secrets.yaml | 10 + .../templates/networkpolicy.yaml | 26 + .../templates/pgpool/configmap.yaml | 15 + .../pgpool/custom-users-secrets.yaml | 12 + .../templates/pgpool/deployment.yaml | 244 ++++++ .../pgpool/initdb-scripts-configmap.yaml | 15 + .../postgresql-ha/templates/pgpool/pdb.yaml | 18 + .../templates/pgpool/secrets.yaml | 11 + .../templates/pgpool/service.yaml | 31 + .../templates/postgresql/configmap.yaml | 29 + .../postgresql/extended-configmap.yaml | 18 + .../postgresql/hooks-scripts-configmap.yaml | 67 ++ .../postgresql/initdb-scripts-configmap.yaml | 21 + .../templates/postgresql/metrics-service.yaml | 19 + .../templates/postgresql/pdb.yaml | 18 + .../templates/postgresql/secrets.yaml | 15 + .../postgresql/service-headless.yaml | 15 + .../templates/postgresql/service.yaml | 15 + .../templates/postgresql/servicemonitor.yaml | 35 + .../templates/postgresql/statefulset.yaml | 351 ++++++++ .../postgresql-ha/values-production.yaml | 664 ++++++++++++++ base/helm-charts/postgresql-ha/values.yaml | 674 +++++++++++++++ .../helm-chartInflator-postgres-ha.yaml | 9 + overlays/mainnet/helm-postgres-ha-values.yaml | 664 ++++++++++++++ overlays/mainnet/kustomization.yaml | 32 + .../mainnet/patches/cardano-node-pvc.yaml | 10 + overlays/mainnet/patches/postgres-ha-pvc.yaml | 10 + .../resources/common-env-configmap.yaml | 14 + overlays/mainnet/resources/ingress.yaml | 113 +++ .../helm-chartInflator-postgres-ha.yaml | 9 + overlays/testnet/helm-postgres-ha-values.yaml | 664 ++++++++++++++ overlays/testnet/kustomization.yaml | 49 ++ .../cardano-db-sync-deployment-env.yaml | 33 + .../cardano-db-sync-deployment-image.yaml | 4 + .../patches/cardano-node-deployment-env.yaml | 5 + .../cardano-node-deployment-image.yaml | 4 + .../testnet/patches/cardano-node-pvc.yaml | 10 + overlays/testnet/patches/genesis-image.yaml | 4 + .../resources/common-env-configmap.yaml | 14 + overlays/testnet/resources/ingress.yaml | 110 +++ 75 files changed, 6377 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 base/cardano-db-sync/cardano-db-sync-deployment.yaml create mode 100644 base/cardano-db-sync/kustomization.yaml create mode 100644 base/cardano-explorer-api/cardano-explorer-api-deployment.yaml create mode 100644 base/cardano-explorer-api/cardano-explorer-api-service.yaml create mode 100644 base/cardano-explorer-api/kustomization.yaml create mode 100644 base/cardano-graphql/cardano-graphql-deployment.yaml create mode 100644 base/cardano-graphql/cardano-graphql-service.yaml create mode 100644 base/cardano-graphql/configmap.yaml create mode 100644 base/cardano-graphql/kustomization.yaml create mode 100644 base/cardano-graphql/pvc.yaml create mode 100644 base/cardano-hasura/hasura-deployment.yaml create mode 100644 base/cardano-hasura/hasura-service-exposed.yaml create mode 100644 base/cardano-hasura/hasura-service.yaml create mode 100644 base/cardano-hasura/kustomization.yaml create mode 100644 base/cardano-node/cardano-node-service.yaml create mode 100644 base/cardano-node/cardano-node-statefulset.yaml create mode 100644 base/cardano-node/kustomization.yaml create mode 100644 base/cardano-submit-api/cardano-submit-api-deployment.yaml create mode 100644 base/cardano-submit-api/cardano-submit-api-service.yaml create mode 100644 base/cardano-submit-api/kustomization.yaml create mode 100644 base/common-env.yaml create mode 100644 base/helm-charts/postgresql-ha/.helmignore create mode 100644 base/helm-charts/postgresql-ha/Chart.yaml create mode 100644 base/helm-charts/postgresql-ha/README.md create mode 100644 base/helm-charts/postgresql-ha/ci/ct-values.yaml create mode 100644 base/helm-charts/postgresql-ha/ci/values-production-with-pdb.yaml create mode 100644 base/helm-charts/postgresql-ha/files/README.md create mode 100644 base/helm-charts/postgresql-ha/files/conf.d/README.md create mode 100644 base/helm-charts/postgresql-ha/files/docker-entrypoint-initdb.d/README.md create mode 100644 base/helm-charts/postgresql-ha/files/pgpool-entrypoint-initdb.d/README.md create mode 100644 base/helm-charts/postgresql-ha/templates/NOTES.txt create mode 100644 base/helm-charts/postgresql-ha/templates/_helpers.tpl create mode 100644 base/helm-charts/postgresql-ha/templates/ldap-secrets.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/networkpolicy.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/pgpool/configmap.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/pgpool/custom-users-secrets.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/pgpool/deployment.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/pgpool/initdb-scripts-configmap.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/pgpool/pdb.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/pgpool/secrets.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/pgpool/service.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/configmap.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/extended-configmap.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/hooks-scripts-configmap.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/initdb-scripts-configmap.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/metrics-service.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/pdb.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/secrets.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/service-headless.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/service.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/servicemonitor.yaml create mode 100644 base/helm-charts/postgresql-ha/templates/postgresql/statefulset.yaml create mode 100644 base/helm-charts/postgresql-ha/values-production.yaml create mode 100644 base/helm-charts/postgresql-ha/values.yaml create mode 100644 overlays/mainnet/helm-chartInflator-postgres-ha.yaml create mode 100644 overlays/mainnet/helm-postgres-ha-values.yaml create mode 100644 overlays/mainnet/kustomization.yaml create mode 100644 overlays/mainnet/patches/cardano-node-pvc.yaml create mode 100644 overlays/mainnet/patches/postgres-ha-pvc.yaml create mode 100644 overlays/mainnet/resources/common-env-configmap.yaml create mode 100644 overlays/mainnet/resources/ingress.yaml create mode 100644 overlays/testnet/helm-chartInflator-postgres-ha.yaml create mode 100644 overlays/testnet/helm-postgres-ha-values.yaml create mode 100644 overlays/testnet/kustomization.yaml create mode 100644 overlays/testnet/patches/cardano-db-sync-deployment-env.yaml create mode 100644 overlays/testnet/patches/cardano-db-sync-deployment-image.yaml create mode 100644 overlays/testnet/patches/cardano-node-deployment-env.yaml create mode 100644 overlays/testnet/patches/cardano-node-deployment-image.yaml create mode 100644 overlays/testnet/patches/cardano-node-pvc.yaml create mode 100644 overlays/testnet/patches/genesis-image.yaml create mode 100644 overlays/testnet/resources/common-env-configmap.yaml create mode 100644 overlays/testnet/resources/ingress.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5bf9d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +output.yaml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..151c28c --- /dev/null +++ b/LICENSE @@ -0,0 +1,188 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a1c2520 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Requirements + +* Kubernetes. For local k8s development environment, we encourage you to use [k3s]/[k3d] lightweight k8s distro. +* kubectl +* [Kustomize] + +# Render k8s manifests + +``` +OVERLAY=mainnet +kustomize build --enable_alpha_plugins overlays/${OVERLAY} > overlays/${OVERLAY}/output.yaml +``` + +# Deploy k8s manifests + +``` +NAMESPACE=dandelion-mainnet +kubectl get ns ${NAMESPACE} || kubectl create ns ${NAMESPACE} +kubectl apply -n ${NAMESPACE} -f overlays/${OVERLAY}/output.yaml +``` + +# Operations + +* Check sync progress +``` +curl -kL 'https://graphql-api.mainnet.local/' \ + -H 'Accept-Encoding: gzip, deflate, br' \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json' \ + --data-binary '{"query":"query cardanoDbSyncProgress {\n cardanoDbMeta {\n initialized\n syncPercentage\n }\n}\n"}' +``` + +[kustomize]: https://kustomize.io/ +[k3d]: https://github.com/rancher/k3d +[k3s]: https://k3s.io/ diff --git a/base/cardano-db-sync/cardano-db-sync-deployment.yaml b/base/cardano-db-sync/cardano-db-sync-deployment.yaml new file mode 100644 index 0000000..0e6c303 --- /dev/null +++ b/base/cardano-db-sync/cardano-db-sync-deployment.yaml @@ -0,0 +1,89 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: cardano-db-sync + name: cardano-db-sync +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: cardano-db-sync + template: + metadata: + labels: + io.kompose.service: cardano-db-sync + spec: + containers: + - name: cardano-db-sync + env: + - name: EXTENDED + value: "true" + - name: NETWORK + value: mainnet + - name: POSTGRES_HOST + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_HOST_RW + - name: POSTGRES_PORT + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_PORT + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_DB + - name: POSTGRES_USER + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: init0-postgresql-ha-postgresql + key: postgresql-password + image: inputoutput/cardano-db-sync:6.0.0 + #command: ["sh", "-c", "while true; do sleep 6969; done"] + imagePullPolicy: Always + resources: {} + volumeMounts: + - name: node-ipc + mountPath: /node-ipc + - name: common-env + mountPath: /run/secrets/common-env + readOnly: true + - name: postgres-password + mountPath: /run/secrets/postgres-password + readOnly: true + - name: socat-socket-server + image: alpine/socat + env: + - name: CARDANO_NODE_SOCKET_TCP_HOST + value: "cardano-node-headless" + - name: CARDANO_NODE_SOCKET_TCP_PORT + value: "30000" + - name: SOCAT_TIMEOUT + value: "3600" + command: ["sh", "-c", "socat -T ${SOCAT_TIMEOUT} UNIX-LISTEN:/ipc/node.socket,fork TCP:${CARDANO_NODE_SOCKET_TCP_HOST}:${CARDANO_NODE_SOCKET_TCP_PORT},ignoreeof"] + #command: ["sh", "-c", "socat -d -d -d -d -v UNIX-LISTEN:/ipc/node.socket TCP:${CARDANO_NODE_SOCKET_TCP_HOST}:${CARDANO_NODE_SOCKET_TCP_PORT},ignoreeof,keepalive,keepidle=10,keepintvl=10,keepcnt=100"] + volumeMounts: + - mountPath: /ipc + name: node-ipc + restartPolicy: Always + serviceAccountName: "" + volumes: + - name: node-ipc + emptyDir: {} + - name: common-env + configMap: + name: common-env + - name: postgres-password + secret: + secretName: init0-postgresql-ha-postgresql + items: + - key: postgresql-password + path: POSTGRES_PASSWORD diff --git a/base/cardano-db-sync/kustomization.yaml b/base/cardano-db-sync/kustomization.yaml new file mode 100644 index 0000000..50cfe1a --- /dev/null +++ b/base/cardano-db-sync/kustomization.yaml @@ -0,0 +1,3 @@ +namespace: dandelion +resources: +- cardano-db-sync-deployment.yaml diff --git a/base/cardano-explorer-api/cardano-explorer-api-deployment.yaml b/base/cardano-explorer-api/cardano-explorer-api-deployment.yaml new file mode 100644 index 0000000..c53a4d0 --- /dev/null +++ b/base/cardano-explorer-api/cardano-explorer-api-deployment.yaml @@ -0,0 +1,70 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: cardano-explorer-api + name: cardano-explorer-api +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: cardano-explorer-api + template: + metadata: + labels: + io.kompose.service: cardano-explorer-api + spec: + containers: + - env: + - name: NETWORK + value: mainnet + - name: POSTGRES_HOST + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_HOST + - name: POSTGRES_PORT + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_PORT + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_DB + - name: POSTGRES_USER + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: init0-postgresql-ha-postgresql + key: postgresql-password + image: inputoutput/cardano-explorer-api:2.1.3 + imagePullPolicy: Always + name: cardano-explorer-api + ports: + - containerPort: 8100 + resources: {} + volumeMounts: + - name: common-env + mountPath: /run/secrets/common-env + readOnly: true + - name: postgres-password + mountPath: /run/secrets/postgres-password + readOnly: true + restartPolicy: Always + serviceAccountName: "" + volumes: + - name: common-env + configMap: + name: common-env + - name: postgres-password + secret: + secretName: init0-postgresql-ha-postgresql + items: + - key: postgresql-password + path: POSTGRES_PASSWORD diff --git a/base/cardano-explorer-api/cardano-explorer-api-service.yaml b/base/cardano-explorer-api/cardano-explorer-api-service.yaml new file mode 100644 index 0000000..98650c0 --- /dev/null +++ b/base/cardano-explorer-api/cardano-explorer-api-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: cardano-explorer-api + name: cardano-explorer-api +spec: + ports: + - name: "8101" + port: 8101 + targetPort: 8100 + selector: + io.kompose.service: cardano-explorer-api +status: + loadBalancer: {} diff --git a/base/cardano-explorer-api/kustomization.yaml b/base/cardano-explorer-api/kustomization.yaml new file mode 100644 index 0000000..80a38de --- /dev/null +++ b/base/cardano-explorer-api/kustomization.yaml @@ -0,0 +1,4 @@ +namespace: dandelion +resources: +- cardano-explorer-api-deployment.yaml +- cardano-explorer-api-service.yaml diff --git a/base/cardano-graphql/cardano-graphql-deployment.yaml b/base/cardano-graphql/cardano-graphql-deployment.yaml new file mode 100644 index 0000000..d7c8066 --- /dev/null +++ b/base/cardano-graphql/cardano-graphql-deployment.yaml @@ -0,0 +1,88 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: cardano-graphql + name: cardano-graphql +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: cardano-graphql + template: + metadata: + labels: + io.kompose.service: cardano-graphql + spec: + initContainers: + - name: configure + command: ["bash", "/configmap/initContainer-entrypoint"] + image: repsistance/cardano-node:iohk-mn-passive-1.21.1 + imagePullPolicy: "Always" + volumeMounts: + - name: cardano-graphql-config + mountPath: /config + - name: cardano-graphql-configmap + mountPath: /configmap + containers: + - env: + - name: ALLOW_INTROSPECTION + value: "true" + - name: CACHE_ENABLED + value: "true" + - name: GENESIS_FILE_BYRON + value: /config/genesis-byron.json + - name: GENESIS_FILE_SHELLEY + value: /config/genesis-shelley.json + - name: HASURA_URI + value: http://hasura-headless:8080 + - name: POSTGRES_HOST + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_HOST_RW + - name: POSTGRES_PORT + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_PORT + - name: POSTGRES_DB_FILE + value: /run/secrets/common-env/POSTGRES_DB + - name: POSTGRES_USER_FILE + value: /run/secrets/common-env/POSTGRES_USER + - name: POSTGRES_PASSWORD_FILE + value: /run/secrets/postgres-password/POSTGRES_PASSWORD + image: inputoutput/cardano-graphql:8226d69b509e070afca85a090fe7f74deacfa61c + #command: ["sh", "-c", "while true; do sleep 6969; done"] + imagePullPolicy: Always + name: cardano-graphql + ports: + - containerPort: 3100 + resources: {} + volumeMounts: + - name: cardano-graphql-config + mountPath: /config + - name: common-env + mountPath: /run/secrets/common-env + readOnly: true + - name: postgres-password + mountPath: /run/secrets/postgres-password + readOnly: true + restartPolicy: Always + serviceAccountName: "" + volumes: + - name: cardano-graphql-config + persistentVolumeClaim: + claimName: cardano-graphql-config + - name: cardano-graphql-configmap + configMap: + name: cardano-graphql-configmap + - name: common-env + configMap: + name: common-env + - name: postgres-password + secret: + secretName: init0-postgresql-ha-postgresql + items: + - key: postgresql-password + path: POSTGRES_PASSWORD diff --git a/base/cardano-graphql/cardano-graphql-service.yaml b/base/cardano-graphql/cardano-graphql-service.yaml new file mode 100644 index 0000000..a780229 --- /dev/null +++ b/base/cardano-graphql/cardano-graphql-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: cardano-graphql + name: cardano-graphql +spec: + ports: + - name: "3100" + port: 3100 + targetPort: 3100 + selector: + io.kompose.service: cardano-graphql +status: + loadBalancer: {} diff --git a/base/cardano-graphql/configmap.yaml b/base/cardano-graphql/configmap.yaml new file mode 100644 index 0000000..2d64d36 --- /dev/null +++ b/base/cardano-graphql/configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: cardano-graphql-configmap +data: + initContainer-entrypoint: | + rm -rf /config/lost+found + + if [ ! -e /config/genesis-shelley.json ] + then + cp /opt/cardano/cnode/files/genesis.json /config/genesis-shelley.json + fi + if [ ! -e /config/genesis-byron.json ] + then + cp /opt/cardano/cnode/files/byron-genesis.json /config/genesis-byron.json + fi diff --git a/base/cardano-graphql/kustomization.yaml b/base/cardano-graphql/kustomization.yaml new file mode 100644 index 0000000..46a73d8 --- /dev/null +++ b/base/cardano-graphql/kustomization.yaml @@ -0,0 +1,6 @@ +namespace: dandelion +resources: +- configmap.yaml +- pvc.yaml +- cardano-graphql-deployment.yaml +- cardano-graphql-service.yaml diff --git a/base/cardano-graphql/pvc.yaml b/base/cardano-graphql/pvc.yaml new file mode 100644 index 0000000..b6e8993 --- /dev/null +++ b/base/cardano-graphql/pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: cardano-graphql-config +spec: + resources: + requests: + storage: 100Mi + accessModes: + - ReadWriteOnce diff --git a/base/cardano-hasura/hasura-deployment.yaml b/base/cardano-hasura/hasura-deployment.yaml new file mode 100644 index 0000000..9af7cc5 --- /dev/null +++ b/base/cardano-hasura/hasura-deployment.yaml @@ -0,0 +1,75 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: hasura + name: hasura +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: hasura + template: + metadata: + labels: + io.kompose.service: hasura + spec: + containers: + - name: hasura + #command: ["sh", "-c", "while true; do sleep 6969; done"] + env: + - name: HASURA_GRAPHQL_ENABLED_LOG_TYPES + value: startup, http-log, webhook-log, websocket-log, query-log + - name: HASURA_GRAPHQL_ENABLE_CONSOLE + value: "true" + - name: HASURA_GRAPHQL_ENABLE_TELEMETRY + value: "false" + - name: POSTGRES_HOST + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_HOST_RW + - name: POSTGRES_PORT + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_PORT + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_DB + - name: POSTGRES_USER + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: init0-postgresql-ha-postgresql + key: postgresql-password + image: inputoutput/cardano-graphql-hasura:8226d69b509e070afca85a090fe7f74deacfa61c + imagePullPolicy: Always + ports: + - containerPort: 8080 + resources: {} + volumeMounts: + - name: common-env + mountPath: /run/secrets/common-env + readOnly: true + - name: postgres-password + mountPath: /run/secrets/postgres-password + readOnly: true + restartPolicy: Always + serviceAccountName: "" + volumes: + - name: common-env + configMap: + name: common-env + - name: postgres-password + secret: + secretName: init0-postgresql-ha-postgresql + items: + - key: postgresql-password + path: POSTGRES_PASSWORD diff --git a/base/cardano-hasura/hasura-service-exposed.yaml b/base/cardano-hasura/hasura-service-exposed.yaml new file mode 100644 index 0000000..ccdd015 --- /dev/null +++ b/base/cardano-hasura/hasura-service-exposed.yaml @@ -0,0 +1,17 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: hasura + name: hasura +spec: + ports: + - name: hasura + port: 8080 + targetPort: 8080 + selector: + io.kompose.service: hasura +status: + loadBalancer: {} + diff --git a/base/cardano-hasura/hasura-service.yaml b/base/cardano-hasura/hasura-service.yaml new file mode 100644 index 0000000..9e94746 --- /dev/null +++ b/base/cardano-hasura/hasura-service.yaml @@ -0,0 +1,38 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: hasura + name: hasura-headless +spec: + sessionAffinity: ClientIP + clusterIP: None + type: ClusterIP + ports: + - name: hasura + port: 8080 + targetPort: 8080 + protocol: TCP + selector: + io.kompose.service: hasura +status: + loadBalancer: {} + +--- +#apiVersion: v1 +#kind: Service +#metadata: +# labels: +# io.kompose.service: hasura +# name: hasura +#spec: +# ports: +# - name: hasura +# port: 8080 +# targetPort: 8080 +# selector: +# io.kompose.service: hasura +#status: +# loadBalancer: {} +# diff --git a/base/cardano-hasura/kustomization.yaml b/base/cardano-hasura/kustomization.yaml new file mode 100644 index 0000000..3756c46 --- /dev/null +++ b/base/cardano-hasura/kustomization.yaml @@ -0,0 +1,4 @@ +namespace: dandelion +resources: +- hasura-deployment.yaml +- hasura-service.yaml diff --git a/base/cardano-node/cardano-node-service.yaml b/base/cardano-node/cardano-node-service.yaml new file mode 100644 index 0000000..69c5420 --- /dev/null +++ b/base/cardano-node/cardano-node-service.yaml @@ -0,0 +1,35 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: cardano-node-headless + labels: + io.kompose.service: cardano-node +spec: + sessionAffinity: ClientIP + clusterIP: None + type: ClusterIP + ports: + - name: socat-tcp-server + port: 30000 + targetPort: 30000 + protocol: TCP + selector: + io.kompose.service: cardano-node + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: cardano-node + name: chisel-server +spec: + ports: + - name: chisel-server + port: 40000 + targetPort: 40000 + selector: + io.kompose.service: cardano-node +status: + loadBalancer: {} diff --git a/base/cardano-node/cardano-node-statefulset.yaml b/base/cardano-node/cardano-node-statefulset.yaml new file mode 100644 index 0000000..2566aef --- /dev/null +++ b/base/cardano-node/cardano-node-statefulset.yaml @@ -0,0 +1,84 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + labels: + io.kompose.service: cardano-node + name: cardano-node +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: cardano-node + serviceName: cardano-node + updateStrategy: + type: OnDelete + template: + metadata: + labels: + io.kompose.service: cardano-node + spec: + initContainers: + - name: remove-lost-n-found + image: busybox + imagePullPolicy: Always + command: ["sh", "-c", "rm -rf /data/db/lost+found"] + resources: {} + volumeMounts: + - mountPath: /data/db + name: node-db + containers: + - name: cardano-node + env: + - name: NETWORK + value: mainnet + image: inputoutput/cardano-node:1.21.1 + imagePullPolicy: Always + resources: {} + volumeMounts: + - mountPath: /data/db + name: node-db + - mountPath: /ipc + name: node-ipc + - name: chisel-server + image: jpillora/chisel + env: + - name: PORT + value: "40000" + command: ["sh", "-c", "/app/chisel server -v --authfile /common-env/chisel-auth-file -p ${PORT:-40000}"] + ports: + - containerPort: 40000 + volumeMounts: + - name: common-env + mountPath: /common-env + readOnly: true + - name: socat-tcp-server + image: alpine/socat + env: + - name: PORT + value: "30000" + command: ["sh", "-c", "socat TCP-LISTEN:${PORT},fork UNIX-CLIENT:/ipc/node.socket,ignoreeof"] + volumeMounts: + - mountPath: /ipc + name: node-ipc + ports: + - containerPort: 30000 + restartPolicy: Always + serviceAccountName: "" + volumes: + - name: node-db + persistentVolumeClaim: + claimName: node-db + - name: node-ipc + emptyDir: {} + - name: common-env + configMap: + name: common-env + + volumeClaimTemplates: + - metadata: + name: node-db + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 8Gi diff --git a/base/cardano-node/kustomization.yaml b/base/cardano-node/kustomization.yaml new file mode 100644 index 0000000..67c7ac3 --- /dev/null +++ b/base/cardano-node/kustomization.yaml @@ -0,0 +1,4 @@ +namespace: dandelion +resources: +- cardano-node-statefulset.yaml +- cardano-node-service.yaml diff --git a/base/cardano-submit-api/cardano-submit-api-deployment.yaml b/base/cardano-submit-api/cardano-submit-api-deployment.yaml new file mode 100644 index 0000000..6dac5df --- /dev/null +++ b/base/cardano-submit-api/cardano-submit-api-deployment.yaml @@ -0,0 +1,47 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: cardano-submit-api + name: cardano-submit-api +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: cardano-submit-api + template: + metadata: + labels: + io.kompose.service: cardano-submit-api + spec: + containers: + - name: socat-socket-server + image: alpine/socat + env: + - name: CARDANO_NODE_SOCKET_TCP_HOST + value: "cardano-node-headless" + - name: CARDANO_NODE_SOCKET_TCP_PORT + value: "30000" + command: ["sh", "-c", "socat -T 300 UNIX-LISTEN:/ipc/node.socket,fork TCP:${CARDANO_NODE_SOCKET_TCP_HOST}:${CARDANO_NODE_SOCKET_TCP_PORT},ignoreeof"] + volumeMounts: + - mountPath: /ipc + name: node-ipc + - name: cardano-submit-api + env: + - name: NETWORK + value: mainnet + image: inputoutput/cardano-submit-api:2.1.3 + imagePullPolicy: Always + ports: + - containerPort: 8090 + resources: {} + volumeMounts: + - mountPath: /node-ipc + name: node-ipc + restartPolicy: Always + serviceAccountName: "" + volumes: + - name: node-ipc + emptyDir: {} + +# TODO: setup-public-exposure diff --git a/base/cardano-submit-api/cardano-submit-api-service.yaml b/base/cardano-submit-api/cardano-submit-api-service.yaml new file mode 100644 index 0000000..2a33bad --- /dev/null +++ b/base/cardano-submit-api/cardano-submit-api-service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + kompose.cmd: kompose convert -c --controller deployment --volumes persistentVolumeClaim + kompose.version: 1.21.0 (992df58d8) + creationTimestamp: null + labels: + io.kompose.service: cardano-submit-api + name: cardano-submit-api +spec: + ports: + - name: "8091" + port: 8091 + targetPort: 8090 + selector: + io.kompose.service: cardano-submit-api +status: + loadBalancer: {} diff --git a/base/cardano-submit-api/kustomization.yaml b/base/cardano-submit-api/kustomization.yaml new file mode 100644 index 0000000..1cc2628 --- /dev/null +++ b/base/cardano-submit-api/kustomization.yaml @@ -0,0 +1,4 @@ +namespace: dandelion +resources: +- cardano-submit-api-deployment.yaml +- cardano-submit-api-service.yaml diff --git a/base/common-env.yaml b/base/common-env.yaml new file mode 100644 index 0000000..b2ec0ff --- /dev/null +++ b/base/common-env.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: common-env +data: + POSTGRES_HOST: init0-postgresql-ha-pgpool + POSTGRES_HOST_RW: init0-postgresql-ha-pgpool + POSTGRES_PORT: "5432" + POSTGRES_DB: cdbs + POSTGRES_USER: postgres diff --git a/base/helm-charts/postgresql-ha/.helmignore b/base/helm-charts/postgresql-ha/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/base/helm-charts/postgresql-ha/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/base/helm-charts/postgresql-ha/Chart.yaml b/base/helm-charts/postgresql-ha/Chart.yaml new file mode 100644 index 0000000..6283900 --- /dev/null +++ b/base/helm-charts/postgresql-ha/Chart.yaml @@ -0,0 +1,26 @@ +annotations: + category: Database +apiVersion: v1 +appVersion: 11.9.0 +description: Chart for PostgreSQL with HA architecture (using Replication Manager + (repmgr) and Pgpool). +engine: gotpl +home: https://www.postgresql.org/ +icon: https://bitnami.com/assets/stacks/postgresql/img/postgresql-stack-110x117.png +keywords: +- postgresql +- repmgr +- pgpool +- postgres +- database +- sql +- replication +- cluster +- high availability +maintainers: +- email: containers@bitnami.com + name: Bitnami +name: postgresql-ha +sources: +- https://github.com/bitnami/bitnami-docker-postgresql +version: 3.5.9 diff --git a/base/helm-charts/postgresql-ha/README.md b/base/helm-charts/postgresql-ha/README.md new file mode 100644 index 0000000..5099c4c --- /dev/null +++ b/base/helm-charts/postgresql-ha/README.md @@ -0,0 +1,470 @@ +# PostgreSQL HA + +This Helm chart has been developed based on [bitnami/postgresql](https://github.com/bitnami/charts/tree/master/bitnami/postgresql) chart but including some changes to guarantee high availability such as: + +- A new deployment, service have been added to deploy [Pgpool-II](Pgpool-II) to act as proxy for PostgreSQL backend. It helps to reduce connection overhead, acts as a load balancer for PostgreSQL, and ensures database node failover. +- Replacing `bitnami/postgresql` with `bitnami/postgresql-repmgr` which includes and configures [repmgr](https://repmgr.org/). Repmgr ensures standby nodes assume the primary role when the primary node is unhealthy. + +## TL;DR + +```console +$ helm repo add bitnami https://charts.bitnami.com/bitnami +$ helm install my-release bitnami/postgresql-ha +``` + +## Introduction + +This [Helm](https://github.com/kubernetes/helm) chart installs [PostgreSQL](https://www.postgresql.org/) with HA architecture in a Kubernetes cluster. Welcome to [contribute](CONTRIBUTING.md) to Helm Chart for PostgreSQL HA. + +## Prerequisites + +- Kubernetes 1.12+ +- Helm 2.12+ or Helm 3.0-beta3+ + +## Installing the Chart + +Install the PostgreSQL HA helm chart with a release name `my-release`: + +```console +$ helm repo add bitnami https://charts.bitnami.com/bitnami +$ helm install my-release bitnami/postgresql-ha +``` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +$ helm delete --purge my-release +``` + +Additionaly, if `persistence.resourcePolicy` is set to `keep`, you should manually delete the PVCs. + +## Parameters + +The following table lists the configurable parameters of the PostgreSQL HA chart and the default values. They can be configured in `values.yaml` or set via `--set` flag during installation. + +| Parameter | Description | Default | +| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | +| **Global** | | | +| `global.imageRegistry` | Global Docker image registry | `nil` | +| `global.imagePullSecrets` | Global Docker registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) | +| `global.storageClass` | Global storage class for dynamic provisioning | `nil` | +| `global.postgresql.existingSecret` | Name of existing secret to use for PostgreSQL passwords (overrides `postgresql.existingSecret`) | `nil` | +| `global.postgresql.username` | PostgreSQL username (overrides `postgresql.username`) | `nil` | +| `global.postgresql.password` | PostgreSQL password (overrides `postgresql.password`) | `nil` | +| `global.postgresql.database` | PostgreSQL database (overrides `postgresql.database`) | `nil` | +| `global.postgresql.repmgrUsername` | PostgreSQL repmgr username (overrides `postgresql.repmgrUsername`) | `nil` | +| `global.postgresql.repmgrPassword` | PostgreSQL repmgr password (overrides `postgresql.repmgrpassword`) | `nil` | +| `global.postgresql.repmgrDatabase` | PostgreSQL repmgr database (overrides `postgresql.repmgrDatabase`) | `nil` | +| `global.ldap.existingSecret` | Name of existing secret to use for LDAP passwords (overrides `ldap.existingSecret`) | `nil` | +| `global.ldap.bindpw` | LDAP bind password (overrides `ldap.bindpw`) | `nil` | +| `global.pgpool.adminUsername` | Pgpool Admin username (overrides `pgpool.adminUsername`) | `nil` | +| `global.pgpool.adminPassword` | Pgpool Admin password (overrides `pgpool.adminPassword`) | `nil` | +| **General** | | | +| `nameOverride` | String to partially override postgres-ha.fullname template with a string | `nil` | +| `fullnameOverride` | String to fully override postgres-ha.fullname template with a string | `nil` | +| `clusterDomain` | Default Kubernetes cluster domain | `cluster.local` | +| **PostgreSQL with Repmgr** | | | +| `postgresqlImage.registry` | Registry for PostgreSQL with Repmgr image | `docker.io` | +| `postgresqlImage.repository` | Repository for PostgreSQL with Repmgr image | `bitnami/postgresql-repmgr` | +| `postgresqlImage.tag` | Tag for PostgreSQL with Repmgr image | `{TAG_NAME}` | +| `postgresqlImage.pullPolicy` | PostgreSQL with Repmgr image pull policy | `IfNotPresent` | +| `postgresqlImage.pullSecrets` | Specify docker-registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) | +| `postgresqlImage.debug` | Specify if debug logs should be enabled | `false` | +| `postgresql.labels` | Map of labels to add to the statefulset. Evaluated as a template | `{}` | +| `postgresql.podLabels` | Map of labels to add to the pods. Evaluated as a template | `{}` | +| `postgresql.replicaCount` | The number of replicas to deploy | `2` | +| `postgresql.updateStrategyType` | Statefulset update strategy policy | `RollingUpdate` | +| `postgresql.podAnnotations` | Additional pod annotations | `{}` | +| `postgresql.affinity` | Map of node/pod affinities | `{}` (The value is evaluated as a template) | +| `postgresql.nodeSelector` | Node labels for pod assignment | `{}` (The value is evaluated as a template) | +| `postgresql.priorityClassName` | Pod priority class | `` | +| `postgresql.tolerations` | Tolerations for pod assignment | `[]` (The value is evaluated as a template) | +| `postgresql.securityContext.enabled` | Enable security context for PostgreSQL with Repmgr | `true` | +| `postgresql.securityContext.fsGroup` | Group ID for the PostgreSQL with Repmgr filesystem | `1001` | +| `postgresql.securityContext.runAsUser` | User ID for the PostgreSQL with Repmgr container | `1001` | +| `postgresql.resources` | The [resources] to allocate for container | `{}` | +| `postgresql.livenessProbe` | Liveness probe configuration for PostgreSQL with Repmgr | `Check values.yaml file` | +| `postgresql.readinessProbe` | Readiness probe configuration for PostgreSQL with Repmgr | `Check values.yaml file` | +| `postgresql.pdb.create` | If true, create a pod disruption budget for PostgreSQL with Repmgr pods | `false` | +| `postgresql.pdb.minAvailable` | Minimum number / percentage of pods that should remain scheduled | `1` | +| `postgresql.pdb.maxUnavailable` | Maximum number / percentage of pods that may be made unavailable | `nil` | +| `postgresql.username` | PostgreSQL username | `postgres` | +| `postgresql.password` | PostgreSQL password | `nil` | +| `postgresql.existingSecret` | Name of existing secret to use for PostgreSQL passwords | `nil` | +| `postgresql.postgresPassword` | PostgreSQL password for the `postgres` user when `username` is not `postgres` | `nil` | +| `postgresql.database` | PostgreSQL database | `postgres` | +| `postgresql.usePasswordFile` | Have the secrets mounted as a file instead of env vars | `false` | +| `postgresql.upgradeRepmgrExtension` | Upgrade repmgr extension in the database | `false` | +| `postgresql.pgHbaTrustAll` | Configures PostgreSQL HBA to trust every user | `false` | +| `postgresql.syncReplication` | Make the replication synchronous. This will wait until the data is synchronized in all the replicas before other query can be run. This ensures the data availability at the expenses of speed. | `false` | +| `postgresql.repmgrUsername` | PostgreSQL repmgr username | `repmgr` | +| `postgresql.repmgrPassword` | PostgreSQL repmgr password | `nil` | +| `postgresql.repmgrDatabase` | PostgreSQL repmgr database | `repmgr` | +| `postgresql.repmgrLogLevel` | Repmgr log level (DEBUG, INFO, NOTICE, WARNING, ERROR, ALERT, CRIT or EMERG) | `NOTICE` | +| `postgresql.repmgrConnectTimeout` | Repmgr backend connection timeout (in seconds) | `5` | +| `postgresql.repmgrReconnectAttempts` | Repmgr backend reconnection attempts | `3` | +| `postgresql.repmgrReconnectInterval` | Repmgr backend reconnection interval (in seconds) | `5` | +| `postgresql.repmgrConfiguration` | Repmgr Configuration | `nil` | +| `postgresql.configuration` | PostgreSQL Configuration | `nil` | +| `postgresql.pgHbaConfiguration` | Content of pg\_hba.conf | `nil (do not create pg_hba.conf)` | +| `postgresql.configurationCM` | ConfigMap with the PostgreSQL configuration files (Note: Overrides `postgresql.repmgrConfiguration`, `postgresql.configuration` and `postgresql.pgHbaConfiguration`) | `nil` (The value is evaluated as a template) | +| `postgresql.extendedConf` | Extended PostgreSQL Configuration (appended to main or default configuration) | `nil` | +| `postgresql.extendedConfCM` | ConfigMap with the extended PostgreSQL configuration files (Note: Overrides `postgresql.extendedConf`) | `nil` (The value is evaluated as a template) | +| `postgresql.initdbScripts` | Dictionary of initdb scripts | `nil` | +| `postgresql.initdbScriptsCM` | ConfigMap with the initdb scripts (Note: Overrides `initdbScripts`). The value is evaluated as a template. | `nil` | +| `postgresql.initdbScriptsSecret` | Secret with initdb scripts that contain sensitive information (Note: can be used with initdbScriptsCM or initdbScripts). The value is evaluated as a template. | `nil` | +| **Pgpool** | | | +| `pgpoolImage.registry` | Registry for Pgpool | `docker.io` | +| `pgpoolImage.repository` | Repository for Pgpool | `bitnami/pgpool` | +| `pgpoolImage.tag` | Tag for Pgpool | `{TAG_NAME}` | +| `pgpoolImage.pullPolicy` | Pgpool image pull policy | `IfNotPresent` | +| `pgpoolImage.pullSecrets` | Specify docker-registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) | +| `pgpoolImage.debug` | Specify if debug logs should be enabled | `false` | +| `pgpool.customUsers.usernames` | Comma or semicolon separeted list of postgres usernames to be added to pgpool_passwd | `nil` | +| `pgpool.customUsers.passwords` | Comma or semicolon separeted list of the associated passwords for the users to be added to pgpool_passwd | `nil` | +| `pgpool.customUsersSecret` | Name of a secret containing the usernames and passwords of accounts that will be added to pgpool_passwd | `nil` | +| `pgpool.labels` | Map of labels to add to the deployment. Evaluated as a template | `{}` | +| `pgpool.podLabels` | Map of labels to add to the pods. Evaluated as a template | `{}` | +| `pgpool.replicaCount` | The number of replicas to deploy | `1` | +| `pgpool.podAnnotations` | Additional pod annotations | `{}` | +| `pgpool.affinity` | Map of node/pod affinities | `{}` (The value is evaluated as a template) | +| `pgpool.initdbScripts` | Dictionary of initdb scripts | `nil` | +| `pgpool.initdbScriptsCM` | ConfigMap with the initdb scripts (Note: Overrides `initdbScripts`). The value is evaluated as a template. | `nil` | +| `pgpool.initdbScriptsSecret` | Secret with initdb scripts that contain sensitive information (Note: can be used with initdbScriptsCM or initdbScripts). The value is evaluated as a template. | `nil` | +| `pgpool.nodeSelector` | Node labels for pod assignment | `{}` (The value is evaluated as a template) | +| `pgpool.priorityClassName` | Pod priority class | `` | +| `pgpool.tolerations` | Tolerations for pod assignment | `[]` (The value is evaluated as a template) | +| `pgpool.securityContext.enabled` | Enable security context for Pgpool | `true` | +| `pgpool.securityContext.fsGroup` | Group ID for the Pgpool filesystem | `1001` | +| `pgpool.securityContext.runAsUser` | User ID for the Pgpool container | `1001` | +| `pgpool.resources` | The [resources] to allocate for container | `{}` | +| `pgpool.livenessProbe` | Liveness probe configuration for Pgpool | `Check values.yaml file` | +| `pgpool.readinessProbe` | Readiness probe configuration for Pgpool | `Check values.yaml file` | +| `pgpool.pdb.create` | If true, create a pod disruption budget for Pgpool pods. | `false` | +| `pgpool.pdb.minAvailable` | Minimum number / percentage of pods that should remain scheduled | `1` | +| `pgpool.pdb.maxUnavailable` | Maximum number / percentage of pods that may be made unavailable | `nil` | +| `pgpool.updateStrategy` | Strategy used to replace old Pods by new ones | `{}` | +| `pgpool.minReadySeconds` | How many seconds a pod needs to be ready before killing the next, during update | `nil` | +| `pgpool.adminUsername` | Pgpool Admin username | `admin` | +| `pgpool.adminPassword` | Pgpool Admin password | `nil` | +| `pgpool.maxPool` | The maximum number of cached connections in each child process | `15` | +| `pgpool.numInitChildren` | The number of preforked Pgpool-II server processes. | `32` | +| `pgpool.configuration` | Content of pgpool.conf | `nil` | +| `pgpool.configurationCM` | ConfigMap with the Pgpool configuration file (Note: Overrides `pgpol.configuration`). The file used must be named `pgpool.conf`. | `nil` (The value is evaluated as a template) | +| `pgpool.useLoadBalancing` | If true, use Pgpool Load-Balancing | `true` | +| **LDAP** | | | +| `ldap.enabled` | Enable LDAP support | `false` | +| `ldap.existingSecret` | Name of existing secret to use for LDAP passwords | `nil` | +| `ldap.uri` | LDAP URL beginning in the form `ldap[s]://:` | `nil` | +| `ldap.base` | LDAP base DN | `nil` | +| `ldap.binddn` | LDAP bind DN | `nil` | +| `ldap.bindpw` | LDAP bind password | `nil` | +| `ldap.bslookup` | LDAP base lookup | `nil` | +| `ldap.scope` | LDAP search scope | `nil` | +| `ldap.tlsReqcert` | LDAP TLS check on server certificates | `nil` | +| `ldap.nssInitgroupsIgnoreusers` | LDAP ignored users | `root,nslcd` | +| **Prometheus metrics** | | | +| `metricsImage.registry` | Registry for PostgreSQL Prometheus exporter | `docker.io` | +| `metricsImage.repository` | Repository for PostgreSQL Prometheus exporter | `bitnami/postgres-exporter` | +| `metricsImage.tag` | Tag for PostgreSQL Prometheus exporter | `{TAG_NAME}` | +| `metricsImage.pullPolicy` | PostgreSQL Prometheus exporter image pull policy | `IfNotPresent` | +| `metricsImage.pullSecrets` | Specify docker-registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) | +| `metricsImage.debug` | Specify if debug logs should be enabled | `false` | +| `metrics.securityContext.enabled` | Enable security context for PostgreSQL Prometheus exporter | `true` | +| `metrics.securityContext.runAsUser` | User ID for the PostgreSQL Prometheus exporter container | `1001` | +| `metrics.resources` | The [resources] to allocate for container | `{}` | +| `metrics.livenessProbe` | Liveness probe configuration for PostgreSQL Prometheus exporter | `Check values.yaml file` | +| `metrics.readinessProbe` | Readiness probe configuration for PostgreSQL Prometheus exporter | `Check values.yaml file` | +| `metrics.annotations` | Annotations for PostgreSQL Prometheus exporter service | `{prometheus.io/scrape: "true", prometheus.io/port: "9187"}` | +| `metrics.serviceMonitor.enabled` | if `true`, creates a Prometheus Operator ServiceMonitor (also requires `metrics.enabled` to be `true`) | `false` | +| `metrics.serviceMonitor.namespace` | Optional namespace which Prometheus is running in | `nil` | +| `metrics.serviceMonitor.interval` | How frequently to scrape metrics (use by default, falling back to Prometheus' default) | `nil` | +| `metrics.serviceMonitor.selector` | Default to kube-prometheus install (CoreOS recommended), but should be set according to Prometheus install | `{prometheus: "kube-prometheus"}` | +| `metrics.serviceMonitor.relabelings` | ServiceMonitor relabelings. Value is evaluated as a template | `[]` | +| `metrics.serviceMonitor.metricRelabelings` | ServiceMonitor metricRelabelings. Value is evaluated as a template | `[]` | +| **Init Container to adapt volume permissions** | | | +| `volumePermissionsImage.registry` | Registry for Bitnami Minideb | `docker.io` | +| `volumePermissionsImage.repository` | Repository for Bitnami Minideb | `bitnami/minideb` | +| `volumePermissionsImage.tag` | Tag for Bitnami Minideb | `latest` | +| `volumePermissionsImage.pullPolicy` | Bitnami Minideb exporter image pull policy | `Always` | +| `volumePermissionsImage.pullSecrets` | Specify docker-registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) | +| `volumePermissions.enabled` | Enable init container to adapt volume permissions | `false` | +| `volumePermissions.securityContext.enabled` | Enable security context for Bitnami Minideb | `false` | +| `volumePermissions.securityContext.runAsUser` | User ID for the Bitnami Minideb container | `0` | +| **Persistence** | | | +| `persistence.enabled` | Enable data persistence | `true` | +| `persistence.existingClaim` | Use a existing PVC which must be created manually before bound | `nil` | +| `persistence.storageClass` | Specify the `storageClass` used to provision the volume | `nil` | +| `persistence.mountPath` | Path to mount data volume at | `nil` | +| `persistence.accessMode` | Access mode of data volume | `ReadWriteOnce` | +| `persistence.size` | Size of data volume | `8Gi` | +| `persistence.annotations` | Persistent Volume Claim annotations | `{}` | +| **Expose** | | | +| `service.type` | Kubernetes service type (`ClusterIP`, `NodePort` or `LoadBalancer`) | `ClusterIP` | +| `service.port` | PostgreSQL port | `5432` | +| `service.nodePort` | Kubernetes service nodePort | `nil` | +| `service.annotations` | Annotations for PostgreSQL service | `{}` | +| `service.loadBalancerIP` | loadBalancerIP if service type is `LoadBalancer` | `nil` | +| `service.loadBalancerSourceRanges` | Address that are allowed when service is LoadBalancer | `[]` | +| `service.clusterIP` | Static clusterIP or None for headless services | `nil` | +| `networkPolicy.enabled` | Enable NetworkPolicy | `false` | +| `networkPolicy.allowExternal` | Don't require client label for connections | `true` | + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```console +$ helm install my-release \ + --set postgresql.password=password \ + bitnami/postgresql-ha +``` + +The above command sets the password for user `postgres` to `password`. + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, + +```console +$ helm install my-release \ + -f values.yaml \ + bitnami/postgresql-ha +``` + +## Configuration and installation details + +### [Rolling VS Immutable tags](https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/) + +It is strongly recommended to use immutable tags in a production environment. This ensures your deployment does not change automatically if the same tag is updated with a different image. + +Bitnami will release a new chart updating its containers if a new version of the main container, significant changes, or critical vulnerabilities exist. + +### Production configuration and horizontal scaling + +This chart includes a `values-production.yaml` file where you can find some parameters oriented to production configuration in comparison to the regular `values.yaml`: + +- Enable Newtworkpolicy blocking external access: + +```diff +- networkPolicy.enabled: false ++ networkPolicy.enabled: true +- networkPolicy.allowExternal: true ++ networkPolicy.allowExternal: false +``` + +- Start a side-car prometheus exporter: + +```diff +- metrics.enabled: false ++ metrics.enabled: true +``` + +To horizontally scale this chart, you can use the `--replicaCount` flag to modify the number of nodes in your PostgreSQL deployment. Also you can use the `values-production.yaml` file or modify the parameters shown above. + +### Change PostgreSQL version + +To modify the PostgreSQL version used in this chart you can specify a [valid image tag](https://hub.docker.com/r/bitnami/postgresql-repmgr/tags/) using the `image.tag` parameter. For example, `image.tag=X.Y.Z`. This approach is also applicable to other images like exporters. + +### Configure the way how to expose PostgreSQL + +- **ClusterIP**: Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster. Set `service.type=ClusterIP` to choose this service type. +- **NodePort**: Exposes the service on each Node's IP at a static port (the NodePort). You’ll be able to contact the NodePort service, from outside the cluster, by requesting `NodeIP:NodePort`. Set `service.type=NodePort` to choose this service type. +- **LoadBalancer**: Exposes the service externally using a cloud provider's load balancer. Set `service.type=LoadBalancer` to choose this service type. + +### Adjust permissions of persistent volume mountpoint + +As the images run as non-root by default, it is necessary to adjust the ownership of the persistent volumes so that the containers can write data into it. + +By default, the chart is configured to use Kubernetes Security Context to automatically change the ownership of the volume. However, this feature does not work in all Kubernetes distributions. +As an alternative, this chart supports using an initContainer to change the ownership of the volume before mounting it in the final destination. + +You can enable this initContainer by setting `volumePermissions.enabled` to `true`. + +### LDAP + +LDAP support can be enabled in the chart by specifying the `ldap.` parameters while creating a release. The following parameters should be configured to properly enable the LDAP support in the chart. + +- **ldap.enabled**: Enable LDAP support. Defaults to `false`. +- **ldap.uri**: LDAP URL beginning in the form `ldap[s]://:`. No defaults. +- **ldap.base**: LDAP base DN. No defaults. +- **ldap.binddn**: LDAP bind DN. No defaults. +- **ldap.bindpw**: LDAP bind password. No defaults. +- **ldap.bslookup**: LDAP base lookup. No defaults. +- **ldap.nss_initgroups_ignoreusers**: LDAP ignored users. `root,nslcd`. +- **ldap.scope**: LDAP search scope. No defaults. +- **ldap.tls_reqcert**: LDAP TLS check on server certificates. No defaults. + +For example: + +```bash +ldap.enabled="true" +ldap.uri="ldap://my_ldap_server" +ldap.base="dc=example\,dc=org" +ldap.binddn="cn=admin\,dc=example\,dc=org" +ldap.bindpw="admin" +ldap.bslookup="ou=group-ok\,dc=example\,dc=org" +ldap.nss_initgroups_ignoreusers="root\,nslcd" +ldap.scope="sub" +ldap.tls_reqcert="demand" +``` + +Next, login to the PostgreSQL server using the `psql` client and add the PAM authenticated LDAP users. + +> Note: Parameters including commas must be escaped as shown in the above example. More information at: https://github.com/helm/helm/blob/master/docs/using_helm.md#the-format-and-limitations-of---set + +### repmgr.conf / postgresql.conf / pg_hba.conf / pgpool.conf files as configMap + +This helm chart also supports to customize the whole configuration file. + +Add your custom files to "files" in your working directory. Those files will be mounted as configMap to the containers and it will be used for configuring Pgpool, Repmgr and the PostgreSQL server. + +Alternatively, you can specify the Pgpool, PostgreSQL and Repmgr configuration using the `pgpool.configuration`, `postgresql.configuration`, `postgresql.pgHbaConfiguration`, and `postgresql.repmgrConfiguration` parameters. + +In addition to these options, you can also set an external ConfigMap(s) with all the configuration files. This is done by setting the `postgresql.configurationCM` and `pgpool.configurationCM` parameters. Note that this will override the two previous options. + +### Allow settings to be loaded from files other than the default `postgresql.conf` + +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. +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`. + +Alternatively, you can specify the extended configuration using the `postgresql.extendedConf` parameter. + +In addition to these options, you can also set an external ConfigMap with all the extra configuration files. This is done by setting the `postgresql.extendedConfCM` parameter. Note that this will override the two previous options. + +### Initialize a fresh instance + +The [Bitnami PostgreSQL with Repmgr](https://github.com/bitnami/bitnami-docker-postgresql-repmgr) 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. + +Alternatively, you can specify custom scripts using the `initdbScripts` parameter as dict. + +In addition to these options, you can also set an external ConfigMap with all the initialization scripts. This is done by setting the `postgresql.initdbScriptsCM` parameter. Note that this will override the two previous options. If your initialization scripts contain sensitive information such as credentials or passwords, you can use the `initdbScriptsSecret` parameter. + +The allowed extensions are `.sh`, `.sql` and `.sql.gz`. + +### Use of global variables + +In more complex scenarios, we may have the following tree of dependencies + +```bash + +--------------+ + | | + +------------+ Chart 1 +-----------+ + | | | | + | --------+------+ | + | | | + | | | + | | | + | | | + v v v ++-------+------+ +--------+------+ +--------+------+ +| | | | | | +|PostgreSQL HA | | Sub-chart 1 | | Sub-chart 2 | +| | | | | | ++--------------+ +---------------+ +---------------+ +``` + +The three charts below depend on the parent chart Chart 1. However, subcharts 1 and 2 may need to connect to PostgreSQL HA as well. In order to do so, subcharts 1 and 2 need to know the PostgreSQL HA credentials, so one option for deploying could be deploy Chart 1 with the following parameters: + +```bash +postgresql.postgresqlPassword=testtest +subchart1.postgresql.postgresqlPassword=testtest +subchart2.postgresql.postgresqlPassword=testtest +postgresql.postgresqlDatabase=db1 +subchart1.postgresql.postgresqlDatabase=db1 +subchart2.postgresql.postgresqlDatabase=db1 +``` + +If the number of dependent sub-charts increases, installing the chart with parameters can become increasingly difficult. An alternative would be to set the credentials using global variables as follows: + +```bash +global.postgresql.postgresqlPassword=testtest +global.postgresql.postgresqlDatabase=db1 +``` + +This way, the credentials will be available in all of the subcharts. + +## Persistence + +The data is persisted by default using PVC templates in the PostgreSQL statefulset. You can disable the persistence setting the `persistence.enabled` parameter to `false`. +A default `StorageClass` is needed in the Kubernetes cluster to dynamically provision the volumes. Specify another StorageClass in the `persistence.storageClass` or set `persistence.existingClaim` if you have already existing persistent volumes to use. + +## Upgrade + +It's necessary to specify the existing passwords while performing a upgrade to ensure the secrets are not updated with invalid randomly generated passwords. Remember to specify the existing values of the `postgresql.password` and `postgresql.repmgrPassword` parameters when upgrading the chart: + +```bash +$ helm upgrade my-release bitnami/postgresql-ha \ + --set postgresql.password=[POSTGRESQL_PASSWORD] \ + --set postgresql.repmgrPassword=[REPMGR_PASSWORD] +``` + +> Note: you need to substitute the placeholders _[POSTGRESQL_PASSWORD]_, and _[REPMGR_PASSWORD]_ with the values obtained from instructions in the installation notes. + +## 3.0.0 + +A new major version of repmgr (5.1.0) was included. To upgrade to this major version, it's necessary to upgrade the repmgr extension installed on the database. To do so, follow the steps below: + +- Reduce your PostgreSQL setup to one replica (primary node) and upgrade to `3.0.0`, enabling the repmgr extension upgrade: + +```bash +$ helm upgrade my-release --version 3.0.0 bitnami/postgresql-ha \ + --set postgresql.password=[POSTGRESQL_PASSWORD] \ + --set postgresql.repmgrPassword=[REPMGR_PASSWORD] \ + --set postgresql.replicaCount=1 \ + --set postgresql.upgradeRepmgrExtension=true +``` + +- Scale your PostgreSQL setup to the original number of replicas: + +```bash +$ helm upgrade my-release --version 3.0.0 bitnami/postgresql-ha \ + --set postgresql.password=[POSTGRESQL_PASSWORD] \ + --set postgresql.repmgrPassword=[REPMGR_PASSWORD] \ + --set postgresql.replicaCount=[NUMBER_OF_REPLICAS] +``` + +> Note: you need to substitute the placeholders _[POSTGRESQL_PASSWORD]_, and _[REPMGR_PASSWORD]_ with the values obtained from instructions in the installation notes. + +## 2.0.0 + +The [Bitnami Pgpool](https://github.com/bitnami/bitnami-docker-pgpool) image was migrated to a "non-root" user approach. Previously the container ran as the `root` user and the Pgpool daemon was started as the `pgpool` user. From now on, both the container and the Pgpool daemon run as user `1001`. You can revert this behavior by setting the parameters `pgpool.securityContext.runAsUser`, and `pgpool.securityContext.fsGroup` to `0`. + +Consequences: + +- No backwards compatibility issues are expected since all the data is at PostgreSQL pods, and Pgpool uses a deployment without persistence. Therefore, upgrades should work smoothly from `1.x.x` versions. +- Environment variables related to LDAP configuration were renamed removing the `PGPOOL_` prefix. For instance, to indicate the LDAP URI to use, you must set `LDAP_URI` instead of `PGPOOL_LDAP_URI` + +## 1.0.0 + +A new major version of repmgr (5.0.0) was included. To upgrade to this major version, it's necessary to upgrade the repmgr extension installed on the database. To do so, follow the steps below: + +- Reduce your PostgreSQL setup to one replica (primary node) and upgrade to `1.0.0`, enabling the repmgr extension upgrade: + +```bash +$ helm upgrade my-release --version 1.0.0 bitnami/postgresql-ha \ + --set postgresql.password=[POSTGRESQL_PASSWORD] \ + --set postgresql.repmgrPassword=[REPMGR_PASSWORD] \ + --set postgresql.replicaCount=1 \ + --set postgresql.upgradeRepmgrExtension=true +``` + +- Scale your PostgreSQL setup to the original number of replicas: + +```bash +$ helm upgrade my-release --version 1.0.0 bitnami/postgresql-ha \ + --set postgresql.password=[POSTGRESQL_PASSWORD] \ + --set postgresql.repmgrPassword=[REPMGR_PASSWORD] \ + --set postgresql.replicaCount=[NUMBER_OF_REPLICAS] +``` + +> Note: you need to substitute the placeholders _[POSTGRESQL_PASSWORD]_, and _[REPMGR_PASSWORD]_ with the values obtained from instructions in the installation notes. + +## 0.4.0 + +In this version, the chart will use PostgreSQL-Repmgr container images with the Postgis extension included. The version used in Postgresql version 10, 11 and 12 is Postgis 2.5, and in Postgresql 9.6 is Postgis 2.3. Postgis has been compiled with the following dependencies: + +- protobuf +- protobuf-c +- json-c +- geos +- proj +- gdal diff --git a/base/helm-charts/postgresql-ha/ci/ct-values.yaml b/base/helm-charts/postgresql-ha/ci/ct-values.yaml new file mode 100644 index 0000000..068f4c2 --- /dev/null +++ b/base/helm-charts/postgresql-ha/ci/ct-values.yaml @@ -0,0 +1 @@ +fullnameOverride: test diff --git a/base/helm-charts/postgresql-ha/ci/values-production-with-pdb.yaml b/base/helm-charts/postgresql-ha/ci/values-production-with-pdb.yaml new file mode 100644 index 0000000..94239c0 --- /dev/null +++ b/base/helm-charts/postgresql-ha/ci/values-production-with-pdb.yaml @@ -0,0 +1,20 @@ +# Test values file for generating all of the yaml and check that +# the rendering is correct + +postgresql: + pdb: + create: true + +pgpool: + pdb: + create: true + +networkPolicy: + enabled: true + allowExternal: false + +metrics: + enabled: true + ## Kubeval doesn't recognise ServiceMonitor as a valid K8s object + # serviceMonitor: + # enabled: true diff --git a/base/helm-charts/postgresql-ha/files/README.md b/base/helm-charts/postgresql-ha/files/README.md new file mode 100644 index 0000000..1813a2f --- /dev/null +++ b/base/helm-charts/postgresql-ha/files/README.md @@ -0,0 +1 @@ +Copy here your postgresql.conf and/or pg_hba.conf files to use it as a config map. diff --git a/base/helm-charts/postgresql-ha/files/conf.d/README.md b/base/helm-charts/postgresql-ha/files/conf.d/README.md new file mode 100644 index 0000000..878363e --- /dev/null +++ b/base/helm-charts/postgresql-ha/files/conf.d/README.md @@ -0,0 +1,4 @@ +If you don't want to provide the whole configuration file and only specify certain parameters, you can copy here your extended `.conf` files. +These files will be injected as a config maps and add/overwrite the default configuration using the `include_dir` directive that allows settings to be loaded from files other than the default `postgresql.conf`. + +More info in the [bitnami-docker-postgresql-repmgr README](https://github.com/bitnami/bitnami-docker-postgresql#configuration-file). diff --git a/base/helm-charts/postgresql-ha/files/docker-entrypoint-initdb.d/README.md b/base/helm-charts/postgresql-ha/files/docker-entrypoint-initdb.d/README.md new file mode 100644 index 0000000..824e0d5 --- /dev/null +++ b/base/helm-charts/postgresql-ha/files/docker-entrypoint-initdb.d/README.md @@ -0,0 +1,3 @@ +You can copy here your custom `.sh`, `.sql` or `.sql.gz` file so they are executed during the first boot of the image. + +More info in the [bitnami-docker-postgresql-repmgr](https://github.com/bitnami/bitnami-docker-postgresql-repmgr#initializing-a-new-instance) repository. \ No newline at end of file diff --git a/base/helm-charts/postgresql-ha/files/pgpool-entrypoint-initdb.d/README.md b/base/helm-charts/postgresql-ha/files/pgpool-entrypoint-initdb.d/README.md new file mode 100644 index 0000000..bfa7962 --- /dev/null +++ b/base/helm-charts/postgresql-ha/files/pgpool-entrypoint-initdb.d/README.md @@ -0,0 +1,3 @@ +You can copy here your custom `.sh` file(s) so they are executed everytime Pgpool container is initialized + +More info in the [bitnami-docker-pgpool](https://github.com/bitnami/bitnami-docker-postgresql-repmgr#initializing-with-custom-scripts) repository. diff --git a/base/helm-charts/postgresql-ha/templates/NOTES.txt b/base/helm-charts/postgresql-ha/templates/NOTES.txt new file mode 100644 index 0000000..2dd5929 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/NOTES.txt @@ -0,0 +1,53 @@ +{{- $clusterDomain:= .Values.clusterDomain }} +** Please be patient while the chart is being deployed ** + +PostgreSQL can be accessed through Pgpool via port {{ .Values.service.port }} on the following DNS name from within your cluster: + + {{ include "postgresql-ha.pgpool" . }}.{{ .Release.Namespace }}.svc.{{ $clusterDomain }} + +Pgpool acts as a load balancer for PostgreSQL and forward read/write connections to the primary node while read-only connections are forwarded to standby nodes. + +To get the password for {{ (include "postgresql-ha.postgresqlUsername" .) | quote }} run: + + export POSTGRES_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "postgresql-ha.postgresqlSecretName" . }} -o jsonpath="{.data.postgresql-password}" | base64 --decode) + +To get the password for {{ (include "postgresql-ha.postgresqlRepmgrUsername" .) | quote }} run: + + export REPMGR_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "postgresql-ha.postgresqlSecretName" . }} -o jsonpath="{.data.repmgr-password}" | base64 --decode) + +To connect to your database run the following command: + + kubectl run {{ include "postgresql-ha.fullname" . }}-client --rm --tty -i --restart='Never' --namespace {{ .Release.Namespace }} --image {{ include "postgresql-ha.postgresqlImage" . }} --env="PGPASSWORD=$POSTGRES_PASSWORD" {{ if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }}--labels="{{ include "postgresql-ha.fullname" . }}-client=true" {{- end }} \ + --command -- psql -h {{ include "postgresql-ha.pgpool" . }} -p {{ .Values.service.port }} -U {{ include "postgresql-ha.postgresqlUsername" . }}{{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} -d {{ include "postgresql-ha.postgresqlDatabase" . }}{{- end }} + +{{- if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }} + +Note: Since NetworkPolicy is enabled, only pods with label "{{ include "postgresql-ha.fullname" . }}-client=true" will be able to connect to this PostgreSQL cluster. + +{{- end }} + +To connect to your database from outside the cluster execute the following commands: + +{{- if contains "NodePort" .Values.service.type }} + + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "postgresql-ha.pgpool" . }} + PGPASSWORD="$POSTGRES_PASSWORD" psql -h $NODE_IP -p $NODE_PORT -U {{ include "postgresql-ha.postgresqlUsername" . }}{{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} -d {{ include "postgresql-ha.postgresqlDatabase" . }}{{- end }} + +{{- else if contains "LoadBalancer" .Values.service.type }} + + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -w {{ include "postgresql-ha.pgpool" . }} + + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "postgresql-ha.pgpool" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + PGPASSWORD="$POSTGRES_PASSWORD" psql -h $SERVICE_IP -p {{ .Values.service.port }} -U {{ include "postgresql-ha.postgresqlUsername" . }}{{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} -d {{ include "postgresql-ha.postgresqlDatabase" . }}{{- end }} + +{{- else if contains "ClusterIP" .Values.service.type }} + + kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ include "postgresql-ha.pgpool" . }} {{ .Values.service.port }}:{{ .Values.service.port }} & + psql -h 127.0.0.1 -p {{ .Values.service.port }} -U {{ include "postgresql-ha.postgresqlUsername" . }}{{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} -d {{ include "postgresql-ha.postgresqlDatabase" . }}{{- end }} + +{{- end }} + +{{- include "postgresql-ha.validateValues" . }} +{{- include "postgresql-ha.checkRollingTags" . }} diff --git a/base/helm-charts/postgresql-ha/templates/_helpers.tpl b/base/helm-charts/postgresql-ha/templates/_helpers.tpl new file mode 100644 index 0000000..81014e1 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/_helpers.tpl @@ -0,0 +1,817 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "postgresql-ha.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "postgresql-ha.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "postgresql-ha.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "postgresql-ha.labels" -}} +app.kubernetes.io/name: {{ template "postgresql-ha.name" . }} +helm.sh/chart: {{ template "postgresql-ha.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector +*/}} +{{- define "postgresql-ha.matchLabels" -}} +app.kubernetes.io/name: {{ template "postgresql-ha.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{/* +Fully qualified app name for PostgreSQL +*/}} +{{- define "postgresql-ha.postgresql" -}} +{{- printf "%s-postgresql" (include "postgresql-ha.fullname" .) -}} +{{- end -}} + +{{/* +Fully qualified app name for Pgpool +*/}} +{{- define "postgresql-ha.pgpool" -}} +{{- printf "%s-pgpool" (include "postgresql-ha.fullname" .) -}} +{{- end -}} + +{{/* +Fully qualified app name for LDAP +*/}} +{{- define "postgresql-ha.ldap" -}} +{{- printf "%s-ldap" (include "postgresql-ha.fullname" .) -}} +{{- end -}} + +{{/* +Return the proper PostgreSQL image name +*/}} +{{- define "postgresql-ha.postgresqlImage" -}} +{{- $registryName := .Values.postgresqlImage.registry -}} +{{- $repositoryName := .Values.postgresqlImage.repository -}} +{{- $tag := .Values.postgresqlImage.tag | toString -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.imageRegistry }} + {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} + {{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} + {{- end -}} +{{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} +{{- end -}} +{{- end -}} + +{{/* +Return the proper Pgpool image name +*/}} +{{- define "postgresql-ha.pgpoolImage" -}} +{{- $registryName := .Values.pgpoolImage.registry -}} +{{- $repositoryName := .Values.pgpoolImage.repository -}} +{{- $tag := .Values.pgpoolImage.tag | toString -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.imageRegistry }} + {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} + {{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} + {{- end -}} +{{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} +{{- end -}} +{{- end -}} + +{{/* +Return the proper PostgreSQL Prometheus exporter image name +*/}} +{{- define "postgresql-ha.volumePermissionsImage" -}} +{{- $registryName := .Values.volumePermissionsImage.registry -}} +{{- $repositoryName := .Values.volumePermissionsImage.repository -}} +{{- $tag := .Values.volumePermissionsImage.tag | toString -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.imageRegistry }} + {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} + {{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} + {{- end -}} +{{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} +{{- end -}} +{{- end -}} + +{{/* +Return the proper PostgreSQL Prometheus exporter image name +*/}} +{{- define "postgresql-ha.metricsImage" -}} +{{- $registryName := .Values.metricsImage.registry -}} +{{- $repositoryName := .Values.metricsImage.repository -}} +{{- $tag := .Values.metricsImage.tag | toString -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.imageRegistry }} + {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}} + {{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} + {{- end -}} +{{- else -}} + {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} +{{- end -}} +{{- end -}} + +{{/* +Return the proper Docker Image Registry Secret Names +*/}} +{{- define "postgresql-ha.imagePullSecrets" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic. +Also, we can not use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} +{{- if .Values.global.imagePullSecrets }} +imagePullSecrets: +{{- range .Values.global.imagePullSecrets }} + - name: {{ . }} +{{- end -}} +{{- else if or .Values.postgresqlImage.pullSecrets .Values.pgpoolImage.pullSecrets .Values.volumePermissionsImage.pullSecrets .Values.metricsImage.pullSecrets }} +imagePullSecrets: +{{- range .Values.postgresqlImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- range .Values.pgpoolImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- range .Values.volumePermissionsImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- range .Values.metricsImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- end -}} +{{- else if or .Values.postgresqlImage.pullSecrets .Values.pgpoolImage.pullSecrets .Values.volumePermissionsImage.pullSecrets .Values.metricsImage.pullSecrets }} +imagePullSecrets: +{{- range .Values.postgresqlImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- range .Values.pgpoolImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- range .Values.volumePermissionsImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- range .Values.metricsImage.pullSecrets }} + - name: {{ . }} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL username +*/}} +{{- define "postgresql-ha.postgresqlUsername" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.username }} + {{- .Values.global.postgresql.username -}} + {{- else -}} + {{- .Values.postgresql.username -}} + {{- end -}} + {{- else -}} + {{- .Values.postgresql.username -}} + {{- end -}} +{{- else -}} + {{- .Values.postgresql.username -}} +{{- end -}} +{{- end -}} + +{{/* +Return PostgreSQL postgres user password +*/}} +{{- define "postgresql-ha.postgresqlPostgresPassword" -}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.postgresPassword }} + {{- .Values.global.postgresql.postgresPassword -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.postgresPassword (empty .Values.postgresql.postgresPassword) -}} + {{- end -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.postgresPassword (empty .Values.postgresql.postgresPassword) -}} + {{- end -}} +{{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.postgresPassword (empty .Values.postgresql.postgresPassword) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL password +*/}} +{{- define "postgresql-ha.postgresqlPassword" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.password }} + {{- .Values.global.postgresql.password -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.password (empty .Values.postgresql.password) -}} + {{- end -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.password (empty .Values.postgresql.password) -}} + {{- end -}} +{{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.password (empty .Values.postgresql.password) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the Pgpool Admin username +*/}} +{{- define "postgresql-ha.pgpoolAdminUsername" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.pgpool }} + {{- if .Values.global.pgpool.adminUsername }} + {{- .Values.global.pgpool.adminUsername -}} + {{- else -}} + {{- .Values.pgpool.adminUsername -}} + {{- end -}} + {{- else -}} + {{- .Values.pgpool.adminUsername -}} + {{- end -}} +{{- else -}} + {{- .Values.pgpool.adminUsername -}} +{{- end -}} +{{- end -}} + +{{/* +Return the Pgpool Admin password +*/}} +{{- define "postgresql-ha.pgpoolAdminPassword" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.pgpool }} + {{- if .Values.global.pgpool.adminPassword }} + {{- .Values.global.pgpool.adminPassword -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.pgpool.adminPassword (empty .Values.pgpool.adminPassword) -}} + {{- end -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.pgpool.adminPassword (empty .Values.pgpool.adminPassword) -}} + {{- end -}} +{{- else -}} + {{- ternary (randAlphaNum 10) .Values.pgpool.adminPassword (empty .Values.pgpool.adminPassword) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL database to create +*/}} +{{- define "postgresql-ha.postgresqlDatabase" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- $postgresqlDatabase := default "postgres" .Values.postgresql.database -}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.database }} + {{- default "postgres" .Values.global.postgresql.database -}} + {{- else -}} + {{- $postgresqlDatabase -}} + {{- end -}} + {{- else -}} + {{- $postgresqlDatabase -}} + {{- end -}} +{{- else -}} + {{- $postgresqlDatabase -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL repmgr username +*/}} +{{- define "postgresql-ha.postgresqlRepmgrUsername" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.repmgrUsername }} + {{- .Values.global.postgresql.repmgrUsername -}} + {{- else -}} + {{- .Values.postgresql.repmgrUsername -}} + {{- end -}} + {{- else -}} + {{- .Values.postgresql.repmgrUsername -}} + {{- end -}} +{{- else -}} + {{- .Values.postgresql.repmgrUsername -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL repmgr password +*/}} +{{- define "postgresql-ha.postgresqlRepmgrPassword" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.repmgrPassword }} + {{- .Values.global.postgresql.repmgrPassword -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.repmgrPassword (empty .Values.postgresql.repmgrPassword) -}} + {{- end -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.repmgrPassword (empty .Values.postgresql.repmgrPassword) -}} + {{- end -}} +{{- else -}} + {{- ternary (randAlphaNum 10) .Values.postgresql.repmgrPassword (empty .Values.postgresql.repmgrPassword) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the database to use for repmgr +*/}} +{{- define "postgresql-ha.repmgrDatabase" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.repmgrDatabase }} + {{- .Values.global.postgresql.repmgrDatabase -}} + {{- else -}} + {{- .Values.postgresql.repmgrDatabase -}} + {{- end -}} + {{- else -}} + {{- .Values.postgresql.repmgrDatabase -}} + {{- end -}} +{{- else -}} + {{- .Values.postgresql.repmgrDatabase -}} +{{- end -}} +{{- end -}} + +{{/* +Return true if a secret object should be created for PostgreSQL +*/}} +{{- define "postgresql-ha.postgresqlCreateSecret" -}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.existingSecret }} + {{- else if (not .Values.postgresql.existingSecret) -}} + {{- true -}} + {{- end -}} + {{- else if (not .Values.postgresql.existingSecret) -}} + {{- true -}} + {{- end -}} +{{- else if (not .Values.postgresql.existingSecret) -}} + {{- true -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL credentials secret. +*/}} +{{- define "postgresql-ha.postgresqlSecretName" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.postgresql }} + {{- if .Values.global.postgresql.existingSecret }} + {{- printf "%s" (tpl .Values.global.postgresql.existingSecret $) -}} + {{- else if .Values.postgresql.existingSecret -}} + {{- printf "%s" (tpl .Values.postgresql.existingSecret $) -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.postgresql" .) -}} + {{- end -}} + {{- else if .Values.postgresql.existingSecret -}} + {{- printf "%s" (tpl .Values.postgresql.existingSecret $) -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.postgresql" .) -}} + {{- end -}} +{{- else -}} + {{- if .Values.postgresql.existingSecret -}} + {{- printf "%s" (tpl .Values.postgresql.existingSecret $) -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.postgresql" .) -}} + {{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Return true if a secret object should be created for Pgpool +*/}} +{{- define "postgresql-ha.pgpoolCreateSecret" -}} +{{- if .Values.global }} + {{- if .Values.global.pgpool }} + {{- if .Values.global.pgpool.existingSecret }} + {{- else if (not .Values.pgpool.existingSecret) -}} + {{- true -}} + {{- end -}} + {{- else if (not .Values.pgpool.existingSecret) -}} + {{- true -}} + {{- end -}} +{{- else if (not .Values.pgpool.existingSecret) -}} + {{- true -}} +{{- end -}} +{{- end -}} + +{{/* +Return the Pgpool credentials secret. +*/}} +{{- define "postgresql-ha.pgpoolSecretName" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.pgpool }} + {{- if .Values.global.pgpool.existingSecret }} + {{- printf "%s" .Values.global.pgpool.existingSecret -}} + {{- else if .Values.pgpool.existingSecret -}} + {{- printf "%s" .Values.pgpool.existingSecret -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.pgpool" .) -}} + {{- end -}} + {{- else if .Values.pgpool.existingSecret -}} + {{- printf "%s" .Values.pgpool.existingSecret -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.pgpool" .) -}} + {{- end -}} +{{- else -}} + {{- if .Values.pgpool.existingSecret -}} + {{- printf "%s" .Values.pgpool.existingSecret -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.pgpool" .) -}} + {{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL configuration configmap. +*/}} +{{- define "postgresql-ha.postgresqlConfigurationCM" -}} +{{- if .Values.postgresql.configurationCM -}} +{{- printf "%s" (tpl .Values.postgresql.configurationCM $) -}} +{{- else -}} +{{- printf "%s-configuration" (include "postgresql-ha.postgresql" .) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL extended configuration configmap. +*/}} +{{- define "postgresql-ha.postgresqlExtendedConfCM" -}} +{{- if .Values.postgresql.extendedConfCM -}} +{{- printf "%s" (tpl .Values.postgresql.extendedConfCM $) -}} +{{- else -}} +{{- printf "%s-extended-configuration" (include "postgresql-ha.postgresql" .) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the Pgpool configuration configmap. +*/}} +{{- define "postgresql-ha.pgpoolConfigurationCM" -}} +{{- if .Values.pgpool.configurationCM -}} +{{- printf "%s" (tpl .Values.pgpool.configurationCM $) -}} +{{- else -}} +{{- printf "%s-configuration" (include "postgresql-ha.pgpool" .) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the PostgreSQL initdb scripts configmap. +*/}} +{{- define "postgresql-ha.postgresqlInitdbScriptsCM" -}} +{{- if .Values.postgresql.initdbScriptsCM -}} +{{- printf "%s" (tpl .Values.postgresql.initdbScriptsCM $) -}} +{{- else -}} +{{- printf "%s-initdb-scripts" (include "postgresql-ha.postgresql" .) -}} +{{- end -}} +{{- end -}} + +{{/* +Get the initialization scripts Secret name. +*/}} +{{- define "postgresql-ha.postgresqlInitdbScriptsSecret" -}} +{{- if .Values.postgresql.initdbScriptsSecret -}} +{{- include "postgresql-ha.tplValue" (dict "value" .Values.postgresql.initdbScriptsSecret "context" $) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the Pgpool initdb scripts configmap. +*/}} +{{- define "postgresql-ha.pgpoolInitdbScriptsCM" -}} +{{- if .Values.pgpool.initdbScriptsCM -}} +{{- printf "%s" (tpl .Values.pgpool.initdbScriptsCM $) -}} +{{- else -}} +{{- printf "%s-initdb-scripts" (include "postgresql-ha.pgpool" .) -}} +{{- end -}} +{{- end -}} + +{{/* +Get the pgpool initialization scripts Secret name. +*/}} +{{- define "postgresql-ha.pgpoolInitdbScriptsSecret" -}} +{{- if .Values.pgpool.initdbScriptsSecret -}} +{{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.initdbScriptsSecret "context" $) -}} +{{- end -}} +{{- end -}} + +{{/* +Return the LDAP bind password +*/}} +{{- define "postgresql-ha.ldapPassword" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.ldap }} + {{- if .Values.global.ldap.bindpw }} + {{- .Values.global.ldap.bindpw -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.ldap.bindpw (empty .Values.ldap.bindpw) -}} + {{- end -}} + {{- else -}} + {{- ternary (randAlphaNum 10) .Values.ldap.bindpw (empty .Values.ldap.bindpw) -}} + {{- end -}} +{{- else -}} + {{- ternary (randAlphaNum 10) .Values.ldap.bindpw (empty .Values.ldap.bindpw) -}} +{{- end -}} +{{- end -}} + + +{{/* +Return the LDAP credentials secret. +*/}} +{{- define "postgresql-ha.ldapSecretName" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic. +Also, we can't use a single if because lazy evaluation is not an option +*/}} +{{- if .Values.global }} + {{- if .Values.global.ldap }} + {{- if .Values.global.ldap.existingSecret }} + {{- printf "%s" .Values.global.ldap.existingSecret -}} + {{- else if .Values.ldap.existingSecret -}} + {{- printf "%s" .Values.ldap.existingSecret -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.ldap" .) -}} + {{- end -}} + {{- else if .Values.ldap.existingSecret -}} + {{- printf "%s" .Values.ldap.existingSecret -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.ldap" .) -}} + {{- end -}} +{{- else -}} + {{- if .Values.ldap.existingSecret -}} + {{- printf "%s" .Values.ldap.existingSecret -}} + {{- else -}} + {{- printf "%s" (include "postgresql-ha.ldap" .) -}} + {{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Return the proper Storage Class +*/}} +{{- define "postgresql-ha.storageClass" -}} +{{/* +Helm 2.11 supports the assignment of a value to a variable defined in a different scope, +but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic. +*/}} +{{- if .Values.global -}} + {{- if .Values.global.storageClass -}} + {{- if (eq "-" .Values.global.storageClass) -}} + {{- printf "storageClassName: \"\"" -}} + {{- else }} + {{- printf "storageClassName: %s" .Values.global.storageClass -}} + {{- end -}} + {{- else -}} + {{- if .Values.persistence.storageClass -}} + {{- if (eq "-" .Values.persistence.storageClass) -}} + {{- printf "storageClassName: \"\"" -}} + {{- else }} + {{- printf "storageClassName: %s" .Values.persistence.storageClass -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- else -}} + {{- if .Values.persistence.storageClass -}} + {{- if (eq "-" .Values.persistence.storageClass) -}} + {{- printf "storageClassName: \"\"" -}} + {{- else }} + {{- printf "storageClassName: %s" .Values.persistence.storageClass -}} + {{- end -}} + {{- end -}} +{{- end -}} +{{- end -}} + +{{/* Check if there are rolling tags in the images */}} +{{- define "postgresql-ha.checkRollingTags" -}} +{{- if and (contains "bitnami/" .Values.postgresqlImage.repository) (not (.Values.postgresqlImage.tag | toString | regexFind "-r\\d+$|sha256:")) }} +WARNING: Rolling tag detected ({{ .Values.postgresqlImage.repository }}:{{ .Values.postgresqlImage.tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment. ++info https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/ +{{- end }} +{{- if and (contains "bitnami/" .Values.pgpoolImage.repository) (not (.Values.pgpoolImage.tag | toString | regexFind "-r\\d+$|sha256:")) }} +WARNING: Rolling tag detected ({{ .Values.pgpoolImage.repository }}:{{ .Values.pgpoolImage.tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment. ++info https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/ +{{- end }} +{{- if and (contains "bitnami/" .Values.metricsImage.repository) (not (.Values.metricsImage.tag | toString | regexFind "-r\\d+$|sha256:")) }} +WARNING: Rolling tag detected ({{ .Values.metricsImage.repository }}:{{ .Values.metricsImage.tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment. ++info https://docs.bitnami.com/containers/how-to/understand-rolling-tags-containers/ +{{- end }} +{{- end -}} + +{{/* +Return the appropriate apiVersion for networkPolicy +*/}} +{{- define "postgresql-ha.networkPolicy.apiVersion" -}} +{{- if semverCompare ">=1.4-0, <1.7-0" .Capabilities.KubeVersion.GitVersion -}} +"extensions/v1beta1" +{{- else if semverCompare "^1.7-0" .Capabilities.KubeVersion.GitVersion -}} +"networking.k8s.io/v1" +{{- end -}} +{{- end -}} + +{{/* +Renders a value that contains template. +Usage: +{{ include "postgresql-ha.tplValue" (dict "value" .Values.path.to.the.Value "context" $) }} +*/}} +{{- define "postgresql-ha.tplValue" -}} + {{- if typeIs "string" .value }} + {{- tpl .value .context }} + {{- else }} + {{- tpl (.value | toYaml) .context }} + {{- end }} +{{- end -}} + +{{/* +Compile all warnings into a single message, and call fail. +*/}} +{{- define "postgresql-ha.validateValues" -}} +{{- $messages := list -}} +{{- $messages := append $messages (include "postgresql-ha.validateValues.nodesHostnames" .) -}} +{{- $messages := append $messages (include "postgresql-ha.validateValues.ldap" .) -}} +{{- $messages := append $messages (include "postgresql-ha.validateValues.ldapPgHba" .) -}} +{{- $messages := append $messages (include "postgresql-ha.validateValues.upgradeRepmgrExtension" .) -}} +{{- $messages := without $messages "" -}} +{{- $message := join "\n" $messages -}} + +{{- if $message -}} +{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} +{{- end -}} +{{- end -}} + +{{/* Validate values of PostgreSQL HA - PostgreSQL nodes hostnames cannot be longer than 128 characters */}} +{{- define "postgresql-ha.validateValues.nodesHostnames" -}} +{{- $postgresqlFullname := include "postgresql-ha.postgresql" . }} +{{- $postgresqlHeadlessServiceName := printf "%s-headless" (include "postgresql-ha.postgresql" .) }} +{{- $releaseNamespace := .Release.Namespace }} +{{- $clusterDomain:= .Values.clusterDomain }} +{{- $nodeHostname := printf "%s-00.%s.%s.svc.%s:1234" $postgresqlFullname $postgresqlHeadlessServiceName $releaseNamespace $clusterDomain }} +{{- if gt (len $nodeHostname) 128 -}} +postgresql-ha: Nodes hostnames + PostgreSQL nodes hostnames ({{ $nodeHostname }}) exceeds the characters limit for Pgpool: 128. + Consider using a shorter release name or namespace. +{{- end -}} +{{- end -}} + +{{/* Validate values of PostgreSQL HA - must provide mandatory LDAP paremeters when LDAP is enabled */}} +{{- define "postgresql-ha.validateValues.ldap" -}} +{{- if and .Values.ldap.enabled (or (empty .Values.ldap.uri) (empty .Values.ldap.base) (empty .Values.ldap.binddn) (empty .Values.ldap.bindpw)) -}} +postgresql-ha: LDAP + Invalid LDAP configuration. When enabling LDAP support, the parameters "ldap.uri", + "ldap.base", "ldap.binddn", and "ldap.bindpw" are mandatory. Please provide them: + + $ helm install {{ .Release.Name }} bitnami/postgresql-ha \ + --set ldap.enabled=true \ + --set ldap.uri="ldap://my_ldap_server" \ + --set ldap.base="dc=example\,dc=org" \ + --set ldap.binddn="cn=admin\,dc=example\,dc=org" \ + --set ldap.bindpw="admin" +{{- end -}} +{{- end -}} + +{{/* Validate values of PostgreSQL HA - PostgreSQL HBA configuration must trust every user when LDAP is enabled */}} +{{- define "postgresql-ha.validateValues.ldapPgHba" -}} +{{- if and .Values.ldap.enabled (not .Values.postgresql.pgHbaTrustAll) }} +postgresql-ha: LDAP & pg_hba.conf + PostgreSQL HBA configuration must trust every user when LDAP is enabled. + Please configure HBA to trust every user (--set postgresql.pgHbaTrustAll=true) +{{- end -}} +{{- end -}} + +{{/* Validate values of PostgreSQL HA - There must be an unique replica when upgrading repmgr extension */}} +{{- define "postgresql-ha.validateValues.upgradeRepmgrExtension" -}} +{{- $postgresqlReplicaCount := int .Values.postgresql.replicaCount }} +{{- if and .Values.postgresql.upgradeRepmgrExtension (gt $postgresqlReplicaCount 1) }} +postgresql-ha: Upgrade repmgr extension + There must be only one replica when upgrading repmgr extension: + + $ helm upgrade {{ .Release.Name }} bitnami/postgresql-ha \ + --set postgresql.replicaCount=1 \ + --set postgresql.upgradeRepmgrExtension=true +{{- end -}} +{{- end -}} + +{{/* Set PGPASSWORD as environment variable depends on configuration */}} +{{- define "postgresql-ha.pgpassword" -}} +{{- if .Values.postgresql.usePasswordFile -}} +PGPASSWORD=$(< $POSTGRES_PASSWORD_FILE) +{{- else -}} +PGPASSWORD=$POSTGRES_PASSWORD +{{- end -}} +{{- end -}} + +{{/* +Return the Pgpool secret containing custom users to be added to +pool_passwd file. +*/}} +{{- define "postgresql-ha.pgpoolCustomUsersSecretName" -}} +{{- if .Values.pgpool.customUsersSecret -}} +{{- printf "%s" (tpl .Values.pgpool.customUsersSecret $) -}} +{{- else -}} +{{- printf "%s-custom-users" (include "postgresql-ha.pgpool" .) -}} +{{- end -}} +{{- end -}} diff --git a/base/helm-charts/postgresql-ha/templates/ldap-secrets.yaml b/base/helm-charts/postgresql-ha/templates/ldap-secrets.yaml new file mode 100644 index 0000000..689fd30 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/ldap-secrets.yaml @@ -0,0 +1,10 @@ +{{- if .Values.ldap.enabled }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "postgresql-ha.ldap" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} +type: Opaque +data: + bind-password: {{ (include "postgresql-ha.ldapPassword" .) | b64enc | quote }} +{{- end -}} diff --git a/base/helm-charts/postgresql-ha/templates/networkpolicy.yaml b/base/helm-charts/postgresql-ha/templates/networkpolicy.yaml new file mode 100644 index 0000000..915d298 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/networkpolicy.yaml @@ -0,0 +1,26 @@ +{{- if .Values.networkPolicy.enabled }} +kind: NetworkPolicy +apiVersion: {{ template "postgresql-ha.networkPolicy.apiVersion" . }} +metadata: + name: {{ include "postgresql-ha.fullname" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} +spec: + podSelector: + matchLabels: {{ include "postgresql-ha.matchLabels" . | nindent 6 }} + app.kubernetes.io/component: postgresql + ingress: + # Allow inbound connections + - ports: + - port: 5432 + {{- if not .Values.networkPolicy.allowExternal }} + from: + - podSelector: + matchLabels: + {{ template "postgresql-ha.fullname" . }}-client: "true" + - podSelector: + matchLabels: {{- include "postgresql-ha.matchLabels" . | nindent 14 }} + {{- end }} + # Allow prometheus scrapes + - ports: + - port: 9187 +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/pgpool/configmap.yaml b/base/helm-charts/postgresql-ha/templates/pgpool/configmap.yaml new file mode 100644 index 0000000..0b686e8 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/pgpool/configmap.yaml @@ -0,0 +1,15 @@ +{{- if and (or (.Files.Glob "files/pgpool.conf") .Values.pgpool.configuration) (not .Values.pgpool.configurationCM) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ printf "%s-configuration" (include "postgresql-ha.pgpool" .) }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: pgpool +data: + {{- if (.Files.Glob "files/pgpool.conf") }} + {{- (.Files.Glob "files/pgpool.conf").AsConfig | nindent 2 }} + {{- else if .Values.pgpool.configuration }} + pgpool.conf: | + {{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.configuration "context" $) | nindent 4 }} + {{- end }} +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/pgpool/custom-users-secrets.yaml b/base/helm-charts/postgresql-ha/templates/pgpool/custom-users-secrets.yaml new file mode 100644 index 0000000..a52a42f --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/pgpool/custom-users-secrets.yaml @@ -0,0 +1,12 @@ +{{- if and (not .Values.pgpool.customUsersSecret) .Values.pgpool.customUsers }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ printf "%s-custom-users" (include "postgresql-ha.pgpool" .) }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: pgpool +type: Opaque +data: + usernames: {{ .Values.pgpool.customUsers.usernames | b64enc | quote }} + passwords: {{ .Values.pgpool.customUsers.passwords | b64enc | quote }} +{{- end -}} diff --git a/base/helm-charts/postgresql-ha/templates/pgpool/deployment.yaml b/base/helm-charts/postgresql-ha/templates/pgpool/deployment.yaml new file mode 100644 index 0000000..4b26c2b --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/pgpool/deployment.yaml @@ -0,0 +1,244 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "postgresql-ha.pgpool" . }} + labels: {{ include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: pgpool + {{- if .Values.pgpool.labels }} + {{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.labels "context" $) | nindent 4 }} + {{- end }} +spec: + replicas: {{ .Values.pgpool.replicaCount }} + selector: + matchLabels: {{ include "postgresql-ha.matchLabels" . | nindent 6 }} + app.kubernetes.io/component: pgpool + {{- if .Values.pgpool.updateStrategy }} + strategy: {{- toYaml .Values.pgpool.updateStrategy | nindent 4 }} + {{- end }} + {{- if .Values.pgpool.minReadySeconds }} + minReadySeconds: {{ .Values.pgpool.minReadySeconds }} + {{- end }} + template: + metadata: + labels: {{ include "postgresql-ha.labels" . | nindent 8 }} + app.kubernetes.io/component: pgpool + {{- if .Values.pgpool.podLabels }} + {{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.podLabels "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.pgpool.podAnnotations }} + annotations: {{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.podAnnotations "context" $) | nindent 8 }} + {{- end }} + spec: +{{- include "postgresql-ha.imagePullSecrets" . | indent 6 }} + {{- if .Values.pgpool.affinity }} + affinity: {{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.affinity "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.pgpool.nodeSelector }} + nodeSelector: {{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.nodeSelector "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.pgpool.priorityClassName }} + priorityClassName: {{ .Values.pgpool.priorityClassName }} + {{- end }} + {{- if .Values.pgpool.tolerations }} + tolerations: {{- include "postgresql-ha.tplValue" (dict "value" .Values.pgpool.tolerations "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.pgpool.securityContext.enabled }} + securityContext: + fsGroup: {{ .Values.pgpool.securityContext.fsGroup }} + {{- end }} + # Auxiliar vars to populate environment variables + {{- $postgresqlReplicaCount := int .Values.postgresql.replicaCount }} + {{- $postgresqlFullname := include "postgresql-ha.postgresql" . }} + {{- $postgresqlHeadlessServiceName := printf "%s-headless" (include "postgresql-ha.postgresql" .) }} + {{- $releaseNamespace := .Release.Namespace }} + {{- $clusterDomain:= .Values.clusterDomain }} + containers: + - name: pgpool + image: {{ include "postgresql-ha.pgpoolImage" . }} + imagePullPolicy: {{ .Values.pgpoolImage.pullPolicy | quote }} + {{- if .Values.pgpool.securityContext.enabled }} + securityContext: + runAsUser: {{ .Values.pgpool.securityContext.runAsUser }} + {{- end }} + env: + - name: BITNAMI_DEBUG + value: {{ ternary "true" "false" .Values.pgpoolImage.debug | quote }} + {{- if or .Values.pgpool.customUsersSecret .Values.pgpool.customUsers }} + - name: PGPOOL_POSTGRES_CUSTOM_USERS + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.pgpoolCustomUsersSecretName" . }} + key: usernames + - name: PGPOOL_POSTGRES_CUSTOM_PASSWORDS + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.pgpoolCustomUsersSecretName" . }} + key: passwords + {{- end }} + - name: PGPOOL_BACKEND_NODES + value: {{range $e, $i := until $postgresqlReplicaCount }}{{ $i }}:{{ $postgresqlFullname }}-{{ $i }}.{{ $postgresqlHeadlessServiceName }}.{{ $releaseNamespace }}.svc.{{ $clusterDomain }}:5432,{{ end }} + - name: PGPOOL_SR_CHECK_USER + value: {{ (include "postgresql-ha.postgresqlRepmgrUsername" .) | quote }} + {{- if .Values.postgresql.usePasswordFile }} + - name: PGPOOL_SR_CHECK_PASSWORD_FILE + value: "/opt/bitnami/pgpool/secrets/pgpool-sr-check-password" + {{- else }} + - name: PGPOOL_SR_CHECK_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.postgresqlSecretName" . }} + key: repmgr-password + {{- end }} + - name: PGPOOL_ENABLE_LOAD_BALANCING + value: {{ ternary "yes" "no" .Values.pgpool.useLoadBalancing | quote }} + - name: PGPOOL_ENABLE_LDAP + value: {{ ternary "yes" "no" .Values.ldap.enabled | quote }} + {{- if .Values.ldap.enabled }} + - name: LDAP_URI + value: {{ .Values.ldap.uri | quote }} + - name: LDAP_BASE + value: {{ .Values.ldap.base | quote }} + - name: LDAP_BIND_DN + value: {{ .Values.ldap.binddn | quote }} + - name: LDAP_BIND_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.ldapSecretName" . }} + key: bind-password + {{- if .Values.ldap.bslookup }} + - name: LDAP_BASE_LOOKUP + value: {{ .Values.ldap.bslookup | quote }} + {{- end }} + {{- if .Values.ldap.scope }} + - name: LDAP_SCOPE + value: {{ .Values.ldap.scope | quote }} + {{- end }} + {{- if .Values.ldap.tlsReqcert }} + - name: LDAP_TLS_REQCERT + value: {{ .Values.ldap.tlsReqcert | quote }} + {{- end }} + - name: LDAP_NSS_INITGROUPS_IGNOREUSERS + value: {{ .Values.ldap.nssInitgroupsIgnoreusers | quote }} + {{- end }} + - name: PGPOOL_POSTGRES_USERNAME + value: {{ (include "postgresql-ha.postgresqlUsername" .) | quote }} + {{- if .Values.postgresql.usePasswordFile }} + - name: PGPOOL_POSTGRES_PASSWORD_FILE + value: "/opt/bitnami/pgpool/secrets/pgpool-password" + {{- else }} + - name: PGPOOL_POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.postgresqlSecretName" . }} + key: postgresql-password + {{- end }} + - name: PGPOOL_ADMIN_USERNAME + value: {{ (include "postgresql-ha.pgpoolAdminUsername" .) | quote }} + {{- if .Values.pgpool.usePasswordFile }} + - name: PGPOOL_ADMIN_PASSWORD_FILE + value: "/opt/bitnami/pgpool/secrets/admin-password" + {{- else }} + - name: PGPOOL_ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.pgpoolSecretName" . }} + key: admin-password + {{- end }} + {{- if .Values.pgpool.maxPool }} + - name: PGPOOL_MAX_POOL + value: {{ .Values.pgpool.maxPool | quote }} + {{- end }} + {{- if or (.Files.Glob "files/pgpool.conf") .Values.pgpool.configuration .Values.pgpool.configurationCM }} + - name: PGPOOL_USER_CONF_FILE + value: "/opt/bitnami/pgpool/user_config/pgpool.conf" + {{- end }} + {{- if .Values.pgpool.numInitChildren }} + - name: PGPOOL_NUM_INIT_CHILDREN + value: {{ .Values.pgpool.numInitChildren | quote }} + {{- end }} + ports: + - name: postgresql + containerPort: 5432 + protocol: TCP + {{- if and .Values.pgpool.livenessProbe.enabled (not .Values.ldap.enabled) }} + livenessProbe: + exec: + command: + - /opt/bitnami/scripts/pgpool/healthcheck.sh + initialDelaySeconds: {{ .Values.pgpool.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.pgpool.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.pgpool.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.pgpool.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.pgpool.livenessProbe.failureThreshold }} + {{- end }} + {{- if and .Values.pgpool.readinessProbe.enabled (not .Values.ldap.enabled) }} + readinessProbe: + exec: + command: + - bash + - -ec + - PGPASSWORD=${PGPOOL_POSTGRES_PASSWORD} psql -U {{ (include "postgresql-ha.postgresqlUsername" .) | quote }} {{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} -d {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }}{{- end }} -h 127.0.0.1 -tA -c "SELECT 1" >/dev/null + initialDelaySeconds: {{ .Values.pgpool.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.pgpool.readinessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.pgpool.readinessProbe.timeoutSeconds }} + successThreshold: {{ .Values.pgpool.readinessProbe.successThreshold }} + failureThreshold: {{ .Values.pgpool.readinessProbe.failureThreshold }} + {{- end }} + {{- if .Values.pgpool.resources }} + resources: {{- toYaml .Values.pgpool.resources | nindent 12 }} + {{- end }} + volumeMounts: + {{- if or (.Files.Glob "files/pgpool.conf") .Values.pgpool.configuration .Values.pgpool.configurationCM }} + - name: pgpool-config + mountPath: /opt/bitnami/pgpool/user_config/ + {{- end }} + {{- if or (.Files.Glob "files/pgpool-entrypoint-initdb.d/*.sh") .Values.pgpool.initdbScripts .Values.pgpool.initdbScriptsCM }} + - name: custom-init-scripts + mountPath: /docker-entrypoint-initdb.d/ + {{- end }} + {{- if .Values.pgpool.initdbScriptsSecret }} + - name: custom-init-scripts-secret + mountPath: /docker-entrypoint-initdb.d/secret + {{- end }} + {{- if .Values.postgresql.usePasswordFile }} + - name: postgresql-password + mountPath: /opt/bitnami/pgpool/secrets/ + {{- end }} + {{- if .Values.pgpool.usePasswordFile }} + - name: pgpool-password + mountPath: /opt/bitnami/pgpool/secrets/ + {{- end }} + volumes: + {{- if or (.Files.Glob "files/pgpool.conf") .Values.pgpool.configuration .Values.pgpool.configurationCM }} + - name: pgpool-config + configMap: + name: {{ include "postgresql-ha.pgpoolConfigurationCM" . }} + {{- end }} + {{- if or (.Files.Glob "files/pgpool-entrypoint-initdb.d/*.sh") .Values.pgpool.initdbScripts .Values.pgpool.initdbScriptsCM }} + - name: custom-init-scripts + configMap: + name: {{ template "postgresql-ha.pgpoolInitdbScriptsCM" . }} + {{- end }} + {{- if .Values.pgpool.initdbScriptsSecret }} + - name: custom-init-scripts-secret + secret: + secretName: {{ template "postgresql-ha.pgpoolInitdbScriptsSecret" . }} + {{- end }} + {{- if .Values.postgresql.usePasswordFile }} + - name: postgresql-password + secret: + secretName: {{ include "postgresql-ha.postgresqlSecretName" . }} + items: + - key: postgresql-password + path: pgpool-password + - key: repmgr-password + path: pgpool-sr-check-password + {{- end }} + {{- if .Values.pgpool.usePasswordFile }} + - name: pgpool-password + secret: + secretName: {{ include "postgresql-ha.pgpoolSecretName" . }} + items: + - key: admin-password + path: admin-password + {{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/pgpool/initdb-scripts-configmap.yaml b/base/helm-charts/postgresql-ha/templates/pgpool/initdb-scripts-configmap.yaml new file mode 100644 index 0000000..902aab3 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/pgpool/initdb-scripts-configmap.yaml @@ -0,0 +1,15 @@ +{{- if and (or (.Files.Glob "files/pgpool-entrypoint-initdb.d/*.sh") .Values.pgpool.initdbScripts) (not .Values.pgpool.initdbScriptsCM) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ printf "%s-initdb-scripts" (include "postgresql-ha.pgpool" .) }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: pgpool +data: + {{- with .Files.Glob "files/pgpool-entrypoint-initdb.d/*.sh" }} + {{- .AsConfig | nindent 2 }} + {{- end }} + {{- with .Values.pgpool.initdbScripts }} + {{- toYaml . | nindent 2 }} + {{- end }} +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/pgpool/pdb.yaml b/base/helm-charts/postgresql-ha/templates/pgpool/pdb.yaml new file mode 100644 index 0000000..dd63b03 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/pgpool/pdb.yaml @@ -0,0 +1,18 @@ +{{- if .Values.pgpool.pdb.create }} +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: {{ include "postgresql-ha.pgpool" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: pgpool +spec: + {{- if .Values.pgpool.pdb.minAvailable }} + minAvailable: {{ .Values.pgpool.pdb.minAvailable }} + {{- end }} + {{- if .Values.pgpool.pdb.maxUnavailable }} + maxUnavailable: {{ .Values.pgpool.pdb.maxUnavailable }} + {{- end }} + selector: + matchLabels: {{- include "postgresql-ha.matchLabels" . | nindent 6 }} + app.kubernetes.io/component: pgpool +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/pgpool/secrets.yaml b/base/helm-charts/postgresql-ha/templates/pgpool/secrets.yaml new file mode 100644 index 0000000..c712d5e --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/pgpool/secrets.yaml @@ -0,0 +1,11 @@ +{{- if (include "postgresql-ha.pgpoolCreateSecret" .) }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "postgresql-ha.pgpool" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: pgpool +type: Opaque +data: + admin-password: {{ (include "postgresql-ha.pgpoolAdminPassword" .) | b64enc | quote }} +{{- end -}} diff --git a/base/helm-charts/postgresql-ha/templates/pgpool/service.yaml b/base/helm-charts/postgresql-ha/templates/pgpool/service.yaml new file mode 100644 index 0000000..dc2b1be --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/pgpool/service.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql-ha.pgpool" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + {{- if .Values.service.annotations }} + annotations: {{- include "postgresql-ha.tplValue" (dict "value" .Values.service.annotations "context" $) | nindent 4 }} + {{- end }} +spec: + type: {{ .Values.service.type }} + {{- if and (not (empty .Values.service.loadBalancerIP)) (eq .Values.service.type "LoadBalancer") }} + loadBalancerIP: {{ .Values.service.loadBalancerIP }} + {{- end }} + {{- if and (eq .Values.service.type "LoadBalancer") .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: {{- toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }} + {{- end }} + {{- if and (eq .Values.service.type "ClusterIP") .Values.service.clusterIP }} + clusterIP: {{ .Values.service.clusterIP }} + {{- end }} + ports: + - name: postgresql + port: {{ .Values.service.port }} + targetPort: postgresql + protocol: TCP + {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePort)) }} + nodePort: {{ .Values.service.nodePort }} + {{- else if eq .Values.service.type "ClusterIP" }} + nodePort: null + {{- end }} + selector: {{- include "postgresql-ha.matchLabels" . | nindent 4 }} + app.kubernetes.io/component: pgpool diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/configmap.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/configmap.yaml new file mode 100644 index 0000000..3b412cb --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/configmap.yaml @@ -0,0 +1,29 @@ +{{- if and (or (.Files.Glob "files/repmgr.conf") (.Files.Glob "files/postgresql.conf") (.Files.Glob "files/pg_hba.conf") .Values.postgresql.repmgrConfiguration .Values.postgresql.configuration .Values.postgresql.pgHbaConfiguration) (not .Values.postgresql.configurationCM) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ printf "%s-configuration" (include "postgresql-ha.postgresql" .) }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +data: + {{- if (.Files.Glob "files/repmgr.conf") }} + {{- (.Files.Glob "files/repmgr.conf").AsConfig | nindent 2 }} + {{- else if .Values.postgresql.repmgrConfiguration }} + repmgr.conf: | + {{- .Values.postgresql.repmgrConfiguration | nindent 4 }} + {{- end }} + {{- if (.Files.Glob "files/postgresql.conf") }} + {{- (.Files.Glob "files/postgresql.conf").AsConfig | nindent 2 }} + {{- else if .Values.postgresql.configuration }} + postgresql.conf: | + {{- range $key, $value := default dict .Values.postgresql.configuration }} + {{ $key | snakecase }}={{ $value }} + {{- end }} + {{- end }} + {{- if (.Files.Glob "files/pg_hba.conf") }} + {{- (.Files.Glob "files/pg_hba.conf").AsConfig | nindent 2 }} + {{- else if .Values.postgresql.pgHbaConfiguration }} + pg_hba.conf: | + {{- .Values.postgresql.pgHbaConfiguration | nindent 4 }} + {{- end }} +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/extended-configmap.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/extended-configmap.yaml new file mode 100644 index 0000000..34be4af --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/extended-configmap.yaml @@ -0,0 +1,18 @@ +{{- if and (or (.Files.Glob "files/conf.d/*.conf") .Values.postgresql.extendedConf) (not .Values.postgresql.extendedConfCM) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ printf "%s-extended-configuration" (include "postgresql-ha.postgresql" .) }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +data: + {{- with .Files.Glob "files/conf.d/*.conf" }} + {{- .AsConfig | nindent 2 }} + {{- end }} + {{- with .Values.postgresql.extendedConf }} + override.conf: | + {{- range $key, $value := . }} + {{ $key | snakecase }}={{ $value }} + {{- end }} + {{- end }} +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/hooks-scripts-configmap.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/hooks-scripts-configmap.yaml new file mode 100644 index 0000000..e83a9e1 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/hooks-scripts-configmap.yaml @@ -0,0 +1,67 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ printf "%s-hooks-scripts" (include "postgresql-ha.postgresql" .) }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +data: + pre-stop.sh: |- + #!/bin/bash + set -o errexit + set -o pipefail + set -o nounset + + # Debug section + exec 3>&1 + exec 4>&2 + + # Load Libraries + . /opt/bitnami/scripts/liblog.sh + . /opt/bitnami/scripts/libpostgresql.sh + . /opt/bitnami/scripts/librepmgr.sh + + # Auxiliar functions + is_new_primary_ready() { + return_value=1 + currenty_primary_node="$(repmgr_get_primary_node)" + currenty_primary_host="$(echo $currenty_primary_node | awk '{print $1}')" + + info "$currenty_primary_host != $REPMGR_NODE_NETWORK_NAME" + if [[ $(echo $currenty_primary_node | wc -w) -eq 2 ]] && [[ "$currenty_primary_host" != "$REPMGR_NODE_NETWORK_NAME" ]]; then + info "New primary detected, leaving the cluster..." + return_value=0 + else + info "Waiting for a new primary to be available..." + fi + return $return_value + } + + export MODULE="pre-stop-hook" + + if [[ "${BITNAMI_DEBUG}" == "true" ]]; then + info "Bash debug is on" + else + info "Bash debug is off" + exec 1>/dev/null + exec 2>/dev/null + fi + + # Load PostgreSQL & repmgr environment variables + eval "$(repmgr_env)" + eval "$(postgresql_env)" + + postgresql_enable_nss_wrapper + + # Prepare env vars for managing roles + primary_node="$(repmgr_get_primary_node)" + primary_host="$(echo $primary_node | awk '{print $1}')" + + # Stop postgresql for graceful exit. + postgresql_stop + + if [[ "$primary_host" == "$REPMGR_NODE_NETWORK_NAME" ]]; then + info "Primary node need to wait for a new primary node before leaving the cluster" + retry_while is_new_primary_ready 10 5 + else + info "Standby node doesn't need to wait, leaving the cluster." + fi diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/initdb-scripts-configmap.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/initdb-scripts-configmap.yaml new file mode 100644 index 0000000..99b4f1d --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/initdb-scripts-configmap.yaml @@ -0,0 +1,21 @@ +{{- if and (or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.postgresql.initdbScripts) (not .Values.postgresql.initdbScriptsCM) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ printf "%s-initdb-scripts" (include "postgresql-ha.postgresql" .) }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +{{- with .Files.Glob "files/docker-entrypoint-initdb.d/*.sql.gz" }} +binaryData: +{{- range $path, $bytes := . }} + {{ base $path }}: {{ $.Files.Get $path | b64enc | quote }} +{{- end }} +{{- end }} +data: + {{- with .Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql}" }} + {{- .AsConfig | nindent 2 }} + {{- end }} + {{- with .Values.postgresql.initdbScripts }} + {{- toYaml . | nindent 2 }} + {{- end }} +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/metrics-service.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/metrics-service.yaml new file mode 100644 index 0000000..d13e4c7 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/metrics-service.yaml @@ -0,0 +1,19 @@ +{{- if .Values.metrics.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql-ha.postgresql" . }}-metrics + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql + {{- if .Values.metrics.annotations }} + annotations: {{- include "postgresql-ha.tplValue" (dict "value" .Values.metrics.annotations "context" $) | nindent 4 }} + {{- end }} +spec: + type: ClusterIP + ports: + - name: metrics + port: 9187 + targetPort: metrics + selector: {{- include "postgresql-ha.matchLabels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/pdb.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/pdb.yaml new file mode 100644 index 0000000..c4e7b6d --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/pdb.yaml @@ -0,0 +1,18 @@ +{{- if .Values.postgresql.pdb.create }} +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: {{ include "postgresql-ha.postgresql" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +spec: + {{- if .Values.postgresql.pdb.minAvailable }} + minAvailable: {{ .Values.postgresql.pdb.minAvailable }} + {{- end }} + {{- if .Values.postgresql.pdb.maxUnavailable }} + maxUnavailable: {{ .Values.postgresql.pdb.maxUnavailable }} + {{- end }} + selector: + matchLabels: {{- include "postgresql-ha.matchLabels" . | nindent 6 }} + app.kubernetes.io/component: postgresql +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/secrets.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/secrets.yaml new file mode 100644 index 0000000..2e5fb46 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/secrets.yaml @@ -0,0 +1,15 @@ +{{- if (include "postgresql-ha.postgresqlCreateSecret" .) }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "postgresql-ha.postgresql" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +type: Opaque +data: + {{- if and (include "postgresql-ha.postgresqlPostgresPassword" .) (not (eq (include "postgresql-ha.postgresqlUsername" .) "postgres")) }} + postgresql-postgres-password: {{ include "postgresql-ha.postgresqlPostgresPassword" . | b64enc | quote }} + {{- end }} + postgresql-password: {{ (include "postgresql-ha.postgresqlPassword" .) | b64enc | quote }} + repmgr-password: {{ (include "postgresql-ha.postgresqlRepmgrPassword" .) | b64enc | quote }} +{{- end -}} diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/service-headless.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/service-headless.yaml new file mode 100644 index 0000000..026b357 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/service-headless.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql-ha.postgresql" . }}-headless + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} +spec: + type: ClusterIP + clusterIP: None + ports: + - name: postgresql + port: 5432 + targetPort: postgresql + protocol: TCP + selector: {{- include "postgresql-ha.matchLabels" . | nindent 4 }} + app.kubernetes.io/component: postgresql diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/service.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/service.yaml new file mode 100644 index 0000000..053f158 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql-ha.postgresql" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql +spec: + type: ClusterIP + ports: + - name: postgresql + port: 5432 + targetPort: postgresql + protocol: TCP + selector: {{- include "postgresql-ha.matchLabels" . | nindent 4 }} + app.kubernetes.io/component: postgresql diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/servicemonitor.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/servicemonitor.yaml new file mode 100644 index 0000000..ca4db5a --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/servicemonitor.yaml @@ -0,0 +1,35 @@ +{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "postgresql-ha.postgresql" . }} + {{- if .Values.metrics.serviceMonitor.namespace }} + namespace: {{ .Values.metrics.serviceMonitor.namespace }} + {{- end }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql + {{- range $key, $value := .Values.metrics.serviceMonitor.selector }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + selector: + matchLabels: {{- include "postgresql-ha.matchLabels" . | nindent 6 }} + app.kubernetes.io/component: postgresql + endpoints: + - port: metrics + {{- if .Values.metrics.serviceMonitor.interval }} + interval: {{ .Values.metrics.serviceMonitor.interval }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.relabelings }} + relabelings: {{- include "postgresql-ha.tplValue" ( dict "value" .Values.metrics.serviceMonitor.relabelings "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.metricRelabelings }} + metricRelabelings: {{- include "postgresql-ha.tplValue" ( dict "value" .Values.metrics.serviceMonitor.metricRelabelings "context" $) | nindent 8 }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} +{{- end }} diff --git a/base/helm-charts/postgresql-ha/templates/postgresql/statefulset.yaml b/base/helm-charts/postgresql-ha/templates/postgresql/statefulset.yaml new file mode 100644 index 0000000..0932226 --- /dev/null +++ b/base/helm-charts/postgresql-ha/templates/postgresql/statefulset.yaml @@ -0,0 +1,351 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "postgresql-ha.postgresql" . }} + labels: {{- include "postgresql-ha.labels" . | nindent 4 }} + app.kubernetes.io/component: postgresql + {{- if .Values.postgresql.labels }} + {{- include "postgresql-ha.tplValue" (dict "value" .Values.postgresql.labels "context" $) | nindent 4 }} + {{- end }} +spec: + serviceName: {{ include "postgresql-ha.postgresql" . }}-headless + replicas: {{ .Values.postgresql.replicaCount }} + updateStrategy: + type: {{ .Values.postgresql.updateStrategyType }} + {{- if (eq "Recreate" .Values.postgresql.updateStrategyType) }} + rollingUpdate: null + {{- end }} + selector: + matchLabels: {{- include "postgresql-ha.matchLabels" . | nindent 6 }} + app.kubernetes.io/component: postgresql + template: + metadata: + labels: {{- include "postgresql-ha.labels" . | nindent 8 }} + app.kubernetes.io/component: postgresql + {{- if .Values.postgresql.podLabels }} + {{- include "postgresql-ha.tplValue" (dict "value" .Values.postgresql.podLabels "context" $) | nindent 8 }} + {{- end }} + {{- if or .Values.postgresql.podAnnotations (and .Values.metrics.enabled .Values.metrics.annotations) }} + annotations: + {{- if .Values.postgresql.podAnnotations }} + {{- include "postgresql-ha.tplValue" (dict "value" .Values.postgresql.podAnnotations "context" $) | nindent 8 }} + {{- end }} + {{- if and .Values.metrics.enabled .Values.metrics.annotations }} + {{- include "postgresql-ha.tplValue" (dict "value" .Values.metrics.annotations "context" $) | nindent 8 }} + {{- end }} + {{- end }} + spec: +{{- include "postgresql-ha.imagePullSecrets" . | indent 6 }} + {{- if .Values.postgresql.affinity }} + affinity: {{- include "postgresql-ha.tplValue" (dict "value" .Values.postgresql.affinity "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.postgresql.nodeSelector }} + nodeSelector: {{- include "postgresql-ha.tplValue" (dict "value" .Values.postgresql.nodeSelector "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.postgresql.priorityClassName }} + priorityClassName: {{ .Values.postgresql.priorityClassName }} + {{- end }} + {{- if .Values.postgresql.tolerations }} + tolerations: {{- include "postgresql-ha.tplValue" (dict "value" .Values.postgresql.tolerations "context" $) | nindent 8 }} + {{- end }} + {{- if .Values.postgresql.securityContext.enabled }} + securityContext: + fsGroup: {{ .Values.postgresql.securityContext.fsGroup }} + {{- end }} + {{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }} + initContainers: + - name: init-chmod-data + image: {{ include "postgresql-ha.volumePermissionsImage" . }} + imagePullPolicy: {{ .Values.volumePermissionsImage.pullPolicy | quote }} + command: + - sh + - -c + - | + mkdir -p {{ .Values.persistence.mountPath }}/conf {{ .Values.persistence.mountPath }}/data + chmod 700 {{ .Values.persistence.mountPath }}/conf {{ .Values.persistence.mountPath }}/data + find {{ .Values.persistence.mountPath }} -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | \ + xargs chown -R {{ .Values.postgresql.securityContext.runAsUser }}:{{ .Values.postgresql.securityContext.fsGroup }} + securityContext: + runAsUser: {{ .Values.volumePermissions.securityContext.runAsUser }} + {{- if .Values.volumePermissions.resources }} + resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }} + {{- end }} + volumeMounts: + - name: data + mountPath: {{ .Values.persistence.mountPath }} + {{- end }} + containers: + - name: postgresql + lifecycle: + preStop: + exec: + command: + - /pre-stop.sh + image: {{ include "postgresql-ha.postgresqlImage" . }} + imagePullPolicy: {{ .Values.postgresqlImage.pullPolicy | quote }} + {{- if .Values.postgresql.securityContext.enabled }} + securityContext: + runAsUser: {{ .Values.postgresql.securityContext.runAsUser }} + {{- end }} + # Auxiliar vars to populate environment variables + {{- $postgresqlReplicaCount := int .Values.postgresql.replicaCount }} + {{- $postgresqlFullname := include "postgresql-ha.postgresql" . }} + {{- $postgresqlHeadlessServiceName := printf "%s-headless" (include "postgresql-ha.postgresql" .) }} + {{- $releaseNamespace := .Release.Namespace }} + {{- $clusterDomain:= .Values.clusterDomain }} + env: + - name: BITNAMI_DEBUG + value: {{ ternary "true" "false" .Values.postgresqlImage.debug | quote }} + # PostgreSQL configuration + - name: POSTGRESQL_VOLUME_DIR + value: {{ .Values.persistence.mountPath | quote }} + - name: PGDATA + value: {{ printf "%s/%s" .Values.persistence.mountPath "data" | quote }} + {{- if and .Values.postgresql.postgresPassword (not (eq .Values.postgresql.username "postgres")) }} + {{- if .Values.postgresql.usePasswordFile }} + - name: POSTGRES_POSTGRES_PASSWORD_FILE + value: "/opt/bitnami/postgresql/secrets/postgresql-postgres-password" + {{- else }} + - name: POSTGRES_POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "postgresql-ha.postgresqlSecretName" . }} + key: postgresql-postgres-password + {{- end }} + {{- end }} + - name: POSTGRES_USER + value: {{ (include "postgresql-ha.postgresqlUsername" .) | quote }} + {{- if .Values.postgresql.usePasswordFile }} + - name: POSTGRES_PASSWORD_FILE + value: "/opt/bitnami/postgresql/secrets/postgresql-password" + {{- else }} + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.postgresqlSecretName" . }} + key: postgresql-password + {{- end }} + {{- if not (empty (include "postgresql-ha.postgresqlDatabase" .)) }} + - name: POSTGRES_DB + value: {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }} + {{- end }} + # Repmgr configuration + - name: MY_POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: REPMGR_UPGRADE_EXTENSION + value: {{ ternary "yes" "no" .Values.postgresql.upgradeRepmgrExtension | quote }} + - name: REPMGR_PGHBA_TRUST_ALL + value: {{ ternary "yes" "no" .Values.postgresql.pgHbaTrustAll | quote }} + - name: REPMGR_MOUNTED_CONF_DIR + value: "/bitnami/repmgr/conf" + - name: REPMGR_PARTNER_NODES + value: {{range $e, $i := until $postgresqlReplicaCount }}{{ $postgresqlFullname }}-{{ $i }}.{{ $postgresqlHeadlessServiceName }}.{{ $releaseNamespace }}.svc.{{ $clusterDomain }},{{ end }} + - name: REPMGR_PRIMARY_HOST + value: {{ printf "%s-0.%s.%s.svc.%s" $postgresqlFullname $postgresqlHeadlessServiceName .Release.Namespace $clusterDomain | quote }} + - name: REPMGR_NODE_NAME + value: "$(MY_POD_NAME)" + - name: REPMGR_NODE_NETWORK_NAME + value: "$(MY_POD_NAME).{{ $postgresqlHeadlessServiceName }}.{{ .Release.Namespace }}.svc.{{ $clusterDomain }}" + - name: REPMGR_LOG_LEVEL + value: {{ .Values.postgresql.repmgrLogLevel | quote }} + - name: REPMGR_CONNECT_TIMEOUT + value: {{ .Values.postgresql.repmgrConnectTimeout | quote }} + - name: REPMGR_RECONNECT_ATTEMPTS + value: {{ .Values.postgresql.repmgrReconnectAttempts | quote }} + - name: REPMGR_RECONNECT_INTERVAL + value: {{ .Values.postgresql.repmgrReconnectInterval | quote }} + - name: REPMGR_USERNAME + value: {{ (include "postgresql-ha.postgresqlRepmgrUsername" .) | quote }} + {{- if .Values.postgresql.usePasswordFile }} + - name: REPMGR_PASSWORD_FILE + value: "/opt/bitnami/repmgr/secrets/repmgr-password" + {{- else }} + - name: REPMGR_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.postgresqlSecretName" . }} + key: repmgr-password + {{- end }} + {{- if (include "postgresql-ha.repmgrDatabase" .) }} + - name: REPMGR_DATABASE + value: {{ (include "postgresql-ha.repmgrDatabase" .) | quote }} + {{- end }} + {{- if .Values.postgresql.syncReplication }} + - name: POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS + value: {{ sub (int .Values.postgresql.replicaCount) 1 | quote }} + {{- end }} + ports: + - name: postgresql + containerPort: 5432 + protocol: TCP + {{- if .Values.postgresql.livenessProbe.enabled }} + livenessProbe: + exec: + command: + - sh + - -c + - '{{ include "postgresql-ha.pgpassword" . }} psql -w -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} -d {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }} -h 127.0.0.1 -c "SELECT 1"' + initialDelaySeconds: {{ .Values.postgresql.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.postgresql.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.postgresql.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.postgresql.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.postgresql.livenessProbe.failureThreshold }} + {{- end }} + {{- if .Values.postgresql.readinessProbe.enabled }} + readinessProbe: + exec: + command: + - sh + - -c + - '{{ include "postgresql-ha.pgpassword" . }} psql -w -U {{ include "postgresql-ha.postgresqlUsername" . | quote }} -d {{ (include "postgresql-ha.postgresqlDatabase" .) | quote }} -h 127.0.0.1 -c "SELECT 1"' + initialDelaySeconds: {{ .Values.postgresql.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.postgresql.readinessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.postgresql.readinessProbe.timeoutSeconds }} + successThreshold: {{ .Values.postgresql.readinessProbe.successThreshold }} + failureThreshold: {{ .Values.postgresql.readinessProbe.failureThreshold }} + {{- end }} + {{- if .Values.postgresql.resources }} + resources: {{- toYaml .Values.postgresql.resources | nindent 12 }} + {{- end }} + volumeMounts: + {{- if or (.Files.Glob "files/repmgr.conf") (.Files.Glob "files/postgresql.conf") (.Files.Glob "files/pg_hba.conf") .Values.postgresql.repmgrConfiguration .Values.postgresql.configuration .Values.postgresql.pgHbaConfiguration .Values.postgresql.configurationCM }} + - name: postgresql-config + mountPath: /bitnami/repmgr/conf + {{- end }} + {{- if or (.Files.Glob "files/conf.d/*.conf") .Values.postgresql.extendedConf .Values.postgresql.extendedConfCM }} + - name: postgresql-extended-config + mountPath: /bitnami/postgresql/conf/conf.d/ + {{- end }} + {{- if or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.postgresql.initdbScriptsCM .Values.postgresql.initdbScripts }} + - name: custom-init-scripts + mountPath: /docker-entrypoint-initdb.d/ + {{- end }} + {{- if .Values.postgresql.initdbScriptsSecret }} + - name: custom-init-scripts-secret + mountPath: /docker-entrypoint-initdb.d/secret + {{- end }} + {{- if .Values.postgresql.usePasswordFile }} + - name: postgresql-password + mountPath: /opt/bitnami/postgresql/secrets/ + {{- end }} + - name: data + mountPath: {{ .Values.persistence.mountPath }} + - name: hooks-scripts + mountPath: /pre-stop.sh + subPath: pre-stop.sh + {{- if .Values.metrics.enabled }} + - name: metrics + image: {{ include "postgresql-ha.metricsImage" . }} + imagePullPolicy: {{ .Values.metricsImage.pullPolicy | quote }} + {{- if .Values.metrics.securityContext.enabled }} + securityContext: + runAsUser: {{ .Values.metrics.securityContext.runAsUser }} + {{- end }} + env: + - name: DATA_SOURCE_URI + value: {{ printf "127.0.0.1:5432/%s?sslmode=disable" (include "postgresql-ha.postgresqlDatabase" .) | quote }} + {{- if .Values.postgresql.usePasswordFile }} + - name: DATA_SOURCE_PASS_FILE + value: "/opt/bitnami/postgresql/secrets/postgresql-password" + {{- else }} + - name: DATA_SOURCE_PASS + valueFrom: + secretKeyRef: + name: {{ include "postgresql-ha.postgresqlSecretName" . }} + key: postgresql-password + {{- end }} + - name: DATA_SOURCE_USER + value: {{ (include "postgresql-ha.postgresqlUsername" .) | quote }} + ports: + - name: metrics + containerPort: 9187 + protocol: TCP + {{- if .Values.metrics.livenessProbe.enabled }} + livenessProbe: + httpGet: + path: / + port: metrics + initialDelaySeconds: {{ .Values.metrics.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.metrics.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.metrics.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.metrics.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.metrics.livenessProbe.failureThreshold }} + {{- end }} + {{- if .Values.metrics.readinessProbe.enabled }} + readinessProbe: + httpGet: + path: / + port: metrics + initialDelaySeconds: {{ .Values.metrics.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.metrics.readinessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.metrics.readinessProbe.timeoutSeconds }} + successThreshold: {{ .Values.metrics.readinessProbe.successThreshold }} + failureThreshold: {{ .Values.metrics.readinessProbe.failureThreshold }} + {{- end }} + {{- if .Values.metrics.resources }} + resources: {{- toYaml .Values.metrics.resources | nindent 12 }} + {{- end }} + volumeMounts: + {{- if .Values.postgresql.usePasswordFile }} + - name: postgresql-password + mountPath: /opt/bitnami/postgresql/secrets/ + {{- end }} + {{- end }} + volumes: + - name: hooks-scripts + configMap: + name: {{ printf "%s-hooks-scripts" (include "postgresql-ha.postgresql" .) }} + defaultMode: 0755 + {{- if or (.Files.Glob "files/repmgr.conf") (.Files.Glob "files/postgresql.conf") (.Files.Glob "files/pg_hba.conf") .Values.postgresql.repmgrConfiguration .Values.postgresql.configuration .Values.postgresql.pgHbaConfiguration .Values.postgresql.configurationCM }} + - name: postgresql-config + configMap: + name: {{ include "postgresql-ha.postgresqlConfigurationCM" . }} + {{- end }} + {{- if or (.Files.Glob "files/conf.d/*.conf") .Values.postgresql.extendedConf .Values.postgresql.extendedConfCM }} + - name: postgresql-extended-config + configMap: + name: {{ template "postgresql-ha.postgresqlExtendedConfCM" . }} + {{- end }} + {{- if .Values.postgresql.initdbScriptsSecret }} + - name: custom-init-scripts-secret + secret: + secretName: {{ template "postgresql-ha.postgresqlInitdbScriptsSecret" . }} + {{- end }} + {{- if .Values.postgresql.usePasswordFile }} + - name: postgresql-password + secret: + secretName: {{ include "postgresql-ha.postgresqlSecretName" . }} + {{- end }} + {{- if or (.Files.Glob "files/docker-entrypoint-initdb.d/*.{sh,sql,sql.gz}") .Values.postgresql.initdbScriptsCM .Values.postgresql.initdbScripts }} + - name: custom-init-scripts + configMap: + name: {{ template "postgresql-ha.postgresqlInitdbScriptsCM" . }} + {{- end }} +{{- if and .Values.persistence.enabled .Values.persistence.existingClaim }} + - name: data + persistentVolumeClaim: +{{- with .Values.persistence.existingClaim }} + claimName: {{ tpl . $ }} +{{- end }} +{{- else if not .Values.persistence.enabled }} + - name: data + emptyDir: {} +{{- else if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} + volumeClaimTemplates: + - metadata: + name: data + {{- if .Values.persistence.annotations }} + annotations: {{- include "postgresql-ha.tplValue" (dict "value" .Values.persistence.annotations "context" $) | nindent 10 }} + {{- end }} + spec: + accessModes: + {{- range .Values.persistence.accessModes }} + - {{ . | quote }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} +{{ include "postgresql-ha.storageClass" . | indent 8 }} +{{- end }} diff --git a/base/helm-charts/postgresql-ha/values-production.yaml b/base/helm-charts/postgresql-ha/values-production.yaml new file mode 100644 index 0000000..c48d59f --- /dev/null +++ b/base/helm-charts/postgresql-ha/values-production.yaml @@ -0,0 +1,664 @@ +## Global Docker image parameters +## Please, note that this will override the image parameters, including dependencies, configured to use the global value +## Current available global Docker image parameters: imageRegistry, imagePullSecrets and storageClass +## +# global: +# imageRegistry: myRegistryName +# imagePullSecrets: +# - myRegistryKeySecretName +# storageClass: myStorageClass +# postgresql: +# username: customuser +# password: custompassword +# database: customdatabase +# repmgrUsername: repmgruser +# repmgrPassword: repmgrpassword +# repmgrDatabase: repmgrdatabase +# existingSecret: myExistingSecret +# ldap: +# bindpw: bindpassword +# existingSecret: myExistingSecret +# pgpool: +# adminUsername: adminuser +# adminPassword: adminpassword +# existingSecret: myExistingSecret + +## Bitnami PostgreSQL image +## ref: https://hub.docker.com/r/bitnami/postgresql/tags/ +## +postgresqlImage: + registry: docker.io + repository: bitnami/postgresql-repmgr + tag: 11.9.0-debian-10-r10 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Pgpool image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +pgpoolImage: + registry: docker.io + repository: bitnami/pgpool + tag: 4.1.3-debian-10-r7 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Minideb image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +volumePermissionsImage: + registry: docker.io + repository: bitnami/minideb + tag: buster + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: Always + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + +## Bitnami PostgreSQL Prometheus exporter image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +metricsImage: + registry: docker.io + repository: bitnami/postgres-exporter + tag: 0.8.0-debian-10-r197 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## String to partially override postgresql-ha.fullname template (will maintain the release name) +## +# nameOverride: + +## String to fully override postgresql-ha.fullname template +## +# fullnameOverride: + +## Kubernetes Cluster Domain +## +clusterDomain: cluster.local + +## PostgreSQL parameters +## +postgresql: + ## Labels to add to the StatefulSet. Evaluated as template + ## + labels: {} + + ## Labels to add to the StatefulSet pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 2 + + ## Update strategy for PostgreSQL statefulset + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies + ## + updateStrategyType: RollingUpdate + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## PostgreSQL containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## PostgreSQL container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## PostgreSQL configuration parameters + ## + username: postgres + # password: + # database: + + ## PostgreSQL password using existing secret + # existingSecret: secret + + ## PostgreSQL admin password (used when `postgresql.username` is not `postgres`) + ## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#creating-a-database-user-on-first-run (see note!) + # postgresPassword: + + ## Mount PostgreSQL secret as a file instead of passing environment variable + # usePasswordFile: false + + ## Upgrade repmgr extension in the database + ## + upgradeRepmgrExtension: false + + ## Configures pg_hba.conf to trust every user + ## + pgHbaTrustAll: false + + ## Synchronous replication + ## + syncReplication: false + + ## Repmgr configuration parameters + ## + repmgrUsername: repmgr + # repmgrPassword: + repmgrDatabase: repmgr + repmgrLogLevel: NOTICE + repmgrConnectTimeout: 5 + repmgrReconnectAttempts: 3 + repmgrReconnectInterval: 5 + + ## Repmgr configuration + ## Specify content for repmgr.conf + ## Default: do not create repmgr.conf + ## Alternatively, you can put your repmgr.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # repmgrConfiguration: |- + ## PostgreSQL configuration + ## Specify runtime configuration parameters as a dict, using camelCase, e.g. + ## {"sharedBuffers": "500MB"} + ## Alternatively, you can put your postgresql.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # configuration: + ## PostgreSQL client authentication configuration + ## Specify content for pg_hba.conf + ## Default: do not create pg_hba.conf + ## Alternatively, you can put your pg_hba.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # pgHbaConfiguration: |- + # local all all trust + # host all all localhost trust + # host mydatabase mysuser 192.168.0.0/24 md5 + ## ConfigMap with PostgreSQL configuration + ## NOTE: This will override repmgrConfiguration, configuration and pgHbaConfiguration + ## + # configurationCM: + ## PostgreSQL extended configuration + ## As above, but _appended_ to the main configuration + ## Alternatively, you can put your *.conf under the files/conf.d/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#allow-settings-to-be-loaded-from-files-other-than-the-default-postgresqlconf + ## + # extendedConf: + ## ConfigMap with PostgreSQL extended configuration + ## NOTE: This will override extendedConf + ## + # extendedConfCM: + ## initdb scripts + ## Specify dictionary of scripts to be run at first boot + ## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + ## ConfigMap with scripts to be run at first boot + ## NOTE: This will override initdbScripts + ## + # initdbScriptsCM: + ## Secret with scripts to be run at first boot + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + +## Pgpool parameters +## +pgpool: + + ## Additional users that will be performing connections to the database using + ## pgpool. Use this property in order to create new user/password entries that + ## will be appended to the "pgpool_passwd" file + ## + customUsers: {} + ## Comma or semicolon separeted list of postgres usernames + # usernames: 'user01;user02' + + ## Comma or semicolon separated list of the associated passwords for the + ## users above + # passwords: 'pass01;pass02' + + ## Alternatively, you can provide the name of a secret containing this information. + ## The secret must contain the keys "usernames" and "passwords" respectively. + ## + customUsersSecret: + + ## Labels to add to the Deployment. Evaluated as template + ## + labels: {} + + ## Labels to add to the pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 1 + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## Pgpool containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Pgpool container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## strategy used to replace old Pods by new ones + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy + ## + updateStrategy: {} + + ## minReadySeconds to avoid killing pods before we are ready + ## + # minReadySeconds: 0 + + ## Pgpool configuration parameters + ## + adminUsername: admin + # adminPassword: + + ## The number of preforked Pgpool-II server processes. It is also the concurrent + ## connections limit to Pgpool-II from clients. Must be a positive integer. (PGPOOL_NUM_INIT_CHILDREN) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # numInitChildren: + + ## The maximum number of cached connections in each child process (PGPOOL_MAX_POOL) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # maxPools: + + ## Pgpool configuration + ## Specify content for pgpool.conf + ## Alternatively, you can put your pgpool.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration-file + ## + # configuration: + + ## ConfigMap with Pgpool configuration + ## NOTE: This will override pgpool.configuration parameter + ## + # configurationCM: + + ## initdb scripts + ## Specify dictionary of scripts to be run everytime Pgpool container is initialized + ## Alternatively, you can put your scripts under the files/pgpool-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + + ## ConfigMap with scripts to be run everytime Pgpool container is initialized + ## NOTE: This will override pgpool.initdbScripts + ## + # initdbScriptsCM: + + ## Secret with scripts to be run at first boot + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + + ## Use Pgpool Load-Balancing + ## + useLoadBalancing: true + +## LDAP parameters +## +ldap: + enabled: false + ## Retrieve LDAP bindpw from existing secret + ## + # existingSecret: myExistingSecret + uri: + base: + binddn: + bindpw: + bslookup: + scope: + tlsReqcert: + nssInitgroupsIgnoreusers: root,nslcd + +## Init Container paramaters +## +volumePermissions: + enabled: false + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + runAsUser: 0 + ## Init container' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 100m + # memory: 128Mi + requests: {} + # cpu: 100m + # memory: 128Mi + +## PostgreSQL Prometheus exporter parameters +## +metrics: + enabled: true + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + runAsUser: 1001 + + ## Prometheus exporter containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Prometheus exporter container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Annotations for Prometheus exporter + ## + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9187" + + ## Enable this if you're using Prometheus Operator + ## + serviceMonitor: + enabled: false + ## Specify a namespace if needed + # namespace: monitoring + # fallback to the prometheus default unless specified + # interval: 10s + # scrapeTimeout: 10s + ## Defaults to what's used if you follow CoreOS [Prometheus Install Instructions](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#tldr) + ## [Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#prometheus-operator-1) + ## [Kube Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#exporters) + ## + selector: + prometheus: kube-prometheus + + ## RelabelConfigs to apply to samples before scraping + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + relabelings: [] + + ## MetricRelabelConfigs to apply to samples before ingestion + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + metricRelabelings: [] + +## Persistence paramaters +## +persistence: + enabled: true + ## A manually managed Persistent Volume and Claim + ## If defined, PVC must be created manually before volume will be bound + ## The value is evaluated as a template + ## + # existingClaim: + ## Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. + ## + # storageClass: "-" + ## The path the volume will be mounted at, useful when using different + ## PostgreSQL images. + ## + mountPath: /bitnami/postgresql + ## Persistent Volume Access Mode + ## + accessModes: + - ReadWriteOnce + ## Persistent Volume Claim size + ## + size: 8Gi + ## Persistent Volume Claim annotations + ## + annotations: {} + +## PgPool service paramaters +## +service: + ## Service type + ## + type: ClusterIP + ## Service Port + ## + port: 5432 + ## Specify the nodePort value for the LoadBalancer and NodePort service types. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport + ## + # nodePort: + ## Set the LoadBalancer service type to internal only. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer + ## + # loadBalancerIP: + ## Load Balancer sources + ## https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/#restrict-access-for-loadbalancer-service + ## + # loadBalancerSourceRanges: + # - 10.10.10.0/24 + ## Set the Cluster IP to use + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#choosing-your-own-ip-address + ## + # clusterIP: None + ## Provide any additional annotations which may be required + ## + annotations: {} + +## NetworkPolicy paramaters +## +networkPolicy: + enabled: true + + ## The Policy model to apply. When set to false, only pods with the correct + ## client labels will have network access to the port PostgreSQL is listening + ## on. When true, PostgreSQL will accept connections from any source + ## (with the correct destination port). + ## + allowExternal: false diff --git a/base/helm-charts/postgresql-ha/values.yaml b/base/helm-charts/postgresql-ha/values.yaml new file mode 100644 index 0000000..62259f9 --- /dev/null +++ b/base/helm-charts/postgresql-ha/values.yaml @@ -0,0 +1,674 @@ +## Global Docker image parameters +## Please, note that this will override the image parameters, including dependencies, configured to use the global value +## Current available global Docker image parameters: imageRegistry, imagePullSecrets and storageClass +## +# global: +# imageRegistry: myRegistryName +# imagePullSecrets: +# - myRegistryKeySecretName +# storageClass: myStorageClass +# postgresql: +# username: customuser +# password: custompassword +# database: customdatabase +# repmgrUsername: repmgruser +# repmgrPassword: repmgrpassword +# repmgrDatabase: repmgrdatabase +# existingSecret: myExistingSecret +# ldap: +# bindpw: bindpassword +# existingSecret: myExistingSecret +# pgpool: +# adminUsername: adminuser +# adminPassword: adminpassword +# existingSecret: myExistingSecret + +## Bitnami PostgreSQL image +## ref: https://hub.docker.com/r/bitnami/postgresql/tags/ +## +postgresqlImage: + registry: docker.io + repository: bitnami/postgresql-repmgr + tag: 11.9.0-debian-10-r10 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Pgpool image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +pgpoolImage: + registry: docker.io + repository: bitnami/pgpool + tag: 4.1.3-debian-10-r7 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Minideb image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +volumePermissionsImage: + registry: docker.io + repository: bitnami/minideb + tag: buster + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: Always + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + +## Bitnami PostgreSQL Prometheus exporter image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +metricsImage: + registry: docker.io + repository: bitnami/postgres-exporter + tag: 0.8.0-debian-10-r197 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## String to partially override postgresql-ha.fullname template (will maintain the release name) +## +# nameOverride: + +## String to fully override postgresql-ha.fullname template +## +# fullnameOverride: + +## Kubernetes Cluster Domain +## +clusterDomain: cluster.local + +## PostgreSQL parameters +## +postgresql: + ## Labels to add to the StatefulSet. Evaluated as template + ## + labels: {} + + ## Labels to add to the StatefulSet pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 2 + + ## Update strategy for PostgreSQL statefulset + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies + ## + updateStrategyType: RollingUpdate + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## PostgreSQL containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## PostgreSQL container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## PostgreSQL configuration parameters + ## + username: postgres + # password: + # database: + + ## PostgreSQL password using existing secret + # existingSecret: secret + + ## PostgreSQL admin password (used when `postgresql.username` is not `postgres`) + ## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#creating-a-database-user-on-first-run (see note!) + # postgresPassword: + + ## Mount PostgreSQL secret as a file instead of passing environment variable + # usePasswordFile: false + + ## Upgrade repmgr extension in the database + ## + upgradeRepmgrExtension: false + + ## Configures pg_hba.conf to trust every user + ## + pgHbaTrustAll: false + + ## Synchronous replication + ## + syncReplication: false + + ## Repmgr configuration parameters + ## + repmgrUsername: repmgr + # repmgrPassword: + repmgrDatabase: repmgr + repmgrLogLevel: NOTICE + repmgrConnectTimeout: 5 + repmgrReconnectAttempts: 3 + repmgrReconnectInterval: 5 + + ## Repmgr configuration + ## Specify content for repmgr.conf + ## Default: do not create repmgr.conf + ## Alternatively, you can put your repmgr.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # repmgrConfiguration: |- + + ## PostgreSQL configuration + ## Specify runtime configuration parameters as a dict, using camelCase, e.g. + ## {"sharedBuffers": "500MB"} + ## Alternatively, you can put your postgresql.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # configuration: + + ## PostgreSQL client authentication configuration + ## Specify content for pg_hba.conf + ## Default: do not create pg_hba.conf + ## Alternatively, you can put your pg_hba.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # pgHbaConfiguration: |- + # local all all trust + # host all all localhost trust + # host mydatabase mysuser 192.168.0.0/24 md5 + + ## ConfigMap with PostgreSQL configuration + ## NOTE: This will override repmgrConfiguration, configuration and pgHbaConfiguration + ## + # configurationCM: + + ## PostgreSQL extended configuration + ## As above, but _appended_ to the main configuration + ## Alternatively, you can put your *.conf under the files/conf.d/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#allow-settings-to-be-loaded-from-files-other-than-the-default-postgresqlconf + ## + # extendedConf: + + ## ConfigMap with PostgreSQL extended configuration + ## NOTE: This will override extendedConf + ## + # extendedConfCM: + + ## initdb scripts + ## Specify dictionary of scripts to be run at first boot + ## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + + ## ConfigMap with scripts to be run at first boot + ## NOTE: This will override initdbScripts + ## + # initdbScriptsCM: + + ## Secret with scripts to be run at first boot + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + +## Pgpool parameters +## +pgpool: + + ## Additional users that will be performing connections to the database using + ## pgpool. Use this property in order to create new user/password entries that + ## will be appended to the "pgpool_passwd" file + ## + customUsers: {} + ## Comma or semicolon separeted list of postgres usernames + # usernames: 'user01;user02' + + ## Comma or semicolon separated list of the associated passwords for the + ## users above + # passwords: 'pass01;pass02' + + ## Alternatively, you can provide the name of a secret containing this information. + ## The secret must contain the keys "usernames" and "passwords" respectively. + ## + customUsersSecret: + + ## Labels to add to the Deployment. Evaluated as template + ## + labels: {} + + ## Labels to add to the pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 1 + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## Pgpool containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Pgpool container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## strategy used to replace old Pods by new ones + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy + ## + updateStrategy: {} + + ## minReadySeconds to avoid killing pods before we are ready + ## + # minReadySeconds: 0 + + ## Pgpool configuration parameters + ## + adminUsername: admin + # adminPassword: + + ## The number of preforked Pgpool-II server processes. It is also the concurrent + ## connections limit to Pgpool-II from clients. Must be a positive integer. (PGPOOL_NUM_INIT_CHILDREN) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # numInitChildren: + + ## The maximum number of cached connections in each child process (PGPOOL_MAX_POOL) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # maxPools: + + ## Pgpool configuration + ## Specify content for pgpool.conf + ## Alternatively, you can put your pgpool.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration-file + ## + # configuration: + + ## ConfigMap with Pgpool configuration + ## NOTE: This will override pgpool.configuration parameter + ## + # configurationCM: + + ## initdb scripts + ## Specify dictionary of scripts to be run everytime Pgpool container is initialized + ## Alternatively, you can put your scripts under the files/pgpool-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + + ## ConfigMap with scripts to be run everytime Pgpool container is initialized + ## NOTE: This will override pgpool.initdbScripts + ## + # initdbScriptsCM: + + ## Secret with scripts to be run everytime Pgpool container is initialized + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + + ## Use Pgpool Load-Balancing + ## + useLoadBalancing: true + +## LDAP parameters +## +ldap: + enabled: false + ## Retrieve LDAP bindpw from existing secret + ## + # existingSecret: myExistingSecret + uri: + base: + binddn: + bindpw: + bslookup: + scope: + tlsReqcert: + nssInitgroupsIgnoreusers: root,nslcd + +## Init Container paramaters +## +volumePermissions: + enabled: false + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + runAsUser: 0 + ## Init container' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 100m + # memory: 128Mi + requests: {} + # cpu: 100m + # memory: 128Mi + +## PostgreSQL Prometheus exporter parameters +## +metrics: + enabled: false + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + runAsUser: 1001 + + ## Prometheus exporter containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Prometheus exporter container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Annotations for Prometheus exporter + ## + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9187" + + ## Enable this if you're using Prometheus Operator + ## + serviceMonitor: + enabled: false + + ## Specify a namespace if needed + # namespace: monitoring + # fallback to the prometheus default unless specified + # interval: 10s + # scrapeTimeout: 10s + + ## Defaults to what's used if you follow CoreOS [Prometheus Install Instructions](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#tldr) + ## [Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#prometheus-operator-1) + ## [Kube Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#exporters) + ## + selector: + prometheus: kube-prometheus + + ## RelabelConfigs to apply to samples before scraping + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + relabelings: [] + + ## MetricRelabelConfigs to apply to samples before ingestion + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + metricRelabelings: [] + +## Persistence paramaters +## +persistence: + enabled: true + ## A manually managed Persistent Volume and Claim + ## If defined, PVC must be created manually before volume will be bound + ## The value is evaluated as a template + ## + # existingClaim: + ## Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. + ## + # storageClass: "-" + ## The path the volume will be mounted at, useful when using different + ## PostgreSQL images. + ## + mountPath: /bitnami/postgresql + ## Persistent Volume Access Mode + ## + accessModes: + - ReadWriteOnce + ## Persistent Volume Claim size + ## + size: 8Gi + ## Persistent Volume Claim annotations + ## + annotations: {} + +## PgPool service paramaters +## +service: + ## Service type + ## + type: ClusterIP + ## Service Port + ## + port: 5432 + ## Specify the nodePort value for the LoadBalancer and NodePort service types. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport + ## + # nodePort: + ## Set the LoadBalancer service type to internal only. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer + ## + # loadBalancerIP: + ## Load Balancer sources + ## https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/#restrict-access-for-loadbalancer-service + ## + # loadBalancerSourceRanges: + # - 10.10.10.0/24 + ## Set the Cluster IP to use + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#choosing-your-own-ip-address + ## + # clusterIP: None + ## Provide any additional annotations which may be required + ## + annotations: {} + +## NetworkPolicy paramaters +## +networkPolicy: + enabled: false + + ## The Policy model to apply. When set to false, only pods with the correct + ## client labels will have network access to the port PostgreSQL is listening + ## on. When true, PostgreSQL will accept connections from any source + ## (with the correct destination port). + ## + allowExternal: true diff --git a/overlays/mainnet/helm-chartInflator-postgres-ha.yaml b/overlays/mainnet/helm-chartInflator-postgres-ha.yaml new file mode 100644 index 0000000..26d249e --- /dev/null +++ b/overlays/mainnet/helm-chartInflator-postgres-ha.yaml @@ -0,0 +1,9 @@ +apiVersion: someteam.example.com/v1 +kind: ChartInflator +metadata: + name: notImportantHere +chartHome: ../../base/helm-charts +chartName: postgresql-ha +releaseName: init0 +releaseNamespace: dandelion-mainnet +values: helm-postgres-ha-values.yaml diff --git a/overlays/mainnet/helm-postgres-ha-values.yaml b/overlays/mainnet/helm-postgres-ha-values.yaml new file mode 100644 index 0000000..7bae211 --- /dev/null +++ b/overlays/mainnet/helm-postgres-ha-values.yaml @@ -0,0 +1,664 @@ +## Global Docker image parameters +## Please, note that this will override the image parameters, including dependencies, configured to use the global value +## Current available global Docker image parameters: imageRegistry, imagePullSecrets and storageClass +## + global: +# imageRegistry: myRegistryName +# imagePullSecrets: +# - myRegistryKeySecretName +# storageClass: myStorageClass + postgresql: + username: postgres + password: cdbsCHANGEME + database: cdbs + repmgrUsername: repmgruser + repmgrPassword: repmgrpassword + repmgrDatabase: repmgrdatabase +# existingSecret: myExistingSecret +# ldap: +# bindpw: bindpassword +# existingSecret: myExistingSecret +# pgpool: +# adminUsername: adminuser +# adminPassword: adminpassword +# existingSecret: myExistingSecret + +## Bitnami PostgreSQL image +## ref: https://hub.docker.com/r/bitnami/postgresql/tags/ +## +postgresqlImage: + registry: docker.io + repository: bitnami/postgresql-repmgr + tag: 11.9.0-debian-10-r10 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Pgpool image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +pgpoolImage: + registry: docker.io + repository: bitnami/pgpool + tag: 4.1.3-debian-10-r7 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Minideb image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +volumePermissionsImage: + registry: docker.io + repository: bitnami/minideb + tag: buster + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: Always + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + +## Bitnami PostgreSQL Prometheus exporter image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +metricsImage: + registry: docker.io + repository: bitnami/postgres-exporter + tag: 0.8.0-debian-10-r197 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## String to partially override postgresql-ha.fullname template (will maintain the release name) +## +# nameOverride: + +## String to fully override postgresql-ha.fullname template +## +# fullnameOverride: + +## Kubernetes Cluster Domain +## +clusterDomain: cluster.local + +## PostgreSQL parameters +## +postgresql: + ## Labels to add to the StatefulSet. Evaluated as template + ## + labels: {} + + ## Labels to add to the StatefulSet pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 1 + + ## Update strategy for PostgreSQL statefulset + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies + ## + updateStrategyType: OnDelete + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## PostgreSQL containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## PostgreSQL container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## PostgreSQL configuration parameters + ## + username: postgres + #password: + database: database + + ## PostgreSQL password using existing secret + # existingSecret: secret + + ## PostgreSQL admin password (used when `postgresql.username` is not `postgres`) + ## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#creating-a-database-user-on-first-run (see note!) + # postgresPassword: + + ## Mount PostgreSQL secret as a file instead of passing environment variable + usePasswordFile: true + + ## Upgrade repmgr extension in the database + ## + upgradeRepmgrExtension: false + + ## Configures pg_hba.conf to trust every user + ## + pgHbaTrustAll: false + + ## Synchronous replication + ## + syncReplication: true + + ## Repmgr configuration parameters + ## + repmgrUsername: repmgr + # repmgrPassword: + repmgrDatabase: repmgr + repmgrLogLevel: NOTICE + repmgrConnectTimeout: 5 + repmgrReconnectAttempts: 3 + repmgrReconnectInterval: 5 + + ## Repmgr configuration + ## Specify content for repmgr.conf + ## Default: do not create repmgr.conf + ## Alternatively, you can put your repmgr.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # repmgrConfiguration: |- + ## PostgreSQL configuration + ## Specify runtime configuration parameters as a dict, using camelCase, e.g. + ## {"sharedBuffers": "500MB"} + ## Alternatively, you can put your postgresql.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # configuration: + ## PostgreSQL client authentication configuration + ## Specify content for pg_hba.conf + ## Default: do not create pg_hba.conf + ## Alternatively, you can put your pg_hba.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # pgHbaConfiguration: |- + # local all all trust + # host all all localhost trust + # host mydatabase mysuser 192.168.0.0/24 md5 + ## ConfigMap with PostgreSQL configuration + ## NOTE: This will override repmgrConfiguration, configuration and pgHbaConfiguration + ## + # configurationCM: + ## PostgreSQL extended configuration + ## As above, but _appended_ to the main configuration + ## Alternatively, you can put your *.conf under the files/conf.d/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#allow-settings-to-be-loaded-from-files-other-than-the-default-postgresqlconf + ## + # extendedConf: + ## ConfigMap with PostgreSQL extended configuration + ## NOTE: This will override extendedConf + ## + # extendedConfCM: + ## initdb scripts + ## Specify dictionary of scripts to be run at first boot + ## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + ## ConfigMap with scripts to be run at first boot + ## NOTE: This will override initdbScripts + ## + # initdbScriptsCM: + ## Secret with scripts to be run at first boot + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + +## Pgpool parameters +## +pgpool: + + ## Additional users that will be performing connections to the database using + ## pgpool. Use this property in order to create new user/password entries that + ## will be appended to the "pgpool_passwd" file + ## + customUsers: {} + ## Comma or semicolon separeted list of postgres usernames + # usernames: 'user01;user02' + + ## Comma or semicolon separated list of the associated passwords for the + ## users above + # passwords: 'pass01;pass02' + + ## Alternatively, you can provide the name of a secret containing this information. + ## The secret must contain the keys "usernames" and "passwords" respectively. + ## + customUsersSecret: + + ## Labels to add to the Deployment. Evaluated as template + ## + labels: {} + + ## Labels to add to the pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 2 + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## Pgpool containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Pgpool container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## strategy used to replace old Pods by new ones + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy + ## + updateStrategy: {} + + ## minReadySeconds to avoid killing pods before we are ready + ## + # minReadySeconds: 0 + + ## Pgpool configuration parameters + ## + adminUsername: admin + # adminPassword: + + ## The number of preforked Pgpool-II server processes. It is also the concurrent + ## connections limit to Pgpool-II from clients. Must be a positive integer. (PGPOOL_NUM_INIT_CHILDREN) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # numInitChildren: + + ## The maximum number of cached connections in each child process (PGPOOL_MAX_POOL) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # maxPools: + + ## Pgpool configuration + ## Specify content for pgpool.conf + ## Alternatively, you can put your pgpool.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration-file + ## + # configuration: + + ## ConfigMap with Pgpool configuration + ## NOTE: This will override pgpool.configuration parameter + ## + # configurationCM: + + ## initdb scripts + ## Specify dictionary of scripts to be run everytime Pgpool container is initialized + ## Alternatively, you can put your scripts under the files/pgpool-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + + ## ConfigMap with scripts to be run everytime Pgpool container is initialized + ## NOTE: This will override pgpool.initdbScripts + ## + # initdbScriptsCM: + + ## Secret with scripts to be run at first boot + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + + ## Use Pgpool Load-Balancing + ## + useLoadBalancing: true + +## LDAP parameters +## +ldap: + enabled: false + ## Retrieve LDAP bindpw from existing secret + ## + # existingSecret: myExistingSecret + uri: + base: + binddn: + bindpw: + bslookup: + scope: + tlsReqcert: + nssInitgroupsIgnoreusers: root,nslcd + +## Init Container paramaters +## +volumePermissions: + enabled: false + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + runAsUser: 0 + ## Init container' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 100m + # memory: 128Mi + requests: {} + # cpu: 100m + # memory: 128Mi + +## PostgreSQL Prometheus exporter parameters +## +metrics: + enabled: true + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + runAsUser: 1001 + + ## Prometheus exporter containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Prometheus exporter container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Annotations for Prometheus exporter + ## + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9187" + + ## Enable this if you're using Prometheus Operator + ## + serviceMonitor: + enabled: false + ## Specify a namespace if needed + # namespace: monitoring + # fallback to the prometheus default unless specified + # interval: 10s + # scrapeTimeout: 10s + ## Defaults to what's used if you follow CoreOS [Prometheus Install Instructions](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#tldr) + ## [Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#prometheus-operator-1) + ## [Kube Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#exporters) + ## + selector: + prometheus: kube-prometheus + + ## RelabelConfigs to apply to samples before scraping + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + relabelings: [] + + ## MetricRelabelConfigs to apply to samples before ingestion + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + metricRelabelings: [] + +## Persistence paramaters +## +persistence: + enabled: true + ## A manually managed Persistent Volume and Claim + ## If defined, PVC must be created manually before volume will be bound + ## The value is evaluated as a template + ## + # existingClaim: + ## Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. + ## + # storageClass: "-" + ## The path the volume will be mounted at, useful when using different + ## PostgreSQL images. + ## + mountPath: /bitnami/postgresql + ## Persistent Volume Access Mode + ## + accessModes: + - ReadWriteOnce + ## Persistent Volume Claim size + ## + size: 40Gi + ## Persistent Volume Claim annotations + ## + annotations: {} + +## PgPool service paramaters +## +service: + ## Service type + ## + type: ClusterIP + ## Service Port + ## + port: 5432 + ## Specify the nodePort value for the LoadBalancer and NodePort service types. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport + ## + # nodePort: + ## Set the LoadBalancer service type to internal only. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer + ## + # loadBalancerIP: + ## Load Balancer sources + ## https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/#restrict-access-for-loadbalancer-service + ## + # loadBalancerSourceRanges: + # - 10.10.10.0/24 + ## Set the Cluster IP to use + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#choosing-your-own-ip-address + ## + # clusterIP: None + ## Provide any additional annotations which may be required + ## + annotations: {} + +## NetworkPolicy paramaters +## +networkPolicy: + enabled: true + + ## The Policy model to apply. When set to false, only pods with the correct + ## client labels will have network access to the port PostgreSQL is listening + ## on. When true, PostgreSQL will accept connections from any source + ## (with the correct destination port). + ## + allowExternal: false diff --git a/overlays/mainnet/kustomization.yaml b/overlays/mainnet/kustomization.yaml new file mode 100644 index 0000000..2e10030 --- /dev/null +++ b/overlays/mainnet/kustomization.yaml @@ -0,0 +1,32 @@ +namespace: dandelion-mainnet +#namePrefix: ptn0- +commonLabels: + environment: production + cardano_network: mainnet + cardano_node_type: haskell + project_name: dandelion +commonAnnotations: + note: free-apis! +generators: +- helm-chartInflator-postgres-ha.yaml +bases: +- ../../base/cardano-db-sync +- ../../base/cardano-explorer-api +- ../../base/cardano-graphql +- ../../base/cardano-hasura +- ../../base/cardano-node +- ../../base/cardano-submit-api +resources: +- resources/common-env-configmap.yaml +- resources/ingress.yaml + +patches: +# cardano-node +- path: patches/cardano-node-pvc.yaml + target: + kind: StatefulSet + name: cardano-node +- path: patches/postgres-ha-pvc.yaml + target: + kind: StatefulSet + name: init0-postgresql-ha-postgresql diff --git a/overlays/mainnet/patches/cardano-node-pvc.yaml b/overlays/mainnet/patches/cardano-node-pvc.yaml new file mode 100644 index 0000000..bef0a0f --- /dev/null +++ b/overlays/mainnet/patches/cardano-node-pvc.yaml @@ -0,0 +1,10 @@ +- op: replace + path: /spec/volumeClaimTemplates + value: + - metadata: + name: node-db + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 42Gi diff --git a/overlays/mainnet/patches/postgres-ha-pvc.yaml b/overlays/mainnet/patches/postgres-ha-pvc.yaml new file mode 100644 index 0000000..f73de5e --- /dev/null +++ b/overlays/mainnet/patches/postgres-ha-pvc.yaml @@ -0,0 +1,10 @@ +- op: replace + path: /spec/volumeClaimTemplates + value: + - metadata: + name: data + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 42Gi diff --git a/overlays/mainnet/resources/common-env-configmap.yaml b/overlays/mainnet/resources/common-env-configmap.yaml new file mode 100644 index 0000000..96a252f --- /dev/null +++ b/overlays/mainnet/resources/common-env-configmap.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: common-env +data: + POSTGRES_HOST: init0-postgresql-ha-pgpool + POSTGRES_HOST_RW: init0-postgresql-ha-pgpool + POSTGRES_PORT: "5432" + POSTGRES_DB: cdbs + POSTGRES_USER: postgres + chisel-auth-file: | + { + "rcmorano:chiselCHANGEME": [""] + } diff --git a/overlays/mainnet/resources/ingress.yaml b/overlays/mainnet/resources/ingress.yaml new file mode 100644 index 0000000..e2a15a8 --- /dev/null +++ b/overlays/mainnet/resources/ingress.yaml @@ -0,0 +1,113 @@ +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: cardano-explorer-api +spec: + rules: + - host: explorer-api.mainnet.local + http: + paths: + - backend: + serviceName: cardano-explorer-api + servicePort: 8101 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - explorer-api.mainnet.local + #secretName: local-tls + +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: cardano-submit-api +spec: + rules: + - host: submit-api.mainnet.local + http: + paths: + - backend: + serviceName: cardano-submit-api + servicePort: 8091 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - submit-api.mainnet.local + #secretName: local-tls + +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: cardano-graphql-api +spec: + rules: + - host: graphql-api.mainnet.local + http: + paths: + - backend: + serviceName: cardano-graphql + servicePort: 3100 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - graphql-api.mainnet.local + #secretName: local-tls + +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: chisel-api +spec: + rules: + - host: chisel-api.mainnet.local + http: + paths: + - backend: + serviceName: chisel-server + servicePort: 40000 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - chisel-api.testnet.local + #secretName: local-tls + +--- +############################## +# TODO: authenticate this :P # +############################## +#apiVersion: networking.k8s.io/v1beta1 +#kind: Ingress +#metadata: +# annotations: +# kubernetes.io/ingress.class: nginx +# name: cardano-hasura-api +#spec: +# rules: +# - host: hasura-api.mainnet.local +# http: +# paths: +# - backend: +# serviceName: hasura +# servicePort: 8080 +# path: / +# # This section is only required if TLS is to be enabled for the Ingress +# tls: +# - hosts: +# - hasura-api.mainnet.local +# secretName: local-tls + +#cardano-node-headless ClusterIP None 30000/TCP 20h diff --git a/overlays/testnet/helm-chartInflator-postgres-ha.yaml b/overlays/testnet/helm-chartInflator-postgres-ha.yaml new file mode 100644 index 0000000..32833a4 --- /dev/null +++ b/overlays/testnet/helm-chartInflator-postgres-ha.yaml @@ -0,0 +1,9 @@ +apiVersion: someteam.example.com/v1 +kind: ChartInflator +metadata: + name: notImportantHere +chartHome: ../../base/helm-charts +chartName: postgresql-ha +releaseName: init0 +releaseNamespace: dandelion-tn-production +values: helm-postgres-ha-values.yaml diff --git a/overlays/testnet/helm-postgres-ha-values.yaml b/overlays/testnet/helm-postgres-ha-values.yaml new file mode 100644 index 0000000..9eb2541 --- /dev/null +++ b/overlays/testnet/helm-postgres-ha-values.yaml @@ -0,0 +1,664 @@ +## Global Docker image parameters +## Please, note that this will override the image parameters, including dependencies, configured to use the global value +## Current available global Docker image parameters: imageRegistry, imagePullSecrets and storageClass +## + global: +# imageRegistry: myRegistryName +# imagePullSecrets: +# - myRegistryKeySecretName +# storageClass: myStorageClass + postgresql: + username: postgres + password: cdbsCHANGEME + database: cdbs + repmgrUsername: repmgruser + repmgrPassword: repmgrpassword + repmgrDatabase: repmgrdatabase +# existingSecret: myExistingSecret +# ldap: +# bindpw: bindpassword +# existingSecret: myExistingSecret +# pgpool: +# adminUsername: adminuser +# adminPassword: adminpassword +# existingSecret: myExistingSecret + +## Bitnami PostgreSQL image +## ref: https://hub.docker.com/r/bitnami/postgresql/tags/ +## +postgresqlImage: + registry: docker.io + repository: bitnami/postgresql-repmgr + tag: 11.9.0-debian-10-r10 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Pgpool image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +pgpoolImage: + registry: docker.io + repository: bitnami/pgpool + tag: 4.1.3-debian-10-r7 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## Bitnami Minideb image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +volumePermissionsImage: + registry: docker.io + repository: bitnami/minideb + tag: buster + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: Always + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + +## Bitnami PostgreSQL Prometheus exporter image +## ref: https://hub.docker.com/r/bitnami/pgpool/tags/ +## +metricsImage: + registry: docker.io + repository: bitnami/postgres-exporter + tag: 0.8.0-debian-10-r197 + ## Specify a imagePullPolicy. Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace) + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistryKeySecretName + + ## Set to true if you would like to see extra information on logs + ## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging + ## + debug: false + +## String to partially override postgresql-ha.fullname template (will maintain the release name) +## +# nameOverride: + +## String to fully override postgresql-ha.fullname template +## +# fullnameOverride: + +## Kubernetes Cluster Domain +## +clusterDomain: cluster.local + +## PostgreSQL parameters +## +postgresql: + ## Labels to add to the StatefulSet. Evaluated as template + ## + labels: {} + + ## Labels to add to the StatefulSet pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 2 + + ## Update strategy for PostgreSQL statefulset + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies + ## + updateStrategyType: RollingUpdate + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## PostgreSQL containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## PostgreSQL container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## PostgreSQL configuration parameters + ## + username: postgres + #password: + database: database + + ## PostgreSQL password using existing secret + # existingSecret: secret + + ## PostgreSQL admin password (used when `postgresql.username` is not `postgres`) + ## ref: https://github.com/bitnami/bitnami-docker-postgresql/blob/master/README.md#creating-a-database-user-on-first-run (see note!) + # postgresPassword: + + ## Mount PostgreSQL secret as a file instead of passing environment variable + usePasswordFile: true + + ## Upgrade repmgr extension in the database + ## + upgradeRepmgrExtension: false + + ## Configures pg_hba.conf to trust every user + ## + pgHbaTrustAll: false + + ## Synchronous replication + ## + syncReplication: true + + ## Repmgr configuration parameters + ## + repmgrUsername: repmgr + # repmgrPassword: + repmgrDatabase: repmgr + repmgrLogLevel: NOTICE + repmgrConnectTimeout: 5 + repmgrReconnectAttempts: 3 + repmgrReconnectInterval: 5 + + ## Repmgr configuration + ## Specify content for repmgr.conf + ## Default: do not create repmgr.conf + ## Alternatively, you can put your repmgr.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # repmgrConfiguration: |- + ## PostgreSQL configuration + ## Specify runtime configuration parameters as a dict, using camelCase, e.g. + ## {"sharedBuffers": "500MB"} + ## Alternatively, you can put your postgresql.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # configuration: + ## PostgreSQL client authentication configuration + ## Specify content for pg_hba.conf + ## Default: do not create pg_hba.conf + ## Alternatively, you can put your pg_hba.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#configuration-file + ## + # pgHbaConfiguration: |- + # local all all trust + # host all all localhost trust + # host mydatabase mysuser 192.168.0.0/24 md5 + ## ConfigMap with PostgreSQL configuration + ## NOTE: This will override repmgrConfiguration, configuration and pgHbaConfiguration + ## + # configurationCM: + ## PostgreSQL extended configuration + ## As above, but _appended_ to the main configuration + ## Alternatively, you can put your *.conf under the files/conf.d/ directory + ## ref: https://github.com/bitnami/bitnami-docker-postgresql-repmgr#allow-settings-to-be-loaded-from-files-other-than-the-default-postgresqlconf + ## + # extendedConf: + ## ConfigMap with PostgreSQL extended configuration + ## NOTE: This will override extendedConf + ## + # extendedConfCM: + ## initdb scripts + ## Specify dictionary of scripts to be run at first boot + ## Alternatively, you can put your scripts under the files/docker-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + ## ConfigMap with scripts to be run at first boot + ## NOTE: This will override initdbScripts + ## + # initdbScriptsCM: + ## Secret with scripts to be run at first boot + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + +## Pgpool parameters +## +pgpool: + + ## Additional users that will be performing connections to the database using + ## pgpool. Use this property in order to create new user/password entries that + ## will be appended to the "pgpool_passwd" file + ## + customUsers: {} + ## Comma or semicolon separeted list of postgres usernames + # usernames: 'user01;user02' + + ## Comma or semicolon separated list of the associated passwords for the + ## users above + # passwords: 'pass01;pass02' + + ## Alternatively, you can provide the name of a secret containing this information. + ## The secret must contain the keys "usernames" and "passwords" respectively. + ## + customUsersSecret: + + ## Labels to add to the Deployment. Evaluated as template + ## + labels: {} + + ## Labels to add to the pods. Evaluated as template + ## + podLabels: {} + + ## Number of replicas to deploy + ## + replicaCount: 2 + + ## Additional pod annotations + ## ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ + ## + podAnnotations: {} + + ## Affinity for pod assignment + ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity + ## + affinity: {} + + ## Node labels for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## + nodeSelector: {} + + ## Pod priority class + ## Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ + ## + priorityClassName: "" + + ## Tolerations for pod assignment. Evaluated as a template. + ## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ + ## + tolerations: {} + + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + fsGroup: 1001 + runAsUser: 1001 + + ## Pgpool containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Pgpool container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + + ## Pod disruption budget configuration + ## + pdb: + ## Specifies whether a Pod disruption budget should be created + ## + create: false + minAvailable: 1 + # maxUnavailable: 1 + + ## strategy used to replace old Pods by new ones + ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy + ## + updateStrategy: {} + + ## minReadySeconds to avoid killing pods before we are ready + ## + # minReadySeconds: 0 + + ## Pgpool configuration parameters + ## + adminUsername: admin + # adminPassword: + + ## The number of preforked Pgpool-II server processes. It is also the concurrent + ## connections limit to Pgpool-II from clients. Must be a positive integer. (PGPOOL_NUM_INIT_CHILDREN) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # numInitChildren: + + ## The maximum number of cached connections in each child process (PGPOOL_MAX_POOL) + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration + # maxPools: + + ## Pgpool configuration + ## Specify content for pgpool.conf + ## Alternatively, you can put your pgpool.conf under the files/ directory + ## ref: https://github.com/bitnami/bitnami-docker-pgpool#configuration-file + ## + # configuration: + + ## ConfigMap with Pgpool configuration + ## NOTE: This will override pgpool.configuration parameter + ## + # configurationCM: + + ## initdb scripts + ## Specify dictionary of scripts to be run everytime Pgpool container is initialized + ## Alternatively, you can put your scripts under the files/pgpool-entrypoint-initdb.d directory + ## + # initdbScripts: + # my_init_script.sh: | + # #!/bin/sh + # echo "Do something." + + ## ConfigMap with scripts to be run everytime Pgpool container is initialized + ## NOTE: This will override pgpool.initdbScripts + ## + # initdbScriptsCM: + + ## Secret with scripts to be run at first boot + ## Note: can be used with initdbScriptsCM or initdbScripts + ## + # initdbScriptsSecret: + + ## Use Pgpool Load-Balancing + ## + useLoadBalancing: true + +## LDAP parameters +## +ldap: + enabled: false + ## Retrieve LDAP bindpw from existing secret + ## + # existingSecret: myExistingSecret + uri: + base: + binddn: + bindpw: + bslookup: + scope: + tlsReqcert: + nssInitgroupsIgnoreusers: root,nslcd + +## Init Container paramaters +## +volumePermissions: + enabled: false + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + runAsUser: 0 + ## Init container' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 100m + # memory: 128Mi + requests: {} + # cpu: 100m + # memory: 128Mi + +## PostgreSQL Prometheus exporter parameters +## +metrics: + enabled: true + ## K8s Security Context + ## https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + ## + securityContext: + enabled: true + runAsUser: 1001 + + ## Prometheus exporter containers' resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: {} + # cpu: 250m + # memory: 256Mi + requests: {} + # cpu: 250m + # memory: 256Mi + + ## Prometheus exporter container's liveness and readiness probes + ## ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes + ## + livenessProbe: + enabled: true + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + readinessProbe: + enabled: true + initialDelaySeconds: 5 + periodSeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 6 + + ## Annotations for Prometheus exporter + ## + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9187" + + ## Enable this if you're using Prometheus Operator + ## + serviceMonitor: + enabled: false + ## Specify a namespace if needed + # namespace: monitoring + # fallback to the prometheus default unless specified + # interval: 10s + # scrapeTimeout: 10s + ## Defaults to what's used if you follow CoreOS [Prometheus Install Instructions](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#tldr) + ## [Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#prometheus-operator-1) + ## [Kube Prometheus Selector Label](https://github.com/bitnami/charts/tree/master/bitnami/prometheus-operator#exporters) + ## + selector: + prometheus: kube-prometheus + + ## RelabelConfigs to apply to samples before scraping + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + relabelings: [] + + ## MetricRelabelConfigs to apply to samples before ingestion + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + ## Value is evalued as a template + ## + metricRelabelings: [] + +## Persistence paramaters +## +persistence: + enabled: true + ## A manually managed Persistent Volume and Claim + ## If defined, PVC must be created manually before volume will be bound + ## The value is evaluated as a template + ## + # existingClaim: + ## Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. + ## + # storageClass: "-" + ## The path the volume will be mounted at, useful when using different + ## PostgreSQL images. + ## + mountPath: /bitnami/postgresql + ## Persistent Volume Access Mode + ## + accessModes: + - ReadWriteOnce + ## Persistent Volume Claim size + ## + size: 40Gi + ## Persistent Volume Claim annotations + ## + annotations: {} + +## PgPool service paramaters +## +service: + ## Service type + ## + type: ClusterIP + ## Service Port + ## + port: 5432 + ## Specify the nodePort value for the LoadBalancer and NodePort service types. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport + ## + # nodePort: + ## Set the LoadBalancer service type to internal only. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer + ## + # loadBalancerIP: + ## Load Balancer sources + ## https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/#restrict-access-for-loadbalancer-service + ## + # loadBalancerSourceRanges: + # - 10.10.10.0/24 + ## Set the Cluster IP to use + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#choosing-your-own-ip-address + ## + # clusterIP: None + ## Provide any additional annotations which may be required + ## + annotations: {} + +## NetworkPolicy paramaters +## +networkPolicy: + enabled: true + + ## The Policy model to apply. When set to false, only pods with the correct + ## client labels will have network access to the port PostgreSQL is listening + ## on. When true, PostgreSQL will accept connections from any source + ## (with the correct destination port). + ## + allowExternal: false diff --git a/overlays/testnet/kustomization.yaml b/overlays/testnet/kustomization.yaml new file mode 100644 index 0000000..67caac6 --- /dev/null +++ b/overlays/testnet/kustomization.yaml @@ -0,0 +1,49 @@ +namespace: dandelion-tn-production +#namePrefix: ptn0- +commonLabels: + environment: production + cardano_network: testnet + cardano_node_type: haskell + project_name: dandelion +commonAnnotations: + note: free-apis! +generators: +- helm-chartInflator-postgres-ha.yaml +bases: +- ../../base/cardano-db-sync +- ../../base/cardano-explorer-api +- ../../base/cardano-graphql +- ../../base/cardano-hasura +- ../../base/cardano-node +- ../../base/cardano-submit-api +resources: +- resources/common-env-configmap.yaml +- resources/ingress.yaml + +patches: +- path: patches/genesis-image.yaml + target: + kind: Deployment + name: cardano-graphql +# cardano-db-sync +- path: patches/cardano-db-sync-deployment-env.yaml + target: + kind: Deployment + name: cardano-db-sync +- path: patches/cardano-db-sync-deployment-image.yaml + target: + kind: Deployment + name: cardano-db-sync +# cardano-node +- path: patches/cardano-node-pvc.yaml + target: + kind: StatefulSet + name: cardano-node +- path: patches/cardano-node-deployment-env.yaml + target: + kind: StatefulSet + name: cardano-node +- path: patches/cardano-node-deployment-image.yaml + target: + kind: StatefulSet + name: cardano-node diff --git a/overlays/testnet/patches/cardano-db-sync-deployment-env.yaml b/overlays/testnet/patches/cardano-db-sync-deployment-env.yaml new file mode 100644 index 0000000..01609ca --- /dev/null +++ b/overlays/testnet/patches/cardano-db-sync-deployment-env.yaml @@ -0,0 +1,33 @@ +- op: replace + path: /spec/template/spec/containers/0/env + value: + - name: EXTENDED + value: "false" + - name: NETWORK + value: testnet + - name: POSTGRES_HOST + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_HOST_RW + - name: POSTGRES_PORT + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_PORT + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_DB + - name: POSTGRES_USER + valueFrom: + configMapKeyRef: + name: common-env + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: init0-postgresql-ha-postgresql + key: postgresql-password + diff --git a/overlays/testnet/patches/cardano-db-sync-deployment-image.yaml b/overlays/testnet/patches/cardano-db-sync-deployment-image.yaml new file mode 100644 index 0000000..d11c1e6 --- /dev/null +++ b/overlays/testnet/patches/cardano-db-sync-deployment-image.yaml @@ -0,0 +1,4 @@ +- op: replace + path: /spec/template/spec/containers/0/image + value: + inputoutput/cardano-db-sync:5.0.3 diff --git a/overlays/testnet/patches/cardano-node-deployment-env.yaml b/overlays/testnet/patches/cardano-node-deployment-env.yaml new file mode 100644 index 0000000..53adffe --- /dev/null +++ b/overlays/testnet/patches/cardano-node-deployment-env.yaml @@ -0,0 +1,5 @@ +- op: replace + path: /spec/template/spec/containers/0/env + value: + - name: NETWORK + value: testnet diff --git a/overlays/testnet/patches/cardano-node-deployment-image.yaml b/overlays/testnet/patches/cardano-node-deployment-image.yaml new file mode 100644 index 0000000..a7b59e2 --- /dev/null +++ b/overlays/testnet/patches/cardano-node-deployment-image.yaml @@ -0,0 +1,4 @@ +- op: replace + path: /spec/template/spec/containers/0/image + value: + inputoutput/cardano-node:1.21.1 diff --git a/overlays/testnet/patches/cardano-node-pvc.yaml b/overlays/testnet/patches/cardano-node-pvc.yaml new file mode 100644 index 0000000..8476f1b --- /dev/null +++ b/overlays/testnet/patches/cardano-node-pvc.yaml @@ -0,0 +1,10 @@ +- op: replace + path: /spec/volumeClaimTemplates + value: + - metadata: + name: node-db + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 8Gi diff --git a/overlays/testnet/patches/genesis-image.yaml b/overlays/testnet/patches/genesis-image.yaml new file mode 100644 index 0000000..021ede5 --- /dev/null +++ b/overlays/testnet/patches/genesis-image.yaml @@ -0,0 +1,4 @@ +- op: replace + path: /spec/template/spec/initContainers/0/image + value: + repsistance/cardano-node:iohk-tn-passive-1.20.0 diff --git a/overlays/testnet/resources/common-env-configmap.yaml b/overlays/testnet/resources/common-env-configmap.yaml new file mode 100644 index 0000000..96a252f --- /dev/null +++ b/overlays/testnet/resources/common-env-configmap.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: common-env +data: + POSTGRES_HOST: init0-postgresql-ha-pgpool + POSTGRES_HOST_RW: init0-postgresql-ha-pgpool + POSTGRES_PORT: "5432" + POSTGRES_DB: cdbs + POSTGRES_USER: postgres + chisel-auth-file: | + { + "rcmorano:chiselCHANGEME": [""] + } diff --git a/overlays/testnet/resources/ingress.yaml b/overlays/testnet/resources/ingress.yaml new file mode 100644 index 0000000..70d67c4 --- /dev/null +++ b/overlays/testnet/resources/ingress.yaml @@ -0,0 +1,110 @@ +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: cardano-explorer-api +spec: + rules: + - host: explorer-api.testnet.local + http: + paths: + - backend: + serviceName: cardano-explorer-api + servicePort: 8101 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - explorer-api.testnet.local + #secretName: local-tls + +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: cardano-submit-api +spec: + rules: + - host: submit-api.testnet.local + http: + paths: + - backend: + serviceName: cardano-submit-api + servicePort: 8091 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - submit-api.testnet.local + #secretName: local-tls + +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: cardano-graphql-api +spec: + rules: + - host: graphql-api.testnet.local + http: + paths: + - backend: + serviceName: cardano-graphql + servicePort: 3100 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - graphql-api.testnet.local + #secretName: local-tls + +--- +apiVersion: networking.k8s.io/v1beta1 +kind: Ingress +metadata: + annotations: + kubernetes.io/ingress.class: nginx + name: chisel-api +spec: + rules: + - host: chisel-api.testnet.local + http: + paths: + - backend: + serviceName: chisel-server + servicePort: 40000 + path: / + # This section is only required if TLS is to be enabled for the Ingress + tls: + - hosts: + - chisel-api.testnet.local + #secretName: local-tls + +--- +#apiVersion: networking.k8s.io/v1beta1 +#kind: Ingress +#metadata: +# annotations: +# kubernetes.io/ingress.class: nginx +# name: cardano-hasura-api +#spec: +# rules: +# - host: hasura-api.testnet.local +# http: +# paths: +# - backend: +# serviceName: hasura +# servicePort: 8080 +# path: / +# tls: +# - hosts: +# - hasura-api.testnet.local +# secretName: local-tls + +#cardano-node-headless ClusterIP None 30000/TCP 20h +#hasura-headless ClusterIP None 8080/TCP 20h