Add jwt-proxy functionality
[nonrtric.git] / service-exposure / postgres.yaml
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
56 data:
57   init.sql: |
58     SELECT 'CREATE DATABASE capif'
59     WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'capif')\gexec
60     DO $$
61     BEGIN
62       IF NOT EXISTS (SELECT FROM pg_user WHERE  usename = 'capif') THEN
63          CREATE USER capif WITH PASSWORD 'capif';
64          GRANT ALL PRIVILEGES ON DATABASE capif TO capif;
65       END IF;
66     END
67     $$;
68 ---
69 apiVersion: v1
70 kind: Service
71 metadata:
72   name: postgres
73   namespace: default
74 spec:
75   type: NodePort
76   selector:
77     app: postgres
78   ports:
79     - protocol: TCP
80       port: 5432
81       nodePort: 30032
82       targetPort: 5432
83 ---
84 apiVersion: apps/v1
85 kind: Deployment
86 metadata:
87   name: postgres
88   namespace: default
89 spec:
90   selector:
91     matchLabels:
92       app: postgres
93   strategy:
94     type: Recreate
95   template:
96     metadata:
97       labels:
98         app: postgres
99     spec:
100       hostname: postgres
101       containers:
102       - image: nexus3.onap.org:10001/postgres
103         name: postgres
104         imagePullPolicy: IfNotPresent
105         env:
106         - name: POSTGRES_DB
107           value: keycloak
108         - name: POSTGRES_USER
109           value: keycloak
110         - name: POSTGRES_PASSWORD
111           value: keycloak
112         - name: PGDATA
113           value: /var/lib/pgsql/data
114         lifecycle:
115           postStart:
116             exec:
117               command: [ "/bin/sh", "-c", "sleep 10 && psql -U $POSTGRES_USER -f /init.sql" ]
118         livenessProbe:
119           exec:
120             command:
121               - /bin/sh
122               - -c
123               - exec pg_isready -U "keycloak" -h 127.0.0.1 -p 5432
124           initialDelaySeconds: 30
125           periodSeconds: 10
126           timeoutSeconds: 5
127         readinessProbe:
128           exec:
129             command: ["psql", "-w", "-U", $(POSTGRES_USER), "-d", $(POSTGRES_DB), "-c", "SELECT 1"]
130           initialDelaySeconds: 15
131           timeoutSeconds: 2
132         ports:
133         - containerPort: 5432
134           name: postgres
135         volumeMounts:
136         - name: postgres-persistent-storage
137           mountPath: /var/lib/pgsql/data
138         - name : tmp-dir
139           mountPath: /tmp
140         - name: db-init
141           mountPath: /init.sql
142           subPath: init.sql
143       volumes:
144       - name: postgres-persistent-storage
145         persistentVolumeClaim:
146           claimName: postgres-storage-pv-claim
147       - name: tmp-dir
148         hostPath:
149           path: /tmp
150           type: Directory
151       - name: db-init
152         configMap:
153           name: db-init
154           defaultMode: 0755