ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 1 | # |
| 2 | # ============LICENSE_START======================================================= |
| 3 | # Copyright (C) 2022 Nordix Foundation. |
| 4 | # ================================================================================ |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # SPDX-License-Identifier: Apache-2.0 |
| 18 | # ============LICENSE_END========================================================= |
| 19 | # |
| 20 | apiVersion: v1 |
| 21 | kind: PersistentVolume |
| 22 | metadata: |
| 23 | name: postgres-storage-pv-volume |
| 24 | namespace: default |
| 25 | labels: |
| 26 | type: local |
| 27 | app: postgres |
| 28 | spec: |
| 29 | storageClassName: manual |
| 30 | capacity: |
| 31 | storage: 2Gi |
| 32 | accessModes: |
| 33 | - ReadWriteOnce |
| 34 | hostPath: |
| 35 | path: "/var/keycloak/data2" |
| 36 | --- |
| 37 | apiVersion: v1 |
| 38 | kind: PersistentVolumeClaim |
| 39 | metadata: |
| 40 | name: postgres-storage-pv-claim |
| 41 | namespace: default |
| 42 | labels: |
| 43 | app: postgres |
| 44 | spec: |
| 45 | storageClassName: manual |
| 46 | accessModes: |
| 47 | - ReadWriteOnce |
| 48 | resources: |
| 49 | requests: |
| 50 | storage: 2Gi |
| 51 | --- |
| 52 | apiVersion: v1 |
| 53 | kind: ConfigMap |
| 54 | metadata: |
| 55 | name: db-init |
ktimoney | 076d02a | 2022-12-13 09:23:43 +0000 | [diff] [blame^] | 56 | namespace: default |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 57 | data: |
| 58 | init.sql: | |
| 59 | SELECT 'CREATE DATABASE capif' |
| 60 | WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'capif')\gexec |
| 61 | DO $$ |
| 62 | BEGIN |
| 63 | IF NOT EXISTS (SELECT FROM pg_user WHERE usename = 'capif') THEN |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 64 | CREATE USER capif WITH PASSWORD 'capif'; |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 65 | GRANT ALL PRIVILEGES ON DATABASE capif TO capif; |
| 66 | END IF; |
| 67 | END |
| 68 | $$; |
| 69 | --- |
| 70 | apiVersion: v1 |
| 71 | kind: Service |
| 72 | metadata: |
| 73 | name: postgres |
| 74 | namespace: default |
| 75 | spec: |
| 76 | type: NodePort |
| 77 | selector: |
| 78 | app: postgres |
| 79 | ports: |
| 80 | - protocol: TCP |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 81 | port: 5432 |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 82 | nodePort: 30032 |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 83 | targetPort: 5432 |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 84 | --- |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 85 | apiVersion: apps/v1 |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 86 | kind: Deployment |
| 87 | metadata: |
| 88 | name: postgres |
| 89 | namespace: default |
| 90 | spec: |
| 91 | selector: |
| 92 | matchLabels: |
| 93 | app: postgres |
| 94 | strategy: |
| 95 | type: Recreate |
| 96 | template: |
| 97 | metadata: |
| 98 | labels: |
| 99 | app: postgres |
| 100 | spec: |
| 101 | hostname: postgres |
| 102 | containers: |
| 103 | - image: nexus3.onap.org:10001/postgres |
| 104 | name: postgres |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 105 | imagePullPolicy: IfNotPresent |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 106 | env: |
| 107 | - name: POSTGRES_DB |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 108 | value: keycloak |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 109 | - name: POSTGRES_USER |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 110 | value: keycloak |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 111 | - name: POSTGRES_PASSWORD |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 112 | value: keycloak |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 113 | - name: PGDATA |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 114 | value: /var/lib/pgsql/data |
| 115 | lifecycle: |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 116 | postStart: |
| 117 | exec: |
| 118 | command: [ "/bin/sh", "-c", "sleep 10 && psql -U $POSTGRES_USER -f /init.sql" ] |
| 119 | livenessProbe: |
| 120 | exec: |
| 121 | command: |
| 122 | - /bin/sh |
| 123 | - -c |
| 124 | - exec pg_isready -U "keycloak" -h 127.0.0.1 -p 5432 |
| 125 | initialDelaySeconds: 30 |
| 126 | periodSeconds: 10 |
| 127 | timeoutSeconds: 5 |
| 128 | readinessProbe: |
| 129 | exec: |
| 130 | command: ["psql", "-w", "-U", $(POSTGRES_USER), "-d", $(POSTGRES_DB), "-c", "SELECT 1"] |
| 131 | initialDelaySeconds: 15 |
| 132 | timeoutSeconds: 2 |
| 133 | ports: |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 134 | - containerPort: 5432 |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 135 | name: postgres |
| 136 | volumeMounts: |
| 137 | - name: postgres-persistent-storage |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 138 | mountPath: /var/lib/pgsql/data |
| 139 | - name : tmp-dir |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 140 | mountPath: /tmp |
| 141 | - name: db-init |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 142 | mountPath: /init.sql |
| 143 | subPath: init.sql |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 144 | volumes: |
| 145 | - name: postgres-persistent-storage |
| 146 | persistentVolumeClaim: |
| 147 | claimName: postgres-storage-pv-claim |
| 148 | - name: tmp-dir |
| 149 | hostPath: |
| 150 | path: /tmp |
ktimoney | 2513eea | 2022-10-03 15:02:44 +0100 | [diff] [blame] | 151 | type: Directory |
ktimoney | 28fa9fb | 2022-05-30 16:08:27 +0100 | [diff] [blame] | 152 | - name: db-init |
| 153 | configMap: |
| 154 | name: db-init |
| 155 | defaultMode: 0755 |