blob: 4bd1333808f52c65e1fbd00f552a0357992023ce [file] [log] [blame]
ktimoney28fa9fb2022-05-30 16:08:27 +01001#
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#
20apiVersion: v1
21kind: PersistentVolume
22metadata:
23 name: postgres-storage-pv-volume
24 namespace: default
25 labels:
26 type: local
27 app: postgres
28spec:
29 storageClassName: manual
30 capacity:
31 storage: 2Gi
32 accessModes:
33 - ReadWriteOnce
34 hostPath:
35 path: "/var/keycloak/data2"
36---
37apiVersion: v1
38kind: PersistentVolumeClaim
39metadata:
40 name: postgres-storage-pv-claim
41 namespace: default
42 labels:
43 app: postgres
44spec:
45 storageClassName: manual
46 accessModes:
47 - ReadWriteOnce
48 resources:
49 requests:
50 storage: 2Gi
51---
52apiVersion: v1
53kind: ConfigMap
54metadata:
55 name: db-init
ktimoney076d02a2022-12-13 09:23:43 +000056 namespace: default
ktimoney28fa9fb2022-05-30 16:08:27 +010057data:
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
ktimoney2513eea2022-10-03 15:02:44 +010064 CREATE USER capif WITH PASSWORD 'capif';
ktimoney28fa9fb2022-05-30 16:08:27 +010065 GRANT ALL PRIVILEGES ON DATABASE capif TO capif;
66 END IF;
67 END
68 $$;
69---
70apiVersion: v1
71kind: Service
72metadata:
73 name: postgres
74 namespace: default
75spec:
76 type: NodePort
77 selector:
78 app: postgres
79 ports:
80 - protocol: TCP
ktimoney2513eea2022-10-03 15:02:44 +010081 port: 5432
ktimoney28fa9fb2022-05-30 16:08:27 +010082 nodePort: 30032
ktimoney2513eea2022-10-03 15:02:44 +010083 targetPort: 5432
ktimoney28fa9fb2022-05-30 16:08:27 +010084---
ktimoney2513eea2022-10-03 15:02:44 +010085apiVersion: apps/v1
ktimoney28fa9fb2022-05-30 16:08:27 +010086kind: Deployment
87metadata:
88 name: postgres
89 namespace: default
90spec:
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
ktimoney2513eea2022-10-03 15:02:44 +0100105 imagePullPolicy: IfNotPresent
ktimoney28fa9fb2022-05-30 16:08:27 +0100106 env:
107 - name: POSTGRES_DB
ktimoney2513eea2022-10-03 15:02:44 +0100108 value: keycloak
ktimoney28fa9fb2022-05-30 16:08:27 +0100109 - name: POSTGRES_USER
ktimoney2513eea2022-10-03 15:02:44 +0100110 value: keycloak
ktimoney28fa9fb2022-05-30 16:08:27 +0100111 - name: POSTGRES_PASSWORD
ktimoney2513eea2022-10-03 15:02:44 +0100112 value: keycloak
ktimoney28fa9fb2022-05-30 16:08:27 +0100113 - name: PGDATA
ktimoney2513eea2022-10-03 15:02:44 +0100114 value: /var/lib/pgsql/data
115 lifecycle:
ktimoney28fa9fb2022-05-30 16:08:27 +0100116 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:
ktimoney2513eea2022-10-03 15:02:44 +0100134 - containerPort: 5432
ktimoney28fa9fb2022-05-30 16:08:27 +0100135 name: postgres
136 volumeMounts:
137 - name: postgres-persistent-storage
ktimoney2513eea2022-10-03 15:02:44 +0100138 mountPath: /var/lib/pgsql/data
139 - name : tmp-dir
ktimoney28fa9fb2022-05-30 16:08:27 +0100140 mountPath: /tmp
141 - name: db-init
ktimoney2513eea2022-10-03 15:02:44 +0100142 mountPath: /init.sql
143 subPath: init.sql
ktimoney28fa9fb2022-05-30 16:08:27 +0100144 volumes:
145 - name: postgres-persistent-storage
146 persistentVolumeClaim:
147 claimName: postgres-storage-pv-claim
148 - name: tmp-dir
149 hostPath:
150 path: /tmp
ktimoney2513eea2022-10-03 15:02:44 +0100151 type: Directory
ktimoney28fa9fb2022-05-30 16:08:27 +0100152 - name: db-init
153 configMap:
154 name: db-init
155 defaultMode: 0755